MQL4 - OnChartEvent (CHARTEVENT_OBJECT_CLICK) - What function should I be using update the template and/or Indicator inputs - so I then can save it?

 

Hi,

 

I am using OnChartEvent > CHARTEVENT_OBJECT_CLICK to change the colour of some text when clicked on, which is working, however when I close MT4 and then open MT4 it has forgot it the change and loaded the default colours from the indicator.

I have tried to save the template using ChartSaveTemplate, but it is not saving the change.


Could someone suggest what function I need to be looking at to, update the template file and/or the indicator inputs, so then I can save the change?


Any help would be gratefully received. :)


Regards,

Gaz

 
GazCBG: however when I close MT4 and then open MT4 it has forgot it the change and loaded the default colours from the indicator.
  1. Why did you post your MT4 question in the MT5 Indicators section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. It did no such thing (unless you don't have Tools → Options (control+O) → Server → Keep personal settings and data at startup checked.
  3. Most likely, you have code (your indicator) that is deleting and recreating your object.
 
William Roeder #:
  1. Why did you post your MT4 question in the MT5 Indicators section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. It did no such thing (unless you don't have Tools → Options (control+O) → Server → Keep personal settings and data at startup checked.
  3. Most likely, you have code (your indicator) that is deleting and recreating your object.

Hi,

Thanks for the reply.

I didn't see the MQL4 secton at the bottom and only saw thje indicator forum,  sorry about that and it will not happen again. I presumed it was a all in one forum which is why I marked it as MQL4

2. I Keep personal settings and data at startup checked.

So, it must be 3, I will take a look at the code and try again, thanks for the reply and sorry for posting in the wrong section :)

If a mod could move it, that be great.

Regards,
Gaz

 

Hi,


I have removed/commented out all of the Object Delete and the problem, hasn't gone away.

I have put all the code below so you can see how I am doing it.

If someone could point me in the right direction that be great.

The idea is if you click on One or Abc which is Level 1 is turns it Aqua and Level 2 to Yellow and the other way around if click on Level 2 which is Two or Def.

The problem I am having, is when I change charts/symbols or time zone (using a chart changer) or close MT4 and Open MT4, it doesn't remember what line should be in Aqua and return both to yellow.

If someone could please, give me some advice of where the issue maybe and then I can take it from there.


#property indicator_chart_window
#property strict
#property show_inputs

extern string STR1 = "------------------------------------------------------------";
extern color lvl1_color = clrYellow; // Lvl 1 ABC Color
extern color lvl2_color = clrYellow; // Lvl 2 DEF Color
extern string STR2 = "------------------------------------------------------------";
extern int window = 0; // Can display in another Window
extern ENUM_BASE_CORNER corner = 0; // Corner to display in
// Stripped out Settings/Inputs not needed for test, have hardcoded them.

int init() {
        IndicatorShortName("TestIndy");
        return(0);
}
int deinit() {
        //ObjectDelete("LVL1_ABC1_v0");
        //ObjectDelete("LVL1_ABC2_v0");
        //ObjectDelete("LVL2_DEF1_v0");
        //ObjectDelete("LVL2_DEF2_v0");
        return(0);
}
int start() {
        //ObjectDelete("LVL1_ABC1_v0");
        ObjectCreate("LVL1_ABC1_v0", OBJ_LABEL, window, 0, 0);
        ObjectSetText("LVL1_ABC1_v0", "One", 9, "Arial Bold", lvl1_color);
        ObjectSet("LVL1_ABC1_v0", OBJPROP_CORNER, corner);
        ObjectSet("LVL1_ABC1_v0", OBJPROP_XDISTANCE, 237);
        ObjectSet("LVL1_ABC1_v0", OBJPROP_YDISTANCE, 20);

        //ObjectDelete("LVL1_ABC2_v0");
        ObjectCreate("LVL1_ABC2_v0", OBJ_LABEL, window, 0, 0);
        ObjectSetText("LVL1_ABC2_v0", "Abc", 9, "Arial Bold", lvl1_color);
        ObjectSet("LVL1_ABC2_v0", OBJPROP_CORNER, corner);
        ObjectSet("LVL1_ABC2_v0", OBJPROP_XDISTANCE, 277);
        ObjectSet("LVL1_ABC2_v0", OBJPROP_YDISTANCE, 40);

        //ObjectDelete("LVL2_DEF1_v0");
        ObjectCreate("LVL2_DEF1_v0", OBJ_LABEL, window, 0, 0);
        ObjectSetText("LVL2_DEF1_v0", "Two", 9, "Arial Bold", lvl2_color);
        ObjectSet("LVL2_DEF1_v0", OBJPROP_CORNER, corner);
        ObjectSet("LVL2_DEF1_v0", OBJPROP_XDISTANCE, 237);
        ObjectSet("LVL2_DEF1_v0", OBJPROP_YDISTANCE, 20);

        //ObjectDelete("LVL2_DEF2_v0");
        ObjectCreate("LVL2_DEF2_v0", OBJ_LABEL, window, 0, 0);
        ObjectSetText("LVL2_DEF2_v0", "Def", 9, "Arial Bold", lvl2_color);
        ObjectSet("LVL2_DEF2_v0", OBJPROP_CORNER, corner);
        ObjectSet("LVL2_DEF2_v0", OBJPROP_XDISTANCE, 277);
        ObjectSet("LVL2_DEF2_v0", OBJPROP_YDISTANCE, 40);
        return(0);
}
void OnChartEvent(const int lvl542, const long& lparam, const double& dparam, const string& sparam) {
        if (lvl542 == CHARTEVENT_OBJECT_CLICK) {
                if (sparam == "LVL1_ABC1_v0" || sparam == "LVL1_ABC2_v0") {
                        lvl1_color = clrAqua;
                        lvl2_color = clrYellow;

                        //ChartSaveTemplate(0,"#default-test1");
                        //ChartApplyTemplate(0, "#default-test1");
                }
                if (sparam == "LVL2_DEF1_v0" || sparam == "LVL2_DEF2_v0") {
                        lvl1_color = clrYellow;
                        lvl2_color = clrAqua;
                }
        }
}


Regards,

Gaz

 
GazCBG #:

Hi,


I have removed/commented out all of the Object Delete and the problem, hasn't gone away.

I have put all the code below so you can see how I am doing it.

If someone could point me in the right direction that be great.

The idea is if you click on One or Abc which is Level 1 is turns it Aqua and Level 2 to Yellow and the other way around if click on Level 2 which is Two or Def.

The problem I am having, is when I change charts/symbols or time zone (using a chart changer) or close MT4 and Open MT4, it doesn't remember what line should be in Aqua and return both to yellow.

If someone could please, give me some advice of where the issue maybe and then I can take it from there.

Create your objects and set their parameters in Init, but only if they do not already exist. Check this with ObjectFind().

In OnChartEvent() just use Object SetInteger() to change the colour if required.