Real-Time Gap-Trading Demo, Basics (v3)

This system was intended to provide signals to demo trade automation. However, its signals are not that frequent and it proved to be quite boring to automate it. The code is left here but I plan to use another system to demo trade automation. You may also note that I separated Real-Time System Design from System Automation. This was done to allow categories to evolve independent from each other.

To develop trade-automation code we need a demo system to generate signals and to test TWS interfacing. To be able to continue this series and not waste time looking for a superb system, I’ll use the following very simple trading rules:

Buy at the Open of the current bar if it falls below the previous Low.
Sell at the Close when the current Low falls below the previous Low.
Short at the Open when the Open exceeds the previous High.
Cover at the Close when the current High exceeds the previous High.

In AFL this looks like this:

SetOption("CommissionMode",3);
SetOption("CommissionAmount"0.005);
SetTradeDelays(0,0,0,0);
Buy &ltRef(L,-1);
BuyPrice O;<br>Sell &ltRef(L,-1);
SellPrice C;<br>Short &gtRef(H,-1);
ShortPrice O;<br>Cover &gtRef(H,-1);
CoverPrice C;
E=Equity(1);<br>Plot(C,"",1,128);
if( PlotTriangles ParamToggle("Triangles","HIDE|SHOW",1) )
{
PlotShapes(IIf(BuyshapeSmallUpTriangleshapeNone),5,0,BuyPrice,0);
PlotShapes(IIf(SellshapeHollowDownTriangleshapeNone),4,0,SellPrice,0);
PlotShapes(IIf(CovershapeHollowUpTriangleshapeNone),5,0,CoverPrice,0);
PlotShapes(IIf(ShortshapeSmallDownTriangleshapeNone),4,0,ShortPrice,0);
}

The above code is a variation of The Full Gap-Trading system. You can read more about this type of system on the Stockcharts site and many other Internet sites.

This system will produce trades in all timeframes, trade frequently, and trade both long and short. Running this system in the 1-15 minute timeframe will give us lots of action and make it easier to develop and debug the Trade-Automation (TA) code. An AT trading system designed around a system that gives only a few signals a day will take forever to debug. Mechanical performance is the first objective.

For now we assume that we can enter at the bar’s Open price. Note that I exit at the Close of the bar because, in the AmiBroker database, this is the next price that is available. At this stage this system is designed to stimulate trade-automation code and not to make you rich; DO NOT TRADE IT. Order types and/or strategies will be decided on later. Trade-Delays are set to zero because they are better handled in the code. The Equity(1) statement is used to remove redundant signals. The indicator should display trades as follows:

Edited by Al Venosa.

Comments are closed.