EA draws Trendline only in the timeframe it is started in, not in other timeframes?

 

I drag and drop my EA onto M30 timeframe in main window 0. This window has also timeframes H4 H1 M15 M5 opened (tabs on the bottom). EA can draw Trendline in M30:


But when I try to draw Trendline in other timeframe like M15 M5, they are not visible there (after I click proper tab).


QLine="lineM5-"+curTime;
ObjectCreate(QLine,OBJ_TREND,0,lastQTimeM5,lastQTickM5,curTime,curTick);
ObjectSet(QLine,OBJPROP_WIDTH,2);
ObjectSet(QLine,OBJPROP_STYLE,1);
ObjectSet(QLine,OBJPROP_RAY,0);
ObjectSet(QLine,OBJPROP_STYLE,STYLE_SOLID);
ObjectSet(QLine,OBJPROP_TIMEFRAMES,OBJ_PERIOD_M5);

that's the code to draw on M5...

Actually Trendline appears in M30 ObjectList, with timeframe M5 checked:


But in M5 ObjectList this line does NOT exist! so:

How to make EA to draw in timeframes, different from the one it was dropped to?

What's happening with init() deinit() when I'm clicking those H4 H1 M15 M5 tabs on the bottom of window 0 - should I put some code into init() deinit()?

thanks!

 
Konst9127:

But in M5 ObjectList this line does NOT exist! so:

How to make EA to draw in timeframes, different from the one it was dropped to?

What's happening with init() deinit() when I'm clicking those H4 H1 M15 M5 tabs on the bottom of window 0 - should I put some code into init() deinit()?



Each chart has it's own set of Objects, if an EA or Indicator draws an object on the M5 chart that Object only appears on the M5 chart, if you want it drawn on the M15 chart you have to run the EA or Indicator on that chart too. If you wan the trend line to appear on the chart when you change the timeframe on the chart from M5 to M15 you need to remove this line of code . . .

ObjectSet(QLine,OBJPROP_TIMEFRAMES,OBJ_PERIOD_M5);

Please use this to post code . . . it makes it easier to read.

 
RaptorUK: you need to remove this line of code . . .

And the start/end points must be different bars on the higher TFs (MT4 will not show a trendline of width zero.)
 
RaptorUK:


Each chart has it's own set of Objects, if an EA or Indicator draws an object on the M5 chart that Object only appears on the M5 chart, if you want it drawn on the M15 chart you have to run the EA or Indicator on that chart too. If you wan the trend line to appear on the chart when you change the timeframe on the chart from M5 to M15 you need to remove this line of code . . .


Thank you! so if I have 5 charts open H4 H1 M30 M15 M5 in the same window 0, I have to run 5 instances of EA... is it kind of waist of computer resources? Because single EA instance watches all 5 timeframes, opens/closes trades based on information from all 5 timeframes.. just can't draw onto 4 charts. Ok, that's still manageable.

But I didn't get the last phrase, which contradicts with all above: " If you want the trend line to appear on the chart when you change the timeframe on the chart from M5 to M15 you need to remove this line of code " - do you mean "when I'm clicking M5 tab with a mouse, while EA continues working on M30"? or when EA (working on M30) tries to draw on M5 (which is impossible as per above)?

Apparently, I didn't use this line in the past at all:

ObjectSet(QueLine,OBJPROP_TIMEFRAMES,OBJ_PERIOD_M5);

and Trendline appeared with "Show on all the timeframes" checked, - still on M30 only.

 
WHRoeder:

And the start/end points must be different bars on the higher TFs (MT4 will not show a trendline of width zero.)

interesting.. I thought it draws Trendline between

datetime time1, double price1,      datetime time2=0, double price2=0

as per MQL4 Reference, not between bars

 
Konst9127:

Thank you! so if I have 5 charts open H4 H1 M30 M15 M5 in the same window 0, I have to run 5 instances of EA... is it kind of waist of computer resources? Because single EA instance watches all 5 timeframes, opens/closes trades based on information from all 5 timeframes.. just can't draw onto 4 charts. Ok, that's still manageable.

But I didn't get the last phrase, which contradicts with all above: " If you want the trend line to appear on the chart when you change the timeframe on the chart from M5 to M15 you need to remove this line of code " - do you mean "when I'm clicking M5 tab with a mouse, while EA continues working on M30"? or when EA (working on M30) tries to draw on M5 (which is impossible as per above)?

Apparently, I didn't use this line in the past at all:

and Trendline appeared with "Show on all the timeframes" checked, - still on M30 only.


Each chart has it's own window 0, it can also have sub windows, some indicator draw in a sub window below the main one. In the images you posted you show that you have 5 charts open . . . these charts are all separate just as if they were different currency pairs.

What I was talking about in the line you quoted is that if you go to one of your charts, say M5 and change it's timeframe to H1 you will see the Trend Line on the same chart that is now showing H1 if you remove that last line of code.

What WHRoeder is talking about is this . . . if you draw a Trend Line on M5 and it starts at 13:05 and ends at 13:50 it spans 10 bars on M5, but the same time range on H1 is all within the 13:00 H1 bar . . . so although the Trend Line is still there on H1 it is drawn from 13:00 to 13:00 and will not be visible.

 

Got it - and it works!

I guess if my EA on one chart desperately needs to draw onto another chart, I have to use GlobalVariable* functions to exchange data between EAs on those charts..

Thank you both!

Reason: