43评论

0收藏

求助高手在副图BOLL 加入K线(如图通达信的BOLL指标)

avatar salem888 | 4233 人阅读 | 43 人评论 | 2020-04-18

以下是MT4的BOLL代码,请帮忙如何加入K线图进去。跪谢


#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 LightSeaGreen
#property indicator_color2 LightSeaGreen
#property indicator_color3 LightSeaGreen
#property indicator_color4 LightSeaGreen
#property indicator_color5 LightSeaGreen
//---- indicator parameters
extern int up1down2 = 0;
extern int    BandsPeriod=20;
extern int    BandsShift=0;
extern double BandsDeviations=2.0;
extern bool AlertFlag = TRUE;

//---- buffers
double MovingBuffer[];
double UpperBuffer[];
double LowerBuffer[];
double d[];
double dd[];
int ii=0;
int iii=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,MovingBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,UpperBuffer);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,LowerBuffer);
//----
   SetIndexDrawBegin(0,BandsPeriod+BandsShift);
   SetIndexDrawBegin(1,BandsPeriod+BandsShift);
   SetIndexDrawBegin(2,BandsPeriod+BandsShift);

   SetIndexStyle(3, DRAW_ARROW);
   SetIndexArrow(3, 108);
   SetIndexBuffer(3, d);
   SetIndexStyle(4, DRAW_ARROW);
   SetIndexArrow(4, 108);
   SetIndexBuffer(4, dd);
   return(0);
  }
//+------------------------------------------------------------------+
//| Bollinger Bands                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int    i,k,counted_bars=IndicatorCounted();
   double deviation;
   double sum,oldval,newres;
//----
   if(Bars<=BandsPeriod) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=BandsPeriod;i++)
        {
         MovingBuffer[Bars-i]=EMPTY_VALUE;
         UpperBuffer[Bars-i]=EMPTY_VALUE;
         LowerBuffer[Bars-i]=EMPTY_VALUE;
        }
//----
   int limit=Bars-counted_bars;
   if(counted_bars>0) limit++;
   for(i=0; i<limit; i++)
      MovingBuffer[i]=iMA(NULL,0,BandsPeriod,BandsShift,MODE_SMA,PRICE_CLOSE,i);
//----
   i=Bars-BandsPeriod+1;
   if(counted_bars>BandsPeriod-1) i=Bars-counted_bars-1;
   while(i>=0)
     {
      sum=0.0;
      k=i+BandsPeriod-1;
      oldval=MovingBuffer[i];
      while(k>=i)
        {
         newres=Close[k]-oldval;
         sum+=newres*newres;
         k--;
        }
      deviation=BandsDeviations*MathSqrt(sum/BandsPeriod);
      UpperBuffer[i]=oldval+deviation;
      LowerBuffer[i]=oldval-deviation;

      if(High[i]>=UpperBuffer[i]&&(up1down2==2||up1down2==3))
      {
         d[i] = High[i];
         if (AlertFlag)
         {
            if (i == 0 && ii == FALSE)
            {
               Alert(Symbol() + " " + Period() + " 价格上穿布林带" + UpperBuffer[i] + "!");
               ii = TRUE;
               iii = FALSE;
            }
         }

      }
      if(Low[i]<=LowerBuffer[i]&&(up1down2==1||up1down2==3))

      {
            dd[i] = Low[i];

            if (AlertFlag)
            {
               if (i == 0 && iii == FALSE)
               {
                  Alert(Symbol() + " " + Period() + " 价格下穿布林带" + LowerBuffer[i] + "!");
                  iii = TRUE;
                  ii = FALSE;
               }
            }
       }




      i--;
     }

//----
   return(0);
  }
//+------------------------------------------------------------------+

void iSetLable(string LableName,string LableDoc,int LableX,int LableY,int DcoSize,string DocStyle,color DocColor)
{

ObjectCreate(LableName,OBJ_LABEL,0,0,0);
ObjectSetText(LableName,LableDoc,40,DocStyle,DocColor);
ObjectSet(LableName,OBJPROP_XDISTANCE,LableX);
ObjectSet(LableName,OBJPROP_YDISTANCE,LableY);
}

微信图片_20200418194832.png
微信图片_20200418194828.png
""
还没有人打赏,支持一下

评论|共 43 个

雨人

发表于 2020-6-22 18:03:12 | 显示全部楼层

LZ说的很不错

inconsolable

发表于 2020-7-2 22:46:18 | 显示全部楼层

前排支持下分享

u5z69b58

发表于 2020-7-18 17:44:37 | 显示全部楼层

学习了,不错

sgerkz3lb7

发表于 2020-7-20 19:50:17 | 显示全部楼层

学习了,不错

just__a___dream

发表于 2020-8-15 21:02:56 | 显示全部楼层

学习了,不错

好客户距离

发表于 2020-11-10 21:49:55 | 显示全部楼层

谢谢

fcdxf

发表于 2020-11-21 15:44:14 | 显示全部楼层

ivan99

发表于 2020-11-29 12:34:49 | 显示全部楼层

谢谢

换掉

发表于 2020-12-1 21:54:13 | 显示全部楼层

谢谢

12345下一页
您需要登录后才可以回帖 登录 | 注册 微信登录

EA之家评论守则