Download MetaTrader 5
To add comments, please log in or register
Publish your task in Freelance service and developers will execute your order.
47803124
154
47803124 2014.08.05 15:31 
//+------------------------------------------------------------------+
//|                                                      两个KD都背离.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID

#property indicator_width1  1
//--- plot Label2
#property indicator_label2  "Label2"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrGreen
#property indicator_style2  STYLE_SOLID

#property indicator_width2  1
//***************KDJ*******************
extern int K1=5;
extern int SLOW1=3;
extern int KDPERIOD1=3;
extern int K2=8;
extern int SLOW2=5;
extern int KDPERIOD2=3;

extern int bigperiod=0;
extern int smallperiod=0;
extern int up=80;
extern int dn=20;
//******************KDJ**********************

//--- indicator buffers
double         Label1Buffer[];
double         Label2Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer);
   SetIndexBuffer(1,Label2Buffer);
   
   SetIndexDrawBegin(0,20);
   SetIndexDrawBegin(1,20);
   SetIndexStyle(0,DRAW_ARROW,EMPTY,2,clrRed);
   SetIndexStyle(1,DRAW_ARROW,EMPTY,2,clrGreen);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   PlotIndexSetInteger(0,PLOT_ARROW,217);
   PlotIndexSetInteger(1,PLOT_ARROW,218);

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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 i,limit;
   if(rates_total<=10 )  return(0);
   limit=rates_total-prev_calculated;
   if(prev_calculated>0)  limit++;

   for(i=0; i<limit; i++)
      {
          double kdjmain0 =iStochastic(Symbol(),bigperiod,K1,SLOW1,KDPERIOD1,MODE_LWMA,0,MODE_MAIN,i+1);
          double kdjsigal0=iStochastic(Symbol(),bigperiod,K1,SLOW1,KDPERIOD1,MODE_LWMA,0,MODE_SIGNAL,i+1);
          double kdjmain1 =iStochastic(Symbol(),bigperiod,K1,SLOW1,KDPERIOD1,MODE_LWMA,0,MODE_MAIN,i+2);
          double kdjsigal1=iStochastic(Symbol(),bigperiod,K1,SLOW1,KDPERIOD1,MODE_LWMA,0,MODE_SIGNAL,i+2);
          double kdjmain2 =iStochastic(Symbol(),bigperiod,K1,SLOW1,KDPERIOD1,MODE_LWMA,0,MODE_MAIN,i+3);
          double kdjsigal2=iStochastic(Symbol(),bigperiod,K1,SLOW1,KDPERIOD1,MODE_LWMA,0,MODE_SIGNAL,i+3);
          
          double kdjmain3 =iStochastic(Symbol(),smallperiod,K2,SLOW2,KDPERIOD2,MODE_LWMA,0,MODE_MAIN,i+1);
          double kdjsigal3=iStochastic(Symbol(),smallperiod,K2,SLOW2,KDPERIOD2,MODE_LWMA,0,MODE_SIGNAL,i+1);
          double kdjmain4 =iStochastic(Symbol(),smallperiod,K2,SLOW2,KDPERIOD2,MODE_LWMA,0,MODE_MAIN,i+2);
          double kdjsigal4=iStochastic(Symbol(),smallperiod,K2,SLOW2,KDPERIOD2,MODE_LWMA,0,MODE_SIGNAL,i+2);
          double kdjmain5 =iStochastic(Symbol(),smallperiod,K2,SLOW2,KDPERIOD2,MODE_LWMA,0,MODE_MAIN,i+3);
          double kdjsigal5=iStochastic(Symbol(),smallperiod,K2,SLOW2,KDPERIOD2,MODE_LWMA,0,MODE_SIGNAL,i+3);
          bool   duo=false;
          bool   kong=false;
          if(((kdjmain0>kdjsigal0)&&(kdjmain1>kdjsigal1)&&(kdjmain2>kdjsigal2))&&((kdjmain3>kdjsigal3)&&(kdjmain4>kdjsigal4)&&(kdjmain5>kdjsigal5)))
            {
               if(((kdjmain0>kdjmain1)&&(kdjmain1>kdjmain2))&&((kdjmain3>kdjmain4)&&(kdjmain4>kdjmain5)))
                  {
                     if(kdjmain0<dn)
                     duo=true;
                  }
            }
          if(((kdjmain0<kdjsigal0)&&(kdjmain1<kdjsigal1)&&(kdjmain2<kdjsigal2))&&((kdjmain3<kdjsigal3)&&(kdjmain4<kdjsigal4)&&(kdjmain5<kdjsigal5)))
            {
               if(((kdjmain0<kdjmain1)&&(kdjmain1<kdjmain2))&&((kdjmain3<kdjmain4)&&(kdjmain4<kdjmain5)))
                  {
                     if(kdjmain2<up)
                     kong=true;
                  }
            }
          
         if((Close[i+1]>Close[i+2])&&(Close[i+2]>Close[i+3]))
            {
               if(kong)
                  {
                      Label1Buffer[i+1]=High[i+1]+20*Point;
                  }
            }
            
          if((Close[i+1]<Close[i+2])&&(Close[i+2]<Close[i+3]))
            {
               if(duo)
                  {
                      Label2Buffer[i+1]=Low[i+1]-20*Point;
                  }
            }
      }
      



   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Alain Verleyen
Moderator
28522
Alain Verleyen 2014.08.05 16:13  
What is the problem ?
47803124
154
47803124 2014.08.05 19:25  
The code can't display arrow int mt4,WHY
Keith Watford
Moderator
7886
Keith Watford 2014.08.05 19:37  
What icon is being displayed and where?
47803124
154
47803124 2014.08.06 03:20  
GumRai:
What icon is being displayed and where?


.


don't display Arrow ,WHY

Keith Watford
Moderator
7886
Keith Watford 2014.08.06 04:06  
zdj231:


.


don't display Arrow ,WHY


Maybe the conditions are not satisfied
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.08.06 07:29  

Yes. Usually that is the case.


zdj231 

You need to strip the codes to bare bones and do troubleshooting and use Print() or Comment() to see if there any output at all.


That is what I usually do.

/
To add comments, please log in or register