盈隆-顺势入场

#property copyright   "****版权所有"
#property description "以量化交易打造绝对盈利********"
#property version     "1.01"
//#property strict
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 clrGreen//长-绿
#property indicator_color2 clrRed//短-红
#property indicator_style3 STYLE_SOLID//画实线 趋势-红
#property indicator_type3  DRAW_HISTOGRAM//画柱状图
#property indicator_width3 4
#property indicator_color3 clrDeepSkyBlue
#property indicator_style4 STYLE_SOLID
#property indicator_type4  DRAW_HISTOGRAM
#property indicator_width4 4
#property indicator_color4 clrRed

extern int MaMetod = 2;
extern int MaPeriod = 4;  // 6
extern int MaMetod2 = 3;
extern int MaPeriod2 = 2;

double g_ibuf_92[];//绿
double g_ibuf_96[];//红
double g_ibuf_100[];//红柱
double g_ibuf_104[];//蓝柱
double g_ibuf_108[];//柱数与均线值 的均数
double g_ibuf_112[];//均线
double g_ibuf_116[];//MIN
double g_ibuf_120[];//MAX

int gi_124 = 0;
int Corner = 1; 

double 金叉箭头间距,金叉文字间距,死叉文字间距,死叉箭头间距;
// bool SoundON=false;
//datetime alertTag=Time[2];

//+------------------------------------------------------------------+
//| Custom indicator SUB function                                    |
//+------------------------------------------------------------------+
//-------------

void iDisplayInfo(string LableName,string LableDoc,int Corner,int LableX,int LableY,int DocSize,string DocStyle,color DocColor)
   {
      if (Corner == -1) return(0);
      ObjectCreate(LableName, OBJ_LABEL, 0, 0, 0);
      ObjectSetText(LableName, LableDoc, DocSize, DocStyle,DocColor);
      ObjectSet(LableName, OBJPROP_CORNER, Corner);
      ObjectSet(LableName, OBJPROP_XDISTANCE, LableX);
      ObjectSet(LableName, OBJPROP_YDISTANCE, LableY);
   }


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
 {

   IndicatorBuffers(10);
   SetIndexDrawBegin(0, 6);///       
   SetIndexBuffer(0, g_ibuf_92);//长-绿
   SetIndexBuffer(1, g_ibuf_96);//短-红
   SetIndexBuffer(2, g_ibuf_100);//趋势-红
   SetIndexBuffer(3, g_ibuf_104);//趋势-蓝
   SetIndexBuffer(4, g_ibuf_108);//  柱数与均线值 的均数
   SetIndexBuffer(5, g_ibuf_112);//均线值域

  //----------------------------------
  //输入标的对应的符号,并标注汉字注释
  //----------------------------------
  string MySymbol;
        if(Symbol()=="GBPUSD" || Symbol()=="GBPUSD-STD"){MySymbol="英镑/美元";}
   else if(Symbol()=="AUDUSD" || Symbol()=="AUDUSD-STD"){MySymbol="澳元/美元";}
   else if(Symbol()=="NZDUSD" || Symbol()=="NZDUSD-STD"){MySymbol="纽元/美元";}
   else if(Symbol()=="EURUSD" || Symbol()=="EURUSD-STD"){MySymbol="欧元/美元";}
   else if(Symbol()=="USDJPY" || Symbol()=="USDJPY-STD"){MySymbol="美元/日元";}
   else if(Symbol()=="USDCAD" || Symbol()=="USDCAD-STD"){MySymbol="美元/加元";}
   else if(Symbol()=="XAUUSD" || Symbol()=="XAUUSD-STD"){MySymbol="黄金-美元";}
   else if(Symbol()=="XAGUSD" || Symbol()=="XAGUSD-STD"){MySymbol="白银-美元";}
   else if(Symbol()=="XTIUSD" || Symbol()=="CL-OIL")    {MySymbol="原油-美元";}
   else MySymbol=Symbol();
   
   if(Period()==PERIOD_M1)       {金叉箭头间距=10*Point;   金叉文字间距=30*Point;   死叉箭头间距=20*Point;   死叉文字间距=30*Point;}
   else if(Period()==PERIOD_M5)  {金叉箭头间距=35*Point;   金叉文字间距=80*Point;   死叉箭头间距=50*Point;   死叉文字间距=90*Point;}
   else if(Period()==PERIOD_M15) {金叉箭头间距=45*Point;   金叉文字间距=100*Point;  死叉箭头间距=80*Point;   死叉文字间距=140*Point;}
   else if(Period()==PERIOD_M30) {金叉箭头间距=55*Point;   金叉文字间距=160*Point;  死叉箭头间距=120*Point;  死叉文字间距=200*Point;}
   else if(Period()==PERIOD_H1)  {金叉箭头间距=100*Point;  金叉文字间距=250*Point;  死叉箭头间距=150*Point;  死叉文字间距=250*Point;}
   else if(Period()==PERIOD_H4)  {金叉箭头间距=200*Point;  金叉文字间距=600*Point;  死叉箭头间距=450*Point;  死叉文字间距=750*Point;}
   else if(Period()==PERIOD_D1)  {金叉箭头间距=300*Point;  金叉文字间距=1030*Point; 死叉箭头间距=680*Point;  死叉文字间距=1340*Point;}
   else if(Period()==PERIOD_W1)  {金叉箭头间距=1150*Point; 金叉文字间距=3050*Point; 死叉箭头间距=1550*Point; 死叉文字间距=3550*Point;}
   else if(Period()==PERIOD_MN1) {金叉箭头间距=2280*Point; 金叉文字间距=7580*Point; 死叉箭头间距=3380*Point; 死叉文字间距=7000*Point;}
   
 //--------------------------
 //显示右上角的其他文字性注释
 //--------------------------   
   iDisplayInfo("Author", "****-交易领导者", Corner, 18, 15, 8, "", Red);
   iDisplayInfo("MySymbol", MySymbol, Corner, 28, 30, 14, "Arial Bold", DodgerBlue);
   iDisplayInfo("TradeInfo", "量化交易打造绝对盈利", Corner, 15, 70, 9, "", White); 
 
    return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinit function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   ObjectDelete("Author");ObjectDelete("MySymbol");ObjectDelete("TradeInfo");ObjectDelete("Price");
   ObjectDelete("低多文字提示");ObjectDelete("向上箭头");ObjectDelete("高空文字提示");ObjectDelete("向下箭头");
   
   for(int i=ObjectsTotal();i>=0;i--)
     {
      if(StringFind(ObjectName(i),"低多文字提示"+i,0)==0 || StringFind(ObjectName(i),"高空文字提示"+i,0)==0 || StringFind(ObjectName(i),"向上箭头"+i,0)==0 ||  StringFind(ObjectName(i),"向下箭头"+i,0)==0 )
        {
         ObjectDelete(ObjectName(i));
         i=ObjectsTotal();
        }
     }
  // return ();
}
//+------------------------------------------------------------------+
//| OnCalculate                                                      |
//+------------------------------------------------------------------+
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[]) 
{   
   iDisplayInfo("Price", DoubleToStr(Bid, Digits), Corner, 35, 50, 15, "Arial", Yellow);
   
   double l_ima_0;
   double l_ima_8;
   double l_ima_16;
   double l_ima_24;
   double ld_32;
   double ld_40;
   double ld_48;
   double ld_56;
   if (Bars <= 10) return (0);
   gi_124 = IndicatorCounted();
   if (gi_124 < 0) return (-1);
   if (gi_124 > 0) gi_124--;
   int li_64 = Bars - gi_124 - 1;
   int li_68 = li_64;
   while (li_64 >= 0)
   {//                          4           2(SMMA)
      l_ima_0 =  iMA(NULL, 0, MaPeriod, 0, MaMetod, PRICE_CLOSE, li_64);
      l_ima_8 =  iMA(NULL, 0, MaPeriod, 0, MaMetod, PRICE_LOW,   li_64);
      l_ima_16 = iMA(NULL, 0, MaPeriod, 0, MaMetod, PRICE_OPEN,  li_64);
      l_ima_24 = iMA(NULL, 0, MaPeriod, 0, MaMetod, PRICE_HIGH,  li_64);
    //---------------  
      ld_32 = (g_ibuf_108[li_64 + 1] + (g_ibuf_112[li_64 + 1])) / 2.0;// 
      ld_56 = (l_ima_0 + l_ima_24 + l_ima_16 + l_ima_8) / 4.0;// 加权MA
      ld_40 = MathMax(l_ima_24, MathMax(ld_32, ld_56));// 区间最大值
      ld_48 = MathMin(l_ima_16, MathMin(ld_32, ld_56)); //区间最小值
       
      g_ibuf_108[li_64] = ld_32; //#4 
      g_ibuf_112[li_64] = ld_56; //#5 赋值均线价格     
   
    
      li_64--;
   }
   //------------------------------------------------
   int li_72;                             //   长线 绿  #0                   Close[0]       3            2
   for (li_72 = 0; li_72 < li_68; li_72++) g_ibuf_92[li_72] = iMAOnArray(g_ibuf_108, Bars, MaPeriod2, 0, MaMetod2, li_72);
                                          //   短线 红  #1                    均线值
   for (li_72 = 0; li_72 < li_68; li_72++) g_ibuf_96[li_72] = iMAOnArray(g_ibuf_112, Bars, MaPeriod2, 0, MaMetod2, li_72);
                                          //   空势 红  #2
   for (li_72 = 0; li_72 < li_68; li_72++) g_ibuf_100[li_72] = iMAOnArray(g_ibuf_108, Bars, MaPeriod2, 0, MaMetod2, li_72);
                                          //   多势 蓝  #3
   for (li_72 = 0; li_72 < li_68; li_72++) g_ibuf_104[li_72] = iMAOnArray(g_ibuf_112, Bars, MaPeriod2, 0, MaMetod2, li_72);
   

   //---------------------------- 
       for (int i = 0; i < li_68; i++)//
     {
        if( g_ibuf_96[i]>g_ibuf_92[i] && g_ibuf_96[i+1]<g_ibuf_92[i+1] )
         { 
      //---------------------------------提示文字符号
           ObjectCreate("低多文字提示"+i, OBJ_TEXT, 0, Time[i], Low[i+1]-金叉文字间距);//
           ObjectSetText("低多文字提示"+i, "逢低做多", 12,"Times New Roman",Red);//
           ObjectCreate("向上箭头"+i,OBJ_ARROW_UP,0,Time[i],Low[i+1]-金叉箭头间距);
           ObjectSet("向上箭头"+i,OBJPROP_WIDTH,2);//
           ObjectSet("向上箭头"+i,OBJPROP_COLOR,Red);// 
        
           
      //--------------------------------- 提示声音
 //         if(SoundON==true && iBarShift(Symbol(),0,alertTag,true) >=1)          
 //         { PlaySound("alert.wav");  alertTag=Time[0]; }
      //---------------------------------------- 
        
         }
      //--------------------------
        else
        if( g_ibuf_96[i]<g_ibuf_92[i] && g_ibuf_96[i+1]>g_ibuf_92[i+1] )
         {         
        
        //------
          ObjectCreate("高空文字提示"+i,OBJ_TEXT,0, Time[i], High[i+1]+死叉文字间距);//
          ObjectSetText("高空文字提示"+i, "逢高做空", 12,"Times New Roman",Yellow);//
          ObjectCreate("向下箭头"+i,OBJ_ARROW_DOWN,0,Time[i],High[i+1]+死叉箭头间距);
          ObjectSet("向下箭头"+i,OBJPROP_WIDTH,2);//
          ObjectSet("向下箭头"+i,OBJPROP_COLOR,Blue);//
        //------
 //         if(SoundON==true && iBarShift(Symbol(),0,alertTag,true) >=1)
  //         { PlaySound("alert.wav");  alertTag=Time[0]; }         
          
         }  
       } 
    //--------------------------- 
  
   //return (0);
   return(rates_total);
}
//+------------------------------------------------------------------+

相关推荐
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页