评论

收藏

这个代码想多搞几个共振周期 ,该怎样改?

avatar 点评 | 315 人阅读 | 0 人评论 | 2024-01-16

这个代码想多搞几个共振周期   ,该怎样改??目前有4个共振周期,有没有高手指点一下,



extern int MA1_Per=5;
extern int MA2_Per=10;
extern ENUM_MA_METHOD MA1_平滑方式=MODE_SMA;
extern ENUM_MA_METHOD MA2_平滑方式=MODE_SMA;
extern ENUM_APPLIED_PRICE MA1_应用于=PRICE_CLOSE;
extern ENUM_APPLIED_PRICE MA2_应用于=PRICE_CLOSE;
extern bool 自动共振周期=true;
extern ENUM_TIMEFRAMES 共振周期2=15;
extern ENUM_TIMEFRAMES 共振周期3=60;
extern ENUM_TIMEFRAMES 共振周期4=240;
extern ENUM_TIMEFRAMES 共振周期5=1440;
extern int 上涨箭头=233;
extern int 下跌箭头=234;
extern int 箭头大小=1;
extern bool 报警开关=true;
extern int 报警K线=0;

double x1[];
double x2[];
double x3[];
double x4[];
double x5[];

double x6[];
double x7[];
double x8[];
double x9[];
double x10[];
double x11[];
double x12[];
double x13[];
double x14[];
double x15[];

double xa1[];
double xa2[];
double xa3[];
double xa4[];
double xa5[];

double xa6[];
double xa7[];
double xa8[];
double xa9[];
double xa10[];

double xa11[];
double xa12[];


double ccc;
int b=0,sub_window=0;

int init()
  {
   IndicatorBuffers(27);

   SetIndexBuffer(0,x1);
   SetIndexStyle(0,DRAW_ARROW,0,箭头大小);
   SetIndexDrawBegin(0,0);
   SetIndexBuffer(1,x2);
   SetIndexStyle(1,DRAW_ARROW,0,箭头大小);
   SetIndexDrawBegin(1,0);

   SetIndexBuffer(2,x3);
   SetIndexStyle(2,DRAW_ARROW,0,箭头大小);
   SetIndexDrawBegin(2,0);
   SetIndexBuffer(3,x4);
   SetIndexStyle(3,DRAW_ARROW,0,箭头大小);
   SetIndexDrawBegin(3,0);

   SetIndexBuffer(4,x5);
   SetIndexStyle(4,DRAW_ARROW,0,箭头大小);
   SetIndexDrawBegin(4,0);
   SetIndexBuffer(5,x6);
   SetIndexStyle(5,DRAW_ARROW,0,箭头大小);
   SetIndexDrawBegin(5,0);


   SetIndexBuffer(6,x7);
   SetIndexStyle(6,DRAW_ARROW,0,箭头大小);
   SetIndexDrawBegin(6,0);
   SetIndexBuffer(7,x8);
   SetIndexStyle(7,DRAW_ARROW,0,箭头大小);
   SetIndexDrawBegin(7,0);


   SetIndexBuffer(8,x9);
   SetIndexStyle(8,DRAW_ARROW,0,箭头大小);
   SetIndexDrawBegin(8,0);
   SetIndexBuffer(9,x10);
   SetIndexStyle(9,DRAW_ARROW,0,箭头大小);
   SetIndexDrawBegin(9,0);

   SetIndexBuffer(10,x11);
   SetIndexStyle(10,DRAW_LINE,0,0,clrNONE);
   SetIndexDrawBegin(10,0);
   SetIndexBuffer(11,x12);
   SetIndexStyle(11,DRAW_LINE,0,0,clrNONE);
   SetIndexDrawBegin(11,0);

   SetIndexBuffer(12,x13);
   SetIndexStyle(12,DRAW_ARROW,0,箭头大小);
   SetIndexDrawBegin(12,0);
   SetIndexBuffer(13,x14);
   SetIndexStyle(13,DRAW_ARROW,0,箭头大小);
   SetIndexDrawBegin(13,0);
   SetIndexBuffer(14,x15);
   SetIndexStyle(14,DRAW_ARROW,0,箭头大小);
   SetIndexDrawBegin(14,0);

   SetIndexArrow(12,108);
   SetIndexArrow(13,108);
   SetIndexArrow(14,108);

   SetIndexArrow(0,上涨箭头);
   SetIndexArrow(1,下跌箭头);
   SetIndexArrow(2,上涨箭头);
   SetIndexArrow(3,下跌箭头);
   SetIndexArrow(4,上涨箭头);
   SetIndexArrow(5,下跌箭头);
   SetIndexArrow(6,上涨箭头);
   SetIndexArrow(7,下跌箭头);
   SetIndexArrow(8,上涨箭头);
   SetIndexArrow(9,下跌箭头);
   SetIndexBuffer(15,xa1);
   SetIndexBuffer(16,xa2);
   SetIndexBuffer(17,xa3);
   SetIndexBuffer(18,xa4);
   SetIndexBuffer(19,xa5);
   SetIndexBuffer(20,xa6);

   SetIndexBuffer(21,xa7);
   SetIndexBuffer(22,xa8);
   SetIndexBuffer(23,xa9);

   SetIndexBuffer(24,xa10);
   SetIndexBuffer(25,xa11);
   SetIndexBuffer(26,xa12);

   SetIndexLabel(0,"");
   SetIndexLabel(1,"");
   SetIndexLabel(2,"");
   SetIndexLabel(3,"");
   SetIndexLabel(4,"");

   SetIndexLabel(5,"");
   SetIndexLabel(6,"");
   SetIndexLabel(7,"");
   SetIndexLabel(8,"");
   SetIndexLabel(9,"");

   IndicatorShortName("任意2条均线金叉死叉多周期共振(" + MA1_Per +","+MA2_Per+","+Period()+","+共振周期2+","+共振周期3+","+共振周期4+","+共振周期5+")");
   return(0);
  }
int deinit()
{
return 0;
}

int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   sub_window=ChartWindowFind();

   if(ccc!=Close[1]) b=1;
   else b=0;

   if(自动共振周期)
   {
   if(Period()==1)
   {
   共振周期2=5;
   共振周期3=15;
   共振周期4=30;
   共振周期5=60;
   }
   else if(Period()==5)
   {
   共振周期2=15;
   共振周期3=30;
   共振周期4=60;
   共振周期5=240;
   }
   else if(Period()==15)
   {
   共振周期2=30;
   共振周期3=60;
   共振周期4=240;
   共振周期5=1440;
   }
   else if(Period()==30)
   {
   共振周期2=60;
   共振周期3=240;
   共振周期4=1440;
   共振周期5=10080;
   }
   else if(Period()==60)
   {
   共振周期2=240;
   共振周期3=1440;
   共振周期4=10080;
   共振周期5=43200;
   }
   else if(Period()==240)
   {
   共振周期2=1440;
   共振周期3=10080;
   共振周期4=43200;
   共振周期5=43200;
   }
   else if(Period()==1440)
   {
   共振周期2=10080;
   共振周期3=43200;
   共振周期4=43200;
   共振周期5=43200;
   }
   else if(Period()==10080)
   {
   共振周期2=43200;
   共振周期3=43200;
   共振周期4=43200;
   共振周期5=43200;
   }
   else if(Period()==43200)
   {
   共振周期2=43200;
   共振周期3=43200;
   共振周期4=43200;
   共振周期5=43200;
   }
   }

   for(int i=limit+1; i>=0; i--)
      {  
      xa1[i]=iMA(NULL,0,MA1_Per,0,MA1_平滑方式,MA1_应用于,i);//快线
      xa2[i]=iMA(NULL,0,MA2_Per,0,MA2_平滑方式,MA2_应用于,i);//慢线

      int iNext1=iBarShift(NULL,共振周期2,iTime(NULL,0,i));
      xa3[i]=iMA(NULL,共振周期2,MA1_Per,0,MA1_平滑方式,MA1_应用于,iNext1);
      xa4[i]=iMA(NULL,共振周期2,MA2_Per,0,MA2_平滑方式,MA2_应用于,iNext1);

      int iNext3=iBarShift(NULL,共振周期3,iTime(NULL,0,i));
      xa5[i]=iMA(NULL,共振周期3,MA1_Per,0,MA1_平滑方式,MA1_应用于,iNext3);
      xa6[i]=iMA(NULL,共振周期3,MA2_Per,0,MA2_平滑方式,MA2_应用于,iNext3);

      int iNext5=iBarShift(NULL,共振周期4,iTime(NULL,0,i));
      xa7[i]=iMA(NULL,共振周期4,MA1_Per,0,MA1_平滑方式,MA1_应用于,iNext5);
      xa8[i]=iMA(NULL,共振周期4,MA2_Per,0,MA2_平滑方式,MA2_应用于,iNext5);

      int iNext7=iBarShift(NULL,共振周期5,iTime(NULL,0,i));
      xa9[i]=iMA(NULL,共振周期5,MA1_Per,0,MA1_平滑方式,MA1_应用于,iNext7);
      xa10[i]=iMA(NULL,共振周期5,MA2_Per,0,MA2_平滑方式,MA2_应用于,iNext7);

      if(xa1[i]>=xa2[i])
      {
      x1[i]=50;
      x2[i]=EMPTY_VALUE;
      }
      else
      {
      x1[i]=EMPTY_VALUE;
      x2[i]=50;
      }

      if(xa3[i]>=xa4[i])
      {
      x3[i]=40;
      x4[i]=EMPTY_VALUE;
      }
      else
      {
      x3[i]=EMPTY_VALUE;
      x4[i]=40;
      }

      if(xa5[i]>=xa6[i])
      {
      x5[i]=30;
      x6[i]=EMPTY_VALUE;
      }
      else
      {
      x5[i]=EMPTY_VALUE;
      x6[i]=30;
      }

      if(xa7[i]>=xa8[i])
      {
      x7[i]=20;
      x8[i]=EMPTY_VALUE;
      }
      else
      {
      x7[i]=EMPTY_VALUE;
      x8[i]=20;
      }

      if(xa9[i]>=xa10[i])
      {
      x9[i]=10;
      x10[i]=EMPTY_VALUE;
      }
      else
      {
      x9[i]=EMPTY_VALUE;
      x10[i]=10;
      }
      x11[i]=-10;
      x12[i]=70;


      if(x3[i]!=EMPTY_VALUE && x5[i]!=EMPTY_VALUE && x7[i]!=EMPTY_VALUE && x9[i]!=EMPTY_VALUE)
      xa11[i]=1;
      else
      xa11[i]=0;

      if(x4[i]!=EMPTY_VALUE && x6[i]!=EMPTY_VALUE && x8[i]!=EMPTY_VALUE && x10[i]!=EMPTY_VALUE)
      xa12[i]=1;
      else
      xa12[i]=0;

      if(xa11[i] && xa11[i+1]==0)
      x13[i]=70;
      else
      x13[i]=EMPTY_VALUE;

      if(xa12[i] && xa12[i+1]==0)
      x14[i]=70;
      else
      x14[i]=EMPTY_VALUE;

      if((xa11[i+1] && xa11[i]==0) || (xa12[i+1] && xa12[i]==0))
      x15[i]=70;
      else
      x15[i]=EMPTY_VALUE;

      }


   ObjectsDeleteAll(0,sub_window,OBJ_TEXT);

   ObjectCreate("共振周期1"+PeriodToText(), OBJ_TEXT, sub_window, Time[0], 50);
   ObjectSetText("共振周期1"+PeriodToText(), "               "+PeriodToText(), 13, "Verdana", Yellow);

   ObjectCreate("共振周期2"+PeriodToText(共振周期2), OBJ_TEXT, sub_window, Time[0], 40);
   ObjectSetText("共振周期2"+PeriodToText(共振周期2), "               "+PeriodToText(共振周期2), 13, "Verdana", Yellow);

   ObjectCreate("共振周期3"+PeriodToText(共振周期3), OBJ_TEXT, sub_window, Time[0], 30);
   ObjectSetText("共振周期3"+PeriodToText(共振周期3), "               "+PeriodToText(共振周期3), 13, "Verdana", Yellow);

   ObjectCreate("共振周期4"+PeriodToText(共振周期4), OBJ_TEXT, sub_window, Time[0], 20);
   ObjectSetText("共振周期4"+PeriodToText(共振周期4), "               "+PeriodToText(共振周期4), 13, "Verdana", Yellow);

   ObjectCreate("共振周期5"+PeriodToText(共振周期5), OBJ_TEXT, sub_window, Time[0], 10);
   ObjectSetText("共振周期5"+PeriodToText(共振周期5), "               "+PeriodToText(共振周期5), 13, "Verdana", Yellow);

   if(报警开关)
   {
   if(x13[报警K线]!=EMPTY_VALUE && b)
   {
   ccc=Close[1];
   Alert(Symbol()," "+PeriodToText()+" 满足条件 做多");
   }

   if(x14[报警K线]!=EMPTY_VALUE && b)
   {
   ccc=Close[1];
   Alert(Symbol()," "+PeriodToText()+" 满足条件 做空");
   }

   if(x15[报警K线]!=EMPTY_VALUE && b)
   {
   ccc=Close[1];
   Alert(Symbol()," "+PeriodToText()+" 满足条件 立即平仓");
   }
   }
   return(0);
  }

void writetext(string Labelname,string data,int x,int y,color ColorValue,int FontSize,int window)//通过Object写文字
{
   ObjectDelete(Labelname);
   ObjectCreate(Labelname,OBJ_LABEL,window,0,0);
   ObjectSetText(Labelname, data, FontSize, "Arial", ColorValue);
   ObjectSet(Labelname, OBJPROP_CORNER, 0);
   ObjectSet(Labelname, OBJPROP_XDISTANCE, x);
   ObjectSet(Labelname, OBJPROP_YDISTANCE, y);
}
string PeriodToText(int 共振周期)
{
   switch (共振周期)
   {
      case 1:
            return("M1");
            break;
      case 5:
            return("M5");
            break;
      case 15:
            return("M15");
            break;
      case 30:
            return("M30");
            break;
      case 60:
            return("H1");
            break;
      case 240:
            return("H4");
            break;
      case 1440:
            return("D1");
            break;
      case 10080:
            return("W1");
            break;
      case 43200:
            return("MN1");
            break;
   }
   return "NULL";
}


string PeriodToText()
{
   switch (Period())
   {
      case 1:
            return("M1");
            break;
      case 5:
            return("M5");
            break;
      case 15:
            return("M15");
            break;
      case 30:
            return("M30");
            break;
      case 60:
            return("H1");
            break;
      case 240:
            return("H4");
            break;
      case 1440:
            return("D1");
            break;
      case 10080:
            return("W1");
            break;
      case 43200:
            return("MN1");
            break;
   }
   return "NULL";
}


""
还没有人打赏,支持一下
您需要登录后才可以回帖 登录 | 注册 微信登录

EA之家评论守则