My Indicator doesn't appear on one minute time frames & some of the 5 minutes time frames .. please help

 

Hi, every one ..

Kindly be generous with info.


Lately I changed my platform to meta trader 4 & I was struggling to convert my indicators to mql4 ,, as it is a new language to me , so after a lot of work & advises ,, at last I built something but unfortunately there is a little problem as mentioned above in the title, that indicators lines didn't appear on the minute time frames & some of the 5 minutes time frames , I will paste here most of the code , hoping that any gentlemen or ladies of course could  help by telling me what I do wrong ?? how can I correct it.

Note: the four Xes in the equations like this "xxxx" supposed to be cache values, please ignore it, I will replace them later by another values that has meaning.


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

//|                                                           MA.mq5 |

//|                        Copyright 2020, MetaQuotes Software Corp. |

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

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

#property copyright "Copyright 2020, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#include <MovingAverages.mqh>

#property indicator_separate_window

#property indicator_chart_window

#property indicator_buffers 3

#property indicator_plots   3

//--- plot Label1

#property indicator_label1  "Open"

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrRed

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot Label2

#property indicator_label2  "Close"

#property indicator_type2   DRAW_LINE

#property indicator_color2  clrBlue

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- plot Label3

#property indicator_label3  "Median"

#property indicator_type3   DRAW_LINE

#property indicator_color3  clrWhite

#property indicator_style3  STYLE_SOLID

#property indicator_width3  1

//--- indicator buffers

double         OpenMABuffer[];

double         CloseMABuffer[];

double         MedianBuffer[];

double         OpenBuffer[];

double         CloseBuffer[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   IndicatorBuffers(5);

   SetIndexBuffer(0,OpenMABuffer,INDICATOR_DATA);

   SetIndexBuffer(1,CloseMABuffer,INDICATOR_DATA);

   SetIndexBuffer(2,MedianBuffer,INDICATOR_DATA);

   SetIndexBuffer(3,OpenBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(4,CloseBuffer,INDICATOR_CALCULATIONS);

//--- bar, starting from which the indicator is drawn

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,29);

   string shortname1;

   string shortname2;

   string shortname3;

   StringConcatenate(shortname1,"OPEN","");

   StringConcatenate(shortname2,"CLOSE","");

   StringConcatenate(shortname3,"MEDIAN","");

//--- set a label do display in DataWindow

   PlotIndexSetString(0,PLOT_LABEL,shortname1);

   PlotIndexSetString(1,PLOT_LABEL,shortname2); 

   PlotIndexSetString(2,PLOT_LABEL,shortname3); 

//--- set a name to show in a separate sub-window or a pop-up help

   IndicatorSetString(INDICATOR_SHORTNAME,"30 Period Moving Average");

//--- set accuracy of displaying the indicator values

   IndicatorSetInteger(INDICATOR_DIGITS,2);

//---

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

  {

   //--- if the size of price[] is too small

   if(rates_total<30) return(0); // do not calculate or draw anything

   int start;

   if(prev_calculated==0) start=0;  // start filling out MTMBuffer[] and AbsMTMBuffer[] from the 1st index 

   else start=prev_calculated-1;    // set start equal to the last index in the arrays 

   double m =0;

   for(int i=start;i<rates_total;i++)

     {

      double x = ((xxxx [i]-xxxx [i])/(xxxx[i]-xxxx[i])) * xxxx;

      double y = ((xxxx[i]-xxxx[i])/(xxxx[i]-xxxx[i])) * xxxx;

      OpenBuffer[i]=x;

      CloseBuffer[i]=y;

      MedianBuffer[i]=50;

     }

   SimpleMAOnBuffer(rates_total,prev_calculated,0,30,OpenBuffer,OpenMABuffer);

   SimpleMAOnBuffer(rates_total,prev_calculated,0,30,CloseBuffer,CloseMABuffer);

     

//--- 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
Dozens of new automated trading applications appear in the MQL5 Market every day. Choose the right app among 10,000 products and forget about unnecessary routine operations of manual trading. Sell your algorithmic trading programs through the largest store of trading applications! One Click Close The script allows users to easily close...
 
Fix your broken code. You obviously have a divide by zero.
      double y = ((xxxx[i]-xxxx[i])/(xxxx[i]-xxxx[i])) * xxxx;
 
William Roeder:
Fix your broken code. You obviously have a divide by zero.

Assume that xxxx-xxxx  are like high price - low price , so it can't be equal to zero ever. kindly please take another close look , perhaps there is something else ...

 
Forex Analyst: Assume that xxxx-xxxx  are like high price - low price , so it can't be equal to zero ever.
  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 2019.05.06
              Messages Editor

  2. xxxx[i]-xxxx[i] is always zero. You didn't say xxxx[i]-yyyy[i] If you want real help post your real code.

    We can't see your broken code.
    How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

  3. Of course, it can be zero. If you get one tick during the minute chart that is exactly what it will be. There can be minutes between ticks during the Asian session, think M1 chart.

Reason: