Placing indicator arrows at fixed offset (like builtin fractals)

 

hi!

i have written an indicator which places arrows either above/below some candles as indicators of sell/buy opportunities. i want these arrows to be placed at a constant (screen or pixel) offset from the high/low of the candle. what i am trying to achieve is precisely what you get with the builtin fractal indicator: the fractal arrows are always at a fixed (screen) distance from the candles, regardless of the time frame or the zoom level. a possible approach is to use an offset which is based on a number of points but which scales according to time frame and zoom level. how to do this is not clear and i am pretty sure that it would be a very big hammer to hit a rather small nail. can anybody point me to a simpler solution?

thanks, andrew. 

 
  1. Do it exactly like fractals does - no offset at all. Fractals - MQL4 Code Base
  2. Do it exactly like Fractal ZigZag (never repaints) - MQL4 Code Base offset based on Period()



 
WHRoeder:
  1. Do it exactly like fractals does - no offset at all. Fractals - MQL4 Code Base
  2. Do it exactly like Fractal ZigZag (never repaints) - MQL4 Code Base offset based on Period()



I'm trying to solve the same problem as collierab. But the examples given so far above haven't helped.
 
yucelh: But the examples given so far above haven't helped.
How can working examples not help? Did you bother to try them? If you did, your code is broken.
 
WHRoeder:
How can working examples not help? Did you bother to try them? If you did, your code is broken.

Yes, I looked through the examples, didn't help.

Example 1) Do as fractals does, no offset at all. How is that helpful? We would like an offset. Giving an example with no offset is useless.

Example 2) Use Period(). Defined as "Returns the amount of minutes determining the used period (chart timeframe)." How is that going to provide a vertical offset for an indicator?

Please try to understand the problem first. 

 
WHRoeder:
How can working examples not help? Did you bother to try them? If you did, your code is broken.


i have also had a look at the examples that you suggest.

1. the fractals code provided does not produce the same output as the builtin fractals indicator. there is no gap between the "dots" (as opposed to arrows for the builtin) and the corresponding bars. the image displayed on that page is misleading: it depicts the builtin fractals indicator which does not look like the code provided.

2. the FractalZigZagNoRepaint.mq4 indicator provides a reasonable solution, using a simple lookup table to provide different offsets for different period charts. this works fairly well across a range of time scales on EURUSD, but there is still some variability in the size of the offset and it breaks rather badly when you try it on USDJPY.

so, thanks for the suggestions, but these do not solve the problem. i am still looking for a robust way to offset these arrows, preferably by a specific number of pixels rather than a number of points. thanks, andrew. 

 
collierab:


i have also had a look at the examples that you suggest.

1. the fractals code provided does not produce the same output as the builtin fractals indicator. there is no gap between the "dots" (as opposed to arrows for the builtin) and the corresponding bars. the image displayed on that page is misleading: it depicts the builtin fractals indicator which does not look like the code provided.

2. the FractalZigZagNoRepaint.mq4 indicator provides a reasonable solution, using a simple lookup table to provide different offsets for different period charts. this works fairly well across a range of time scales on EURUSD, but there is still some variability in the size of the offset and it breaks rather badly when you try it on USDJPY.

so, thanks for the suggestions, but these do not solve the problem. i am still looking for a robust way to offset these arrows, preferably by a specific number of pixels rather than a number of points. thanks, andrew. 

You cannot. Arrows are placed by time and price not pixels,  you can find the size of the window in pixels and the size of the window in price and scale the price to offset  . . .  but if the chart scale is adjusted manually or automatically as price changes you will have to re-adjust the offset to maintain the same pixel gap. 
 
RaptorUK:
You cannot. Arrows are placed by time and price not pixels,  you can find the size of the window in pixels and the size of the window in price and scale the price to offset  . . .  but if the chart scale is adjusted manually or automatically as price changes you will have to re-adjust the offset to maintain the same pixel gap. 


hi raptoruk,

thanks for clarifying that. okay, so i have settled on a plan to use WindowPriceMin() and WindowPriceMax() to choose an appropriate offset. this seems to work really well. BUT there is one small snag: the values returned by these functions appear not to be updated. this is what i mean: if i start off on M5 chart, the min/max values that i get are not correct. if i change to the M15 chart then, once again, the min/max values are not correct for the current (M15) chart, however they are precisely the correct ones for the previous (M5) chart. is there something that i need to do to get these values to update properly? i have tried introducing a 2 second delay into init() because i thought that it might take the platform a moment to catch up with what has happened to the windows, but this does not solve the problem.

final note: if i remove the indicator and then re-attach it to the chart then the initial min/max values are 100% correct. however, as soon as i shift time frames i end up in the same situation as before. 

thanks, andrew. 

 
collierab:


hi raptoruk,

thanks for clarifying that. okay, so i have settled on a plan to use WindowPriceMin() and WindowPriceMax() to choose an appropriate offset. this seems to work really well. BUT there is one small snag: the values returned by these functions appear not to be updated. this is what i mean: if i start off on M5 chart, the min/max values that i get are not correct. if i change to the M15 chart then, once again, the min/max values are not correct for the current (M15) chart, however they are precisely the correct ones for the previous (M5) chart. is there something that i need to do to get these values to update properly? i have tried introducing a 2 second delay into init() because i thought that it might take the platform a moment to catch up with what has happened to the windows, but this does not solve the problem.

final note: if i remove the indicator and then re-attach it to the chart then the initial min/max values are 100% correct. however, as soon as i shift time frames i end up in the same situation as before. 

thanks, andrew. 

Read them in start() not just in init()
 

thanks, but i am doing that already. here is the basic outline of the indicator (just showing where i am getting the window data):

double GAP;

int init()
{
}

int deinit()
{
}

int start()
{   
   GAP = (WindowPriceMax() - WindowPriceMin()) * 0.1;
   Print(WindowPriceMax(0), " ", WindowPriceMin(0), " ", DoubleToStr(GAP, Digits));
}
 
collierab:

thanks, but i am doing that already. here is the basic outline of the indicator (just showing where i am getting the window data):

I found that WindowPriceMin() and Max did not update if MT4 was minimized to the task bar . . .  other than that I found it worked.

The following Indicator,  based on your code, seems to work for me . . .  what do you get ? 

Reason: