ZBSKVFRT
ZBSKVFRT
0 at
https://mozilla.org/MPL/2.0/
// © GrusTech
//@version=5
strategy("Nikitha ORB Strategy v2.2", shorttitle="Nikitha ORB Strategy v2.2",
overlay=true, default_qty_type=strategy.fixed, default_qty_value=1,
initial_capital=300000, currency=currency.NONE, commission_value=0,
commission_type=strategy.commission.percent, process_orders_on_close=false,
calc_on_every_tick=true, calc_on_order_fills=false)
////======================================================
paraRefTF = input.timeframe("5", "Reference Timeframe", group = "Trade Settings")
////======================================================
GetTradeSetup() =>
_FC = session.isfirstbar
_BSFC = ta.barssince(_FC) + 1
_FCH = ta.valuewhen(_FC, high, 0)
_FCL = ta.valuewhen(_FC, low, 0)
////======================================================
////======================================================
FC = session.isfirstbar
LC = session.islastbar
st = paraSystemMode=="Positional" ? 1 : time(timeframe.period, s)
et = paraSystemMode=="Intraday" and time(timeframe.period, e)
RefBarChange = ta.change(RefBSFC)
eSignal = 0
eBuyPos = 0
eShortPos = 0
eBuy = st and paraTradeMode!="ShortOnly" and BuyEntryCond and barstate.isconfirmed
and BacktestCheck
eShort = st and paraTradeMode!="LongOnly" and ShortEntryCond and
barstate.isconfirmed and BacktestCheck
eSell = et or LC
eCover = et or LC
eSignal := eBuy ? 1 : eShort ? -1 : eSell and eSignal[1] > 0 ? 0 : eCover and
eSignal[1] < 0 ? 0 : eSignal[1]
eBuyPos := eBuy ? 1 : eSell and eSignal[1] > 0 ? 0 : eBuyPos[1]
eShortPos := eShort ? -1 : eCover and eSignal[1] < 0 ? 0 : eShortPos[1]
////======================================================
symbol = syminfo.ticker
LESym = str.tostring(syminfo.ticker)
LXSym = str.tostring(syminfo.ticker)
SESym = str.tostring(syminfo.ticker)
SXSym = str.tostring(syminfo.ticker)
BuyTradeQty := paraQty
ShortTradeQty := paraQty
if (paraQtyType=="Exposure")
BuyTradeQty := paraQty / eBuyPrice
BuyTradeQty := math.round(BuyTradeQty / syminfo.pointvalue)
ShortTradeQty := paraQty / eShortPrice
ShortTradeQty := math.round(ShortTradeQty / syminfo.pointvalue)
if (BuyTradeQty < 0)
BuyTradeQty := 1
if (ShortTradeQty < 0)
ShortTradeQty := 1
////======================================================
var int BTF = 0
var int STF = 0
var int BREF = 0
var int SREF = 0
var float PosSize = na
var int sellLossCtr = 0
var int coverLossCtr = 0
var bool LongPosChanged = false
var bool ShortPosChanged = false
var bool BuyEntryCandle = false
var bool ShortEntryCandle = false
var float LTFPrevHigh = na
var float LTFPrevLow = na
PosSize := math.abs(strategy.position_size)
LongPosChanged := (strategy.position_size > 0 and strategy.position_size[1] <= 0)
and barstate.isconfirmed
ShortPosChanged := (strategy.position_size < 0 and strategy.position_size[1] >= 0)
and barstate.isconfirmed
if RefBarChange
if (paraReEntryValid == "NextCandleOnly")
if strategy.position_size <= 0
BREF := 0
if strategy.position_size >= 0
SREF := 0
if (paraSetupValid == "NextCandleOnly")
BTF := 0
STF := 0
strategy.cancel("BUY")
strategy.cancel("SHORT")
if (eBuy)
BTF := 1
LTFPrevHigh := high
if strategy.position_size <= 0
BREF := 0
else
BTF := 0
if (eShort)
LTFPrevLow := low
STF := 1
if strategy.position_size >= 0
SREF := 0
else
STF := 0
if (BREF and not eBuy and not BTF) and PosSize == 0 and eBuyPos > 0 and st and
barstate.isconfirmed
strategy.entry('BUY', strategy.long, qty=BuyTradeQty, comment="Re-Buy",
stop=math.max(eBuyHigh, high[1]), alert_message="["+buyData+"]")
if (SREF and not eShort and not STF) and PosSize == 0 and eShortPos < 0 and st and
barstate.isconfirmed
strategy.entry('SHORT', strategy.short, qty=ShortTradeQty, comment="Re-Sell",
stop=math.min(eShortLow, low[1]), alert_message="["+shortData+"]")
ut = (paraTGTMode != "Off")
us = (paraSLMode != "Off")
T1ExQty := math.round(BuyTradeQty*(paraT1Qty/100))
T2ExQty := math.round(BuyTradeQty*(paraT2Qty/100))
T3ExQty := math.round(BuyTradeQty*(paraT3Qty/100))
sellData := '{"Exchange": "' + str.tostring(syminfo.prefix) + '","Close": ' +
str.tostring(close) + ',"Ticker": "' + LXSym + '","OrderType":
"SELL","ProductType": "' + paraProductType + '","InstrumentType": "' + paraInstr +
'","Quantity": '+str.tostring(BuyTradeQty)+', "Strategy": "'+paraStag+'", "Code":
"'+paraCode+'"}'
if (paraSLMode=="%")
BuySL := BuyPrice * (1-(paraSL/100))
else if (paraSLMode=="Pts")
BuySL := BuyPrice - (paraSL)
else if (paraSLMode=="PrevCandle")
BuySL := low[1]
else if (paraSLMode=="EntryCandle")
BuySL := low
if (paraTGTMode=="%")
BuyTGT1 := BuyPrice * (1+(paraTGT1/100))
BuyTGT2 := BuyPrice * (1+(paraTGT2/100))
BuyTGT3 := BuyPrice * (1+(paraTGT3/100))
BuyTGT := BuyPrice * (1+(paraTGT/100))
else if (paraTGTMode=="Pts")
BuyTGT1 := BuyPrice + (paraTGT1)
BuyTGT2 := BuyPrice + (paraTGT2)
BuyTGT3 := BuyPrice + (paraTGT3)
BuyTGT := BuyPrice + (paraTGT)
if (paraTGT1 == 0)
BuyTGT1 := na
if (paraTGT2 == 0)
BuyTGT2 := na
if (paraTGT3 == 0)
BuyTGT3 := na
else
BuyEntryCandle := false
ShortPrice := strategy.position_avg_price
ShortEntryCandle := false
STF := 0
SREF := SREF + 1
T1ExQty := math.round(ShortTradeQty*(paraT1Qty/100))
T2ExQty := math.round(ShortTradeQty*(paraT2Qty/100))
T3ExQty := math.round(ShortTradeQty*(paraT3Qty/100))
coverData := '{"Exchange": "' + str.tostring(syminfo.prefix) + '","Close": ' +
str.tostring(close) + ',"Ticker": "' + SXSym + '","OrderType":
"COVER","ProductType": "' + paraProductType + '","InstrumentType": "' + paraInstr +
'","Quantity": '+str.tostring(ShortTradeQty)+', "Strategy": "'+paraStag+'", "Code":
"'+paraCode+'"}'
if (paraSLMode=="%")
ShortSL := ShortPrice * (1+(paraSL/100))
else if (paraSLMode=="Pts")
ShortSL := ShortPrice + (paraSL)
else if (paraSLMode=="PrevCandle")
ShortSL := high[1]
else if (paraSLMode=="EntryCandle")
ShortSL := high
if (paraTGTMode=="%")
ShortTGT1 := ShortPrice * (1-(paraTGT1/100))
ShortTGT2 := ShortPrice * (1-(paraTGT2/100))
ShortTGT3 := ShortPrice * (1-(paraTGT3/100))
ShortTGT := ShortPrice * (1-(paraTGT/100))
else if (paraTGTMode=="Pts")
ShortTGT1 := ShortPrice - (paraTGT1)
ShortTGT2 := ShortPrice - (paraTGT2)
ShortTGT3 := ShortPrice - (paraTGT3)
ShortTGT := ShortPrice - (paraTGT)
if (paraTGT1 == 0)
ShortTGT1 := na
if (paraTGT2 == 0)
ShortTGT2 := na
if (paraTGT3 == 0)
ShortTGT3 := na
else
ShortEntryCandle := false
if (strategy.position_size > 0 and strategy.position_size[1] > 0 and
barstate.isconfirmed)
if (paraTSLMode != "Off")
if (paraTSLMode=="%")
BuyTSL := high[1] * (1-(paraTSL/100))
else if (paraTSLMode=="Custom")
else if (paraTSLMode=="Pts")
BuyTSL := high[1] - paraTSL
if (paraTGTTSL)
if (high[1] >= BuyTGT1 and BuySL < BuyPrice)
BuySL := BuyPrice
if (high[1] >= BuyTGT2 and BuySL < BuyTGT1)
BuySL := BuyTGT1
if (high[1] >= BuyTGT3 and BuySL < BuyTGT2)
BuySL := BuyTGT2
if (paraTSLMode != "Off")
if (paraTSLMode=="%")
ShortTSL := low[1] * (1+(paraTSL/100))
else if (paraTSLMode=="Custom")
else if (paraTSLMode=="Pts")
ShortTSL := low[1] + paraTSL
if (paraTGTTSL)
if (low[1] <= ShortTGT1 and ShortSL > ShortPrice)
ShortSL := ShortPrice
if (low[1] <= ShortTGT2 and ShortSL > ShortTGT1)
ShortSL := ShortTGT1
if (low[1] <= ShortTGT3 and ShortSL > ShortTGT2)
ShortSL := ShortTGT2
PosSize := math.abs(strategy.position_size)
if ((paraT1Qty > 0 and paraTGT1 > 0) or (paraT2Qty > 0 and paraTGT2 > 0) or
(paraT3Qty > 0 and paraTGT3 > 0))
sellData := '{"Exchange": "' + str.tostring(syminfo.prefix) + '","Close": ' +
str.tostring(close) + ',"Ticker": "' + LXSym + '","OrderType":
"SELL","ProductType": "' + paraProductType + '","InstrumentType": "' + paraInstr +
'","Quantity": '+str.tostring(PosSize)+', "Strategy": "'+paraStag+'", "Code":
"'+paraCode+'"}'
coverData := '{"Exchange": "' + str.tostring(syminfo.prefix) + '","Close": ' +
str.tostring(close) + ',"Ticker": "' + SXSym + '","OrderType":
"COVER","ProductType": "' + paraProductType + '","InstrumentType": "' + paraInstr +
'","Quantity": '+str.tostring(PosSize)+', "Strategy": "'+paraStag+'", "Code":
"'+paraCode+'"}'
if (strategy.position_size <= 0)
strategy.cancel('LongExit')
strategy.cancel('LongT1Exit')
strategy.cancel('LongT2Exit')
strategy.cancel('LongT3Exit')
if (strategy.position_size >= 0)
strategy.cancel('ShortExit')
strategy.cancel('ShortT1Exit')
strategy.cancel('ShortT2Exit')
strategy.cancel('ShortT3Exit')
////======================================================
////======================================================
plotshape(strategy.position_size<=0?eBuy:na, style=shape.diamond ,
location=location.belowbar, color=color.green, size=size.tiny)
plotshape(strategy.position_size>=0?eShort:na, style=shape.diamond,
location=location.abovebar, color=color.red, size=size.tiny)