custom indicator drawing problem

 

Hi

I am trying to write a custom indicator. The custom indicator draws a single line between highs of some candles and lows of other candles. However sometimes the line needs to join the low and the high of the same candle. As far as I can see, this cannot be done using a buffer as that appears to restrict me to one plot per candle.

The only way I can think of approaching this is by using ObjectCreate() to manually draw a line between each 2 plots.

Can anyone suggest any other approach to drawing the output other than using ObjectCreate()?

thanks

chris

 
Two buffers
 
WHRoeder:
Two buffers


thanks for the reply WHRoeder.

I had considered 2 buffers. But would this not draw 2 lines when I only want a single one?

To be clear about my requirement, the output indicator is a single "jagged line". If for example it is currently drawn to the high of candle a, it may then join to the high or low of candle b, or may join to the low of candle a before joining to the high or low of candle b.

Please could you elaborate on your answer a little.

chris

 
chrismcdonald: I had considered 2 buffers. But would this not draw 2 lines when I only want a single one?

If you are "join the low and the high" That's two lines.

If you don't want a second line, don't write to the buffer.

 
WHRoeder:

If you are "join the low and the high" That's two lines.

If you don't want a second line, don't write to the buffer.


Hmm - sorry I am just not getting what you are saying here.

So to join the low of a candle with the high of the same candle (ie a vertical line between the low and the high of a single candle), are you telling me I can use 2 buffers? Then I dont understand how to do this. Would it be possible for you to provide a few lines of code to illustrate this please

I do apologise for not understanding your point - maybe I am not understanding a bit of mql4 and how to use buffers - a snippet of code would really be appreciated

chris

 

Lines ines use 1 y co-ordinate per bar, you wont be able to make 1 line buffer draw in two places on 1 bar. Two lines would allow you to end one on open and start a new one on close, but they will not join together. You might be able to make it do that with two buffers and DRAW_SECTION or DRAW_ZIGZAG ...

If you dont understand buffers read creation of custom indicators

Reason: