OPEN-SOURCE SCRIPT
My script

//version=5
strategy("Algo Bot Starter (EMA+ATR, RR, Webhook)",
overlay=true,
initial_capital=10000,
commission_type=strategy.commission.percent,
commission_value=0.02,
calc_on_every_tick=false,
calc_on_order_fills=true,
pyramiding=0,
process_orders_on_close=true)
//================ Inputs ================
emaFastLen = input.int(20, "EMA Fast", minval=1)
emaSlowLen = input.int(50, "EMA Slow", minval=1)
atrLen = input.int(14, "ATR Length", minval=1)
atrMultSL = input.float(2.0, "SL = ATR x", step=0.1)
rr = input.float(1.5, "Risk:Reward (TP = RR x Risk)", step=0.1, minval=0.2)
riskPct = input.float(1.0, "Risk % per Trade", step=0.1, minval=0.1, maxval=5)
slipPips = input.float(0.0, "Extra buffer (price units)", step=0.0001)
sessionFilt = input.session("0000-2400", "Trading Session")
useSession = input.bool(false, "Use Session Filter?")
closeOnFlip = input.bool(true, "Close & Reverse on signal flip?")
useBarClose = input.bool(true, "Signal on Bar Close? (recommended)")
//================ Helpers ================
inSess = useSession ? time(timeframe.period, sessionFilt) : true
emaFast = ta.ema(close, emaFastLen)
emaSlow = ta.ema(close, emaSlowLen)
atr = ta.atr(atrLen)
// Cross conditions (optionally on bar close)
bull = useBarClose ? ta.crossover(emaFast, emaSlow) : ta.cross(emaFast, emaSlow) and (emaFast > emaSlow)
bear = useBarClose ? ta.crossunder(emaFast, emaSlow) : ta.cross(emaFast, emaSlow) and (emaFast < emaSlow)
//================ Risk & Position Sizing ================
// ملاحظة: TradingView ما يعرف رصيدك الحقيقي، فاعتمدنا على initial_capital أو عدّل أدناه يدويًا
equity = strategy.equity
riskAmount = equity * (riskPct/100.0)
// سنحسب الكمية حسب المسافة إلى وقف الخسارة بالوحدات السعرية (تقريب عام)
calcQty(entryPrice, slPrice) =>
riskPerUnit = math.abs(entryPrice - slPrice)
riskPerUnit := risk
strategy("Algo Bot Starter (EMA+ATR, RR, Webhook)",
overlay=true,
initial_capital=10000,
commission_type=strategy.commission.percent,
commission_value=0.02,
calc_on_every_tick=false,
calc_on_order_fills=true,
pyramiding=0,
process_orders_on_close=true)
//================ Inputs ================
emaFastLen = input.int(20, "EMA Fast", minval=1)
emaSlowLen = input.int(50, "EMA Slow", minval=1)
atrLen = input.int(14, "ATR Length", minval=1)
atrMultSL = input.float(2.0, "SL = ATR x", step=0.1)
rr = input.float(1.5, "Risk:Reward (TP = RR x Risk)", step=0.1, minval=0.2)
riskPct = input.float(1.0, "Risk % per Trade", step=0.1, minval=0.1, maxval=5)
slipPips = input.float(0.0, "Extra buffer (price units)", step=0.0001)
sessionFilt = input.session("0000-2400", "Trading Session")
useSession = input.bool(false, "Use Session Filter?")
closeOnFlip = input.bool(true, "Close & Reverse on signal flip?")
useBarClose = input.bool(true, "Signal on Bar Close? (recommended)")
//================ Helpers ================
inSess = useSession ? time(timeframe.period, sessionFilt) : true
emaFast = ta.ema(close, emaFastLen)
emaSlow = ta.ema(close, emaSlowLen)
atr = ta.atr(atrLen)
// Cross conditions (optionally on bar close)
bull = useBarClose ? ta.crossover(emaFast, emaSlow) : ta.cross(emaFast, emaSlow) and (emaFast > emaSlow)
bear = useBarClose ? ta.crossunder(emaFast, emaSlow) : ta.cross(emaFast, emaSlow) and (emaFast < emaSlow)
//================ Risk & Position Sizing ================
// ملاحظة: TradingView ما يعرف رصيدك الحقيقي، فاعتمدنا على initial_capital أو عدّل أدناه يدويًا
equity = strategy.equity
riskAmount = equity * (riskPct/100.0)
// سنحسب الكمية حسب المسافة إلى وقف الخسارة بالوحدات السعرية (تقريب عام)
calcQty(entryPrice, slPrice) =>
riskPerUnit = math.abs(entryPrice - slPrice)
riskPerUnit := risk
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.