Forex Factory (https://www.forexfactory.com/)
-   Platform Tech (https://www.forexfactory.com/forum/69-platform-tech)
-   -   How to place characters JUST above a candle wick on any Timeframe? (https://www.forexfactory.com/thread/234302-how-to-place-characters-just-above-a-candle)

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?

e.g.

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);
SetIndexArrow(3,code[signal[b]]);
//
}
else
{
ObjectSet(text[signal[b]]+" "+sctr, OBJPROP_COLOR, CornflowerBlue);
ObjectSet(text[signal[b]]+" "+sctr, OBJPROP_XDISTANCE, 20);
SetIndexArrow(3,code[signal[b]]);
}
sctr++; Print("Signal[",b,"]=",signal[b]);
}
}

return(0);
}

but the height

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

Not Easy
 
http://www.forexfactory.com/showthre...ow#post3582131

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.

Range=(WindowPriceMax()-WindowPriceMin)/20;

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

ObjectCreate("Arrow",OBJ_ARROW,WindowVal,DateTimeValue,PriceValue+Range);

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;
hi=-9999;lo=9999;
for(int x=0; x<WindowFirstVisibleBar();x++)
{
hi=MathMax(hi,High[x];
lo=MathMin(lo,Low[x];
}
double PercentVar,PriceForObject;
PriceForObject=WhateverYouChoose;
PercentVar=(1/(hi-lo)*(PriceForObject-lo))*100;
NewPriceForObject=PriceForObject/PercentVar*(PercentVar+PercentAboveRequired)
ObjectCreate("Arrow",OBJ_ARROW,WindowVal,DateTimeValue,NewPriceForObject);

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)

BlueMental.

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

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


© Forex Factory