有您的持续关注
我们会做得更好

指标StochasticOnChart在主图绘制通道及标注KD信号



StochasticOnChart指标在主图绘制通道及标注KD信号。

StochasticOnChart指标图表效果如下:StochasticOnChart指标StochasticOnChart指标MQL4源码如下:

//+------------------------------------------------------------------+
//|                                            StochasticOnChart.mq4 |
//|                                       Copyright @2013, 125808047 |
//+------------------------------------------------------------------+
#property copyright "www.125808047.com"
#property link      "http://www.125808047.com"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Yellow
#property indicator_width1 2
#property indicator_color2 Yellow
#property indicator_width2 1
#property indicator_color3 Yellow
#property indicator_width3 1
#property indicator_color4 Yellow
#property indicator_width4 1

#import  "shell32.dll"           //Connect a dll (provided with Windows)             
  int ShellExecuteA(int hwnd, string Operation, string File, string Parameters, string Directory, int ShowCmd); 
#import "user32.dll"
  int MessageBoxA(int hWnd , string lpText, string lpCaption, int uType);
//------------------------------------------------------------------------------------------------------

extern int K周期   = 5;
extern int D周期   = 3;
extern int 慢周期  = 3;
extern int MA      = 50;
extern int Scale   = 100;
extern int 使用通道显示   = 1;
extern int 使用箭头显示   = 1;

double 信率Ma[];
double 黄上轨[];
double 黄下轨[];
double 黄中轨[];
double KD信组[];
//----
int 始绘处1   = 0;
int 始绘处2   = 0;

int 绘箭数   = 15;

//---------------初始化----------------+

int init()
  {
   string 简称;
   
   string 箭头名;
   for(int n=0; n<绘箭数; n++){
      箭头名= "KD信号"+K周期+"_"+n;
      ObjectDelete(箭头名);
     }

   CheckDonate();

   IndicatorBuffers(4);

   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, 信率Ma);

   if(使用通道显示==1){
      SetIndexStyle(1, DRAW_LINE);
      SetIndexBuffer(1, 黄上轨);
      SetIndexStyle(2, DRAW_LINE);
      SetIndexBuffer(2, 黄中轨);
      SetIndexStyle(3, DRAW_LINE);
      SetIndexBuffer(3, 黄下轨);
     }
   else
      for(int i=1; i<=3; i++)
         SetIndexStyle(i, DRAW_NONE);
   
   for(i=4; i<=7; i++)
       SetIndexStyle(i, DRAW_NONE);
   
   //--
   简称="Sto("+K周期+", "+D周期+", "+慢周期+")";
   IndicatorShortName(简称);
   SetIndexLabel(0, 简称);
   SetIndexLabel(1, "80%");
   SetIndexLabel(2, "50%");
   SetIndexLabel(3, "20%");
   //--
   始绘处1= K周期+慢周期;
   始绘处2= 始绘处1+D周期;
   SetIndexDrawBegin(0, 始绘处1);
   SetIndexDrawBegin(1, 始绘处1);
   SetIndexDrawBegin(2, 始绘处1);
   SetIndexDrawBegin(3, 始绘处1);
   //--
   ArraySetAsSeries(KD信组, true);
   return(0);
  }

//--------------反初始化--------------+

void deinit()
  {
   string 箭头名;
   for(int n=0; n<绘箭数; n++){
      箭头名= "KD信号"+K周期+"_"+n;
      ObjectDelete(箭头名);
     }
  }

//---------------主函数----------------+

int start()
  {
   int    i, n;
   int    已计= IndicatorCounted();

   if(Bars<=始绘处2)
     return(0);

   if(ArraySize(KD信组)!=Bars)
      ArrayResize(KD信组, Bars);

   //--初始归0
   if(已计<1)
      for(i=1;i<=始绘处2;i++){
         信率Ma[Bars-i]= 0;
         黄下轨[Bars-i]= 0;
         黄上轨[Bars-i]= 0;
         黄中轨[Bars-i]= 0;
         KD信组[Bars-i]= 0;
        }

   //--缓组赋值
   double kk= Point*Scale/100;
   int limit= Bars-已计;
   for(i=0; i<limit; i++){
      KD信组[i]= iStochastic(Symbol(), 0, K周期, D周期, 慢周期, MODE_SMA, 0, MODE_SIGNAL, i);
      信率Ma[i]= iMA(Symbol(), 0, MA, 0, MODE_EMA, PRICE_MEDIAN, i)+(KD信组[i]-50)*kk;
      if(使用通道显示==1){
         黄上轨[i]= iMA(Symbol(), 0, MA, 0, MODE_EMA, PRICE_MEDIAN, i)+30*kk;
         黄中轨[i]= iMA(Symbol(), 0, MA, 0, MODE_EMA, PRICE_MEDIAN, i);
         黄下轨[i]= iMA(Symbol(), 0, MA, 0, MODE_EMA, PRICE_MEDIAN, i)-30*kk;
        }
     }
   
   //--物件箭头
   if(使用箭头显示==1){
      int 标志;
      double 值D0, 值D1, 值D2, 值D3;
      i= 0;
      n= 0;
      while(n<绘箭数 && i<Bars/*-已计*/){
         标志= 0;
         while(i<Bars/*-已计*/ && 标志==0){
            值D0= iStochastic(Symbol(), 0, K周期, D周期, 慢周期, MODE_SMA, 0, MODE_SIGNAL, i+0);
            值D1= iStochastic(Symbol(), 0, K周期, D周期, 慢周期, MODE_SMA, 0, MODE_SIGNAL, i+1);
            值D2= iStochastic(Symbol(), 0, K周期, D周期, 慢周期, MODE_SMA, 0, MODE_SIGNAL, i+2);
            值D3= iStochastic(Symbol(), 0, K周期, D周期, 慢周期, MODE_SMA, 0, MODE_SIGNAL, i+3);

            if(值D0>值D1 && 值D2>值D1 && 值D3>值D2)
               标志= +1;
            if(值D0<值D1 && 值D2<值D1 && 值D3<值D2)
               标志= -1;
            if(标志!=0)
               break;
            i++;
           }

         string 箭头名="KD信号"+K周期+"_"+n;
         ObjectDelete(箭头名);
         if(标志==+1){
            ObjectCreate(箭头名, OBJ_ARROW, 0, Time[i], Low[i]);
            ObjectSet(箭头名, OBJPROP_ARROWCODE, 108);
            ObjectSet(箭头名, OBJPROP_COLOR, Blue);
            n++;
           }
         if(标志==-1){
            ObjectCreate(箭头名, OBJ_ARROW, 0, Time[i], High[i]+(WindowPriceMax()-WindowPriceMin())/10);
            ObjectSet(箭头名, OBJPROP_ARROWCODE, 108);
            ObjectSet(箭头名, OBJPROP_COLOR, Red);
            n++;
           }
         i+=1;
        }
     }
   return(0);
  }

//---------------CheckDonate----------------+

void CheckDonate()
  {
   int 手柄= 0; 
   string pay= "0"; 
   datetime dt= 0;
   string 文件名= "StochOC.txt";

   手柄= FileOpen(文件名, FILE_READ|FILE_CSV, ";");
   if(手柄>=1){
      pay= FileReadString(手柄);
      if(pay!= "0" && pay!="1")
         pay= "0";
      dt= StrToTime(FileReadString(手柄));
     }
   else{
      dt= TimeCurrent();
      手柄= FileOpen(文件名, FILE_WRITE|FILE_CSV, ";");
      FileWrite(手柄, "0", TimeToStr(dt, TIME_DATE));
     }
   FileClose(手柄);
   
   if(pay=="0" && (TimeCurrent()-dt)>10*24*60*60){
      dt= TimeCurrent();
      
      手柄= FileOpen(文件名, FILE_WRITE|FILE_CSV, ";");
      FileWrite(手柄, pay, TimeToStr(dt, TIME_DATE));
      FileClose(手柄);
     }
   FileClose(手柄);
  }

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

如您喜欢此文章请点下面分享按钮↴峰汇在线 » 指标StochasticOnChart在主图绘制通道及标注KD信号
上一篇:
下一篇:
分享到:更多 ()