设为首页 收藏本站 切换语言

识别十字星K线的源码  

| 发表于 2023-9-24 09:49:20 | 显示全部楼层 |复制链接
十字星K线的开盘价和收盘价大致相等,它有一个极易识别的形状,被认为是趋势结束和潜在的逆转信号。 以下是识别十字星K线的源码:


  1. //----------------------------------------------------------------------------------------
  2. #property indicator_separate_window
  3. #property indicator_buffers 1
  4. #property indicator_plots   1
  5. #property indicator_type1  DRAW_HISTOGRAM
  6. #property indicator_color1 Orange
  7. #property indicator_style1 STYLE_SOLID
  8. #property indicator_width1 2
  9. //---- input parameters
  10. input int     Candle_WidthMin          = 1;      // Minimum candlestick width in bars
  11. input int     Candle_WidthMax          = 2;      // Maximum candlestick width in bars
  12. input double  Candle_HeightPowerMin    = 0.5;    // Candlestick strength = Height/Width, points per minute
  13. input double  Candle_BodyPowerMax      = 0.2;    // Maximum body height relative to the candlestick height
  14. input double  Candle_ShadowPowerMax    = 0.2;    // Maximum shadow height relative to the candlestick height
  15. //---- indicator buffers
  16. double ExtBuf_Signal[];
  17. int SkipBars; // how many of the oldest bars of the indicator to skip
  18. //+------------------------------------------------------------------+
  19. void OnInit()
  20. {
  21.    ArraySetAsSeries(ExtBuf_Signal , true);
  22.    SetIndexBuffer(0, ExtBuf_Signal, INDICATOR_DATA);
  23.    PlotIndexSetDouble (0, PLOT_EMPTY_VALUE, 0.0);
  24.    
  25.    SkipBars = Candle_WidthMax;
  26.    PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, SkipBars);
  27. }
  28. //+------------------------------------------------------------------+
  29. int OnCalculate(
  30.                 const int        rates_total,       // size of the input timeseries
  31.                 const int        prev_calculated,   // number of bars processed om previous call
  32.                 const datetime&  time[],
  33.                 const double&    open[],
  34.                 const double&    high[],
  35.                 const double&    low[],
  36.                 const double&    close[],
  37.                 const long&      tick_volume[],
  38.                 const long&      volume[],
  39.                 const int&       spread[]
  40.                )
  41. {
  42.    ArraySetAsSeries(open , true);
  43.    ArraySetAsSeries(high , true);
  44.    ArraySetAsSeries(low  , true);
  45.    ArraySetAsSeries(close, true);
  46.    int MaxBarNum = rates_total - SkipBars - 1;
  47.    int BarCount  = rates_total - prev_calculated;
  48.    // Пройдем по всем барам, которые надо посчитать
  49.    for (int BarNum=0; BarNum < BarCount; BarNum++)
  50.    {
  51.       double IndValue = 0; // default value (empty) for the calculated indicator bar
  52.       if (BarNum <= MaxBarNum)
  53.       {
  54.          bool DojiExists = false;
  55.          double CandleO=0, CandleH=0, CandleL=0, CandleC=0;
  56.          double CandleWidth=0, CandleHeight, CandleHeightH, CandleHeightL, CandleBody, CandleShadow;
  57.          int    CandleDir=0;
  58.          // Construct metabars with different widths
  59.          for (int CandleBarNum=1; CandleBarNum<=Candle_WidthMax; CandleBarNum++)
  60.          {
  61.             int CurBar=BarNum+CandleBarNum;
  62.             
  63.             // Calculate OHLC prices of the metabar
  64.             CandleO=open[CurBar];
  65.             if (CandleBarNum==1) CandleC=close[CurBar];
  66.             if (CandleBarNum==1 || high[CurBar] > CandleH) CandleH=high[CurBar];      
  67.             if (CandleBarNum==1 || low [CurBar] < CandleL) CandleL=low [CurBar];
  68.       
  69.             CandleWidth=CandleBarNum;
  70.             // If the minimum candlestick width is reached, check other criteria
  71.             if (CandleWidth >= Candle_WidthMin)
  72.             {
  73.                DojiExists=true; // until proven otherwise
  74.         
  75.                //--- Calculate heights of all parts of the candlestick
  76.         
  77.                if (CandleO > CandleC)
  78.                {
  79.                   CandleHeightH=CandleH-CandleO;
  80.                   CandleHeightL=CandleC-CandleL;
  81.                   CandleBody=CandleO-CandleC;
  82.                }
  83.                else
  84.                {
  85.                   CandleHeightH=CandleH-CandleC;
  86.                   CandleHeightL=CandleO-CandleL;
  87.                   CandleBody=CandleC-CandleO;
  88.                }
  89.         
  90.                CandleHeight=CandleH-CandleL;
  91.                
  92.                if (CandleHeightH > CandleHeightL)
  93.                {
  94.                   CandleDir=1;
  95.                   CandleShadow=CandleHeightL;
  96.                }
  97.                else
  98.                {
  99.                   CandleDir=-1;
  100.                   CandleShadow=CandleHeightH;
  101.                }
  102.         
  103.                if (CandleHeight==0) DojiExists=false;
  104.                else
  105.                {
  106.                   // Candlestick power
  107.                   if ((CandleHeight/CandleWidth/_Point) < (Candle_HeightPowerMin*PeriodSeconds()/60)) DojiExists = false;
  108.                   // Body power
  109.                   if ((CandleBody/CandleHeight)   > Candle_BodyPowerMax)   DojiExists = false;
  110.                   // Counter-shadow power
  111.                   if ((CandleShadow/CandleHeight) > Candle_ShadowPowerMax) DojiExists = false;
  112.                }
  113.       
  114.                if (DojiExists)
  115.                {
  116.                   break; // got a candlestick, do not expand the metabar further
  117.                }
  118.         
  119.             }
  120.          }
  121.          // The indicator values are the direction and width of the found Doji candlestick
  122.          if(DojiExists) IndValue = CandleDir * CandleWidth;
  123.       }   
  124.       
  125.       // Show results on a chart
  126.       ExtBuf_Signal[BarNum] = IndValue;
  127.    }
  128.    return(rates_total);
  129. }
  130. //+------------------------------------------------------------------+
复制代码
举报

评论 使用道具

热门主题

精彩评论15

新风向圈
DDD
| 发表于 2023-9-25 10:05:54 | 显示全部楼层
路国路国 路过
举报

点赞 评论 使用道具

qwe11
CCC
| 发表于 2023-10-9 19:12:08 | 显示全部楼层
好啊,,,
举报

点赞 评论 使用道具

joker888
D
| 发表于 2023-10-12 18:21:11 | 显示全部楼层
十字星星
举报

点赞 评论 使用道具

Toomore
DDD
| 发表于 2023-10-13 04:11:35 | 显示全部楼层
路国 路过路国 路过
举报

点赞 评论 使用道具

夕阳西下
DDD
| 发表于 2023-10-16 08:36:27 | 显示全部楼层
感谢分享
举报

点赞 评论 使用道具

xcf2004
DD
| 发表于 2023-10-20 07:35:26 | 显示全部楼层
是趋势结束和潜在的逆转信号
举报

点赞 评论 使用道具

xinhua123
DDD
| 发表于 2023-10-30 00:14:26 | 显示全部楼层
十字星形态
举报

点赞 评论 使用道具

静观明
DD
| 发表于 2023-10-30 08:43:40 | 显示全部楼层
学习  感谢
举报

点赞 评论 使用道具

zhyu56666
D
| 发表于 2023-11-9 20:36:50 | 显示全部楼层
十字星形态啊
举报

点赞 评论 使用道具

STONE1968
D
| 发表于 2023-11-14 18:30:31 | 显示全部楼层
十字星K线的开盘价和收盘价大致相等,它有一个极易识别的形状,被认为是趋势结束和潜在的逆转信号。
举报

点赞 评论 使用道具

石头1968
DD
| 发表于 2023-11-19 01:04:22 | 显示全部楼层
识别十字星K线的源码
举报

点赞 评论 使用道具

静观明
DD
| 发表于 2023-11-28 16:56:02 | 显示全部楼层
十字星有事没有用
举报

点赞 评论 使用道具

xinhua123
DDD
| 发表于 2023-12-4 00:20:22 | 显示全部楼层
K线形态
举报

点赞 评论 使用道具

aliang9887
C
| 发表于 2023-12-4 08:57:56 | 显示全部楼层
学习了
举报

点赞 评论 使用道具

ken138888
B
| 发表于 2023-12-7 20:54:02 | 显示全部楼层
效果可以吗
举报

点赞 评论 使用道具

发新帖
EA交易
您需要登录后才可以评论 登录 | 立即注册

简体中文
繁體中文
English(英语)
日本語(日语)
Deutsch(德语)
Русский язык(俄语)
بالعربية(阿拉伯语)
Türkçe(土耳其语)
Português(葡萄牙语)
ภาษาไทย(泰国语)
한어(朝鲜语/韩语)
Français(法语)