Forex Factory (
-   Platform Tech (
-   -   How to place characters JUST above a candle wick on any Timeframe? (

f451 Apr 30, 2010 2:19am | Post# 1

How to place characters JUST above a candle wick on any Timeframe?
I can place Objects above candle's wick using ObjectSet with the Price co-ordinate stored in vsa[b] (i.e. based on High[b] or Low[b] as appropriate.
BUT if I add a small gap based on points or a fixed factor, the characters will appear at different distances away from the candles wick depending on the timeframe - because the charts price scale varies.

How can I avoid this?
Get I get the charts current scale?


int DisplaySignal(int b)

if (signal[b] != EMPTY_VALUE)
if (ObjectCreate(text[signal[b]]+" "+sctr, OBJ_ARROW, 0, Time[b], vsa[b]) == true)
ObjectSet(text[signal[b]]+" "+sctr, OBJPROP_ARROWCODE, code[signal[b]]);
if (signal[b] > 2)
ObjectSet(text[signal[b]]+" "+sctr, OBJPROP_COLOR, Crimson);
ObjectSet(text[signal[b]]+" "+sctr, OBJPROP_XDISTANCE, 20);
ObjectSet(text[signal[b]]+" "+sctr, OBJPROP_COLOR, CornflowerBlue);
ObjectSet(text[signal[b]]+" "+sctr, OBJPROP_XDISTANCE, 20);
sctr++; Print("Signal[",b,"]=",signal[b]);


but the height

CodeMeister Apr 30, 2010 2:53am | Post# 2

Not Easy

This is not an easy problem. I eventually solved it by making it a user setting.

BlueMental Apr 30, 2010 8:37am | Post# 3

The Mq4 Blues
You have encountered one of the many Mq4 idiosyncrasies.

One of the ways that almost solves the problem is by setting a range variable.


which then gets added to the value of the height. (Or subtracted if below Low[x])


This gives you an acceptable gap that remains constant, but can also be a headache that needs the divisor variable altered.

If you want to delve deeper into solving this issue, then you do a high/low of bars viewed, and formulate the percentage height of each bars price related to the windows price range, and add a percentage to the objects height value.

double hi,lo;
for(int x=0; x<WindowFirstVisibleBar();x++)
double PercentVar,PriceForObject;

That little formula (the one in bold) puts low as 0 and high as 100.
If however your range changes then the new objects heights vary. But as long as your chart window remains a similar size, it is fine because the range remains the same locally.

In other words when you scroll back, the range goes back to where it was when the object was created.

You can (if you want to use more coding and eat a bit more cpu) reset the heights of all objects within the visible screen (same as the for loop from first visible bar)


f451 May 1, 2010 9:01am | Post# 4

Thank you both!
This one has been driving me nuts.

© Forex Factory