快捷导航
查看: 10|回复: 0

[策略/信号] 识别十字星K线的源码 (MT5)

[复制链接]

284

主题

6

回帖

1060

积分

管理员

积分
1060
发表于 昨天 11:38 | 显示全部楼层 |阅读模式
  • //----------------------------------------------------------------------------------------
  • #property indicator_separate_window
  • #property indicator_buffers 1
  • #property indicator_plots   1
  • #property indicator_type1  DRAW_HISTOGRAM
  • #property indicator_color1 Orange
  • #property indicator_style1 STYLE_SOLID
  • #property indicator_width1 2
  • //---- input parameters
  • input int     Candle_WidthMin          = 1;      // Minimum candlestick width in bars
  • input int     Candle_WidthMax          = 2;      // Maximum candlestick width in bars
  • input double  Candle_HeightPowerMin    = 0.5;    // Candlestick strength = Height/Width, points per minute
  • input double  Candle_BodyPowerMax      = 0.2;    // Maximum body height relative to the candlestick height
  • input double  Candle_ShadowPowerMax    = 0.2;    // Maximum shadow height relative to the candlestick height
  • //---- indicator buffers
  • double ExtBuf_Signal[];
  • int SkipBars; // how many of the oldest bars of the indicator to skip
  • //+------------------------------------------------------------------+
  • void OnInit()
  • {
  •    ArraySetAsSeries(ExtBuf_Signal , true);
  •    SetIndexBuffer(0, ExtBuf_Signal, INDICATOR_DATA);
  •    PlotIndexSetDouble (0, PLOT_EMPTY_VALUE, 0.0);
  •    SkipBars = Candle_WidthMax;
  •    PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, SkipBars);
  • }
  • //+------------------------------------------------------------------+
  • int OnCalculate(
  •                 const int        rates_total,       // size of the input timeseries
  •                 const int        prev_calculated,   // number of bars processed om previous call
  •                 const datetime&  time[],
  •                 const double&    open[],
  •                 const double&    high[],
  •                 const double&    low[],
  •                 const double&    close[],
  •                 const long&      tick_volume[],
  •                 const long&      volume[],
  •                 const int&       spread[]
  •                )
  • {
  •    ArraySetAsSeries(open , true);
  •    ArraySetAsSeries(high , true);
  •    ArraySetAsSeries(low  , true);
  •    ArraySetAsSeries(close, true);
  •    int MaxBarNum = rates_total - SkipBars - 1;
  •    int BarCount  = rates_total - prev_calculated;
  •    // Пройдем по всем барам, которые надо посчитать
  •    for (int BarNum=0; BarNum < BarCount; BarNum++)
  •    {
  •       double IndValue = 0; // default value (empty) for the calculated indicator bar
  •       if (BarNum <= MaxBarNum)
  •       {
  •          bool DojiExists = false;
  •          double CandleO=0, CandleH=0, CandleL=0, CandleC=0;
  •          double CandleWidth=0, CandleHeight, CandleHeightH, CandleHeightL, CandleBody, CandleShadow;
  •          int    CandleDir=0;
  •          // Construct metabars with different widths
  •          for (int CandleBarNum=1; CandleBarNum<=Candle_WidthMax; CandleBarNum++)
  •          {
  •             int CurBar=BarNum+CandleBarNum;
  •             // Calculate OHLC prices of the metabar
  •             CandleO=open[CurBar];
  •             if (CandleBarNum==1) CandleC=close[CurBar];
  •             if (CandleBarNum==1 || high[CurBar] > CandleH) CandleH=high[CurBar];
  •             if (CandleBarNum==1 || low [CurBar] < CandleL) CandleL=low [CurBar];
  •             CandleWidth=CandleBarNum;
  •             // If the minimum candlestick width is reached, check other criteria
  •             if (CandleWidth >= Candle_WidthMin)
  •             {
  •                DojiExists=true; // until proven otherwise
  •                //--- Calculate heights of all parts of the candlestick
  •                if (CandleO > CandleC)
  •                {
  •                   CandleHeightH=CandleH-CandleO;
  •                   CandleHeightL=CandleC-CandleL;
  •                   CandleBody=CandleO-CandleC;
  •                }
  •                else
  •                {
  •                   CandleHeightH=CandleH-CandleC;
  •                   CandleHeightL=CandleO-CandleL;
  •                   CandleBody=CandleC-CandleO;
  •                }
  •                CandleHeight=CandleH-CandleL;
  •                if (CandleHeightH > CandleHeightL)
  •                {
  •                   CandleDir=1;
  •                   CandleShadow=CandleHeightL;
  •                }
  •                else
  •                {
  •                   CandleDir=-1;
  •                   CandleShadow=CandleHeightH;
  •                }
  •                if (CandleHeight==0) DojiExists=false;
  •                else
  •                {
  •                   // Candlestick power
  •                   if ((CandleHeight/CandleWidth/_Point) < (Candle_HeightPowerMin*PeriodSeconds()/60)) DojiExists = false;
  •                   // Body power
  •                   if ((CandleBody/CandleHeight)   > Candle_BodyPowerMax)   DojiExists = false;
  •                   // Counter-shadow power
  •                   if ((CandleShadow/CandleHeight) > Candle_ShadowPowerMax) DojiExists = false;
  •                }
  •                if (DojiExists)
  •                {
  •                   break; // got a candlestick, do not expand the metabar further
  •                }
  •             }
  •          }
  •          // The indicator values are the direction and width of the found Doji candlestick
  •          if(DojiExists) IndValue = CandleDir * CandleWidth;
  •       }
  •       // Show results on a chart
  •       ExtBuf_Signal[BarNum] = IndValue;
  •    }
  •    return(rates_total);
  • }
  • //+------------------------------------------------------------------+

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|量化魔方 ( 陕ICP备2025062059号-3 )|网站地图

GMT+8, 2026-9-18 01:19 , Processed in 0.141677 second(s), 6 queries , Redis On.

快速回复 返回顶部 返回列表