BlackAndWhite

Author: Copyright 2020, Maxim Kuznetsov
0 Views
0 Downloads
0 Favorites
BlackAndWhite
ÿþ//+------------------------------------------------------------------+

//|                                                BlackAndWhite.mq4 |

//|                                  Copyright 2020, Maxim Kuznetsov |

//|                                          https://www.luxtrade.tk |

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

#property copyright "Copyright 2020, Maxim Kuznetsov"

#property link      "https://www.luxtrade.tk"

#property version   "1.00"

#property description "Show Black and White difference"

#property strict

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_plots   2

//--- plot BW

#property indicator_label1  "BW"

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrRed

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1



#property indicator_label2  "ZZ"

#property indicator_type2   DRAW_SECTION

#property indicator_color2  clrDarkGray

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1



//--- indicator buffers

double         BW[];

double         ZZ[];    // >?>@=K9 ZZ

const int DEPTH=3;

int OnInit()

{

   IndicatorDigits(_Digits);

   SetIndexBuffer(0,BW);

   SetIndexBuffer(1,ZZ);

   return(INIT_SUCCEEDED);

}

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[])

{

   ArraySetAsSeries(BW,true);

   ArraySetAsSeries(ZZ,true);

   ArraySetAsSeries(open,true);

   ArraySetAsSeries(close,true);

   for(int bar=(prev_calculated==0?0:prev_calculated-1);bar<rates_total;bar++) {

      int i=rates_total-bar-1;

      BW[i]=EMPTY_VALUE;

      if (bar==0) {

         BW[i]=0;

      } else {

         if (BW[i+1]==EMPTY_VALUE) {

            BW[i]=0;

         } else {

            if (close[i]>open[i]) BW[i]=BW[i+1]+1;

            else if (close[i]<open[i]) BW[i]=BW[i+1]-1;

            else if (bar>1 && BW[i+1]!=EMPTY_VALUE && BW[i+2]!=EMPTY_VALUE) {

               // doji

               if (BW[i+1]>BW[i+2]) BW[i]=BW[i+1]-1;

               else if (BW[i+1]<BW[i+2]) BW[i]=BW[i+1]+1;

            } else {

               BW[i]=BW[i+1];

            }

         }

      }

      // ZZ

      ZZ[i]=EMPTY_VALUE;

      if (bar<2) {

         ZZ[i]=BW[i];

      } else if (i>0) {

         int j;

         for(j=i+1;j<rates_total-1;j++) {

            if (ZZ[j]!=EMPTY_VALUE) break;

         }

         if (j==rates_total-1) break;

         if (BW[j]>BW[j+1]) {

            // 783703 225@E

            if (BW[i]>=ZZ[j]) {

               ZZ[j]=EMPTY_VALUE;

               ZZ[i]=BW[i];

            } else if (BW[i]<=ZZ[j]-DEPTH) {

               ZZ[i]=BW[i];

            }

         } else {

            // 783703 2=87

            if (BW[i]<=ZZ[j]) {

               ZZ[j]=EMPTY_VALUE;

               ZZ[i]=BW[i];

            } else if (BW[i]>=ZZ[j]+DEPTH) {

               ZZ[i]=BW[i];

            }

         }

      }

   }

   return(rates_total);

}



Comments