十字星K线的开盘价和收盘价大致相等,它有一个极易识别的形状,被认为是趋势结束和潜在的逆转信号。 以下是识别十字星K线的源码:
- //----------------------------------------------------------------------------------------
-
- #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);
-
- }
-
- //+------------------------------------------------------------------+
复制代码
|