0% found this document useful (0 votes)
367 views4 pages

Algobaba ORB Trading Script

This strategy uses a moving average crossover technique to generate buy and sell signals for an intraday trading strategy. It defines inputs for trade direction, options vs futures, strike type, quantity, session times, profit/loss levels. On signals, it places orders to enter long/short positions and exits them at target or stop levels using the Algobaba platform.

Uploaded by

Abdul Kalam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
367 views4 pages

Algobaba ORB Trading Script

This strategy uses a moving average crossover technique to generate buy and sell signals for an intraday trading strategy. It defines inputs for trade direction, options vs futures, strike type, quantity, session times, profit/loss levels. On signals, it places orders to enter long/short positions and exits them at target or stop levels using the Algobaba platform.

Uploaded by

Abdul Kalam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
[Link]
// © VEMO0020
//@version=4

strategy("Algobaba ORB Strategy", overlay=true)

// FIRST CANDLE OF THE DAY


t = time("1440", [Link]) // 1440=60*24 is the number of minutes in a whole
day. You may use "0930-1600" as second session parameter
//plot(t, style=linebr) // Uncomment for better understanding
is_first = na(t[1]) and not na(t) or t[1] < t

var float orbh = na


var float orbl = na

if is_first //newbar
orbl:=low
orbh:=high

plot(orbh,color=[Link],style=plot.style_circles,linewidth=2)
plot(orbl,color=[Link],style=plot.style_circles,linewidth=2)

[Link].max_intraday_filled_orders(count=2)
//**********************************
//Algobaba Integration START

//Declare your Buy and Sell conditions don't change the variable name
//**********************************

buySignal = crossover(high,orbh)
sellSignal = crossunder(low,orbl)

bsym=[Link]

// SETTING UP VARIABLES //
tlg=input(defval=true,title="Long ",inline="tdir",group="Trade Setup:")
tst=input(defval=false,title="Short <<||>> Trade in: ",inline="tdir",group="Trade
Setup:")

tt1=input(defval="Hedge",title=" ",options = ["Futures", "Options",


"Hedge"],inline="tdir",group="Trade Setup:")
//tt2=input(defval=false,title="Options ",inline="tdir",group="Trade Setup:")
//otype= tt2?"Options":"Futures"
otype = tt1

stag=input(title="Strategy
Type:",defval="BNOPTIONS",type=[Link],inline="hpar2",group="Trade Setup:")

qty=input(title="Quantity:",type=[Link],defval=1,minval=1,
maxval=10,inline="hpar2",group="Trade Setup:",tooltip="Qty in Lots")
//trade_side = tst?"Short":"Long"
trade_side=tlg and tst?"Both":tlg?"Long":"Short"

opt1=input(defval=false,title="ITM ",inline="stype",group="Strike Type:")


opt2=input(defval=true,title="ATM ",inline="stype",group="Strike Type:")
opt3=input(defval=false,title="OTM ",inline="stype",group="Strike Type:")
stype=opt3?"OTM":opt1?"ITM":"ATM"
// ***************
// Derive Option strike price based on user selection
// ***************

csym= otype=="Futures"?bsym:bsym+stype+"CE"
psym= otype=="Futures"?bsym:bsym+stype+"PE"
//csym= bsym+stype+"CE"
//psym= bsym+stype+"PE"

string lx ="", string sx="", string le="",string se=""


// lx = "TYPE: LX :SYMBOL:"+csym+":QTY:"+tostring(qty)+":STAG:"+stag //NIFTYCALL
// sx = (otype=="Futures"? "TYPE: SX :SYMBOL:":"TYPE: LX :SYMBOL:")
+psym+":QTY:"+tostring(qty)+":STAG:"+stag //NIFTYPUT
// le = "TYPE: LE :SYMBOL:"+csym+":QTY:"+tostring(qty)+":STAG:"+stag //NIFTYCALL
// se = (otype=="Futures"? "TYPE: SE :SYMBOL:":"TYPE: LE :SYMBOL:")
+psym+":QTY:"+tostring(qty)+":STAG:"+stag //NIFTYPUT

if otype=="Hedge"
lx := "TYPE: LX :SYMBOL:"+bsym+":QTY:"+tostring(qty)+":STAG:"+stag+";\n"+"TYPE:
LX :SYMBOL:"+bsym+stype+"PE"+":QTY:"+tostring(qty)+":STAG:"+stag //NIFTYCALL
sx := "TYPE: SX :SYMBOL:"+bsym+":QTY:"+tostring(qty)+":STAG:"+stag+";\n"+"TYPE:
LX :SYMBOL:"+bsym+stype+"CE"+":QTY:"+tostring(qty)+":STAG:"+stag //NIFTYPUT
le := "TYPE: LE :SYMBOL:"+bsym+":QTY:"+tostring(qty)+":STAG:"+stag+";\n"+"TYPE:
LE :SYMBOL:"+bsym+stype+"PE"+":QTY:"+tostring(qty)+":STAG:"+stag //NIFTYCALL
se := "TYPE: SE :SYMBOL:"+bsym+":QTY:"+tostring(qty)+":STAG:"+stag+";\n"+"TYPE:
LE :SYMBOL:"+bsym+stype+"CE"+":QTY:"+tostring(qty)+":STAG:"+stag //NIFTYPUT
else
lx:= "TYPE: LX :SYMBOL:"+csym+":QTY:"+tostring(qty)+":STAG:"+stag //NIFTYCALL
sx:= (otype=="Futures"? "TYPE: SX :SYMBOL:":"TYPE: LX :SYMBOL:")
+psym+":QTY:"+tostring(qty)+":STAG:"+stag //NIFTYPUT
le:= "TYPE: LE :SYMBOL:"+csym+":QTY:"+tostring(qty)+":STAG:"+stag //NIFTYCALL
se:= (otype=="Futures"? "TYPE: SE :SYMBOL:":"TYPE: LE :SYMBOL:")
+psym+":QTY:"+tostring(qty)+":STAG:"+stag //NIFTYPUT

// ****************
// Adding Stoploss and Target selection
// ****************
ut=input(defval=true,title="",inline="sltgtpts",group="Define SL & TGT in Points:")
tar1=input(defval=10.0,title="Target:",inline="sltgtpts",group="Define SL & TGT in
Points:")
us=input(defval=true,title="",inline="sltgtpts",group="Define SL & TGT in Points:")
stop1=input(defval=5.0,title="Stop Loss:",inline="sltgtpts",group="Define SL & TGT
in Points:")
customBuffer = input(defval=0,title="SL Buffer in Pts.",type=[Link])

tar=tar1/[Link]
stop=stop1/[Link]
symbol=[Link]

// ****************
// INTRA DAY TRADE SESSION Initialization
// ****************

s=input(title="Start Session:",type=[Link],defval="0915-
1515",group="Intraday Session")
st=time([Link],s)
e=input(title="End Session:",type=[Link],defval="1515-1530",group="Intraday
Session")
et=time([Link],e)

// ****************
// ***************
// Algobaba ORDER Placement Section
//for long entry conditions store in buySignal variable and for short entry store
in sellSignal variables
// ***************

//Initiate Long Buy Order and otype=="CE"


buycond = (buySignal and st and ((otype=="Options" and (trade_side=="Long" or
trade_side=="Both")) or (otype=="Futures" and (trade_side=="Long" or
trade_side=="Both")) ))

//Initiate Short Buy Order and otype=="PE"


sellcond = (sellSignal and st and ((otype=="Options" and (trade_side=="Short" or
trade_side=="Both")) or (otype=="Futures" and (trade_side=="Short" or
trade_side=="Both")) ))

if otype=="Hedge"
buycond:= (buySignal and st)
sellcond:= (sellSignal and st)

// *****************************************
// Send signals to IAB based on user selection
// *****************************************

// BUY or SELL when condtions are met and within the Intraday Trading session and
backtesting date and time
// if(buycond and strategy.position_size==-1)
// [Link]("BUY", [Link],qty=qty, when = st,comment=sx+";"+le)
if(buycond and strategy.position_size==0)
[Link]("BUY", [Link],qty=qty, when = st ,comment=le)

// if(sellcond and strategy.position_size==1)


// [Link]("SELL", [Link],qty=qty, when = st,comment=lx+";"+se)

if(sellcond and strategy.position_size==0)


[Link]("SELL", [Link],qty=qty, when = st,comment=se)

//Send Exit signals to IAB for the open position if Target or Stop loss hit on
BANKNIFTY Future price
if(ut==true and us==false)
[Link](id="LongExit",from_entry="BUY",profit=tar,stop=(orbl-
customBuffer),comment=lx)

[Link](id="ShortExit",from_entry="SELL",profit=tar,stop=(orbh+customBuffer),
comment=sx)
if(us==true and ut==false)
[Link](id="LongExit",from_entry="BUY",loss=stop,comment=lx)
[Link](id="ShortExit",from_entry="SELL",loss=stop,comment=sx)

if(ut==true and us==true)


[Link](id="LongExit",from_entry="BUY",profit=tar,loss=stop,comment=lx)
[Link](id="ShortExit",from_entry="SELL",profit=tar,loss=stop,comment=sx)
// if(us==false)
//
[Link](id="LongExit",from_entry="BUY",profit=orbl,loss=stop,comment=lx)
//
[Link](id="ShortExit",from_entry="SELL",profit=orbh,loss=stop,comment=sx)

// *****************************************
//ADDING SQUAREOFF TIME or Manul close all open positions
// *****************************************
[Link](id="BUY", when=et, comment=lx)
[Link](id="SELL", when=et, comment=sx)

// for order execution using Alerts in alert window use {{[Link]}}

//ALGOBABA INTEGRATION END

You might also like