AFL of the week: Intraday Open High Low Trading System

On popular demand, we have developed an Amibroker AFL for Intraday Open High Low strategy. In this strategy, positions are taken when Open=High or Open=Low for a given security in Intraday Timeframe. We have already posted an Excel sheet and Live signals for this system. Please check out the below links:

Intraday Open High Low Strategy- Live Signals

A Profitable Intraday Trading System: Excel Sheet

In the next section,  we’ll go through an AFL and backtest report for this Trading System. Read our article on AFL tutorial here.

AFL Overview

Paramter Value
Preferred Timeframe Intraday 5 minute
Indicators Used None
Buy Condition Open=Low in Intraday Timeframe post 30 minutes of market open
Short Condition Open=High in Intraday Timeframe post 30 minutes of market open
Sell Condition
  • Stop Loss hit
  • Target Met
  • End of Day
Cover Condition
  • Stop Loss hit
  • Target Met
  • End of Day
Stop Loss 0.5%
Targets 2.5%
Position Size 50% of Equity
Initial Equity 200000
Brokerage 100 per order
Margin 10%

AFL Code

//------------------------------------------------------
//
//  Formula Name:    Intraday Open High Low Trading System
//  Author/Uploader: Trading Tuitions
//  E-mail:          support@tradingtuitions.com
//  Website:         www.tradingtuitions.com
//------------------------------------------------------

_SECTION_BEGIN("Intraday Open High Low Trading System"); 

SetTradeDelays( 1, 1, 1, 1 );
SetOption( "InitialEquity", 200000);
SetOption("FuturesMode" ,True);
SetOption("MinShares",1);
SetOption("CommissionMode",2);
SetOption("CommissionAmount",100);
SetOption("AccountMargin",10);
SetOption("RefreshWhenCompleted",True);
SetPositionSize(50,spsPercentOfEquity);
SetOption( "AllowPositionShrinking", True );
SetOption("MaxOpenPositions",10);
BuyPrice=Open;
SellPrice=Open;
ShortPrice=Open;
CoverPrice=Open;

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C ));
Plot( Close, "Price", colorWhite, styleCandle );

NewDay = (Day()!= Ref(Day(), -1)) OR BarIndex() == 0;  
 
Plot(NewDay,"",colorlightGrey,styleHistogram|styleDots|styleNoLabel|styleOwnScale);

FirstTradeTime=094500;
SquareOffTime = 151500;

DayOpen=TimeFrameGetPrice("O",inDaily);
DayHigh = HighestSince(NewDay,H,1);  
DayLow = LowestSince(NewDay,L,1);  

printf("\nDayOpen : " + DayOpen );  
printf("\nDayHigh : " + DayHigh );  
printf("\nDayLow : " + DayLow );  

Buy = (round(DayOpen)==round(DayLow)) AND High>=(sqrt(DayOpen)+0.0833)^2 AND (TimeNum()  >= FirstTradeTime) AND TimeNum()<SquareOffTime;  
Short = (round(DayOpen)==round(DayHigh)) AND Low<=(sqrt(DayOpen)-0.0833)^2 AND (TimeNum()  >= FirstTradeTime) AND TimeNum()<SquareOffTime; 

Sell = TimeNum() >= SquareOffTime;
Cover = TimeNum() >= SquareOffTime; 

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);

Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);

printf("\nBuy : " + Buy );  
printf("\nSell : " + Sell );  
printf("\nShort : " + Short );  
printf("\nCover : " + Cover ); 

StopLoss=0.5;
ApplyStop(Type=0,Mode=1,Amount=StopLoss);

Target=2.5;
ApplyStop(Type=1,Mode=1,Amount=Target);

/* Plot Buy and Sell Signal Arrows */
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

_SECTION_END();

AFL Screenshot

Intraday Open High Low

Backtest Report

 Paramter Value
  Fixed Position Size
Initial Capital  200000
Final Capital 538807.42
Scrip Name NSE Nifty, NSE BankNifty
Backtest Period 02-Jan-2015 to 26-Apr-2016
Timeframe 5 Minutes
Net Profit % 169.40%
Annual Return % 111.15%
Number of Trades 130
Winning Trade % 48.46%
Average holding Period 48.95 periods
Max consecutive losses 8
Max system % drawdown -16.20%
Max Trade % drawdown -11.64%

Download the detailed backtest report here.

Equity Curve

IntradayOpenHighLow_EquityCurve

Additional Amibroker settings for backtesting

Goto Symbol–>Information, and specify the lot size and margin requirement. The below screenshot shows lot size of 75 and margin requirement of 10% for NSE Nifty:

Symbol Info_Nifty

Disclaimer:

All the AFL’s posted in this section are for learning purpose. Trading Tuitions does not necessarily own these AFL’s and we don’t have any intellectual property rights on them. We might copy useful AFL’s from public forums and post it in this section in a presentable format. The intent is not to copy anybody’s work but to share knowledge. If you find any misleading or non-reproducible content then please inform us at support@tradingtuitions.com

18 Comments

  1. Dear Sir,
    Thank you for sharing this excellent AFL.

    I have an AFL with exploration function, when I explore it to my NSE futures watch-list, I get both current and past signals for every symbol. I would like to know how to get only the current (or the most recent) signals of every symbols in my watch-list. Kindly advise me what AFL command I should apply.

    Thank you very much.

  2. SIR, KINDLY EXPLAIN IN DETAIL AS HOW TO DO THE BACK TESTING.
    THANKS

  3. What ia the purpose of C-lang coding You’ve posted above? And where can i use that coding? Kindly do the needful

  4. This strategy and the corresponding result looks astonishing. Thanks for publishing the same.

    It would be great if you can help me to understand this back testing result. I believe these 130 trades over a period of 16 months are incorrect. Why I feel this number is incorrect? When we start the trading day there are many long and short trade signals. We would take all the trades(let us assume). But out of these trades few of the signals get obsolete at the end of the day. E.g. On 29june16 there was a Short call in BPCL at 9:45 A.M because the Open and High price was same 1054.9. During the course of the day the counter went up above the Open price and the signal got closed.
    Hence at the end of the day wherever the long and short signals are valid we are performing the back testing results. But we are not considering those trades which got executed and finally the stop loss got hit at the mid of the day. If we incorporate these cases results won’t be that rosy I believe. To backtest these trades you need to use 5 mins OHLC data instead of daily data. Then freeze all the signals generated till 9:45 A.M, that means first six 5mins candle.

    Hope I have explained you all my thoughts.

    I use a similar strategy but select stocks from the strongest sector to buy and weakest sector to sell out of all the signals generated.

    Cheers !!

    • Hi Abhishek,

      Thanks for your in-depth review. However, the strategy has been backtested on 5 Min data itself. And the example you mentioned would definitely trigger a Short signal at 9:45 but would be covered later hitting the stop loss.

  5. Great work..
    But many times the entry price is not reached after 30 mins of market opening..
    and in excell profit is calculated for those companies also..
    what do you suggest for these conditions..?

  6. Dear Admin & Abhishek,

    I also have gone thru 100s off AFLs and whats common problem with us is like we check AFLs result on EOD and than apply the same in Intraday as we neednot trade overnight untill we get confidence in system and all times end up loosing money.

    I have view and also tried I execute all trades in live and in backtesting ignoring 15 mins first and last from trading time.

    Means while scanning it takes trades executed from 9.30 to 3.15 only.

    This will give you exact idea of AFL and its result

  7. Hi Admin
    you have indicated below extra condition in addition to the strategy signal in the AFL
    High>=(sqrt(DayOpen)+0.0833)^2 FOR BUY &
    Low<=(sqrt(DayOpen)-0.0833)^2 FOR SELL
    Appreciate if could you explain bit more what is that extra condition and what exactly it checks.

    Many Thanks

  8. Will it possible for You to backtest this AFL and post the results for Nifty 50 Stocks. A backtest data of even 1 – 2 months would suffice.
    Thanks .

  9. I copy pasted this afl in my ami. I am not getting any buy sell signal. Please help me.

    • Hi Rajneesh,

      We are currently working on a volume based strategy. Will post it once its back-tested and ready.

  10. I copypasted this afl and ran in 5 min chart. It is giving very wrong signals. Where can I send the screen shots of it you?

Leave a Reply

Your email address will not be published. Required fields are marked *