Update or delete line

To add comments, please log in or register
marketcycle17
75
marketcycle17  

Hi

I have an indicator that draws a line at candle open of 1h timeframe. Then I switch to 5min timeframe. When 1h candle is closed and price moves, the line that has been drawn previously is not deleted and a new one is drawn (still in 5 min tf). How can I delete it and recreate it? or rather update it? (for update i would need to check when 1hour candle is closed before update. don't know how to do it)

Indicator is attached.

Files:
Vladimir Karputov
Moderator
216458
Vladimir Karputov  

Try this:

   int pos=prev_calculated-1;
   if(prev_calculated=0)
      pos=0;
marketcycle17
75
marketcycle17  
Vladimir Karputov:

Try this:

I tried it but still doesn't work.

Seng Joo Thio
1774
Seng Joo Thio  
marketcycle17:

I tried it but still doesn't work.

Since you're drawing the entire line, you can just set i to start from 0... don't need the pos variable.

But bear in mind that your indicator goes through everything (including copyrates and update line buffer) every tick, which is unnecessary... consider adding time check, or simply add:

if (rates_total==prev_calculated)
   return (rates_total);

before your first line in OnCalculate().

marketcycle17
75
marketcycle17  

I tried that too, doesn't work either :)

I made a screenshot just to describe better what happens, see attachment.

As you can see, it's on the 1min timeframe, but i made the indicator to draw based on 5min-candle. For every 5 candles a new line is drawn and that's just as it is meant to do. But the previous line is not removed and there are also slanting lines that connects the horisontal lines (which should be removed too). Problem is it just doesn't update. But if I rightclick on the chart and choose Refresh then chart refreshes and all previous lines are removed while a new one is drawn.

It is meant to autodraw every time one 5min candle has closed and a new one has opened and autoremove previous lines.
Files:
openlevel.png 30 kb
Seng Joo Thio
1774
Seng Joo Thio  
marketcycle17:

I tried that too, doesn't work either :)

I don't know what you tried, but I'm sure you didn't read my post or implement my suggestion correctly. Because this is what I get:

BEFORE:

AFTER:



amando
2984
amando  
Delete the line in ondeinit
marketcycle17
75
marketcycle17  
Seng Joo Thio:

I don't know what you tried, but I'm sure you didn't read my post or implement my suggestion correctly. Because this is what I get:

BEFORE:

AFTER:



Probably I didn't implement it correctly. I don't know much about MQL programming, niether about adding time check. Could you write the code in the file I attached and upload it? I would greatly appreciate it.

Seng Joo Thio
1774
Seng Joo Thio  
marketcycle17:

Probably I didn't implement it correctly. I don't know much about MQL programming, niether about adding time check. Could you write the code in the file I attached and upload it? I would greatly appreciate it.

Just change:

   int pos=prev_calculated-1;
   if(pos<0) pos=0;

   for(int i=pos; i<rates_total; i++)

to:

   for(int i=0; i<rates_total; i++)

And add the time check lines I mentioned in my earlier post (affects efficiency rather than functionality).

marketcycle17
75
marketcycle17  
Thank you so much, it works great!
Fabio Cavalloni
9663
Fabio Cavalloni  
Seng Joo Thio:

Just change:

to:

And add the time check lines I mentioned in my earlier post (affects efficiency rather than functionality).

With you suggestion for each new tick the indicator recalculates all candles.
This is not a solution, this is the beginning of a lots of other issues, like the indicator calculation speed
12
To add comments, please log in or register