AFL help for a simple strategy

#1
Hi,

I am new to AmiBroker and I require some help with AFL in coding a simple strategy. I want to create the most basic form of a Bullish Engulfing strategy.

Buy on tomorrow's Open when:
- Today's Close > Previous day's Open
- Today's Open < Previous day's Close

Sell on Open after holding on the 7th day (inclusive of Buy Day).

Here is what I have done:

1) Analysis Tab > Settings > Trades
- Set Buy Price = Open, Sell Price = Open
- Set Buy Delay = 0, Sell Delay = 0

2) AFL Script:
Buy = Close > Ref(Open, -1) AND Open < Ref(Close, -1);
Sell = BarsSince(Buy)== 6;

Is this correct? What is the difference between using "Sell = BarsSince(Buy)== 6;" and "Sell = ApplyStop( stopTypeNBar, stopModeBars, 6 );" ?

When I show arrows for actual trades and look at the buy and exit signals, they are not reflecting what I have in mind. The entry signals and exit signals are wrong.

Is there anything wrong with my AFL? Can someone kindly help me out here. Thanks!
 

mastermind007

Well-Known Member
#2
Hi,

I am new to AmiBroker and I require some help with AFL in coding a simple strategy. I want to create the most basic form of a Bullish Engulfing strategy.

Buy on tomorrow's Open when:
- Today's Close > Previous day's Open
- Today's Open < Previous day's Close

Sell on Open after holding on the 7th day (inclusive of Buy Day).

Here is what I have done:

1) Analysis Tab > Settings > Trades
- Set Buy Price = Open, Sell Price = Open
- Set Buy Delay = 0, Sell Delay = 0

2) AFL Script:
Buy = Close > Ref(Open, -1) AND Open < Ref(Close, -1);
Sell = BarsSince(Buy)== 6;

Is this correct? What is the difference between using "Sell = BarsSince(Buy)== 6;" and "Sell = ApplyStop( stopTypeNBar, stopModeBars, 6 );" ?

When I show arrows for actual trades and look at the buy and exit signals, they are not reflecting what I have in mind. The entry signals and exit signals are wrong.

Is there anything wrong with my AFL? Can someone kindly help me out here. Thanks!

"Sell = ApplyStop( stopTypeNBar, stopModeBars, 6 );" will not even compile.
 
#3
"Sell = ApplyStop( stopTypeNBar, stopModeBars, 6 );" will not even compile.
May I know why? I do not have any programming background. Another question, why does "Sell = BarSince(Buy) == 6;" not work well? When I look at the chart, the Sell signal is not 7 days (inclusive of Buy Day) away from the Buy Day. The Sell signal can sometimes be more than 10 days away. However I managed to use another method by going to the settings and set the N-Bar Stop to 6 and checking the "Has Priority" box. Is this the correct way of doing it?
 

Similar threads