My indicator draws multiple pair's daily percetage change as line in the indicator window.
However I noticed a very weird problem, that the value are sometimes wrong as the ticks goes by on chart, but if I refresh or reload the indicator,
the value goes back to the correct value. But this does not happen in the strategy tester using everytick mode, everything is correct there when I ran the indicator.
You could see this happening if you put it on the M1 chart and let it tick for a few bars then reload the indicator.
Have anyone ever encounter such problem? Any help would be appreciated. Thanks in Advance.
Below are the codes:
Code: Select all
#property strict
#property indicator_separate_window
#property indicator_buffers 7
extern string NNN = "---------------Color Settings----------------"; //-
extern color Line1 = clrDodgerBlue; //Line 1 Color
extern color Line2 = clrLime; //Line 2 Color
extern color Line3 = clrRed; //Line 3 Color
extern color Line4 = clrWheat; //Line 4 Color
extern color Line5 = clrGold; //Line 5 Color
extern color Line6 = clrDeepPink; //Line 6 Color
extern color Line7 = clrPurple; //Line 7 Color
double DP1[], DP2[], DP3[], DP4[], DP5[], DP6[], DP7[];
string Pair1, Pair2, Pair3, Pair4, Pair5, Pair6, Pair7;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true);
IndicatorBuffers(7);
IndicatorDigits(5);
Pair1 = "EURUSD"; Pair2 = "EURGBP"; Pair3 = "EURJPY"; Pair4 = "EURCAD"; Pair5 = "EURAUD"; Pair6 = "EURNZD"; Pair7 = "EURCHF";
SetIndexBuffer(0, DP1);
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 1, Line1);
SetIndexLabel(0, Pair1);
SetIndexBuffer(1, DP2);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 1, Line2);
SetIndexLabel(1, Pair2);
SetIndexBuffer(2, DP3);
SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 1, Line3);
SetIndexLabel(2, Pair3);
SetIndexBuffer(3, DP4);
SetIndexStyle(3, DRAW_LINE, STYLE_SOLID, 1, Line4);
SetIndexLabel(3, Pair4);
SetIndexBuffer(4, DP5);
SetIndexStyle(4, DRAW_LINE, STYLE_SOLID, 1, Line5);
SetIndexLabel(4, Pair5);
SetIndexBuffer(5, DP6);
SetIndexStyle(5, DRAW_LINE, STYLE_SOLID, 1, Line6);
SetIndexLabel(5, Pair6);
SetIndexBuffer(6, DP7);
SetIndexStyle(6, DRAW_LINE, STYLE_SOLID, 1, Line7);
SetIndexLabel(6, Pair7);
//---
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 ExtCountedBars=IndicatorCounted();
if (ExtCountedBars<0) return(-1);
int pos;
int limit=1000; //Past 1000 Bar only
if(ExtCountedBars>2) limit=Bars-ExtCountedBars-1;
pos=limit;
for(int t=0; t<=limit; t++)
{
int mtfBar = iBarShift(_Symbol, PERIOD_D1, Time[t]);
double Open1 = iOpen(Pair1, PERIOD_D1, mtfBar); double Close1 = iClose(Pair1, _Period, t);
double Open2 = iOpen(Pair2, PERIOD_D1, mtfBar); double Close2 = iClose(Pair2, _Period, t);
double Open3 = iOpen(Pair3, PERIOD_D1, mtfBar); double Close3 = iClose(Pair3, _Period, t);
double Open4 = iOpen(Pair4, PERIOD_D1, mtfBar); double Close4 = iClose(Pair4, _Period, t);
double Open5 = iOpen(Pair5, PERIOD_D1, mtfBar); double Close5 = iClose(Pair5, _Period, t);
double Open6 = iOpen(Pair6, PERIOD_D1, mtfBar); double Close6 = iClose(Pair6, _Period, t);
double Open7 = iOpen(Pair7, PERIOD_D1, mtfBar); double Close7 = iClose(Pair7, _Period, t);
DP1[t] = ((Close1-Open1)/Open1*100);
DP2[t] = ((Close2-Open2)/Open2*100);
DP3[t] = ((Close3-Open3)/Open3*100);
DP4[t] = ((Close4-Open4)/Open4*100);
DP5[t] = ((Close5-Open5)/Open5*100);
DP6[t] = ((Close6-Open6)/Open6*100);
DP7[t] = ((Close7-Open7)/Open7*100);
}
//--- return value of prev_calculated for next call
return(rates_total);
}