{"id":963,"date":"2007-08-15T17:00:27","date_gmt":"2007-08-15T17:00:27","guid":{"rendered":"http:\/\/www.amibroker.org\/userkb\/2007\/08\/15\/real-time-gap-trading-demo-basics\/"},"modified":"2007-10-19T21:39:42","modified_gmt":"2007-10-19T21:39:42","slug":"real-time-gap-trading-demo-basics","status":"publish","type":"post","link":"http:\/\/www.amibroker.org\/editable_userkb\/2007\/08\/15\/real-time-gap-trading-demo-basics\/","title":{"rendered":"Real-Time Gap-Trading Demo, Basics (v3)"},"content":{"rendered":"
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.<\/p>\n
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:<\/p>\n
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.<\/p>\n
In AFL this looks like this:<\/p>\n
SetOption<\/span>(<\/span>"CommissionMode"<\/span>,<\/span>3<\/span>);\r<\/span>SetOption<\/span>(<\/span>"CommissionAmount"<\/span>, <\/span>0.005<\/span>);\r<\/span>SetTradeDelays<\/span>(<\/span>0<\/span>,<\/span>0<\/span>,<\/span>0<\/span>,<\/span>0<\/span>);\r<\/span>Buy <\/span>= <\/span>O <\/span>&<\/span>lt<\/span>; <\/span>Ref<\/span>(<\/span>L<\/span>,-<\/span>1<\/span>);\r<\/span>BuyPrice <\/span>= <\/span>O<\/span>;<<\/span>br<\/span>><\/span>Sell <\/span>= <\/span>L <\/span>&<\/span>lt<\/span>; <\/span>Ref<\/span>(<\/span>L<\/span>,-<\/span>1<\/span>);\r<\/span>SellPrice <\/span>= <\/span>C<\/span>;<<\/span>br<\/span>><\/span>Short <\/span>= <\/span>O <\/span>&<\/span>gt<\/span>; <\/span>Ref<\/span>(<\/span>H<\/span>,-<\/span>1<\/span>);\r<\/span>ShortPrice <\/span>= <\/span>O<\/span>;<<\/span>br<\/span>><\/span>Cover <\/span>= <\/span>H <\/span>&<\/span>gt<\/span>; <\/span>Ref<\/span>(<\/span>H<\/span>,-<\/span>1<\/span>);\r<\/span>CoverPrice <\/span>= <\/span>C<\/span>;\r<\/span>E<\/span>=<\/span>Equity<\/span>(<\/span>1<\/span>);<<\/span>br<\/span>><\/span>Plot<\/span>(<\/span>C<\/span>,<\/span>""<\/span>,<\/span>1<\/span>,<\/span>128<\/span>);\rif( <\/span>PlotTriangles <\/span>= <\/span>ParamToggle<\/span>(<\/span>"Triangles"<\/span>,<\/span>"HIDE|SHOW"<\/span>,<\/span>1<\/span>) )\r{\r<\/span>PlotShapes<\/span>(<\/span>IIf<\/span>(<\/span>Buy<\/span>, <\/span>shapeSmallUpTriangle<\/span>, <\/span>shapeNone<\/span>),<\/span>5<\/span>,<\/span>0<\/span>,<\/span>BuyPrice<\/span>,<\/span>0<\/span>);\r<\/span>PlotShapes<\/span>(<\/span>IIf<\/span>(<\/span>Sell<\/span>, <\/span>shapeHollowDownTriangle<\/span>, <\/span>shapeNone<\/span>),<\/span>4<\/span>,<\/span>0<\/span>,<\/span>SellPrice<\/span>,<\/span>0<\/span>);\r<\/span>PlotShapes<\/span>(<\/span>IIf<\/span>(<\/span>Cover<\/span>, <\/span>shapeHollowUpTriangle<\/span>, <\/span>shapeNone<\/span>),<\/span>5<\/span>,<\/span>0<\/span>,<\/span>CoverPrice<\/span>,<\/span>0<\/span>);\r<\/span>PlotShapes<\/span>(<\/span>IIf<\/span>(<\/span>Short<\/span>, <\/span>shapeSmallDownTriangle<\/span>, <\/span>shapeNone<\/span>),<\/span>4<\/span>,<\/span>0<\/span>,<\/span>ShortPrice<\/span>,<\/span>0<\/span>);\r}<\/span><\/pre>\n