afl help required

lvgandhi

Well-Known Member
#1
I have an afl which has buy and short conditions. For sell I have a condition as follows
When buy occurs at close price, stoploss is close-low of bar of the bar where buy occurs. Sell to be done either when price goes below buyprice-stoploss points or goes above buyprice+stoplosspoints+brokerage cost.
I have coded as follows
lastBuyPrice = ValueWhen(Buy,BuyPrice,1);
brokeragePoints=5;
stopLossInPoints = abs(LastBuyPrice - Ref(Low,-BarsSince(Buy))); //as i want the stop loss to be the low of the bar i bought at.
BuyExitPrice = LastBuyPrice + stopLossInPoints + brokeragePoints;//earning sl + brokerage will make rest 50% position free
Sell= L<(lastBuyPrice-stopLossInPoints) OR H >BuyExitPrice;
But in chart I see, though in buy candle everything is ok,second candle onwards close of second candle is taken as buyprice and accordingly buyexitprice is calculated.
Request help to correct it. Pictures are attached for candle1,2 and 3.
http://postimage.org/image/aa1d4aksp/
http://postimage.org/image/fp3isxtyb/
http://postimage.org/image/5uo1dox2t/
 

johnnypareek

Well-Known Member
#3
I have an afl which has buy and short conditions. For sell I have a condition as follows
When buy occurs at close price, stoploss is close-low of bar of the bar where buy occurs. Sell to be done either when price goes below buyprice-stoploss points or goes above buyprice+stoplosspoints+brokerage cost.
I have coded as follows
lastBuyPrice = ValueWhen(Buy,BuyPrice,1);
brokeragePoints=5;
stopLossInPoints = abs(LastBuyPrice - Ref(Low,-BarsSince(Buy))); //as i want the stop loss to be the low of the bar i bought at.
BuyExitPrice = LastBuyPrice + stopLossInPoints + brokeragePoints;//earning sl + brokerage will make rest 50% position free
Sell= L<(lastBuyPrice-stopLossInPoints) OR H >BuyExitPrice;
But in chart I see, though in buy candle everything is ok,second candle onwards close of second candle is taken as buyprice and accordingly buyexitprice is calculated.
Request help to correct it. Pictures are attached for candle1,2 and 3.
http://postimage.org/image/aa1d4aksp/
http://postimage.org/image/fp3isxtyb/
http://postimage.org/image/5uo1dox2t/
check after inserting below line before ur buy sell
settradedelays( 0, 0, 0, 0 ) ;
 

Similar threads