1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.
Source Code
31 lines of Pine Script v4 from Generic Strategy Code.txt, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.
Generic Strategy Code.txt
//@version=4
strategy(title="Generic Strategy", shorttitle="GS", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100, currency=currency.USD,commission_type=strategy.commission.percent,commission_value=0.1)
// === GENERAL INPUTS ===
//strategy start date
start_day = input(defval=1, title="Backtest Start Day")
start_month = input(defval=1, title="Backtest Start Month")
start_year = input(defval=2020, title="Backtest Start Year")
// === LOGIC ===
fast = ema(hl2, 15)
slow = ema(hl2, 45)
plot(fast)
plot(slow)
// === STRATEGY - LONG POSITION EXECUTION ===
enterLong() =>
crossover(fast,slow) and
time > timestamp(start_year, start_month, start_day, 01, 01)
exitLong() =>
false
strategy.entry(id="Long", long=strategy.long, when=enterLong())
strategy.close(id="Long", when=exitLong())
// === STRATEGY - SHORT POSITION EXECUTION ===
enterShort() =>
crossunder(fast,slow) and
time > timestamp(start_year, start_month, start_day, 01, 01)
exitShort() =>
false
strategy.entry(id="Short", long=strategy.short, when=enterShort())
strategy.close(id="Short", when=exitShort())
Overview
Generic Strategy enters long on an upward cross and short on a downward cross, reversing between the two, and starts trading from a date set by day, month and year inputs. Position size is the full equity with a small percentage commission. It has no stop loss or take profit and is meant to be edited.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Backtest Start Day
int
1
start_day
Backtest Start Month
int
1
start_month
Backtest Start Year
int
2020
start_year
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
Doge SMA is a long-only moving-average crossover strategy drawn on the price chart. It calculates a fast and a slow simple moving average of close and enters a long position when the fast average crosses above the slow average, but only inside a user-defined s
This strategy calculates and plots a fast Exponential Moving Average (EMA) and a slow EMA directly on the main price chart. It enters long trades when the fast EMA crosses above the slow EMA and exits when the fast EMA crosses below the slow EMA. Inputs allow
2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the
This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can
This strategy calculates dynamic support and resistance levels using pivot highs and lows alongside a custom smoothed trend filter and a 3-period EMA. It identifies entry opportunities when price breaks out relative to the trend filter and short-term EMA cross
EMA Crossover Strategy plots a fast and a slow exponential moving average on the price chart. It treats a confirmed fast-over-slow cross as a long condition and a confirmed cross under as a short condition. Position size is a percentage of equity. Optional per