Inidicator deinitialisation after timeframe change - how to keep values for graphical object (HLINE)?
Hello all,
just wondering, if this is possible in MT5:
In an indicator I create a horizontal line.
Whenever this line is moved, the new price value is stored and can be obtained from an underlying object.
The line's name is created dynamically using the current time.
Unfortunately, whenever the timeframe is changed, OnDeinit() is called and the line is created again and the former price value is lost.
Which is the preferred way keeping information even OnDeinit() is called for an indicator? Or would that be impossible?
Thanks!
z3tr4d3r
The blue colored words is a link, click it please.
1. Yes you can create a horizontal line using Object Functions and specify OBJ_HLINE in ObjectCreate .
2. Yes, you can get the the price value from that object line by specifying OBJPROP_PRICE in ObjectGetDouble function.
3. Yes, you can create it's name dynamically - actually, if there are more than one object, you must create those lines using different names. You can get it's name using ObjectsTotal and ObjectName.
4. Fortunately you can save those object name, values, etc using File Functions
The blue colored words is a link, click it please.
1. Yes you can create a horizontal line using Object Functions and specify OBJ_HLINE in ObjectCreate .
2. Yes, you can get the the price value from that object line by specifying OBJPROP_PRICE in ObjectGetDouble function.
3. Yes, you can create it's name dynamically - actually, if there are more than one object, you must create those lines using different names. You can get it's name using ObjectsTotal and ObjectName.
4. Fortunately you can save those object name, values, etc using File Functions
Thanks very much for your detailed answer!
1. Yes you can create a horizontal line using Object Functions and specify OBJ_HLINE in ObjectCreate .
2. Yes, you can get the the price value from that object line by specifying OBJPROP_PRICE in ObjectGetDouble function.
3. Yes, you can create it's name dynamically - actually, if there are more than one object, you must create those lines using different names.
I see - what I did was using a class (in the *.mqh file) that subclassed CChartObjectHLine. Here I used the standard Create(...) method to create the horizontal line.
In the indicator file (*.mq5) I created an instance of the custom class using the 'new' operator and did not delete the instance when the symbol/timeframe chart event occurred. This b.t.w. leads to a warning about leaked memory, which is ok I guess as long I take care of deleting the instance in case the indicator or the line qet deleted.
4. Fortunately you can save those object name, values, etc using File Functions
Ok, I see, then I go this way and learn a bit :-)
Thanks again for your help!
Ok, I see, then I go this way and learn a bit :-)
I got stuck and guess this is because of a design bug not allowing passing properties of graphical objects when the timeframe is changed.
The indicator I'd like to use is as simple as you can imagine: It should just draw a line and do some action if the price level of the line was hit.
Problem is now: The Hline will be moved after first initalisation the price level gets internally stored (in a surrounding class object). If I switch to another timeframe, the price value is not stored (actually even if the surrounding class object is created with the 'new' operator) as it get's re-initialised.
If I would store the price level in a file and then re-initialize the price value in OnInit() - how could I differentiate between the creation of a new line (here: a third line) and the need of creating a new line?
IMHO it would be very handy being able to skip the timeframe change based reinitialisation for an indicator, e.g. with an INDICATOR_IGNORE_TIMEFRAME_CHANGE property.
Any more hints?
int OnInit(void) { ... if (GlobalVariableCheck("line000") == true) { GlobalVariableGet("line000", value); .... GlobalVariableDel("line000");}
... } void OnDeinit(const int reason) { if (reason == REASON_CHARTCHANGE) GlobalVariableSet("line000", value); .... }
What I rather need - the more I think of it, it seems to be more obvious - are extensible graphical objects.
Any more hints?
prego ;),
you should consider the naming possibilities:
string name = MQL5InfoString(MQL5_PROGRAM_NAME) + "_" + _Symbol+ "_line" + IntegerToString(count) + "_" + TimeToString(scannedDateLast, TIME_DATE); GlobalVariableSet(name, value);

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello all,
just wondering, if this is possible in MT5:
In an indicator I create a horizontal line.
Whenever this line is moved, the new price value is stored and can be obtained from an underlying object.
The line's name is created dynamically using the current time.
Unfortunately, whenever the timeframe is changed, OnDeinit() is called and the line is created again and the former price value is lost.
Which is the preferred way keeping information even OnDeinit() is called for an indicator? Or would that be impossible?
Thanks!
z3tr4d3r