In this post I share with you the Amibroker Formula Language code for this ORB trading system. The code is simple to understand and it is the codification of the strategy I wrote about in the first post of this series, but if you need any clarification you have only to post a comment.
The trading system code is
#include_once ".\Formulas\Custom\Functions\RoundToTick.afl"; SetPositionSize( 1, spsShares ); SetOption( "ActivateStopsImmediately", 0 ); SetOption ( "CommissionMode", 2 ); SetOption( "CommissionAmount", 0 ); SetTradeDelays( 0, 0 , 0, 0 ); Doji = 0.4; Threshold = 0.4; Stop = 200; start_time = 92000; end_time = 170000; close_position_time = 172959; TimeFrameSet( inDaily ); TrueRange = ATR( 1 ); TradingPermission = abs( Close - Open ) < Doji * TrueRange; PriceThresholdUp = RoundToNearestTick(Ref( Open, 1 ) + Threshold * TrueRange); PriceThresholdDn = RoundToNearestTick(Ref( Open, 1 ) - Threshold * TrueRange); TimeFrameRestore(); TradingPermission = TimeFrameExpand( TradingPermission , inDaily ); PriceThresholdUp = TimeFrameExpand( PriceThresholdUp , inDaily ); PriceThresholdDn = TimeFrameExpand( PriceThresholdDn , inDaily ); D = DateNum(); T = TimeNum(); TimeFilter = T > start_time AND T < end_time; Buy = TimeFilter AND TradingPermission AND High >= PriceThresholdUp ; Buy = Buy AND !Flip( Ref( Buy, -1 ), D != Ref( D, -1 ) ); Short = TimeFilter AND TradingPermission AND Low <= PriceThresholdDn ; Short = Short AND !Flip( Ref( Short, -1 ), D != Ref( D, -1 ) ); BuyPrice = IIf( Open < PriceThresholdUp, PriceThresholdUp, Open ); ShortPrice = IIf( Open > PriceThresholdDn, PriceThresholdDn, Open ); Sell = Cover = T >= close_position_time; SellPrice = CoverPrice = Close; ApplyStop( stopTypeLoss, stopModePoint, Stop, 1 );
As you can see the trading system is perfectly symmetrical on both sides. The parameters are few: only 6 parameters for a backtesting which counts 1147 trades. It seems that there is no overfitting problem.
Moreover there is no specific time-frame for this trading system to work, nothing matter about the bar length. It may be 1 minute, 5 minutes or more, the result does not change a lot.
It is an intraday trading system, no position remains opened overnight. Allows you to sleep soundly. But what about its performance to date?
You can download the code here