i am experience some issue with an indicator that i am working on , can somebody please take a look and tell me why its causing this issue ?
to put it simply the indicator is not refreshing
Explanation: when i attach the indicator to the chart and leave it on, after sometime when i attach another instance of the same indicator with similar parameters then then new indicator shows different lines then the one that was previously attached to the chart even if i dont attach the new indicator , and simply double click on the currently attached indicator and then click on the OK button it changes the lines for the previously drawn candles see the screenshot please
Sometimes the change is too much and sometimes the change is not too much , but there is always some changes , depending on after how many bars i double click and press OK on the indicator
i will highly appreciate if someone can point what am i doing wrong, thanks
Here is my code :
#property copyright ""
#property link ""
#property version ""
#property description ""
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_type1 DRAW_LINE
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
#property indicator_color1 Yellow
#property indicator_label1 "USD"
#property indicator_type2 DRAW_LINE
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
#property indicator_color2 Aqua
#property indicator_label2 "EUR"
//--- indicator buffers
double Buffer1[];
double Buffer2[];
//--- Rsi Value
extern int R_Value = 5;
double myPoint; //initialized in OnInit
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
string per = R_Value;
per = StringConcatenate("RSI(",per,")");
IndicatorShortName(per);
printf(per);
IndicatorBuffers(2);
SetIndexBuffer(0, Buffer1);
SetIndexEmptyValue(0, EMPTY_VALUE);
SetIndexBuffer(1, Buffer2);
SetIndexEmptyValue(1, EMPTY_VALUE);
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 limit = rates_total - prev_calculated;
//--- counting from 0 to rates_total
ArraySetAsSeries(Buffer1, true);
ArraySetAsSeries(Buffer2, true);
//--- initial zero
if(prev_calculated < 1)
{
ArrayInitialize(Buffer1, 0);
ArrayInitialize(Buffer2, 0);
}
else
limit++;
//--- main loop
for(int i = limit-1; i >= 0; i--)
{
if (i >= MathMin(5000-1, rates_total-1-50)) continue;
//Indicator Buffer 1
double EURUSDs=0;
double GBPUSDs=0;
double AUDUSDs=0;
double NZDUSDs=0;
double USDCADs=0;
double USDCHFs=0;
double USDJPYs=0;
EURUSDs = iRSI("EURUSD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
double USD1 = 100-EURUSDs;
GBPUSDs = iRSI("GBPUSD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
double USD2 = 100-GBPUSDs;
AUDUSDs = iRSI("AUDUSD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
double USD3 = 100-AUDUSDs;
NZDUSDs = iRSI("NZDUSD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
double USD4 = 100-NZDUSDs;
double USD5 = iRSI("USDCAD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
double USD6 = iRSI("USDCHF",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
double USD7 = iRSI("USDJPY",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
double USDtotal= (USD1+USD2+USD3+USD4+USD5+USD6+USD7);
double USDtota2= USDtotal/7;
{
Buffer1[i] = USDtota2;
}
//Indicator Buffer 2
EURUSDs=0;
double EURGBPs=0;
double EURJPYs=0;
double EURAUDs=0;
double EURCADs=0;
double EURCHFs=0;
double EURNZDs=0;
double EUR1 = iRSI("EURUSD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
double EUR2 = iRSI("EURGBP",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
double EUR3 = iRSI("EURJPY",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
double EUR4 = iRSI("EURAUD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
double EUR5 = iRSI("EURCAD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
double EUR6 = iRSI("EURCHF",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
double EUR7 = iRSI("EURNZD",PERIOD_CURRENT,R_Value,PRICE_CLOSE,i);
double EURtotal= (EUR1+EUR2+EUR3+EUR4+EUR5+EUR6+EUR7);
double EURtota2= EURtotal/7;
{
Buffer2[i] = EURtota2;
}
}
return(rates_total);
}
I think the issue is that you got to declare all 7 variable of the USD and EUR in a buffer and like this.... and put them in a separate for loop