Handle Buy & Sell Signals on same bar

#1
Hi
I am experimenting with a simple system with following rules:

1.Buy today at close if close is more than open.
2.Sell tomorrow at open if Gaps Up ELSE sell tomorrow at close.


BuyPrice = Close;
SellPrice = IIf(O>Ref(C,-1),O,C);

Buy = C>O;
Sell=Barssince(Buy)==1;


The problem is : if tomorrows close>Open (buy signal ) amibroker Do not sell at Open even if it is a Gap up.which makes it a forward looking system.
I want the system to sell tomorrow at open if Gap UP & again buy at close if Close>Open.
I experimented with exrem & flip but it didnt work for me.

Thanks in advance for any suggestions.
 
#3
Thanks johnnypareek for your reply.
If the solution was to swap the position of buy/sell statements with buyprice/sellprice statements , it didn't work.
Any other clues.
 

asnavale

Well-Known Member
#4
Hi
I am experimenting with a simple system with following rules:

1.Buy today at close if close is more than open.
2.Sell tomorrow at open if Gaps Up ELSE sell tomorrow at close.


BuyPrice = Close;
SellPrice = IIf(O>Ref(C,-1),O,C);

Buy = C>O;
Sell=Barssince(Buy)==1;


The problem is : if tomorrows close>Open (buy signal ) amibroker Do not sell at Open even if it is a Gap up.which makes it a forward looking system.
I want the system to sell tomorrow at open if Gap UP & again buy at close if Close>Open.
I experimented with exrem & flip but it didnt work for me.

Thanks in advance for any suggestions.
Are you using the AFL on intraday data or EOD data?

-Anant
 

DanPickUp

Well-Known Member
#6
What about limit orders placed at any time ?

Is this a solution your Exchange not allows or allows.

If it is not allowed, what kind of reason you have to trade in a country which does any thing to keep away retail traders from trading?

DanPickUp
 

asnavale

Well-Known Member
#7
I am using the afl on EOD data not intraday data.
In that case you can not have this AFL working as you are waiting for the Closing price to take the decision. Today's closing price is available only after market closes (may be about an hour later) and you can not trade after market closes.

-Anant
 
#8
Thanks Anant & DanPickUp for your comments.

Anant : You are correct in pointing out that closing price is available only after market hours.but practically I buy only after 3.25 .Its not perfect ,but I can live with the slippage & occasional wrong trade.
Amibroker do not have any issue in placing the buy order as per conditions , its the sell order which is being goofed up.

DanPickUp : Limit orders are allowed by my exchange.

I am using amibroker to backtest the system & intend to place orders manually.
 

asnavale

Well-Known Member
#9
Thanks Anant & DanPickUp for your comments.

Anant : You are correct in pointing out that closing price is available only after market hours.but practically I buy only after 3.25 .Its not perfect ,but I can live with the slippage & occasional wrong trade.
Amibroker do not have any issue in placing the buy order as per conditions , its the sell order which is being goofed up.

DanPickUp : Limit orders are allowed by my exchange.

I am using amibroker to backtest the system & intend to place orders manually.
You can manually decide at about 3:25PM to take the trade. But AmiBroker running in EOD mode does not know today's prices till EOD data is available and updated. However, if you are feeding Real Time data then you can program Ami to follow your strategy. It is quite easy to write this AFL.

If you are back testing with historical EOD data then it is possible to do the back test, the last candle result would be looking in future.

-Anant
 

Similar threads