# BUY=last price > previous 4 bar hhv

HI everyone . i am new to amibroker and done my work best of my knowledge . I want to genrate Buy = last traded price > previous 4 candle hhv .For Example if last 4 candle hhv is 400 then i want to buy at price 400.05 and if it close to 402 then buy signal created that is the issue .I am stuck with close price . is there any other solution that take buy signal as soon as it comes to 400.05.

``````O1 = Ref(O,-1);O2 = Ref(O,-2);O3 = Ref(O,-3);O4 = Ref(O,-4);
H1 = Ref(H,-1);H2 = Ref(H,-2);H3 = Ref(H,-3);H4 = Ref(H,-4);
L1 = Ref(L,-1);L2 = Ref(L,-2);L3 = Ref(L,-3);L4 = Ref(L,-4);
C1 = Ref(C,-1);C2 = Ref(C,-2);C3 = Ref(C,-3);C4 = Ref(C,-4);

Buy =(O>=H4) AND (O>=H3) AND (O>=H2) AND (O>=H1) OR (C>=H4) AND (C>=H3) AND (C>=H2) AND (C>=H1);
``````

The entry signal (Buy) and the entry price (BuyPrice) are two different things. Something like this should work for you:

``````// Highest price of the previous four bars, excluding the current bar
// Based on your example, you may want to add 0.05 or some other constant to the limit price
LimitPrice = Ref(HHV(H,4), -1);

// Enter on the bar that exceeds the limit price

// If the Open gaps past the limit price, then enter at the open. Otherwise, enter at the limit.
``````
1 Like

HI Mradtke ur suggestion work on HHV . i have seen ur previous comment on trailing stop loss which i add to my alf but it is not working . plz suggest where is the error
``

LimitPrice = Ref(HHV(H,4), -1);

// Enter on the bar that exceeds the limit price

// If the Open gaps past the limit price, then enter at the open. Otherwise, enter at the limit.
Sell=0;
ApplyStop( stopTypeLoss, stopModePercent, 5 );

Since you have no Sell signals, you won’t be able to use ExRem like that. What is it that you’re trying to accomplish?

Hello Mradtke as U suggested i have made my all effort but not getting proper buy and sell signal . plz help to run this Alf . ``````_SECTION_BEGIN;

LimitPrice = Ref(HHV(H,4), -1);