Correction Required to the Indicator Code made in Pine Language

Muhammad Fraz  
Hi,

I would like to ask for help to correct the code. Basically I have made a private indicator in Pine Language. I converted that indicator to mql5. But It shows lots of errors. Due to 0 knowledge in Mql5 language, I stucked and requires Help from Experts. Thanks

Code is here and File is attached as well:

//+------------------------------------------------------------------+
//|                                                   Percentile.mq5 |
//+------------------------------------------------------------------+
#property      description "Percentile"
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Lime
#property indicator_color3 White
#property indicator_color4 Lime

input int LookBackPeriodStandardDeviationHighLow = 22;
input int BollingerBandLength = 20;
input double BollingerBandStandardDeviationUpDown = 2.0;
input int LookBackPeriodPercentileHighLow = 50;
input double HighestPercentileTop = 0.99;
input double HighestPercentileBottom = 0.85;
input double LowestPercentileTop = 1.15;
input double LowestPercentileBottom = 1.01;
input bool ShowMarketTop = true;
input bool ShowMarketBottom = true;
input bool ShowPercentileMeterNormalized = true;
input bool ShowPercentileMeterExtremes = true;

double WVF[];
double WVF2[];
double SDev[];
double SDev2[];
double DiffPMN[];
double DiffPME[];

int OnInit()
{
  SetIndexBuffer(0, WVF);
  SetIndexBuffer(1, WVF2);
  SetIndexBuffer(2, DiffPMN);
  SetIndexBuffer(3, DiffPME);
   
   ArraySetAsSeries(WVF,true);
   ArraySetAsSeries(WVF2,true);
   ArraySetAsSeries(DiffPMN,true);
   ArraySetAsSeries(DiffPME,true);
   
  PlotIndexSetInteger(0, DRAW_HISTOGRAM, STYLE_SOLID, 4, Red);
  PlotIndexSetInteger(1, DRAW_HISTOGRAM, STYLE_SOLID, 4, Lime);
  PlotIndexSetInteger(2, DRAW_LINE, STYLE_SOLID, 1, Lime);
  PlotIndexSetInteger(3, DRAW_LINE, STYLE_SOLID, 1, White);
  IndicatorSetString(0, "Muhammad Fraz Vix Fix For Market Top");
  IndicatorSetString(1, "Muhammad Fraz Vix Fix For Market Bottom");
  IndicatorSetString(2, "Percentile Meter Normalized");
  IndicatorSetString(3, "Percentile Meter Extremes");
  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[])
{
  int limit = rates_total - prev_calculated;
  if (limit <= 0) return(0);
  int i;
  for (i = 0; i < limit; i++)
  {
    WVF[i] = ((iLowest(close, rates_total, LookBackPeriodStandardDeviationHighLow) - high[i]) / (iLowest(close, rates_total, LookBackPeriodStandardDeviationHighLow))) * 100;
    WVF2[i] = ((iHighest(close, rates_total, LookBackPeriodStandardDeviationHighLow) - low[i]) / (iHighest(close, rates_total, LookBackPeriodStandardDeviationHighLow))) * 100;
}

for (i = LookBackPeriodPercentileHighLow; i < rates_total; i++)
{
SDev[i] = iBands(close, BollingerBandLength, BollingerBandStandardDeviationUpDown, MODE_UPPER, i);
SDev2[i] = iBands(close, BollingerBandLength, BollingerBandStandardDeviationUpDown, MODE_LOWER, i);
}

for (i = LookBackPeriodPercentileHighLow; i < rates_total; i++)
{
DiffPMN[i] = (((high[i] - SDev2[i]) / (SDev[i] - SDev2[i])) - LowestPercentileBottom) / (HighestPercentileTop - LowestPercentileBottom);
DiffPME[i] = (((high[i] - SDev2[i]) / (SDev[i] - SDev2[i])) - LowestPercentileBottom) / (HighestPercentileTop - LowestPercentileBottom);
}

for (i = 0; i < rates_total; i++)
{
if (DiffPMN[i] < 0)
{
DiffPMN[i] = 0;
}
if (DiffPMN[i] > 1)
{
DiffPMN[i] = 1;
}
if (DiffPME[i] < 0)
{
DiffPME[i] = 0;
}
if (DiffPME[i] > 1)
{
DiffPME[i] = 1;
}
}

for (i = 0; i < rates_total; i++)
{
if (!ShowMarketTop)
{
WVF[i] = 0;
}
if (!ShowMarketBottom)
{
WVF2[i] = 0;
}
if (!ShowPercentileMeterNormalized)
{
DiffPMN[i] = 0;
}
if (!ShowPercentileMeterExtremes)
{
DiffPME[i] = 0;
}
}

return(rates_total);
}
Files:
Yashar Seyyedin  
Muhammad Fraz:
Hi,

I would like to ask for help to correct the code. Basically I have made a private indicator in Pine Language. I converted that indicator to mql5. But It shows lots of errors. Due to 0 knowledge in Mql5 language, I stucked and requires Help from Experts. Thanks

Code is here and File is attached as well:

You may be lucky and someone helps you. But you should create a freelance order.

One thing to say is you do not access arrays the way you did.

William Roeder  
Muhammad Fraz Due to 0 knowledge in Mql5 language,
  1. You need to learn

    MT4: Learn to code it.
    MT5: Begin learning to code it.

    If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.

  2.   int limit = rates_total - prev_calculated;
      if (limit <= 0) return(0);
      int i;
      for (i = 0; i < limit; i++)

    Decide whether you are reading as series or not. Determine your lookback amounts.
              How to do your lookbacks correctly #9#14 & #19 (2016)

  3.     WVF[i] = ((iLowest(close, rates_total, LookBackPeriodStandardDeviationHighLow) - high[i]) / (iLowest(close, rates_total, LookBackPeriodStandardDeviationHighLow))) * 100;
        WVF2[i] = ((iHighest(close, rates_total, LookBackPeriodStandardDeviationHighLow) - low[i]) / (iHighest(close, rates_total, LookBackPeriodStandardDeviationHighLow))) * 100;
    

    Perhaps you should read the manual. What do iLowest/iHighest return?
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

  4. To define the indexing direction in the time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[] arrays, call the ArrayGetAsSeries() function. In order not to depend on defaults, call the ArraySetAsSeries() function for the arrays to work with.
              Event Handling / OnCalculate - Reference on algorithmic/automated trading language for MetaTrader 5
  5. SDev[i] = iBands(close, BollingerBandLength, BollingerBandStandardDeviationUpDown, MODE_UPPER, i);
    SDev2[i] = iBands(close, BollingerBandLength, BollingerBandStandardDeviationUpDown, MODE_LOWER, i);
    }

    Perhaps you should read the manual, especially the examples.
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
              MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
              How to call indicators in MQL5 - MQL5 Articles (2010)

Muhammad Fraz  
William Roeder #:
  1. You need to learn

    MT4: Learn to code it.
    MT5: Begin learning to code it.

    If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.

  2. Decide whether you are reading as series or not. Determine your lookback amounts.
              How to do your lookbacks correctly #9#14 & #19 (2016)

  3. Perhaps you should read the manual. What do iLowest/iHighest return?
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

  4. Perhaps you should read the manual, especially the examples.
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
              MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
              How to call indicators in MQL5 - MQL5 Articles (2010)

Thanks for your Help. I will learn more.
Reason: