OPEN-SOURCE SCRIPT
MA Crossover BIFTY BNF with Broker Inputs

//version=6
strategy("MA Crossover with Broker Inputs", overlay=true, margin_long=100, margin_short=100, process_orders_on_close=true)
// === BROKER & ORDER SETTINGS ===
broker = input.string("Dhan", title="Broker", options=["Dhan","Other"])
orderType = input.string("MKT", title="Order Type", options=["MKT","LMT"])
clientID = input.string("", title="Client ID (Optional)")
secretKey = input.string("", title="Secret Key (from JSON)")
// === INSTRUMENT SELECTION ===
instrument = input.string("BANKNIFTY", title="Select Instrument", options=["BANKNIFTY","NIFTY","FINNIFTY"])
expiryMode = input.string("Auto", title="Expiry Mode", options=["Auto","Manual"])
manualExpiry = input.string("17Dec2025", title="Manual Expiry Date (if Manual Mode)")
optionType = input.string("CE", title="Option Type", options=["CE","PE"])
strikeSel = input.string("ATM", title="Strike Selection", options=["ATM","OTM","ITM"])
// === RISK MANAGEMENT ===
stopLossPts = input.int(50, title="Stop Loss (points)")
takeProfitPts = input.int(100, title="Take Profit (points)")
// === STRATEGY LOGIC: Moving Average Crossover ===
fastLength = input.int(9, title="Fast MA Length")
slowLength = input.int(18, title="Slow MA Length")
price = close
maFast = ta.sma(price, fastLength)
maSlow = ta.sma(price, slowLength)
// Crossover Long
if (ta.crossover(maFast, maSlow))
strategy.entry("Long", strategy.long, comment="MA Crossover Long")
// Crossunder Short
if (ta.crossunder(maFast, maSlow))
strategy.entry("Short", strategy.short, comment="MA Crossover Short")
// Apply SL and TP
strategy.exit("Exit Long", from_entry="Long", stop=close - stopLossPts, limit=close + takeProfitPts)
strategy.exit("Exit Short", from_entry="Short", stop=close + stopLossPts, limit=close - takeProfitPts)
// === PLOTS ===
plot(maFast, color=color.green, title="Fast MA")
plot(maSlow, color=color.red, title="Slow MA")
strategy("MA Crossover with Broker Inputs", overlay=true, margin_long=100, margin_short=100, process_orders_on_close=true)
// === BROKER & ORDER SETTINGS ===
broker = input.string("Dhan", title="Broker", options=["Dhan","Other"])
orderType = input.string("MKT", title="Order Type", options=["MKT","LMT"])
clientID = input.string("", title="Client ID (Optional)")
secretKey = input.string("", title="Secret Key (from JSON)")
// === INSTRUMENT SELECTION ===
instrument = input.string("BANKNIFTY", title="Select Instrument", options=["BANKNIFTY","NIFTY","FINNIFTY"])
expiryMode = input.string("Auto", title="Expiry Mode", options=["Auto","Manual"])
manualExpiry = input.string("17Dec2025", title="Manual Expiry Date (if Manual Mode)")
optionType = input.string("CE", title="Option Type", options=["CE","PE"])
strikeSel = input.string("ATM", title="Strike Selection", options=["ATM","OTM","ITM"])
// === RISK MANAGEMENT ===
stopLossPts = input.int(50, title="Stop Loss (points)")
takeProfitPts = input.int(100, title="Take Profit (points)")
// === STRATEGY LOGIC: Moving Average Crossover ===
fastLength = input.int(9, title="Fast MA Length")
slowLength = input.int(18, title="Slow MA Length")
price = close
maFast = ta.sma(price, fastLength)
maSlow = ta.sma(price, slowLength)
// Crossover Long
if (ta.crossover(maFast, maSlow))
strategy.entry("Long", strategy.long, comment="MA Crossover Long")
// Crossunder Short
if (ta.crossunder(maFast, maSlow))
strategy.entry("Short", strategy.short, comment="MA Crossover Short")
// Apply SL and TP
strategy.exit("Exit Long", from_entry="Long", stop=close - stopLossPts, limit=close + takeProfitPts)
strategy.exit("Exit Short", from_entry="Short", stop=close + stopLossPts, limit=close - takeProfitPts)
// === PLOTS ===
plot(maFast, color=color.green, title="Fast MA")
plot(maSlow, color=color.red, title="Slow MA")
Skrypt open-source
W duchu TradingView twórca tego skryptu udostępnił go jako open-source, aby traderzy mogli analizować i weryfikować jego funkcjonalność. Brawo dla autora! Możesz korzystać z niego za darmo, ale pamiętaj, że ponowna publikacja kodu podlega naszym Zasadom Społeczności.
Wyłączenie odpowiedzialności
Informacje i publikacje przygotowane przez TradingView lub jego użytkowników, prezentowane na tej stronie, nie stanowią rekomendacji ani porad handlowych, inwestycyjnych i finansowych i nie powinny być w ten sposób traktowane ani wykorzystywane. Więcej informacji na ten temat znajdziesz w naszym Regulaminie.
Skrypt open-source
W duchu TradingView twórca tego skryptu udostępnił go jako open-source, aby traderzy mogli analizować i weryfikować jego funkcjonalność. Brawo dla autora! Możesz korzystać z niego za darmo, ale pamiętaj, że ponowna publikacja kodu podlega naszym Zasadom Społeczności.
Wyłączenie odpowiedzialności
Informacje i publikacje przygotowane przez TradingView lub jego użytkowników, prezentowane na tej stronie, nie stanowią rekomendacji ani porad handlowych, inwestycyjnych i finansowych i nie powinny być w ten sposób traktowane ani wykorzystywane. Więcej informacji na ten temat znajdziesz w naszym Regulaminie.