How to change user input values with OnChartEvent and a button in an indicator.
Enau:
How to change input values with OnChartEvent and a button in an indicator.
I don't think you can redo "OnInit" and "OnCalculate".
Why don't you just call the calculation part as a separate 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[]) { // --- return value of prev_calculated for next call if(Init) return(rates_total); Init = true; ReCalculate(); Print("FROM OnCalculate", "_", LOOKBACK, "_", Average); return(rates_total); } // +------------------------------------------------------------------+ void ReCalculate() { Average = 0.0; for(int i = LOOKBACK; i < LOOKBACK + 44; i++) { Average = Average + (Open[i]) / LOOKBACK; } } // +------------------------------------------------------------------+ // | ChartEvent function | // +------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if(!Init) return; if (id == CHARTEVENT_OBJECT_CLICK) { if (sparam == "NAME_BUTTON") { if (LOOKBACK == 99) LOOKBACK = 20; else LOOKBACK = 99; ReCalculate(); Print("FROM OnChartEvent", "_", LOOKBACK, "_", Average); ChartRedraw(0); // ObjectSetInteger(0,"NAME_BUTTON",OBJPROP_COLOR,clrBlack); // ObjectSetInteger(0,"NAME_BUTTON",OBJPROP_BGCOLOR,clrWhite); // ObjectSetInteger(0,"NAME_BUTTON",OBJPROP_BORDER_COLOR,clrBlack); ObjectSetInteger(0, "NAME_BUTTON", OBJPROP_STATE, false); return; } } }
How to change input values with OnChartEvent and a button in an indicator.
I want my indicator to change one of it's user input with a button, then to recalculate everything in OnInit and redo all the loops in OnCalculate, so I create a button, then I change the values of the input in the OnChartEvent, but this value is never passed to the OnInit and OnCalculate. So this code doesnt work
the output is
#BUTTON XLMUSD,Daily: FROM OnChartEvent_99_0.5778444999999999
#BUTTON XLMUSD,Daily: FROM OnChartEvent_99_0.5778444999999999
#BUTTON XLMUSD,Daily: FROM OnCalculate_20_0.5778444999999999
so the Average is never recomputed.