Indicator Problem

 

hi 

i write indicator for draw arrow when cross moving array and when i change time farme it mess up

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

//|                                                     Tamrin 1.mq4 |

//|                        Copyright 2020, MetaQuotes Software Corp. |

//|                                             https://www.mql5.com |

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

#property copyright "Ali Shirmohammadi"

#property link      ";).com"

#property version   "1.00"

#property strict

#property indicator_chart_window



#property indicator_buffers 3



#property indicator_color1 clrBlue

#property indicator_color1 clrGreen

#property indicator_color1 clrMagenta



#property indicator_width1 2

#property indicator_width2 4

#property indicator_width3 4



#property indicator_label1 "Moving"

#property indicator_label2 "Up Buffer"

#property indicator_label3 "Down Buffer"



input string MA1 = "__________MA1__________"; //__________MA1__________

input int ma_Period = 14;                          // Period 

input int ma_Shift = 0;                            // Shift

input ENUM_MA_METHOD ma_Method = MODE_SMA;         // Ma Method

input ENUM_APPLIED_PRICE ma_Apply = PRICE_CLOSE;   // Apply To



double MaBuffer[], UpArrowBuffer[], DnArrowBuffer[];



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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping



   Comment("");

   

      SetIndexBuffer(0, MaBuffer);

      SetIndexStyle(0, DRAW_LINE);

      SetIndexShift(0, ma_Shift);

      SetIndexDrawBegin(0, ma_Period);

      

      SetIndexBuffer(1, UpArrowBuffer);

      SetIndexStyle(1, DRAW_ARROW);

      SetIndexArrow(1, 225);

      

      SetIndexBuffer(1, DnArrowBuffer);

      SetIndexStyle(1, DRAW_ARROW);

      SetIndexArrow(1, 226);

      

      SetIndexEmptyValue(0, EMPTY_VALUE);

      SetIndexEmptyValue(1, EMPTY_VALUE);

      SetIndexEmptyValue(2, EMPTY_VALUE);

      

      IndicatorDigits(6);

      

//---

   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 limit;

     

     if(prev_calculated == 0)

     {

         limit = rates_total - 1 - ma_Period;

     }

     else

     {

         limit = rates_total - prev_calculated;

     }

     

     for(int i = limit; i >= 0; i--)

      {

         MaBuffer[i] = iMA(_Symbol, PERIOD_CURRENT, ma_Period, ma_Shift, ma_Method, ma_Apply, i);

         

         if(i < rates_total - 1 - ma_Period - 2)

         {

            if(Close[i+2] < MaBuffer[i+2] && Close[i+1] > MaBuffer[i+2])

            {

               UpArrowBuffer[i+2] = Low[i+1];

            }

            if(Close[i+2] > MaBuffer[i+2] && Close[i+1] < MaBuffer[i+2])

            {

               DnArrowBuffer[i+2] = High[i+1];

               

            }

         }

      }

                                              

//--- return value of prev_calculated for next call

   return(rates_total);

  }

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

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
Ask questions on technical analysis, discuss trading systems and improve your MQL5 programming skills to develop your own trading strategies. Communicate and share your experience with traders from anywhere in the world, answer questions and help beginners — MQL5.community is developing along with you. Stop loss must be above order...
Files:
 
Ali Shirmohammadi: when i change time farme it mess up
      SetIndexBuffer(1, UpArrowBuffer);
      SetIndexStyle(1, DRAW_ARROW);
      SetIndexArrow(1, 225);

      SetIndexBuffer(1, DnArrowBuffer);
      SetIndexStyle(1, DRAW_ARROW);
      SetIndexArrow(1, 226);
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. You can't have two buffers with the same index.
 
William Roeder:
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. You can't have two buffers with the same index.
Oh i forgot it
And next? 
 
Ali Shirmohammadi: when i change time farme it mess up
            if(Close[i+2] < MaBuffer[i+2] && Close[i+1] > MaBuffer[i+2])
               UpArrowBuffer[i+2] = Low[i+1];

            if(Close[i+2] > MaBuffer[i+2] && Close[i+1] < MaBuffer[i+2])
               DnArrowBuffer[i+2] = High[i+1];
  1. Old bug in MT4, buffers are not cleared to EMPTY_VALUE. A) if you set an Up, remove the Dn. B) I clear all buffers at the top of the loop.
Reason: