3 Trading Strategies You Can Code and Backtest on PHI 1 Right Now

(Disclaimer: These strategies were showcased as part of our educational webinar – Trading Strategies: Introduction on 18th September 2020. The purpose of sharing these strategies is purely educational. Please do not consider these for investment purpose)

1. Pairs Trading Strategy (Using Kotak Bank & HDFC Bank using Day Frequency)

Init:

self.val = self.datas[0].close/self.datas[1].close

self.boll = BollingerBands(self.val, period=40, devfactor=2)

—————————————————————————————

Step:

if (self.val[0] < self.boll.lines.bot[0]) and (self.position.size==0):

  self.sell(data = self.datas[1])

  self.buy(data =  self.datas[0])

if (self.val[0] > self.boll.lines.mid[0]) and (self.position.size>0):

  self.sell(data = self.datas[0])

  self.buy(data =  self.datas[1])

READ :   Top 5 Best Algo Trading Software in India 2021

2. Trend Following Strategy (TURTLE TREND on Reliance Industries, 1 day)

Init:

class DonchianChannels(bt.Indicator):

    lines = (‘dch’, ‘dcl’,)  #dc high, dc low

    params = dict(

        period=20,

        lookback=-1,  # consider current bar or not

    )

    def _init_(self):

        hi, lo = self.data.high, self.data.low

        hi, lo = hi(self.p.lookback), lo(self.p.lookback)

 

        self.l.dch = bt.ind.Highest(hi, period=self.p.period)

        self.l.dcl = bt.ind.Lowest(lo,  period=self.p.period)

       self.donchian = DonchianChannels()

self.count1 = 0      

———————————————————————————————

Step:

if (self.data.close[0] > self.donchian.dch[0]) and (self.position.size==0):

   order_target_percent(target=1)

if (self.data.close[0] < self.donchian.dcl[0]) and (self.position.size>0):

   order_target_percent(target=0)

if (self.data.close[0] < self.donchian.dcl[0]) and (self.position.size==0):

   order_target_percent(target=-1)    

if (self.data.close[0] > self.donchian.dch[0]) and (self.position.size<0):

   order_target_percent(target=0)

3. Mean Reversion Strategy (ONGC Hour frequency; Calendar Selection: Wednesday)

Init:

self.boll = BollingerBands(period=21, devfactor=2)

self.count1 = 0

Step:

curr_date = self.datetime.datetime(ago=0)

if risk_control_window(curr_date):

 

   if (close < self.boll.lines.bot) and (self.position.size==0):

       order_target_percent(target=1)

 

if (self.position.size > 0):

   self.count1 = self.count1 + 1

  

if (close > self.boll.lines.top) and (self.position.size>0) and (close[0] > close[-self.count1]):

    order_target_percent(target=0)

    self.count1 = 0

 

if (self.count1 > 4) and (close > self.boll.lines.mid) and (self.position.size>0) and (close[0] > close[-self.count1]):

    order_target_percent(target=0)

    self.count1 = 0

 

if (self.count1 > 4) and (close[0]/close[-self.count1] > 1.02) and (self.position.size>0):

    order_target_percent(target=0)

    self.count1 = 0

   

if (self.count1 > 4) and (close[0]/close[-self.count1] < 0.98) and (self.position.size>0):

    order_target_percent(target=0)

    self.count1 = 0

  

if (self.count1 > 10):

   order_target_percent(target=0)

   self.count1 = 0

(Click here to watch the complete recording of the webinar)

READ :   Q & A - Creating a MACD Strategy on PHI 1 (Webinar)

How to use this code on PHI 1?

  1. Copy & Paste the Init code in the – Enter initialize code here section
  2. Copy & Paste the Step code in the – Enter step code here section
  3. Click Run And Save

Trading Strategies Webinar Screenshot

If you need any help or have any questions, then please schedule a demo session with us and we will help you out.

Happy Trading,
Team PHI 1

Tagged : / / / / / / /
0 Shares
Share via
Copy link
Powered by Social Snap