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

【MACD背离信号九转信号】主要是体现MACD背离信号, 以提供判趋势的拐点!  

| 发表于 2023-9-1 11:47:08 | 显示全部楼层 |复制链接

image.png
image.png

#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//指标显示位置
#property indicator_separate_window
//指标数量
#property indicator_buffers 74//确保按要求实时修改该数据
//指标数组
double dif[];//0
double dea[];//1
double macd2[];//2
double positive_macd[];//3
double negtive_macd[];//4
double stick_macd[];//5
double cref4[];//6
double nt[];//7
double ay[];//8
double drawtext1[];//9
double drawtext2[];//10
double nt0[];//11
double ay1[];//12
double drawtext3[];//13
double drawtext4[];//14
double difref1[];//15
double difref2[];//16
double drawicon[];//17
double czlh_2[];//18
double czlh_3[];//19
double czlh_4[];//20
double czlh_5[];//21
double czlh_6[];//22
double drawline0[];//23
double drawicon1[];//24
double macdsw01[];//25
double czlh_7[];//26
double czlh_8[];//27
double czlh_9[];//28
double macdsw10[];//29
double czlh_02[];//30
double drawicon2[];//31
double czlh_10[];//32
double drawiconx[];//33
double czlh_11[];//34
double czlh_12[];//35
double czlh_13[];//36
double czlh_14[];//37
double czlh_15[];//38
double czlh_16[];//39
double czlh_17[];//40
double czlh_18[];//41
double czlh_19[];//42
double czlh_20[];//43
double czlh_21[];//44
double czlh_22[];//45
double czlh_23[];//46
double czlh_24[];//47
double czlh_25[];//48
double czlh_26[];//49
double czlh_27[];//50
double czlh_28[];//51
double czlh_29[];//52
double cmref2[];//53
double cmref2max[];//54
double cmref2abs[];//55
double drawnull1[];//56
double drawnull2[];//57
double p9n1[];//58
double p9n2[];//59
double p9n3[];//60
double p9n4[];//61
double p9n5[];//62
double p9n6[];//63
double p9n7[];//64
double p9n8[];//65
double n9n1[];//66
double n9n2[];//67
double n9n3[];//68
double n9n4[];//69
double n9n5[];//70
double n9n6[];//71
double n9n7[];//72
double n9n8[];//73


int OnInit()
{
   IndicatorDigits(6);
   IndicatorShortName("九转系统一");
   double levels[1]={0};
   indicator_style(1,false,0,0,levels);


   //设置指标值
   SetIndexBuffer(0,dif);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,clrRed);

   SetIndexBuffer(1,dea);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,clrYellow);

   SetIndexBuffer(2,macd2);
   SetIndexStyle(2,DRAW_NONE);

   SetIndexBuffer(3,positive_macd);
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,1,clrRed);

   SetIndexBuffer(4,negtive_macd);
   SetIndexStyle(4,DRAW_HISTOGRAM,STYLE_SOLID,1,clrAqua);

   SetIndexBuffer(5,stick_macd);
   SetIndexStyle(5,DRAW_HISTOGRAM,STYLE_SOLID,2,clrTomato);

   SetIndexBuffer(6,cref4);
   SetIndexStyle(6,DRAW_NONE);

   SetIndexBuffer(7,nt);
   SetIndexStyle(7,DRAW_NONE);

   SetIndexBuffer(8,ay);
   SetIndexStyle(8,DRAW_NONE);

   SetIndexBuffer(9,drawtext1);
   SetIndexStyle(9,DRAW_ARROW,EMPTY,1,clrBisque);
   SetIndexArrow(9,171);

   SetIndexBuffer(10,drawtext2);
   SetIndexStyle(10,DRAW_ARROW,EMPTY,2,clrOrange);
   SetIndexArrow(10,148);

   SetIndexBuffer(11,nt0);
   SetIndexStyle(11,DRAW_NONE);

   SetIndexBuffer(12,ay1);
   SetIndexStyle(12,DRAW_NONE);

   SetIndexBuffer(13,drawtext3);
   SetIndexStyle(13,DRAW_ARROW,EMPTY,1,clrMagenta);
   SetIndexArrow(13,171);

   SetIndexBuffer(14,drawtext4);
   SetIndexStyle(14,DRAW_ARROW,EMPTY,2,clrOrchid);
   SetIndexArrow(14,148);

   SetIndexBuffer(15,difref1);
   SetIndexStyle(15,DRAW_NONE);

   SetIndexBuffer(16,difref2);
   SetIndexStyle(16,DRAW_NONE);

   SetIndexBuffer(17,drawicon);
   SetIndexStyle(17,DRAW_ARROW,EMPTY,3,clrRed);
   SetIndexArrow(17,233);

   SetIndexBuffer(18,czlh_2);
   SetIndexStyle(18,DRAW_NONE);

   SetIndexBuffer(19,czlh_3);
   SetIndexStyle(19,DRAW_NONE);

   SetIndexBuffer(20,czlh_4);
   SetIndexStyle(20,DRAW_NONE);

   SetIndexBuffer(21,czlh_5);
   SetIndexStyle(21,DRAW_NONE);

   SetIndexBuffer(22,czlh_6);
   SetIndexStyle(22,DRAW_NONE);

   SetIndexBuffer(23,drawline0);
   SetIndexStyle(23,DRAW_LINE,STYLE_DASHDOT,1,clrRed);

   SetIndexBuffer(24,drawicon1);
   SetIndexStyle(24,DRAW_ARROW,EMPTY,5,clrRed);
   SetIndexArrow(24,171);

   SetIndexBuffer(25,macdsw01);
   SetIndexStyle(25,DRAW_NONE);

   SetIndexBuffer(26,czlh_7);
   SetIndexStyle(26,DRAW_NONE);

   SetIndexBuffer(27,czlh_8);
   SetIndexStyle(27,DRAW_NONE);

   SetIndexBuffer(28,czlh_9);
   SetIndexStyle(28,DRAW_NONE);

   SetIndexBuffer(29,macdsw10);
   SetIndexStyle(29,DRAW_NONE);

   SetIndexBuffer(30,czlh_02);
   SetIndexStyle(30,DRAW_NONE);

   SetIndexBuffer(31,drawicon2);
   SetIndexStyle(31,DRAW_ARROW,EMPTY,5,clrYellow);
   SetIndexArrow(31,171);

   SetIndexBuffer(32,czlh_10);
   SetIndexStyle(32,DRAW_NONE);

   SetIndexBuffer(33,drawiconx);
   SetIndexStyle(33,DRAW_ARROW,EMPTY,3,clrLimeGreen);
   SetIndexArrow(33,234);

   SetIndexBuffer(34,czlh_11);
   SetIndexStyle(34,DRAW_NONE);

   SetIndexBuffer(35,czlh_12);
   SetIndexStyle(35,DRAW_NONE);

   SetIndexBuffer(36,czlh_13);
   SetIndexStyle(36,DRAW_NONE);

   SetIndexBuffer(37,czlh_14);
   SetIndexStyle(37,DRAW_NONE);

   SetIndexBuffer(38,czlh_15);
   SetIndexStyle(38,DRAW_NONE);

   SetIndexBuffer(39,czlh_16);
   SetIndexStyle(39,DRAW_NONE);

   SetIndexBuffer(40,czlh_17);
   SetIndexStyle(40,DRAW_NONE);

   SetIndexBuffer(41,czlh_18);
   SetIndexStyle(41,DRAW_NONE);

   SetIndexBuffer(42,czlh_19);
   SetIndexStyle(42,DRAW_NONE);

   SetIndexBuffer(43,czlh_20);
   SetIndexStyle(43,DRAW_NONE);

   SetIndexBuffer(44,czlh_21);
   SetIndexStyle(44,DRAW_NONE);

   SetIndexBuffer(45,czlh_22);
   SetIndexStyle(45,DRAW_NONE);

   SetIndexBuffer(46,czlh_23);
   SetIndexStyle(46,DRAW_NONE);

   SetIndexBuffer(47,czlh_24);
   SetIndexStyle(47,DRAW_NONE);

   SetIndexBuffer(48,czlh_25);
   SetIndexStyle(48,DRAW_NONE);

   SetIndexBuffer(49,czlh_26);
   SetIndexStyle(49,DRAW_NONE);

   SetIndexBuffer(50,czlh_27);
   SetIndexStyle(50,DRAW_NONE);

   SetIndexBuffer(51,czlh_28);
   SetIndexStyle(51,DRAW_NONE);

   SetIndexBuffer(52,czlh_29);
   SetIndexStyle(52,DRAW_NONE);

   SetIndexBuffer(53,cmref2);
   SetIndexStyle(53,DRAW_NONE);

   SetIndexBuffer(54,cmref2max);
   SetIndexStyle(54,DRAW_NONE);

   SetIndexBuffer(55,cmref2abs);
   SetIndexStyle(55,DRAW_NONE);

   SetIndexBuffer(56,drawnull1);
   SetIndexStyle(56,DRAW_ARROW,EMPTY,1,clrMagenta);
   SetIndexArrow(56,159);

   SetIndexBuffer(57,drawnull2);
   SetIndexStyle(57,DRAW_ARROW,EMPTY,1,clrYellow);
   SetIndexArrow(57,159);

   SetIndexBuffer(58,p9n1);
   SetIndexStyle(58,DRAW_ARROW,EMPTY,2,clrOrange);
   SetIndexArrow(58,140);

   SetIndexBuffer(59,p9n2);
   SetIndexStyle(59,DRAW_ARROW,EMPTY,2,clrOrange);
   SetIndexArrow(59,141);

   SetIndexBuffer(60,p9n3);
   SetIndexStyle(60,DRAW_ARROW,EMPTY,2,clrOrange);
   SetIndexArrow(60,142);

   SetIndexBuffer(61,p9n4);
   SetIndexStyle(61,DRAW_ARROW,EMPTY,2,clrOrange);
   SetIndexArrow(61,143);

   SetIndexBuffer(62,p9n5);
   SetIndexStyle(62,DRAW_ARROW,EMPTY,2,clrOrange);
   SetIndexArrow(62,144);

   SetIndexBuffer(63,p9n6);
   SetIndexStyle(63,DRAW_ARROW,EMPTY,2,clrOrange);
   SetIndexArrow(63,145);

   SetIndexBuffer(64,p9n7);
   SetIndexStyle(64,DRAW_ARROW,EMPTY,2,clrOrange);
   SetIndexArrow(64,146);

   SetIndexBuffer(65,p9n8);
   SetIndexStyle(65,DRAW_ARROW,EMPTY,2,clrOrange);
   SetIndexArrow(65,147);

   SetIndexBuffer(66,n9n1);
   SetIndexStyle(66,DRAW_ARROW,EMPTY,2,clrOrchid);
   SetIndexArrow(66,140);

   SetIndexBuffer(67,n9n2);
   SetIndexStyle(67,DRAW_ARROW,EMPTY,2,clrOrchid);
   SetIndexArrow(67,141);

   SetIndexBuffer(68,n9n3);
   SetIndexStyle(68,DRAW_ARROW,EMPTY,2,clrOrchid);
   SetIndexArrow(68,142);

   SetIndexBuffer(69,n9n4);
   SetIndexStyle(69,DRAW_ARROW,EMPTY,2,clrOrchid);
   SetIndexArrow(69,143);

   SetIndexBuffer(70,n9n5);
   SetIndexStyle(70,DRAW_ARROW,EMPTY,2,clrOrchid);
   SetIndexArrow(70,144);

   SetIndexBuffer(71,n9n6);
   SetIndexStyle(71,DRAW_ARROW,EMPTY,2,clrOrchid);
   SetIndexArrow(71,145);

   SetIndexBuffer(72,n9n7);
   SetIndexStyle(72,DRAW_ARROW,EMPTY,2,clrOrchid);
   SetIndexArrow(72,146);

   SetIndexBuffer(73,n9n8);
   SetIndexStyle(73,DRAW_ARROW,EMPTY,2,clrOrchid);
   SetIndexArrow(73,147);

   for(int Indexes=0;Indexes<74;Indexes++)
      SetIndexLabel(Indexes,NULL);

   ChartRedraw(ChartID());

   return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                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[])
{
   int limit=prepare_limit(rates_total,prev_calculated,50);

   int i;
   int index;

   //loop1,K图自带的参数,直接使用
   for(i=0;i<limit;i++)
   {
      //DIF:EMA(C,12)-EMA(C,26);
      //dif=DIF(i);
      dif=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i);

      //DEA:EMA(DIF,9);
      //dea=DEA(dif,i);
      dea=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,i);

      //REF(C,4)
      if((i+4)<Bars)
      {
         cref4=Close[i+4];
      }

      //CZLH_11:=CLOSE/MA(CLOSE,40)*100<78;
      if((i+39)<Bars)
         if((Close/iMA(NULL,0,40,0,MODE_SMA,PRICE_CLOSE,i))*100<78)
            czlh_11=1;
         else
            czlh_11=0;

      //CZLH_12:=CLOSE/MA(CLOSE,60)*100<74;
      if((i+59)<Bars)
         if((Close/iMA(NULL,0,60,0,MODE_SMA,PRICE_CLOSE,i))*100<74)
            czlh_12=1;
         else
            czlh_12=0;

      //CZLH_13:=HIGH>LOW*1.051;
      if(High>(Low*1.051))
         czlh_13=1;
      else
         czlh_13=0;

      //CZLH_23:=MA(CLOSE,5);
      if((i+4)<Bars)
         czlh_23=iMA(NULL,0,5,0,MODE_SMA,PRICE_CLOSE,i);

      //CZLH_24:=IF(CLOSE>SAR(10,2,20),1,0);
      if(Close>iSAR(NULL,0,0.02,0.2,i))
         czlh_24=1;
      else
         czlh_24=0;

      //CZLH_25:=IF(CLOSE<SAR(10,2,20),(-1),0);
      if(Close<iSAR(NULL,0,0.02,0.2,i))
         czlh_25=-1;
      else
         czlh_25=0;

      //初始化
      nt=0;
      nt0=0;
      ay=0;
      ay1=0;
   }

   //loop2 需要基于loop1计算出的数组
   for(i=0;i<limit;i++)
   {
      //REF(dif,1)
      if((i+1)<Bars)
         difref1=dif[i+1];
      //REF(dif,2)
      if((i+2)<Bars)
         difref2=dif[i+2];

      //DRAWICON(REF(DIF,1)<REF(DIF,2) AND DIF>REF(DIF,1) AND DIF<0 AND DIF<DEA,DIF*1.1,1),COLORRED;
      if(difref1<difref2 && dif>difref1 && dif<0 && dif<dea)
         drawicon=dif*1.1;
      if(difref1>difref2 && dif<difref1 && dif>0 && dif>dea)
         drawiconx=dif*1.1;

      //MACD:(DIF-DEA)*2,COLORSTICK;   
      macd2=2*(dif-dea);
      if(macd2>0)
         positive_macd=macd2;
      else
         negtive_macd=macd2;

      if(i<(Bars-4-9))
      {
         //A1:=C>REF(C,4);
         //NT:=BARSLASTCOUNT(A1);
         nt=BARSLASTCOUNT(1,cref4,i,9,true);
         //B1:=C《REF(C,4);
         //NT0:=BARSLASTCOUNT(B1);
         nt0=BARSLASTCOUNT(1,cref4,i,9,false);

         //如果连续九个收盘价大于四天前的收盘价,将九个K图标上图标,若最新的K图有五个或以上成立,也标上
         if(nt==9)
         {
            BACKSET(true,9,i,ay);
         }
         else
         {
            if(Time[0]==Time && nt>=5)
               BACKSET(true,nt,i,ay);
            else
               BACKSET(false,nt,i,ay);
         }

         //如果连续九个收盘价小于四天前的收盘价,将九个K图标上图标,若最新的K图有五个或以上成立,也标上
         if(nt0==9)
         {
            BACKSET(true,9,i,ay1);
         }
         else
         {
            if(Time[0]==Time && nt0>=5)
               BACKSET(true,nt0,i,ay1);
            else
               BACKSET(false,nt0,i,ay1);
         }
      }

      //CZLH_14:=CZLH_13 AND COUNT(CZLH_13,5)>1;
      if(czlh_13==1 && COUNT(czlh_13,5,i)>1)
         czlh_14=1;
      else
         czlh_14=0;

      //CZLH_15:=IF(CZLH_14 AND (CZLH_11 OR CZLH_12),2,0);
      if(czlh_14==1 && (czlh_11==1 || czlh_12==1))
         czlh_15=2;
      else
         czlh_15=0;

      //CZLH_16:=CLOSE/REF(CLOSE,25)<=1.1;
      if((i+25)<Bars)
         if((Close/Close[i+25])<=1.1)
            czlh_16=1;
         else
            czlh_16=0;

      //cmref:=CLOSE-REF(CLOSE,2)
      if((i+2)<Bars)
      {
         cmref2=Close-Close[i+2];
         cmref2max=MathMax(cmref2,0);
         cmref2abs=MathAbs(cmref2);
      }

      //CZLH_18:=(CLOSE-LLV(LOW,8))/(HHV(HIGH,8)-LLV(LOW,8))*100;
      if((i+7)<Bars)
         czlh_18=((Close-Low[iLowest(NULL,0,MODE_LOW,8,i)])/(High[iHighest(NULL,0,MODE_HIGH,8,i)]-Low[iLowest(NULL,0,MODE_LOW,8,i)]))*100;

      //CZLH_26:=ATAN((CZLH_23/REF(CZLH_23,1)-1)*100)*180/3.1416;  
      if((i+1)<Bars)
         czlh_26=(MathArctan((czlh_23/(czlh_23[i+1])-1)*100)*180)/3.1416;

      //CZLH_27:=IF(CZLH_26>30,1,0);  
      if(czlh_26>30)
         czlh_27=1;
      else
         czlh_27=0;

      //CZLH_28:=IF(CZLH_26<(-30),(-1),0);
      if(czlh_26<-30)
         czlh_28=-1;
      else
         czlh_28=0;

      //CZLH_29:=CZLH_24+CZLH_27+CZLH_25+CZLH_28;
      czlh_29=czlh_24+czlh_27+czlh_25+czlh_28;
   }

   //loop3,一些基于Loop2数组的操作,在loop3中操作
   for(i=0;i<limit;i++)
   {
      if(i<(Bars-1))
      {
         //STICKLINE(MACD>REF(MACD,1) AND MACD>0,0,MACD,0.5,0),COLORLIRED;MACD处于0线以上,且后线大于前线,换色
         //macd处于上升阶段,标成白线
         if(macd2>macd2[i+1] && macd2>0)
         {
            stick_macd=macd2;
         }

         //macd上穿0的点
         if(macd2>0 && macd2[i+1]<0)
         {
            macdsw01=0;
         }
         else
         {
            macdsw01=-1;
         }

         //macd下穿0的点
         if(macd2<0 && macd2[i+1]>0)
         {
            macdsw10=0;
         }
         else
         {
            macdsw10=-1;
         }
      }

      //对连续九天收盘价高于或低于四天前的收盘价的MACD进行标注,高于用橙色,低于用于orchid
      if(ay>0)
         if(ay!=9)
            drawtext1=MathMax(dif,macd2)*1.1;
         else
         {
            drawtext2=MathMax(dif,macd2)*1.1;
            //标注1-8
            if((i+1)<Bars)
               if(nt[i+1]!=9)//第一个九
               {
                  int nts;
                  for(int j=1;j<9;j++)//第一个九前面八个数字
                  {
                     nts=nt[i+j];
                     switch(nts)
                     {
                        case 8:
                           p9n8[i+j]=MathMax(dif[i+j],macd2[i+j])*1.1;
                           break;
                        case 7:
                           p9n7[i+j]=MathMax(dif[i+j],macd2[i+j])*1.1;
                           break;
                        case 6:
                           p9n6[i+j]=MathMax(dif[i+j],macd2[i+j])*1.1;
                           break;
                        case 5:
                           p9n5[i+j]=MathMax(dif[i+j],macd2[i+j])*1.1;
                           break;
                        case 4:
                           p9n4[i+j]=MathMax(dif[i+j],macd2[i+j])*1.1;
                           break;
                        case 3:
                           p9n3[i+j]=MathMax(dif[i+j],macd2[i+j])*1.1;
                           break;
                        case 2:
                           p9n2[i+j]=MathMax(dif[i+j],macd2[i+j])*1.1;
                           break;
                        case 1:
                           p9n1[i+j]=MathMax(dif[i+j],macd2[i+j])*1.1;
                           break;
                        default:
                           break;
                     }
                  }
               }
         }

      if(ay1>0)
         if(ay1!=9)
            drawtext3=MathMin(dif,macd2)*1.1;
         else
         {
            drawtext4=MathMin(dif,macd2)*1.1;
            //标注1-8
            if((i+1)<Bars)
               if(nt0[i+1]!=9)//第一个九
               {
                  int nt0s;
                  for(int j=1;j<9;j++)//第一个九前面八个数字
                  {
                     nt0s=nt0[i+j];
                     switch(nt0s)
                     {
                        case 8:
                           n9n8[i+j]=MathMin(dif[i+j],macd2[i+j])*1.1;
                           break;
                        case 7:
                           n9n7[i+j]=MathMin(dif[i+j],macd2[i+j])*1.1;
                           break;
                        case 6:
                           n9n6[i+j]=MathMin(dif[i+j],macd2[i+j])*1.1;
                           break;
                        case 5:
                           n9n5[i+j]=MathMin(dif[i+j],macd2[i+j])*1.1;
                           break;
                        case 4:
                           n9n4[i+j]=MathMin(dif[i+j],macd2[i+j])*1.1;
                           break;
                        case 3:
                           n9n3[i+j]=MathMin(dif[i+j],macd2[i+j])*1.1;
                           break;
                        case 2:
                           n9n2[i+j]=MathMin(dif[i+j],macd2[i+j])*1.1;
                           break;
                        case 1:
                           n9n1[i+j]=MathMin(dif[i+j],macd2[i+j])*1.1;
                           break;
                        default:
                           break;
                     }
                  }
               }
         }

       //CZLH_17:=SMA(MAX(CLOSE-REF(CLOSE,2),0),7,1)/SMA(ABS(CLOSE-REF(CLOSE,2)),7,1)*100<15;
      if((i+6)<Bars)
         if(((iMAOnArray(cmref2max,0,7,0,MODE_SMA,i)/iMAOnArray(cmref2abs,0,7,0,MODE_SMA,i))*100)<15)
            czlh_17=1;
         else
            czlh_17=0;


      //CZLH_19:=SMA(CZLH_18,2,1);
      if((i+1)<Bars)
         czlh_19=iMAOnArray(czlh_18,0,2,0,MODE_SMA,i);

   }

   for(i=limit-1;i>=0;i--)
   {
      //CZLH_2:=BARSLAST(REF(MACD,1)<0 AND MACD>0);MACD从负到正,距离当前柱图的距离,从0开始
      if(macdsw01==0)      //处于突变位置,
         czlh_2=0;
      else
         if((i+1)==Bars)      //超始BAR,且不是突变,设为-20
            czlh_2=-20;
         else
            if(czlh_2[i+1]>=0)      //不为起始BAR,且前面不为负,则已经有过突变,正常计步
               czlh_2=czlh_2[i+1]+1;
            else                    //前面为负,则未出现过突变,设为-20
               czlh_2=-20;

      //CZLH_02:=BARSLAST(REF(MACD,1)>0 AND MACD<0);MACD从正到负,距离当前柱图的距离,从0开始
      if(macdsw10==0)      //处于突变位置,
         czlh_02=0;
      else
         if((i+1)==Bars)      //超始BAR,且不是突变,设为-20
            czlh_02=-20;
         else
            if(czlh_02[i+1]>=0)      //不为起始BAR,且前面不为负,则已经有过突变,正常计步
               czlh_02=czlh_02[i+1]+1;
            else                    //前面为负,则未出现过突变,设为-20
               czlh_02=-20;

      //CZLH_20:=SMA(CZLH_19,2,1);
      if((i+1)<Bars)
         czlh_20=iMAOnArray(czlh_19,0,2,0,MODE_SMA,i);

      //CZLH_21:=IF(CZLH_19>REF(CZLH_19,1) AND REF(CZLH_19,1)<REF(CZLH_19,2) AND CZLH_19<23,1.5,0);
      if((i+2)<Bars)
         if(czlh_19>czlh_19[i+1] && czlh_19[i+1]<czlh_19[i+2] && czlh_19<23)
            czlh_21=1.5;
         else
            czlh_21=0;

      //CZLH_22:=100-100*(HHV(HIGH,5*8)-CLOSE)/(HHV(HIGH,5*8)-LLV(LOW,5*8));
      if((i+5*8)<Bars)     
         czlh_22=100-100*((High[iHighest(NULL,0,MODE_HIGH,8,i)]-Close)/(High[iHighest(NULL,0,MODE_HIGH,8,i)]-Low[iLowest(NULL,0,MODE_LOW,8,i)]));

      //IF(CZLH_29<(-1) OR CZLH_22<25.01,DIF,DRAWNULL),COLORLIGREEN;
      if(czlh_29<-1 || czlh_22<25.01)
         drawnull1=dif;

      //IF(CZLH_22>74.989998 OR CZLH_29>0,DIF,DRAWNULL),COLORRED;     
      if(czlh_29>0 || czlh_22>74.989998)
         drawnull2=dif;
   }

   for(i=0;i<limit;i++)
   {
      //CZLH_3:=LLVBARS(MACD,CZLH_2+20);当前MACD柱图至由负变正前20个柱图间最小LOW值的shift
      double lowest=macd2;
      int nCount=0;
      for(int j=0;j<czlh_2+20;j++)
         if((i+j)<Bars)
            if(lowest>macd2[i+j])
            {
               lowest=macd2[i+j];
               nCount=j;
            }
      czlh_3=nCount;

      //CZLH_7:=HHVBARS(MACD,CZLH_2+20);当前MACD柱图至由负变正前20个柱图间最大high值的shift
      double highest=macd2;
      nCount=0;
      for(int j=0;j<czlh_02+20;j++)
         if((i+j)<Bars)
            if(highest<macd2[i+j])
            {
               highest=macd2[i+j];
               nCount=j;
            }
      czlh_7=nCount;

      //CZLH_4:=IF(CZLH_3>CZLH_2,REF(MACD,CZLH_3),0);最低点在穿越0线的左边,czlh_4取这个最低点的MACD值,否则取0
      if(czlh_3>czlh_2)
      {
         if((i+czlh_3)<Bars)
         {
            index=czlh_3;//为了从double转变成int
            czlh_4=macd2[i+index];
         }
      }
      else
         czlh_4=0;

      //CZLH_8:=IF(CZLH_7>CZLH_2,REF(MACD,CZLH_7),0);最高点在穿越0线的左边,czlh_7取这个最高点的MACD值,否则取0
      if(czlh_7>czlh_02)
      {
         if((i+czlh_7)<Bars)
         {
            index=czlh_7;//为了从double转变成int
            czlh_8=macd2[i+index];
         }
      }
      else
         czlh_8=0;

      //CZLH_5:=MACD<0 AND MACD>CZLH_4 AND LOW=LLV(LOW,CZLH_2+20) AND CZLH_4<0;MACD值突变上0后又下了0,且MACD的最低值在突变前20内。MACD最低值与0之间在,且K线创新低
      if(macd2<0 && macd2>czlh_4 && Low==LLV(MODE_LOW,czlh_2+20,i) && czlh_4<0)
         czlh_5=1;
      else
         czlh_5=0;

      //CZLH_9:=MACD>0 AND MACD<CZLH_8 AND HIGH=HHV(HIGH,CZLH_2+20) AND CZLH_8>0;
      if(macd2>0 && macd2<czlh_8 && High==HHV(MODE_HIGH,czlh_02+20,i) && czlh_8>0)
         czlh_9=1;
      else
         czlh_9=0;
   }

   datetime tltime=Time[0];
   datetime tltime1=Time[0];  
   for(i=0;i<limit;i++)
   {
      index=czlh_3;
      //CZLH_6:=REF(CZLH_5,1)=1 AND MACD>REF(MACD,1) AND REF(DIF,CZLH_3)<0 AND MACD<0;
      if((i+1)<Bars && (i+index)<Bars)
         if(czlh_5[i+1]==1 && macd2>macd2[i+1] && dif[i+index]<0 && macd2<0)
            czlh_6=1;
         else
            czlh_6=0;

      //底背:DRAWLINE(CZLH_4=CZLH_3,MACD,CZLH_6,MACD,0),COLORRED,DOTLINE;
      if(czlh_4==czlh_3 || czlh_6==1)  
      {
         index=czlh_3;
         if((i+index)<Bars)
            if(tltime!=Time[i+index])
            {
               TrendCreate(0,"TL"+TimeToStr(Time,TIME_DATE|TIME_MINUTES),WindowFind("九转系统一"),Time[index+i],macd2[index+i],Time,macd2);
               tltime=Time[i+index];
            }
      }
         //drawline0=macd2;

      //DRAWICON(CZLH_6,MACD*1.2,9);
      if(czlh_6==1)
         drawicon1=macd2*1.2;

      //CZLH_10:=REF(CZLH_9,1)=1 AND MACD>REF(MACD,1) AND REF(DIF,CZLH_7)>0;
      if((i+1)<Bars && (i+index)<Bars)
         if(czlh_9[i+1]==1 && macd2<macd2[i+1] && dif[i+index]>0 && macd2>0)
            czlh_10=1;
         else
            czlh_10=0;

      //顶背:DRAWLINE(CZLH_8=CZLH_7,MACD,CZLH_10,MACD,0),COLORGREEN,DOTLINE;
      if(czlh_8==czlh_7 || czlh_10==1)  
      {
         index=czlh_7;
         if((i+index)<Bars)
            if(tltime1!=Time[i+index])
            {
               TrendCreate(0,"TL"+TimeToStr(Time,TIME_DATE|TIME_MINUTES),WindowFind("九转系统一"),Time[index+i],macd2[index+i],Time,macd2);
               tltime1=Time[i+index];
            }
      }

      //DRAWICON(CZLH_10,MACD*1.2,9);
      if(czlh_10==1)
         drawicon2=macd2*1.2;

   }
   ChartRedraw(ChartID());

   return(rates_total);
}

int prepare_limit(int rates_total,int prev_calculated,int shift_required)
{
   //确保移动平均值计算时数据数量满足要求
   if(rates_total<shift_required)
   {
      return(0);
   }

   //防止重复计算浪费资源,避免重复计算
   int limit;
   limit=rates_total-prev_calculated;

   //最新K线实时变化
   if(prev_calculated>0)
   {
      limit++;
   }

   return(limit);
}

void indicator_style(int levels,bool minmax,double minimum,double maximum,double &levelvalue[])
{
   //设置指标的水平位
   //基本特征
   IndicatorSetInteger(INDICATOR_LEVELS,2);
   IndicatorSetInteger(INDICATOR_LEVELSTYLE,STYLE_DOT);
   IndicatorSetInteger(INDICATOR_LEVELCOLOR,clrWhite);
   IndicatorSetInteger(INDICATOR_LEVELWIDTH,1);
   //高低位
   if(minmax)
   {
      IndicatorSetDouble(INDICATOR_MINIMUM,minimum);
      IndicatorSetDouble(INDICATOR_MAXIMUM,maximum);
   }
   //水平线
   for(int i=0;i<levels;i++)
      IndicatorSetDouble(INDICATOR_LEVELVALUE,i,levelvalue);
}


double HHV(int mode_value,int count,int start_index)
{
   return(High[iHighest(NULL,0,mode_value,count,start_index)]);
}

double LLV(int mode_value,int count,int start_index)
{
   return(Low[iLowest(NULL,0,mode_value,count,start_index)]);
}

void REF(double &ret_value[],double &src_value[],int shift,int start_index)
{
   if(start_index<(Bars-shift))
      ret_value[start_index]=src_value[shift+start_index];
}

bool Gold_CROSS(double &first_indicator[],double &second_indecator[],int start_index)
{
   if(first_indicator[start_index]>second_indecator[start_index] && first_indicator[start_index+1]<second_indecator[start_index+1])
      return(true);
   else
      return(false);
}

bool Dead_CROSS(double &first_indicator[],double &second_indecator[],int start_index)
{
   if(first_indicator[start_index]<second_indecator[start_index] && first_indicator[start_index+1]>second_indecator[start_index+1])
      return(true);
   else
      return(false);
}

double Custom_MA(double &src_array[],int mode,int count,int start_index)
{
   return(iMAOnArray(src_array,0,count,0,mode,start_index));
}

double DIF(int start_index)
{
   return(iMA(NULL,0,12,0,MODE_EMA,PRICE_CLOSE,start_index)-iMA(NULL,0,26,0,MODE_EMA,PRICE_CLOSE,start_index));
}

double DEA(double &src_array[],int start_index)
{
   return(Custom_MA(src_array,MODE_EMA,9,start_index));
}

//返回满足条件的个数,最多lastcount,start_index:开始比较的位置,up:方向
int BARSLASTCOUNT(int value_type,double &array[],int start_index,int lastcount,bool up)
{
   int nCount=0;
   //防止数组越界
   while((nCount+start_index)<Bars)
   {
      //1:PRICE_CLOSE
      if(value_type==1)
         if(up)      //array数组小于PRICE_MODE数组
            if(Close[start_index+nCount]>array[start_index+nCount])     //从当前(start_index)柱图开始,nCountdhb
            {
               nCount++;
               if(nCount>=lastcount)
                  break;
            }
            else
               break;
         else        //array数组大于PRICE_MODE数组
            if(Close[start_index+nCount]<array[start_index+nCount])
            {
               nCount++;
               if(nCount>=lastcount)
                  break;
            }
            else
               break;
   }
   return(nCount);
}

//设定ret_value数组中从start_index开始的count个数组值,数组的值在con成立时设成count,否则设成0
void BACKSET(bool con,int count,int start_index,double &ret_value[])
{
   int i=0;
   if(con)
   {
      for(i=0;i<count;i++)
         if((start_index+i)<Bars)
            ret_value[start_index+i]=count;
   }
   else
   {
      for(i=0;i<count;i++)
         if((start_index+i)<Bars)
            ret_value[start_index+i]=0;
   }
}

void draw_string(datetime x,double y,string contents,int size,string font_type,color clrColor)
{
   string objName="TEXT"+TimeToStr(x,TIME_DATE|TIME_MINUTES);
   if(ObjectFind(objName)<0)
   {
      long current_chart_id=ChartID();
      ObjectCreate(current_chart_id,objName,OBJ_TEXT,WindowFind("jzxt"),x,y);
      ObjectSetText(objName,contents,10,font_type,clrColor);
      ChartRedraw(current_chart_id);
   }
}

int iCustomLowest(double &array[],int count,int start_index)
{
   int nCount=0;
   double tmp=array[start_index];

   for(int i=0;i<count;i++)
      if((start_index+i)<Bars)
         if(array[start_index+i]<tmp)
         {
            nCount=i;
            tmp=array[start_index+i];
         }
   return(nCount);
}

bool TrendCreate(const long            chart_ID=0,        // chart's ID
                 const string          name="TrendLine",  // line name
                 const int             sub_window=0,      // subwindow index
                 datetime              time1=0,           // first point time
                 double                price1=0,          // first point price
                 datetime              time2=0,           // second point time
                 double                price2=0)          // second point price

{
   ChangeTrendEmptyPoints(time1,price1,time2,price2);
   ResetLastError();
   if(!ObjectCreate(chart_ID,name,OBJ_TREND,sub_window,time1,price1,time2,price2))
     {
      return(false);
     }
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clrRed);
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,STYLE_DASHDOT);
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,1);
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,false);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,false);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,false);
   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,false);
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,false);
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,0);
   ObjectSetInteger(chart_ID,name,OBJPROP_TIMEFRAMES,Period());

   return(true);
}

void ChangeTrendEmptyPoints(datetime &time1,double &price1,
                            datetime &time2,double &price2)
{
   if(!time1)
      time1=TimeCurrent();
   if(!price1)
      price1=SymbolInfoDouble(Symbol(),SYMBOL_BID);
   if(!time2)
     {
      datetime temp[10];
      CopyTime(Symbol(),Period(),time1,10,temp);
      time2=temp[0];
     }
   if(!price2)
      price2=price1;
}

int COUNT(double& array[],int count,int start_index)
{
   int nCount=0;
   for(int i=0;i<count;i++)
      if((i+start_index)<Bars)
         if(array[i+start_index]==1)
            nCount++;

   return(nCount);
}
如果有帮助,就支持一下我呗
举报

评论 使用道具

精彩评论10

红心大蜜柚
D
| 发表于 2023-9-1 13:52:35 | 显示全部楼层
好评给到你
举报

点赞 评论 使用道具

红心大蜜柚
D
| 发表于 2023-9-1 13:56:04 | 显示全部楼层
不能用啊,好多报错
举报

点赞 评论 使用道具

湘聚缘
DD
| 发表于 2023-9-1 14:09:11 | 显示全部楼层
弯弯曲曲,柳柳捏捏。
举报

点赞 评论 使用道具

qin324
DDD
| 发表于 2023-9-1 17:01:47 | 显示全部楼层
能用吗版本
举报

点赞 评论 使用道具

爱交易
DD
| 发表于 2023-9-2 00:30:10 | 显示全部楼层
感谢分享。。 源码不全。。。可否分享指标源码文件。。
举报

点赞 评论 使用道具

猪猪听风
D
| 发表于 2023-9-2 08:40:24 | 显示全部楼层
看不懂源码
举报

点赞 评论 使用道具

石头1968
DD
| 发表于 2023-9-3 00:03:12 | 显示全部楼层
不能用哦,这是MT5的吗?
举报

点赞 评论 使用道具

hawkbig
DD
| 发表于 2023-9-3 12:53:23 | 显示全部楼层
MT4的吗        ?
举报

点赞 评论 使用道具

6669
DDD
| 发表于 2023-10-18 19:18:44 | 显示全部楼层
九转信号指标可以
举报

点赞 评论 使用道具

1594135666
DDD
| 发表于 2023-10-18 20:13:54 | 显示全部楼层
分享源码 非常感谢
举报

点赞 评论 使用道具

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

tonglinew

tonglinew DDD

《老子·四章》:“和其光,同其尘。” 意思是涵蓄着光耀,混同着尘垢,与好坏都能相合,不自立异。后多指

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