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
Buy = H > LimitPrice;
// If the Open gaps past the limit price, then enter at the open. Otherwise, enter at the limit.
BuyPrice = Max (Open, LimitPrice);
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
Buy = H > LimitPrice;
// If the Open gaps past the limit price, then enter at the open. Otherwise, enter at the limit.
BuyPrice = Max (Open, LimitPrice);
Sell=0;
ApplyStop( stopTypeLoss, stopModePercent, 5 );
Buy = ExRem(Buy,Sell);
Sell= ExRem(Sell,Buy);
I suggest using an Exploration to see whether the Buy and Sell signals are being generated as you expect. Also, there are many messages here on the forum about using the Equity function to generate Sell signals from the ApplyStop function. Reviewing those may uncover some clues as well.