Newbie Trying To Make Simple Indicator

Hi,

Newbie here.

I want to make simple indicator but error. I’m stuck. Actually this is my first indi to make.

Formula :

Indicator Signal = ((Highest Hi previous 10 period - Lowest Low previous 10 period) / 3) + Lowest Low previous 10 period

Anyone can help me?

//+------------------------------------------------------------------+
//|                                                     310-indi.mq5 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Signal
#property indicator_label1  "Signal"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         SignalBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,SignalBuffer,INDICATOR_DATA);
  
   
//---
   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[])
  {
//---

double HH[], LL[], Range [];

ArraySetAsSeries(HH,true);
ArraySetAsSeries(LL,true);
ArraySetAsSeries(Range,true);


int i;
for(i=prev_calculated;i<rates_total;i++)
{

HH[i]  = ArrayMaximum (high,0,11);
LL[i] = ArrayMinimum (low,0,11);
Range[i] = round((HH[i]-LL[i])/3);
double newLL = LL[i]+Range[i];

SignalBuffer[i] = newLL;
}
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

There are so much problems in such a little code. You need to learn, see this to start.

https://www.mql5.com/en/forum/6202

Tq…I already add buffer…

But how to get Higher high in previous 10 data? Help me… my loop problem…

You don’t need CopyHigh/CopyLow as you already have all history available as OnCalculate() parameters.

ArrayMaximum/ArrayMinimum is the correct way (though not the fastest solution to apply it on each candle, but forget that for now). However you have to pay attention to the indexing, in MT5 arrays/buffers are not indexed as series by default (see ArraySetAseries()). Also these functions returns an index not the maximum itself.

int highest  = ArrayMaximum (high,i,10);

HH[i]=high[highest];

Ty all…I almost finish…but only fail at line:

CL[bar]= close[ArrayMinimum(close,bar-i,10)];

“Error : Array Out of Range

Why this happen?

Wrong parameters and your ArrayMinimum() returns -1 as a result. Check the parameters for the function call