Strategy · Pine Script v4 · On the chart

AlgoSight Strategy

by ashishanildhage· code credited to AlgoSoft

This long-only momentum strategy combines the Relative Strength Index with the Moving Average Convergence Divergence indicator.

View on GitHub

GitHub stars6on the repository
Pine versionv4older, still runs
Lines of code49
Settings10inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago19 Jan 2022

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 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

49 lines of Pine Script v4 from AlgoBot.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

AlgoBot.pine
// @version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlgoSoft
strategy("AlgoSight Strategy", shorttitle = "ASV1_Strat",overlay=true, margin_long=100, margin_short=100,default_qty_type=strategy.percent_of_equity, default_qty_value=100)

//Stoploss and Profits Inputs
stoploss_input=input(1.0,title="Stop Loss %", type=input.float, minval=1.0)/100
takeprofit_input=input(2.0,title="Take Profit %", type=input.float, minval=1.0)/100
enable=input(false,title="Enable Stoploss and Profit?")

stoploss_level = strategy.position_avg_price * (1 - stoploss_input)
takeprofit_level = strategy.position_avg_price * (1 + takeprofit_input)
plot(enable and stoploss_input and stoploss_level ? stoploss_level : na, color=color.red)
plot(enable and stoploss_input and takeprofit_level ? takeprofit_level : na, color=color.green)

//RSI Inputs
RSIOverSold = input(30, minval=1, title="RSI Over Sold Level")
RSIOverBought = input(70, minval=1, title="RSI Over Bought Level")
src = close
len = input(14, minval=1, title="RSI Line Length")
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)
wasOversold = rsi[0] <= RSIOverSold or rsi[1] <= RSIOverSold or rsi[2] <= RSIOverSold or rsi[3] <= RSIOverSold or rsi[4] <= RSIOverSold or rsi[5] <= RSIOverSold
wasOverbought = rsi[0] >= RSIOverBought or rsi[1] >= RSIOverBought or rsi[2] >= RSIOverBought or rsi[3] >= RSIOverBought or rsi[4] >= RSIOverBought or rsi[5] >= RSIOverBought


// MACD INPUTS
FastMA = input(title="MACD FastMA", type=input.integer, defval=12)
SlowMA = input(title="MACD SlowMA", type=input.integer, defval=26)
Signal = input(title="MACD Signal Line", type=input.integer, minval = 1, maxval = 50, defval = 9)
Source = input(title="Source", type=input.source, defval=close)
[currMacd, _, _] = macd(close[0], FastMA, SlowMA, Signal)
signal = ema(currMacd, 9)
avg_1 = avg(currMacd, signal)
crossoverBear = cross(currMacd, signal) and currMacd < signal ? avg_1 : na
avg_2 = avg(currMacd, signal)
crossoverBull = cross(currMacd, signal) and currMacd > signal ? avg_2 : na

// Strategy Long
strategy.risk.allow_entry_in(strategy.direction.long)
Long = wasOversold and crossoverBull
LongCondition1 = wasOverbought and crossoverBear
LongCondition2 = crossunder(FastMA, SlowMA) and avg_1 > .1
ExitLongCondition = wasOverbought and crossoverBear

strategy.entry("Long", strategy.long, when=Long)
strategy.close("Long", when=LongCondition1)
strategy.exit("Stop Loss/TP", "Long", when=enable, loss=stoploss_level, limit=takeprofit_level)

Overview

AlgoSight Strategy opens a long trade when the RSI has been in oversold territory within the last five bars and the MACD line crosses above its signal line. It closes open positions when the RSI was recently overbought alongside a bearish MACD cross. Optional percentage-based stop loss and take profit levels are plotted on the chart but remain disabled by default, meaning exits rely solely on technical signals.

Details

Published by

ashishanildhage on GitHub

Code credit

AlgoSoft, as written in the script's header

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Oscillators & momentum, Trend

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Stop Loss %float1.0stoploss_input
Take Profit %float2.0takeprofit_input
Enable Stoploss and Profit?boolfalseenable
RSI Over Sold Levelint30RSIOverSold
RSI Over Bought Levelint70RSIOverBought
RSI Line Lengthint14len
MACD FastMAint12FastMA
MACD SlowMAint26SlowMA
MACD Signal Lineint9Signal
SourcesourcecloseSource
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.

Similar Pine Scripts

330 stars

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

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

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

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy
285 stars

Mean Reversion Strategy is an overlay strategy that identifies pullbacks using a long-term EMA, RSI, and candlestick patterns. It generates long signals when a bullish engulfing candle forms below the EMA while RSI is oversold, and short signals when a bearish

Strategy v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Strategy
218 stars

This strategy generates trading signals based on a selectable momentum engine, supporting MACD, RSI, Stochastic, or Rate of Change. Entries trigger on signal crosses, zero-line crosses, or threshold crosses, with an optional moving average trend filter. Risk m

Strategy v6 Oscillators & momentumTrend
Updated 3 months ago · None stated GitHub repository of Momentum Strategy Template

255 EMA Strategy

by hasnocool
106 stars

255 EMA Strategy combines an exponential moving average with Average True Range bands and standard MACD crossovers to generate entry signals. Drawn directly on the price chart, it plots the central 255 EMA along with upper and lower volatility envelopes. Trade

Strategy v4 Moving averagesOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 255 EMA Strategy

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers