Dinesh Tarte Dinesh is software Engineer by profession and a trader in equity and commodity markets. He does research with various technical analysis and loves to develop strategies in amibroker. Remarkably he is a student of Marketcalls and does freelancing for creating custom indicators in Amibroker

Full Gap Open Range Strategy – Amibroker AFL Code

57 sec read

Here is a simple Full Gap Open Range Strategy for intraday traders to trade the big gap ups and gap downs using open range breakout. And more important strategy is back-testable.

Bank Nifty 5min Chart
[wp_ad_camp_5]

 
Full Gap: Today’s open is outside the range of yesterday high or low .i.e. today’s open should be higher of yesterday’s high or lower of yesterday’s low.

Open Range: Calculate the range (High and Low) after-market open till certain time e.g . If we want calculate the range till 9.30a.m ( to determine high-low range for the first 15min after market open).

Rules

ORB Range : First 15min Range High and Range Low is Computed

Buy : If Gap Up or Gap Down and the Range High Breaks (First 15min) breaks on intraday basis
Short : If Gap Up or Gap Down and the Range Low Breaks (First 15min) breaks on intraday basis.

Sell : Exit Longs if the target Range High * (1+target/100) is met on intraday basis or exit at 3:15p.m if target is not met. Stop Loss : Yesterday Low
Cover : Exit shorts if the target Range low * (1-target/100) is met on intraday or exit at 3:15p.m if target is not met. Stop Loss : Yesterday High

GapORB – Amibroker AFL Code
https://gist.github.com/35dc4972bd957445918a

Assumptions

1)Which Instrument you had backtested :BankNifty
2)What is the time frame used? :5Min
3)Commissions – Rs 100 per leg.
4)How many years the data got backtested? – 3Yrs

Download the Bank Nifty – Backtest Report

Download GapORB Strategy for Amibroker

Dinesh Tarte Dinesh is software Engineer by profession and a trader in equity and commodity markets. He does research with various technical analysis and loves to develop strategies in amibroker. Remarkably he is a student of Marketcalls and does freelancing for creating custom indicators in Amibroker

Fisher Transform – Amibroker AFL Code

The Fisher Transform is a technical analysis indicator developed by John F. Ehlers, designed to identify potential turning points in the price movements of...
Rajandran R
2 min read

My Experience Converting SSL Hybrid from PineScript to Amibroker…

As a trader and coding enthusiast, I often find myself needing to translate trading indicators from one programming language to another. Recently, I embarked...
Rajandran R
8 min read

Line Trading – OpenAlgo Automation Module for Amibroker Users

The line Trading Automation tool is designed for Manual traders who want to perform level-based trade execution faster and also bring some advanced trade...
Rajandran R
59 sec read

18 Replies to “Full Gap Open Range Strategy – Amibroker AFL Code”

  1. Could you please elaborate how do we handle a scenario when both Range High/low breaks on the same candle? Will it take the 1st trade only? Or both buy/.short trades?

  2. when we are entering on the range breakout, we should consider the buy/short price at value when it breaks the level right? Then, why close price is mentioned as Buy/short price? As per the below code, i assume we are not entering on the price breakout, we need to wait for the candle close above/below the range and only when this condition satisfies we need to enter.?

    BuyPrice=ValueWhen(Buy,C);
    ShortPrice=ValueWhen(Short,C);
    CoverPrice=ValueWhen(Cover,C);
    SellPrice=ValueWhen(Sell,C);

    1. For calculation Close is good option rather then the range price. You can modify the code as per the requirement

  3. Thanks for sharing your strategy.
    Could you please clarify terms, TARGET RANGE HIGH & TARGET in the Exit Long Formula?
    Let say, first 15 min range is 10 points, what is the target please…

    Thanks for your valuable time.

    1. Range High -Low : first 15 min high low pice and if you want you can change it
      Currently target has been set 2.5% after entry .However you can modify the target say 1 %,1.5% etc …

  4. Can I explore this AFL for knowing which stocks are available for Buy and Sell ?

    1. Currently Exploration is not added in the code However you can scan the stock using SCAN button

  5. Does this strategy apply to Nifty? at what % of volatality it wii work best? pl. define high & Low volatalty % range for Nifty

    1. I don’t have nifty data .May be you can back test this strategy nifty and any other high beta stock

  6. Thanks for the strategy & afl code! I’d be interested in INTRADAY methods & AB code e.g. (a) Pivot Levels
    (b) News Trading (c) Scalping (d) Range Trading (e) Pairs Trading…. Best Regards, Amarjit

  7. An extension for the strategy maybe:

    if “n” trades in LONG direction are losing for the day then stop trading for the day
    if “n” trades in SHORT direction are losing for the day then stop trading for the day

    I am new with AB, how would I code in afl the above rule?

    many thanks,
    Amarjit

  8. Has anyone tested this strategy with any other index or stock (other than Bank Nifty) where it gives similar or better results? I tested with 12-13 Nifty stocks (cash segment data) with last 7 years of data (5 min time frame). The maximum profit with an initial capital of 250000 was around 60000, which is not good enough to deploy in practice. Average brokerage per trade was 100.

  9. 1.) Can You Pls mention the year on which backtest result is attached.
    2.) Sell = Cross(H,RangeHigh*(1+target/100)) OR Cross(DayH,L) OR TimeNum()>151500 ;

    1. 2. if i have buy position than STOPLOSS is yesterday Low,but you mentioned here Cross(DayH,L) i.e previous day high crosses the cur day low. is this right?

  10. Is this possible to create AFL Code for Stopping Volume and Is there any VSA and OI combined strategies?
    Kindly Reply.

  11. HI,
    Regarding the Sell and cover as mentioned below is not clear.

    Sell = Cross(H,RangeHigh*(1+target/100)) OR Cross(DayH,L) OR TimeNum()>151500 ;
    Cover = Cross(RangeLow*(1-target/100),L) OR Cross(H,DayL) OR TimeNum()>151500 ;

    Can you please explain why “Cross(DayH,L)” is mentioned for sell ?

  12. the the condition is evaluated true, dont you think it will result in multiple trades for the same script every time the conditino is satisfied as true

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More