enigmasim 发表于 2023-9-24 09:49:20

识别十字星K线的源码

十字星K线的开盘价和收盘价大致相等,它有一个极易识别的形状,被认为是趋势结束和潜在的逆转信号。 以下是识别十字星K线的源码:


//----------------------------------------------------------------------------------------

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_plots   1



#property indicator_type1DRAW_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 doubleCandle_HeightPowerMin    = 0.5;    // Candlestick strength = Height/Width, points per minute

input doubleCandle_BodyPowerMax      = 0.2;    // Maximum body height relative to the candlestick height

input doubleCandle_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;

            if (CandleBarNum==1) CandleC=close;

            if (CandleBarNum==1 || high > CandleH) CandleH=high;      

            if (CandleBarNum==1 || low < CandleL) CandleL=low ;

      

            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 = IndValue;

   }



   return(rates_total);

}

//+------------------------------------------------------------------+

退休老头 发表于 2023-9-25 10:05:54

路国路国 路过

qwe11 发表于 2023-10-9 19:12:08

好啊,,,

joker888 发表于 2023-10-12 18:21:11

十字星星[撇嘴]

牛策智创 发表于 2023-10-13 04:11:35

路国 路过路国 路过

夕阳西下 发表于 2023-10-16 08:36:27

感谢分享

静观明 发表于 2023-10-30 08:43:40

学习感谢

zhyu56666 发表于 2023-11-9 20:36:50

十字星形态啊

静观明 发表于 2023-11-28 16:56:02

十字星有事没有用

xinhua123 发表于 2023-12-4 00:20:22

K线形态

aliang9887 发表于 2023-12-4 08:57:56

学习了[咖啡]

ken138888 发表于 2023-12-7 20:54:02

效果可以吗

shzq 发表于 2024-5-6 14:32:15

虚心学习。感谢分享[憨笑]

shllwk 发表于 2024-5-7 06:40:40

识别十字星K线的源码感谢分享

liguangxing2007 发表于 2024-6-21 09:23:24

路锅一下

奔跑的蓝天 发表于 2024-9-12 18:10:43

感谢楼主分享源码

yuwentao4761 发表于 2024-9-15 19:23:37

感谢分享!!看看,学习一下!!

liuyong168 发表于 2024-9-16 23:22:34

有用过的吗

hanbin618 发表于 2024-9-22 13:25:13

感谢分享[微笑]

xinhua123 发表于 2024-10-31 01:09:53

试试这款
页: [1] 2
查看完整版本: 识别十字星K线的源码