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:

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;
if( PlotTriangles ParamToggle("Triangles","HIDE|SHOW",1) )

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.

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 3.00 out of 5)

2 Responses to “Real-Time Gap-Trading Demo, Basics (v3)”

  1. Martin
    August 16th, 2007 | 8:47 am

    Great results for 30-Years US T-bonds on ECBOT 5 minutes data.
    Do you trade this system?


  2. Herman
    August 16th, 2007 | 10:31 am

    Hi Martin, please note that the commission level in the Setting’s capture was wrong, it should have read 0.005/share (thanks Tomasz). To prevent such errors it is always best to hard-code trading parameters. To make it clear that the code has changed I will from now append a revision number to the post’s title.

    No martin, I don’t trade this system. Be cautious to trade this system in very small timeframes; it will take special techniques to get orders filled. I plan to increase profits by trading 10-20 tickers simultaneously.

    Best regards,