Strategy · Pine Script v4 · On the chart

Dual Moving Average

by hirawatt· code credited to yesgoods

Dual Moving Average is a Pine Script v4 strategy that overlays the price chart.

View on GitHub

Repaints

GitHub stars11on the repository
Pine versionv4older, still runs
Lines of code44
Settings5inputs
LicenceMIT
Last update2 years ago11 Dec 2023

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

44 lines of Pine Script v4 from strategy/defaultStrategy.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

defaultStrategy.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © yesgoods

//@version=4
// Strategy {

strategy(title="Dual Moving Average", overlay=true,
     pyramiding=0, initial_capital=100000,
     commission_type=strategy.commission.cash_per_order,
     commission_value=60, slippage=5,
     format=format.price,
     max_bars_back=375,
     default_qty_type=strategy.fixed,
     calc_on_every_tick=true)
strategy.risk.max_cons_loss_days(15)

// Variables {

// Using close is faster than using hlc3
src = input(title="Source", type=input.source, defval=hlc3)

start = input(title="Date", type=input.time, defval=timestamp("20 Feb 2001 00:00 +0300"))
end = input(title="Date", type=input.time, defval=timestamp("20 Feb 2022 00:00 +0300"))

sym = input(title="Symbol", type=input.symbol, defval="BANKNIFTY")
res = input(title="Resolution", type=input.resolution, defval="1D")

//}


// Design {

var table t = table.new(position.top_right, 2, 3)

table.cell(t, 0, 0, "RSI", rsi(src, 14), bgcolor = color.lime)
table.cell(t, 0, 1, "RSI", rsi(src, 14), bgcolor = color.lime)
table.cell(t, 0, 2, "RSI", rsi(src, 14), bgcolor = color.lime)

table.cell(t, 1, 0, "RSI", rsi(src, 14), bgcolor = color.lime)
table.cell(t, 1, 1, "RSI", rsi(src, 14), bgcolor = color.lime)
table.cell(t, 1, 2, "RSI", rsi(src, 14), bgcolor = color.lime)

//}
//}

Overview

The shown code declares a strategy with fixed quantity, cash commission, slippage, and calculation on every tick. Inputs set the price source, a start and end date, a symbol that defaults to BANKNIFTY, and a resolution that defaults to one day. A top-right table prints the 14-period RSI of the source in every cell. No moving-average calculation, entry, exit, or stop loss appears in the provided code. It can change on the live bar.

Details

Published by

hirawatt on GitHub

Code credit

yesgoods, as written in the script's header

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Oscillators & momentum, Screeners & dashboards

Markets

Indices

Timeframes

H4 and above

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • The strategy enters trades without a stop loss

Topics

pinescriptpinescript-indicatorspinescript-strategiestradingview

Settings

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

SettingTypeDefaultVariable
Sourcesourcehlc3src
Datetimetimestamp("20 Feb 2001 00:00 +0300")start
Datetimetimestamp("20 Feb 2022 00:00 +0300")end
SymbolsymbolBANKNIFTYsym
Resolutiontimeframe1Dres
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

104 stars

This overlay strategy combines a machine-learning distance model with a MACD oscillator to open trades on the price chart. It compares recent history using cosine similarity or Euclidean and Lorentzian distance, then filters direction with selectable moving-av

Strategy v5 AI / machine learningOscillators & momentum
Updated 3 years ago · MIT GitHub repository of MLCEL and MACD Strategy
13 stars

This strategy automates the TradingLatino methodology by evaluating Squeeze Momentum combined with the Average Directional Index (ADX). It executes long or short positions based on momentum shifts and directional strength. Risk management options include const

Strategy v5 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of Ruckard Lupown TradingLatino A002

This long-only trend-following strategy combines Ichimoku Kinko Hyo components with higher timeframe moving average filters. It triggers long entries when price trades above a higher timeframe EMA and a bullish Tenkan-Sen cross above Kijun-Sen occurs under fav

Strategy v5 TrendOscillators & momentum
Updated 1 year ago · MPL-2.0 GitHub repository of Ichimoku Kinko Hyo Momentum Strategy
7 stars

This strategy plots RSI on the price chart and enters a long when RSI falls below the oversold level or a short when it rises above the overbought level, only while flat. It exits with a take profit and stop loss measured in pips from the current close. Inputs

Strategy v6 Oscillators & momentumScalping
Updated 3 months ago · None stated GitHub repository of XAUUSD 1-Minute Scalping Strategy
4 stars

Momentum Rotation (Top 3) ranks ten large-cap US tech stocks by their six-month returns using daily closes. It rebalances monthly and holds the top three performing stocks long only on the price chart. A ranking table shows the current order. Main settings adj

Strategy v6 Oscillators & momentumTrend
Updated 5 months ago · None stated GitHub repository of Momentum Rotation (Top 3)
4 stars

This strategy enters a long position when a short RSI falls below a user threshold and price is above a simple moving average trend filter. It closes the long when RSI rises above a second threshold and does not set a stop loss. Position size defaults to full

Strategy v6 Oscillators & momentumMoving averages
Updated 13 days ago · MIT GitHub repository of RSI(2) pullback + TokIO check

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