Indicator · Pine Script v5 · On the chart

Dual MA Crossover Call Put Targets

by g-moe· code credited to goodgains

This indicator plots custom dual moving average crossovers directly on the price chart to signal potential Call (long) and Put (short) entries.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code134
Settings17inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 2026

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 indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

134 lines of Pine Script v5 from Tradingview/dual-ma-crossover-call-put-targets.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

dual-ma-crossover-call-put-targets.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains


//@version=5
indicator("Dual MA Crossover Call Put Targets", overlay = true)

// @keywords: dual-ma-crossover, moving-average-types, call-label, put-label, long-entry, short-entry, three-take-profits, stop-loss-line, entry-line, distance-multiples, trade-labels, price-labels, profit-zone-fill, loss-zone-fill, crossover-alert, crossunder-alert, target-hit-exit, pending-call-put, wma-ema-hma, band-between-levels


ma1_length = input.int(8, title = 'MA1', group = 'Signal Settings', inline = '1')
ma1_type = input.string(title=' ', defval='EMA', options=['MA', 'WMA', 'VWMA', 'EMA', 'HMA'],  group='Signal Settings', inline = '1')
ma1_price = input.source(close, title = '',  group='Signal Settings', inline = '1')

ma2_length = input.int(21, title = 'MA2', group = 'Signal Settings', inline = '2')
ma2_type = input.string(title=' ', defval='EMA', options=['MA', 'WMA', 'VWMA', 'EMA', 'HMA'],  group='Signal Settings', inline = '2')
ma2_price = input.source(close, title = '',  group='Signal Settings', inline = '2')

tgt1_mult = input.float(2.0, title = 'Target 1', group = 'Signal Settings', inline = '3')
tgt2_mult = input.float(2.5, title = 'Target 2', group = 'Signal Settings', inline = '4')
tgt3_mult = input.float(3.0, title = 'Target 3', group = 'Signal Settings', inline = '5')

// --FUNCTION TO CALCULATE MA-- //
getMA(src, len, type) =>
    ma_value = type == 'MA' ? ta.sma(src, len) : type == 'WMA' ? ta.wma(src, len) : type == 'VWMA' ? ta.vwma(src, len) : type == 'EMA' ? ta.ema(src, len) : type == 'HMA' ? ta.hma(src, len) : na
    ma_value
// --FUNCTION TO CALCULATE MA-- //



// define vars
var in_trade = false
var trade_side = 0

var float tgt1 = na
var float tgt2 = na
var float tgt3 = na
var float stop = na
var float entry_price = na
var float distance = na

var long_entry = false
var short_entry = false

var tgt_hit = false
var stop_hit = false

// calculate vars
ma1_value = getMA(ma1_price, ma1_length, ma1_type)
ma2_value = getMA(ma2_price, ma2_length, ma2_type)

long_entry := barstate.isconfirmed and ta.crossover(ma1_value, ma2_value) and trade_side != 1
short_entry := barstate.isconfirmed and ta.crossunder(ma1_value, ma2_value) and trade_side != -1

entry_price := long_entry[1] or short_entry[1] ? close[1] :  in_trade == true ? entry_price[1] : na
trade_side := long_entry[1] ? 1 : short_entry[1] ? -1 : in_trade == false ? 0 : trade_side[1]

stop := long_entry[1] or short_entry[1] ? open[1] : in_trade ? stop[1] : na
distance := math.abs(entry_price - stop)

tgt1 := long_entry[1] ? entry_price + distance * tgt1_mult : short_entry[1] ? entry_price - distance * tgt1_mult : in_trade ? tgt1[1] : na
tgt2 := long_entry[1] ? entry_price + distance * tgt2_mult : short_entry[1] ? entry_price - distance * tgt2_mult : in_trade ? tgt2[1] : na
tgt3 := long_entry[1] ? entry_price + distance * tgt3_mult : short_entry[1] ? entry_price - distance * tgt3_mult : in_trade ? tgt3[1] : na

tgt_hit := trade_side == 1 and high >= tgt3 or trade_side == -1 and low <= tgt3
stop_hit := trade_side == 1 and low <= stop or trade_side == -1 and high >= stop

in_trade := long_entry or short_entry ? true : tgt_hit or stop_hit ?  false : in_trade[1]
// bgcolor(trade_side == 1 ? color.green : trade_side ==  -1 ? color.red : na)
// barcolor(long_entry ? color.green : short_entry ? color.red : na)

//  calculate variables for text
profit_pct = math.round(math.abs((tgt3 - entry_price) / tgt3 * 100),2)
stop_pct = math.round(math.abs((stop - entry_price) / stop * 100),2)


target_text = 'TG 3 ' + str.tostring(math.round_to_mintick(tgt3))
stoploss_text = 'SL ' + str.tostring(math.round_to_mintick(stop)) 

// display vars
plot(ma1_value, title = 'MA1', color = color.green)
plot(ma2_value, title = 'MA2', color = color.red)

show_lines = input.bool(true, title = 'Show Lines', inline='1', group='Visual Settings')
show_positionlabels = input.bool(true, title = 'Show Trade Labels', inline='2', group='Visual Settings')
position_label_size = input.string('Medium', title = '', options = ['Small', 'Medium', 'Large'], inline='2', group='Visual Settings')
show_pricelabels = input.bool(true, title = 'Show Price Labels', inline='3', group='Visual Settings')
price_label_size = input.string('Small', title = '', options = ['Small', 'Medium', 'Large'], inline='3', group='Visual Settings')

entry_color = input.color(color.blue, title = 'Entry Color', group = 'Visual Settings', inline = '5')
tgt_color = input.color(color.green, title = 'Tgt Color', group = 'Visual Settings', inline = '5')
stop_color = input.color(color.red, title = 'Stop Color', group = 'Visual Settings', inline = '5')

position_labelsize = position_label_size == 'Small' ? size.tiny : position_label_size == 'Medium' ? size.small : position_label_size == 'Large' ? size.normal : size.small
if long_entry and show_positionlabels
    label.new(x = time, y = close, text = close > open ? 'CALL' : 'P.CALL', xloc = xloc.bar_time, yloc = yloc.belowbar, color = close > open ? tgt_color: color.gray, 
     textcolor = color.white, size = position_labelsize, textalign = text.align_center, style = label.style_label_up)
    
if short_entry and show_positionlabels
    label.new(x = time, y = close, text = close < open ? 'PUT' : 'P.PUT', xloc = xloc.bar_time, yloc = yloc.abovebar, color = close < open ? stop_color : color.gray, 
     textcolor = color.white, size = position_labelsize, textalign = text.align_center, style = label.style_label_down)



// lines
entry_plot = plot(show_lines ? entry_price : na, title = 'Entry Line', color = entry_color, style = plot.style_linebr, editable = true, offset = -1)
tp1_plot = plot(show_lines ? tgt1 : na, title = 'TP1', color = tgt_color, style = plot.style_linebr, editable = true, offset = -1)
tp2_plot = plot(show_lines ? tgt2 : na, title = 'TP2', color = tgt_color, style = plot.style_linebr, editable = true, offset = -1)
tp3_plot = plot(show_lines ? tgt3 : na, title = 'TP3', color = tgt_color, style = plot.style_linebr, editable = true, offset = -1)
stop_plot = plot(show_lines ? stop : na, title = 'SL', color = stop_color, style = plot.style_linebr, editable = true, offset = -1)

// background
fill(entry_plot, tp3_plot, color = color.new(color.green, 70), title = 'Profit BG')
fill(entry_plot, stop_plot, color = color.new(color.red, 70), title = 'Loss BG')

// labels
price_labelsize = price_label_size == 'Small' ? size.tiny : price_label_size == 'Medium' ? size.small : price_label_size == 'Large' ? size.normal : size.small
if (long_entry[1] or short_entry[1]) and show_pricelabels
    label.new(x = time[2], y = entry_price, text = (long_entry[1] ? '📈 ' : '📉 ') + str.tostring(entry_price), xloc = xloc.bar_time, yloc = yloc.price, color = entry_color, 
     textcolor = color.white, size = price_labelsize, textalign = text.align_center, style = label.style_label_center)
    label.new(x = time[2], y = tgt1, text = 'TP1 ' + str.tostring(tgt1), xloc = xloc.bar_time, yloc = yloc.price, color = tgt_color, 
     textcolor = color.white, size = price_labelsize, textalign = text.align_center, style = label.style_label_center)
    label.new(x = time[2], y = tgt2, text = 'TP2 ' + str.tostring(tgt2), xloc = xloc.bar_time, yloc = yloc.price, color = tgt_color, 
     textcolor = color.white, size = price_labelsize, textalign = text.align_center, style = label.style_label_center)
    label.new(x = time[2], y = tgt3, text = 'TP3 ' + str.tostring(tgt3), xloc = xloc.bar_time, yloc = yloc.price, color = tgt_color, 
     textcolor = color.white, size = price_labelsize, textalign = text.align_center, style = label.style_label_center)
    label.new(x = time[2], y = stop, text = 'SL ' + str.tostring(stop), xloc = xloc.bar_time, yloc = yloc.price, color = stop_color, 
     textcolor = color.white, size = price_labelsize, textalign = text.align_center, style = label.style_label_center)

// alerts
alertcondition(long_entry, 'CALL', 'CALL')
alertcondition(short_entry, 'PUT', 'PUT')
alertcondition(stop_hit, 'STOP HIT', 'STOP HIT')
alertcondition(tgt_hit, 'TP3 HIT', 'TP3 HIT')

Overview

Users can choose from SMA, EMA, WMA, VWMA, or HMA types for both moving averages. Upon a confirmed crossover, the script projects an entry price, a stop-loss level based on the previous bar open, and three profit targets using distance multipliers. It displays trade lines and labels to track active trade management on the price chart.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Moving averages, Trend, Support & resistance

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

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

SettingTypeDefaultVariable
MA1int8ma1_length
stringEMAma1_type
ma1_pricesourceclosema1_price
MA2int21ma2_length
stringEMAma2_type
ma2_pricesourceclosema2_price
Target 1float2.0tgt1_mult
Target 2float2.5tgt2_mult
Target 3float3.0tgt3_mult
Show Linesbooltrueshow_lines
Show Trade Labelsbooltrueshow_positionlabels
position_label_sizestringMediumposition_label_size
Show all 17 settings
SettingTypeDefaultVariable
Show Price Labelsbooltrueshow_pricelabels
price_label_sizestringSmallprice_label_size
Entry Colorcolorcolor.blueentry_color
Tgt Colorcolorcolor.greentgt_color
Stop Colorcolorcolor.redstop_color
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

257 stars

This indicator analyzes short-term price action on index futures and options charts by applying Rational Quadratic kernel smoothing to detect sideways consolidation ranges and potential breakouts. It processes pivot highs and lows over customizable loopback pe

Indicator v5 Support & resistanceTrend Repaints
Updated 6 weeks ago · None stated GitHub repository of SPX 30M - Trading Chart

Ichimoku Cloud

by harryguiacorn
219 stars

This indicator plots Ichimoku Cloud elements on the price chart, including Tenkan-sen, Kijun-sen, Senkou Span A and B lines with optional Chikou Span. It signals trend changes via Tenkan-sen and Kijun-sen crosses and places arrows at Kijun-sen direction shifts

Indicator v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of Ichimoku Cloud

MA Envelope (MAE)

by mihakralj
99 stars

The MA Envelope indicator calculates upper and lower channel bands shifted by a user-defined percentage around a baseline moving average. It supports Simple Moving Average, Exponential Moving Average, and Weighted Moving Average calculation types. The script p

Indicator v6 Moving averagesSupport & resistance
Updated 4 weeks ago · Apache-2.0 GitHub repository of MA Envelope (MAE)
56 stars

This indicator calculates an Exponential Moving Average and a Zero-Lag Moving Average to identify market trends on the price chart. It plots both moving averages and fills the space between them with color to highlight trend direction. Upon a crossover or cros

Indicator v5 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of No-Lag MA Trend Levels

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers