Using ref function


#1

Can Anyone provide code snippet for previous day high and previous day low using ref function


#2

@sandeep.sd9 The Ref function, Ref( ARRAY, period ) a negative period references "n" periods ago.

http://www.amibroker.com/guide/afl/ref.html

Ref(High, -1);
Ref(Low, -1);

#3

@portfoliobuilder
this code snippet is not giving me the previous day high and previous day low


#4

@sandeep.sd9 it give the previous bar, or previous "period". So if you are using daily bars then it works fine. You did not mention what time frame your data is using?

If you are using intraday data (5 min, 15 min, etc) then you need to learn about MultiTimeFrame functions, https://www.amibroker.com/guide/h_timeframe.html

One possible way to code it would be

PrevDayH = TimeFrameGetPrice( "H", inDaily, -1 );
PrevDayL = TimeFrameGetPrice( "L", inDaily, -1 );

And if you wanted to see it on a chart maybe something like this

Plot( PrevDayH, "PrevDayH", colorBlue, styleLine );
Plot( PrevDayL, "PrevDayL", colorRed, styleLine );

#5

It does on daily bars. You did not say that you use intraday data.

So use timeframe functions

https://www.amibroker.com/guide/afl/timeframegetprice.html

dhi = TimeFrameGetPrice( "H", inDaily, -1 );
dlo = TimeFrameGetPrice( "L", inDaily, -1 );

#6

@fxshrat

i want to generate buy and sell call

if close of any candle is more than previous day high and close of any candle is more than current day high
then generate a buy call
if close of any candle is less than previous day low and close of any candle is less than previous day low
then generate a sell call


#7

@portfoliobuilder
i want to generate buy and sell call

if close of any candle is more than previous day high and close of any candle is more than current day high
then generate a buy call
if close of any candle is less than previous day low and close of any candle is less than previous day low
then generate a sell call


#8

Close of current candle can not be larger than current today's day High and can not be lower than current today's day low.

You would have to compare to previous bar's day high/low.

And BTW you have opened thread on that topic already.


#9

@sandeep.sd9 - you already created the topic on very same matter Afl code to get current day constant value

Creation of multiple topics on same subject by same person is considered SPAM. If you already created topic you should CONTINUE in that topic instead of creating new one. If you do that again your duplicate posts will be deleted. You have been warned.