Skip to main content

Examples

Introduction

This page showcases Examples of how the Code Builder has been used to build meaningful trading strategies—from the most basic patterns to sophisticated multi-leg logic. The goal isn't to teach you trading theory. It's to show you what can be done inside the Code Builder, using examples that cover:

  • ✅ What the strategy was aiming to do
  • 🔁 How different features (like indicators, exits, loops) were used
  • 📊 What kind of indicators were used
  • 🧩 How different building blocks came together

Most people learn by doing—or seeing how others have done it.
Whether you're just starting or you're looking to design more complex trades, these examples act as blueprints, not tutorials.

Code Builder Template

When you open the strategy builder and switch to the code builder, the following default view is displayed:

import datetime
import pandas as pd
from eventManager import Strategy, runEvents

class st_trial1(Strategy):
def init(self):
self.actions_all = {'act_ac380': {'trigger': False, 'legs': []}, 'act_ac396': {'trigger': False, 'legs': []}}

def minTrigger(self):

if (self.currentCandle + datetime.timedelta(minutes=1)).time() == datetime.time(15,15,0):
self.squareoff_all()
self.finish

def data_init(self):
pass

def indicator_init(self):
pass


def act_ac380(self):
self.actions_all['act_ac380']['trigger'] = True
## ATM Straddle
leg = self.addLeg(transactionType='sell', optionType='CE',
strikeSelection={'strikeBy' : 'moneyness', 'strikeVal':0, 'asof':'None', 'roundoff' : None},
qty=75, expiry={'expType':'weekly','expNo':0},
target={'isTarget':True,'targetOn':'%','targetValue':75},
SL={'isSL' : True, 'SLon': '%', 'SLvalue' : 35},
trailSL = {'isTrailSL':False, 'trailSLon':'val', 'trailSL_X': 1, 'trailSL_Y': 1},
reEntryTg = {'isReEntry' : False, 'reEntryOn' : 'asap', 'reEntryVal' : 0, 'reEntryMaxNo':20},
reEntrySL = {'isReEntry' : False, 'reEntryOn' : '0', 'reEntryVal' : None, 'reEntryMaxNo':20},
waitTrade = {'isWT' : False, 'wtOn' : 'val-up', 'wtVal' : 1, 'triggers': []},
segment = 'OPT', entryValidity = 'Day',
remark = 'Entering Leg',
squareoff = 'this', legName = 'lg_ac380_1',
webhook = {'is' : False, 'entryMessage' : {}, 'exitMessage' : {}})
self.actions_all['act_ac380']['legs'].append(leg)
leg = self.addLeg(transactionType='sell', optionType='PE',
strikeSelection={'strikeBy' : 'moneyness', 'strikeVal':0, 'asof':'None', 'roundoff' : None},
qty=75, expiry={'expType':'weekly','expNo':0},
target={'isTarget':True,'targetOn':'%','targetValue':75},
SL={'isSL' : True, 'SLon': '%', 'SLvalue' : 35},
trailSL = {'isTrailSL':False, 'trailSLon':'val', 'trailSL_X': 1, 'trailSL_Y': 1},
reEntryTg = {'isReEntry' : False, 'reEntryOn' : 'asap', 'reEntryVal' : 0, 'reEntryMaxNo':20},
reEntrySL = {'isReEntry' : False, 'reEntryOn' : '0', 'reEntryVal' : None, 'reEntryMaxNo':20},
waitTrade = {'isWT' : False, 'wtOn' : 'val-up', 'wtVal' : 1, 'triggers': []},
segment = 'OPT', entryValidity = 'Day',
remark = 'Entering Leg',
squareoff = 'this', legName = 'lg_ac380_2',
webhook = {'is' : False, 'entryMessage' : {}, 'exitMessage' : {}})
self.actions_all['act_ac380']['legs'].append(leg)


def act_ac396(self):
self.actions_all['act_ac396']['trigger'] = True
## Square off
self.squareoff_all(remark='Square off all')


def onNewDay(self):
self.data_init()
self.indicator_init()
self.entries = {'cnd_ct1': {'max': 0, 'cur': 0}}

def onCandleClose(self):

## Entry Condition
if (self.position == []) and \
(self._triggers == []) and \
(((self.candleTime == datetime.time(9,30,0)))):
self.act_ac380()

## Exit Condition
if (self.position != []) and \
(((self.candleTime >= datetime.time(15,15,0)))):
self.act_ac396()


def onEnd(self):
pass

This is the default template for an At-The-Money (ATM) Straddle Sell strategy, identical to the one automatically loaded when opening the No-Code Strategy Builder. This serves as the foundation—we can now proceed to build upon it.

Conclusion

The ATM Straddle Sell shown above is just the starting point. It demonstrates how even a simple idea—selling an at-the-money call and put—translates into actual code within the Code Builder.

But remember, this isn’t the limit. The Code Builder is designed to let you:

  • 🔧 Tweak simple strategies by adding indicators, adjusting exit rules, or layering conditions.
  • 🏗️ Scale up into more complex, multi-leg setups like strangles, iron condors, or calendar spreads.
  • 🚀 Experiment with advanced logic using loops, event triggers, and dynamic position sizing.

The real value comes when you start combining these building blocks to reflect your own trading logic.

👉 Explore more examples in this section, adapt them, and treat them as blueprints for your next strategy.