The "rates total" is the number of bars for each individual chart, it is out of range cause one chart has more bars than the other ... Print the value of "i" before "calc", then the rates total for the individual charts
Get the symbol with the least amount of bars and only copy what is needed.
//--- input parameters input int Period=14; //--- indicator buffers double PlotBuffer[]; //--- double EURUSD[]; double EURGBP[]; double EURJPY[]; //--- int handleEURUSD; int handleEURGBP; int handleEURJPY; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { if(!SymbolSelect("EURUSD",true) || !SymbolSelect("EURGBP",true) || !SymbolSelect("EURJPY",true)) return(INIT_FAILED); //--- if((handleEURUSD=iCustom("EURUSD",_Period,"overbs.ex5",Period))==INVALID_HANDLE || (handleEURGBP=iCustom("EURGBP",_Period,"overbs.ex5",Period))==INVALID_HANDLE || (handleEURJPY=iCustom("EURJPY",_Period,"overbs.ex5",Period))==INVALID_HANDLE) return(INIT_PARAMETERS_INCORRECT); //--- indicator buffers mapping SetIndexBuffer(0,PlotBuffer,INDICATOR_DATA); ArraySetAsSeries(PlotBuffer,true); //--- ArraySetAsSeries(EURUSD,true); ArraySetAsSeries(EURGBP,true); ArraySetAsSeries(EURJPY,true); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { //--- int totalEURUSD=iBars("EURUSD",_Period); int totalEURGBP=iBars("EURGBP",_Period); int totalEURJPY=iBars("EURJPY",_Period); static int calcEURUSD=0,calcEURGBP=0,calcEURJPY=0; if(BarsCalculated(handleEURUSD)<totalEURUSD || BarsCalculated(handleEURGBP)<totalEURGBP || BarsCalculated(handleEURJPY)<totalEURJPY) return(calcEURUSD=calcEURGBP=calcEURJPY=0); //--- const int toCopy=(prev_calculated<1)?MathMin(rates_total-Period, MathMin(totalEURUSD-Period, MathMin(totalEURGBP-Period,totalEURJPY-Period))): (rates_total!=prev_calculated)?MathMax(rates_total-prev_calculated, MathMax(totalEURUSD-calcEURUSD, MathMax(totalEURGBP-calcEURGBP,totalEURJPY-calcEURJPY))):1; //--- if(CopyBuffer(handleEURUSD,0,0,toCopy,EURUSD)!=toCopy || CopyBuffer(handleEURGBP,0,0,toCopy,EURGBP)!=toCopy || CopyBuffer(handleEURJPY,0,0,toCopy,EURJPY)!=toCopy) return(calcEURUSD=calcEURGBP=calcEURJPY=0); //--- int limit=toCopy-1; //--- for(int i=limit;i>=0 && !IsStopped();i--) PlotBuffer[i]=(EURUSD[i]+EURGBP[i]+EURJPY[i]); //--- calcEURUSD=totalEURUSD; calcEURGBP=totalEURGBP; calcEURJPY=totalEURJPY; //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| Custom Indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { IndicatorRelease(handleEURUSD); IndicatorRelease(handleEURGBP); IndicatorRelease(handleEURJPY); //--- } //+------------------------------------------------------------------+ //--- input parameters input int Period=14; //--- indicator buffers double PlotBuffer[]; int divider=1; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,PlotBuffer,INDICATOR_DATA); divider=StringFind(_Symbol,"JPY")!=-1?100:1; //--- 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[]) { //--- const int begin=(prev_calculated<1)?Period:(rates_total!=prev_calculated)?prev_calculated:prev_calculated-1; //--- double calc; for(int i=begin,n;i<rates_total && !IsStopped();i++) { calc=0.; for(n=0;n<Period;n++) calc+=close[i-n]-open[i-n]; //--- PlotBuffer[i]=calc/divider; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Trapheal:
The "rates total" is the number of bars for each individual chart, it is out of range cause one chart has more bars than the other ... Print the value of "i" before "calc", then the rates total for the individual charts
The "rates total" is the number of bars for each individual chart, it is out of range cause one chart has more bars than the other ... Print the value of "i" before "calc", then the rates total for the individual charts
Thanks, it worked.
Trapheal:
The "rates total" is the number of bars for each individual chart, it is out of range cause one chart has more bars than the other ... Print the value of "i" before "calc", then the rates total for the individual charts
The "rates total" is the number of bars for each individual chart, it is out of range cause one chart has more bars than the other ... Print the value of "i" before "calc", then the rates total for the individual charts
Thank you!
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi, im developing a multi currency indicator, but always give me array out of range
So my problem is where i put double calc = eurusdBuffer[i] + eurjpyBuffer[i].close * 100000; -> In the chart always says that is out of range, but when i put only eurusd doesnt show the error
I have always the currency in observation market and both currency chart open