Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

//@version=4

strategy("Candle H/L - TARGET", overlay = true, calc_on_every_tick=true,


process_orders_on_close=true)

square = input("1500",title = "Square Off Timings")


api = input("48108702-709a-4eb5-9188-d858f97bf825",title = "API KEY")
nbf = input(title="NIFTY/BANKNIFTY", type=input.bool, defval=false)
date = input("09",title = "Expirty Date")
mon = input("SEP",title = "Expirty Month")

ce_strike = input(title="CE calc", type=input.integer, defval=200, minval=0,


maxval=2000)
pe_strike = input(title="PE calc", type=input.integer, defval=200, minval=0,
maxval=2000)

ce_target = input(title="CE TARGET", type=input.integer, defval=140, minval=0,


maxval=5000)
pe_target = input(title="PE TARGET", type=input.integer, defval=160, minval=0,
maxval=5000)

st = time(timeframe.period,"0936-"+square)
t = time(timeframe.period, "0924-0935" + ":1234567")

is_newbar(res) => change(time(res)) != 0


in_session = not na(t)
is_first = in_session and not in_session[1]
can_high = float(na)
can_low = float(na)
if is_first
can_high := high
can_low := low
else
can_high := can_high[1]
can_low := can_low[1]
if high > can_high and in_session
can_high := high
if low < can_low and in_session
can_low := low

//strike selection
//
==================================================================================
mid_value = nbf ? 25 : 50
IndexMultiplier= nbf ? 50 : 100
mod_CE= can_high % IndexMultiplier
CE = iff(mod_CE>=mid_value,can_high+IndexMultiplier-mod_CE,can_high-mod_CE) -
ce_strike

mod_PE= can_low % IndexMultiplier


PE = iff(mod_PE>=mid_value,can_low+IndexMultiplier-mod_PE,can_low-mod_PE) +
pe_strike

//
==================================================================================

index = nbf ? "NIFTY" : "BANKNIFTY"


Lx = '{"command": "PLACE_ORDERS","apiKey": "'+api+'","orders": [{"account":
"HIGH_PROFILE","group": true,"variety": "REGULAR","exchange": "NSE","symbol":
"'+index+'_'+date+'-'+mon+'-2021_CE_'+tostring(CE)+'","tradeType":
"BUY","orderType": "MARKET","validity": "DAY","productType": "INTRADAY","quantity":
25}]}'
Le = '{"command": "SQUARE_OFF_POSITION","apiKey": "'+api+'","positions":
[{"account": "HIGH_PROFILE","group": true,"category": "NET","exchange":
"NSE","symbol": "'+index+'_'+date+'-'+mon+'-2021_CE_'+tostring(CE)+'","type":
"MIS"}]}'

Sx = '{"command": "PLACE_ORDERS","apiKey": "'+api+'","orders": [{"account":


"HIGH_PROFILE","group": true,"variety": "REGULAR","exchange": "NSE","symbol":
"'+index+'_'+date+'-'+mon+'-2021_PE_'+tostring(PE)+'","tradeType":
"BUY","orderType": "MARKET","validity": "DAY","productType": "INTRADAY","quantity":
25}]}'
Se = '{"command": "SQUARE_OFF_POSITION","apiKey": "'+api+'","positions":
[{"account": "HIGH_PROFILE","group": true,"category": "NET","exchange":
"NSE","symbol": "'+index+'_'+date+'-'+mon+'-2021_PE_'+tostring(PE)+'","type":
"MIS"}]}'

target_CE = can_high + ce_target


target_PE = can_low - pe_target

plot(target_CE , style=plot.style_line, color=can_high[1] != can_high ? na :


color.blue, title="TGT High", linewidth=2)
plot(target_PE , style=plot.style_line, color=can_low[1] != can_low ? na :
color.blue, title="TGT Low", linewidth=2)
// longCondition = crossover(close,target_CE) and st// and barstate.isconfirmed
// shortCondition = crossunder(close,target_PE) and st// and barstate.isconfirmed

// var h_line = close

// var l_line = close

// if longCondition
// h_line := high

// if shortCondition
// h_line := 1000000

// if not st
// h_line := 1000000
// l_line := 0

// if shortCondition
// l_line := low

// if longCondition
// l_line := 0

strategy.entry(id="Long", long=true , stop = target_CE,comment = Le, when = st)

strategy.entry(id="Short", long=false , stop = target_PE,comment = Se, when = st)

strategy.close_all(when = not st)//, comment = Le)

strategy.cancel("Long" , when =target_CE != target_CE[1] )


strategy.cancel("Short" , when =target_PE != target_PE[1] )

//end//

You might also like