SMA Pine Language Tutorial Strategy Script
Pine Script strategy by Zer3192.
The original spec has no written description. Read the source below.
Source Pine Script
//@version=4
study("SMA Cross", overlay=true)
//strategy("strategy.percent_of_equity", overlay = false, default_qty_value = 100, default_qty_type = strategy.percent_of_equity, initial_capital = 1000000)
//SMA
fastSMA = sma(close, 10)
slowSMA = sma(close, 200)
//Buy
longCondition = crossover(fastSMA, slowSMA)
longStop = strategy.position_avg_price * 0.95
longEntry = strategy.position_avg_price * 1.05
//Sell
shortCondition = crossunder(fastSMA, slowSMA)
shortStop = strategy.position_avg_price * 1.05
shortEntry = strategy.position_avg_price * 0.95
//Alert
alertcondition(longCondition, title="SMA Cross", message="Buy Signal")
alertcondition(shortCondition, title="SMA Cross", message="Sell Signal")
//Plot
plotshape(longCondition, style=shape.triangleup, location=location.belowbar, color=color.green, text="Buy")
plotshape(shortCondition, style=shape.triangledown, location=location.abovebar, color=color.red, text="Sell")
//Strategy
strategy.entry("Long", strategy.long, when=longCondition)
strategy.entry("Short", strategy.short, when=shortCondition)
// StopLoss/Takeprofit
if (strategy.position_size > 0)
strategy.exit("stoploss/takeprofit","Long",stop=longStop, limit=longEntry)
if (strategy.position_size < 0)
strategy.exit("stoploss/takeprofit","Short", stop=shortStop, limit=shortEntry)Published by Zer3192 on the FMZ strategy square · last modified 2023-02-15. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/SMA-Pine-Language-Tutorial-Strategy-Script.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- Angle Attack Follow Line IndicatorPine Script · Other · 15m
- Customizable Backtest Start Time StrategyPine Script · Other · 2d
- Gann High LowPine Script · Other · 4h
- MACD StrategyPine Script · Other
- Monthly Performance PnL Calendar StrategyPine Script · Other · 1d
- QQE MOD SSL Hybrid Waddah Attar ExplosionPine Script · Other · 4h