Algo Trading using Gap and Range Breakout Strategy

Algo Trading using Gap and Range Breakout Strategy

Algo Trading using Gap and Range Breakout Strategy

ups and gap downs based on open range breakout. This strategy is back-testable.

First, let’s discuss about the strategy. This involves GAP and Range breakout..

So, let’s begin…

Gap: If today’s open is outside the range of yesterday high or low .i.e. if today’s open is higher than yesterday’s high or if it is lower than yesterday’s low, then our gap condition will be satisfied.

Range Breakout: Next is the range breakout part, we need to calculate the open range of the day using the day’s High and Low values after-market open till certain time

e.g . If we want calculate the range till 9.30a.m, then we need to find the high-low range for the first 15min after market opens.

Now comes the buy and sell rules.

Rules

Buy : We need to buy, If stock Gap Up or Gap Down and First 15min Range High Breaks on intraday basis
 Short : We need to short, If stock Gap Up or Gap Down and First 15min Range Low Breaks on intraday basis

Sell : We need to sell (i.e) Exit Longs if the target is met or exit at 3:15p.m if target is not met.

Target for the trade is calculated based on simple formula. It is simply a % move from the entry, which is Range high. Formula: Range High * (1+target/100)

And Stop Loss for longs will be Yesterday’s Low

Cover : We need to cover (i.e) Exit shorts if the target is met or exit at 3:15p.m if target is not met.

Target for the trade is calculated based on simple formula. It is simply a % move from the entry, which is Range low. Formula: Range low * (1-target/100)

And Stop Loss for shorts will be Yesterday’s High

Moving on to the script part.

First, we are plotting the price candles.

Then we are getting previous day’s high, low, close values and today’s open price.

Then we are checking for gapup and gapdown using builtin function in the next 2 lines.

In the next 2 lines of code, we are assigning the breakout time, which is 9.30 AM and target %, which is 0.1%.

Now, in the next 4 lines of code, we take the high and low of first 15 mins of the day and use it to draw the high and low range of the day.

And now comes the buy and sell signal,

We will buy, if there is a gapup/ gapdown and time is above 9.30 and time is below 3 PM, and price crosses above the range high.

Likewise, We will short, if there is a gapup /gapdown and time is above 9.30 and time is below 3 PM, and price crosses below the range low.

Next set of code is to remove excess signals and exit the trades if the target or SL is hit. If either TGT ot SL is not hit by 3.15, it will exit the trade automatically. We are targeting 1% with each trades. Also, we are assigning the entry and exit prices

Finally, we are plotting this all in the charts.

Now, let’s move to backtesting. We can run backtest of this strategy in multiple TFs to check the results.

Check Out Script Library to get script used for this episode:
https://marketsecrets.in/script-library/

To know more, checkout:
https://youtu.be/0VwT3MwlBSI

 

Leave a Reply

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

error: Content is protected !!