High/Low of the bar previous to the signal bar

#1
Really appreciate if someone can show how to refer high/low of the bar previous to signal bar - with no applystop function.
This can help in calculating position size automatically through afl and could display on screen.
Any help is highly appreciated. Thanks.
 
#2
Dear friend,
I think this is what u r looking for :happy:
Code:
//plotting price
Plot( C,"",colorDefault,styleCandle);

//condition for buying
Buy = Cross( MACD(), Signal() );

//plot a green arrow below the candle on chart when condition is true
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGreen,0,L,-12);

//referring to the previous bar before the condition
bar_before_buy=Ref(Buy,1);

//plot a yellow arrow below that candle
PlotShapes(IIf(bar_before_buy,shapeUpArrow,shapeNone),colorYellow,0,L,-12);

//referring to the previous bar's high before the condition
hh=ValueWhen(bar_before_buy,H);

//referring to the previous bar's low before the condition
ll=ValueWhen(bar_before_buy,L);

//plotting those highs and lows
Plot(hh,"",colorBlue,styleLine|styleDots);
Plot(ll,"",colorViolet,styleLine|styleDots);
:happy:
 
Last edited:
#4
Many thanks!!
However, can you explain how Ref(Buy,1) refers to the previous bar? Would it not look for the bar after the Buy Signal?

Dear friend,
I think this is what u r looking for :happy:
Code:
//plotting price
Plot( C,"",colorDefault,styleCandle);

//condition for buying
Buy = Cross( MACD(), Signal() );

//plot a green arrow below the candle on chart when condition is true
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGreen,0,L,-12);

//referring to the previous bar before the condition
bar_before_buy=Ref(Buy,1);

//plot a yellow arrow below that candle
PlotShapes(IIf(bar_before_buy,shapeUpArrow,shapeNone),colorYellow,0,L,-12);

//referring to the previous bar's high before the condition
hh=ValueWhen(bar_before_buy,H);

//referring to the previous bar's low before the condition
ll=ValueWhen(bar_before_buy,L);

//plotting those highs and lows
Plot(hh,"",colorBlue,styleLine|styleDots);
Plot(ll,"",colorViolet,styleLine|styleDots);
:happy:
 
#7
yes u r right friend,
but when i used ref(buy,-1), the arrow was shown after the condition bar :D
so then i used ref(buy,1) n then it was shown before the condition bar :D
i have no idea how this worked :D
 

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?