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
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.