Indicator · Pine Script v5 · On the chart

Mix1: EMA Cross + Trend Channel [Gu5]

by theonetrade· code credited to gu5tavo71 (Gustavo Cardelle)

Mix1: EMA Cross + Trend Channel combines fast and medium exponential moving averages with a 200-period baseline trend moving average to detect momentum and trend direction.

View on GitHub

GitHub stars34on the repository
Pine versionv5runs as is
Lines of code315
Settings18inputs
LicenceMIT
Last update2 weeks ago8 Nov 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

315 lines of Pine Script v5 from assets/indicator/bit-exact/mix1_ema_cross_trend_channel_gu5_YflOVb17.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

mix1_ema_cross_trend_channel_gu5_YflOVb17.pine
// This source code is subject to these terms:
// Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)
// https://creativecommons.org/licenses/by-nc/4.0/
// You are free to:
// Share, copy and redistribute this script
// Adapt, transform and build on this script
// Under the following terms:
// Non-commercial: You cannot sell my indicator. You can't sell my work.
// Attribution: If you post part of my code, you must give me proper credit
// © gu5tavo71 (Gustavo Cardelle)

//@version=5
indicator(title = 'Mix1 : Ema Cross + Trend Channel [Gu5]', shorttitle = 'Mix1', overlay = true)

// Indicator to combines:
//           Trend Channel[Gu5] (by @gu5tavo71) +
//           EMA's cross  (26, 50 ) +
//           Golden Cross (50, 200)
// Actual Study Version: @gu5tavo71
// v2.4.19, 2022.09.18
// Project #101
// This script was written using open source code from another authors:
// @PineCoders, Built-in Library, and Community Scripts
// And using the recommendations from the Pine Script™ User Manual's Style Guide
// Disclaimer: I am not a financial advisor.
//             For purpose educate only. Use at your own risk.

// ——————————— <constant_declarations> {
O_MALEN1     =                              'EMA'
O_MALEN2     =                              'SMA'
O_POSSEL1    =                              'Only Long'
O_POSSEL2    =                              'Only Short'
O_POSSEL3    =                              'Both'
O_TYPES1     =                              'Strategy 1'
O_TYPES2     =                              'Strategy 2'
O_START      = timestamp        (           '2020-01-01 00:00 GMT-3'        )
O_END        = timestamp        (           '2099-12-31 00:00 GMT-3'        )
C_GREEN      =                   #006400    //Green
C_GREENLIGHT =                   #388e3c    //Green Light
C_RED        =                   #8B0000    //Red
C_REDLIGHT   =                   #b71c1c    //Red Light

//}
// ——————————— <inputs> {
//           |                  |           |                               |         |
i_maSrc      = input.source     (close,     'MA Source'                     , group   = 'EMAs')
i_maFast1    = input.int        (26,        'EMA Fast'                      , group   = 'EMAs')
i_maFast2    = input.int        (50,        'EMA Medium'                    , group   = 'EMAs')
i_maLen      = input.int        (200,       'MA Trend'                      , group   = 'Trend Channel')
i_maLenSel   = input.string     (O_MALEN2,  'MA Type'                       , group   = 'Trend Channel',
     options =                              [O_MALEN1, O_MALEN2],
     tooltip =                              'EMA or SMA')
i_htf        = input.timeframe  ('',        'Select Higher Timeframe'       , group    = 'Trend Channel',
     tooltip =                              'Only for MA Trend'  )
i_rangeLen   = input.float      (0.618,     'Channel Range Length'          , group    = 'Trend Channel',
     tooltip =                              'ATR of the MA Trend')
//<stop loss>
i_slOn       = input.bool       (false,     '■ Stop Loss On/Off'            , group   = 'Stop Loss')
i_sl         = input.float      (2.618,     'SL %'                          , group   = 'Stop Loss', step    = 0.1)
i_periodSw   = input.bool       (false,     '■ Period On/Off'               , group   = 'Period')
//<period>
i_periodStar = input.time       (O_START,   'Start Time'                    , group   = 'Period')
i_periodEnd  = input.time       (O_END,     'End Time'                      , group   = 'Period')
i_posSel     = input.string     (O_POSSEL3, 'Position Type'                 , group   = 'Strategy',
     options =                              [O_POSSEL1, O_POSSEL2, O_POSSEL3],
     tooltip =                              "Only Long, Only shortE or Both")
i_typeS      = input.string     (O_TYPES2,  'Strategy Type'                 , group   = 'Strategy',
     options =                              [O_TYPES1, O_TYPES2],
     tooltip =                              "Strategy 1:\n
                                             Long, when the price (close) crosses the ema.\n
                                             Strategy 2:\n
                                             Long, only when ema goes up")
i_barColOn   = input.bool       (true,      '■ Bar Color On/Off'            , group   = 'Display')
i_alertOn    = input.bool       (true,      '■ Alert On/Off'                , group   = 'Display')
i_channelOn  = input.bool       (false,     '■ Channel Range On/Off'        , group   = 'Display',
     tooltip =                              'If the price (close) is over than the channel, the trend is bullish. If the price is under, bearish. And if the price is in the channel, it is in range')
i_goldenOn   = input.bool       (false,     '■ Golden Cross On/Off'         )
//}
// ——————————— <calculations> {
//<set initial values>
condition    = 0.0

maFast1      = ta.ema(i_maSrc, i_maFast1)
maFast2      = ta.ema(i_maSrc, i_maFast2)
maDir        = maFast1 > maFast2 ? 1 : -1
maTrend      = request.security(syminfo.tickerid, i_htf,
               i_maLenSel == "SMA" ? ta.sma(close, i_maLen)[1] : ta.ema(close, i_maLen)[1],
               lookahead = barmerge.lookahead_on)  //No repaint
maTrendDir   = i_maSrc >= maTrend ? 1 : -1
rangeAtr     = ta.atr(i_maLen) * i_rangeLen
rangeTop     = maTrend + rangeAtr
rangeBot     = maTrend - rangeAtr
rangeCh      = (open <= rangeTop or close <= rangeTop) and
               (open >= rangeBot or close >= rangeBot)
trendDir     = i_typeS  ==  'Strategy 1'                              ?
               rangeCh                                                ?  0 :
               maTrendDir ==  1 and maDir ==  1 and maTrend > maFast2 ?  0 :
               maTrendDir == -1 and maDir == -1 and maTrend < maFast2 ?  0 :
               maTrendDir ==  1 and maDir ==  1                       ?  1 :
               maTrendDir == -1 and maDir == -1                       ? -1 : 0 :
               rangeCh                                                ?  0 :
               maTrendDir ==  1 and maDir ==  1                       ?  1 :
               maTrendDir == -1 and maDir == -1                       ? -1 : 0
GCross       = i_goldenOn ? ta.crossover (maFast2, maTrend) : na
DCross       = i_goldenOn ? ta.crossunder(maFast2, maTrend) : na
period       = i_periodSw ? 
               time >= i_periodStar and time <= i_periodEnd : true
//<rules>
entryLong    = i_posSel != 'Only Short' and
               trendDir ==  1           and
               period 
entryShort   = i_posSel != 'Only Long'  and
               trendDir == -1           and
               period 
exitLong     = i_posSel != 'Only Short' and (
               trendDir !=  1           or
               maDir    == -1)          and
               condition[1] ==  1       and
               period
exitShort    = i_posSel != 'Only Long'  and (
               trendDir != -1           or
               maDir    ==  1)          and
               condition[1] == -1       and
               period
//<stop loss>
slEntry      = i_slOn ?
               close * i_sl / 100 : na
slTop        = close + slEntry
slBot        = close - slEntry
slTopBuff    = ta.valuewhen(condition[1] !=  1 and entryLong,  slBot, 0)
slBotBuff    = ta.valuewhen(condition[1] != -1 and entryShort, slTop, 0)
slLine       = condition[1] == -1 and entryLong  ? slTopBuff :
               condition[1] ==  1 and entryShort ? slBotBuff :
               condition[1] ==  1  or entryLong  ? slTopBuff :
               condition[1] == -1  or entryShort ? slBotBuff : na
slLong       = condition[1] ==  1 and ta.crossunder(close, slLine) or high > slLine and low < slLine
slShort      = condition[1] == -1 and ta.crossover (close, slLine) or high > slLine and low < slLine
//<conditions>
condition   := condition[1] !=  1 and entryLong  ?  1 :
               condition[1] != -1 and entryShort ? -1 :
               condition[1] ==  1 and slLong     ?  0 :
               condition[1] == -1 and slShort    ?  0 :
               condition[1] !=  0 and exitLong   ?  0 :
               condition[1] !=  0 and exitShort  ?  0 : nz(condition[1])
longE        = condition[1] !=  1 and condition ==  1
shortE       = condition[1] != -1 and condition == -1
longX        = condition[1] ==  1 and exitLong  and not slLong
shortX       = condition[1] == -1 and exitShort and not slShort
longSL       = condition[1] ==  1 and slLong
shortSL      = condition[1] == -1 and slShort
//<color>
c_emas       = longX                          ? color.new(color.orange, 99) :
               shortX                         ? color.new(color.orange, 99) :
               trendDir ==  1 and maDir ==  1 ? color.new(C_GREEN,      99) :
               trendDir == -1 and maDir == -1 ? color.new(C_RED,        99) :
               color.new(color.orange, 99)
c_maFill     = longX                          ? color.new(color.orange, 70) :
               shortX                         ? color.new(color.orange, 70) :
               trendDir ==  1 and maDir ==  1 ? color.new(C_GREEN,      70) :
               trendDir == -1 and maDir == -1 ? color.new(C_RED,        70) :
               color.new(color.orange, 70)
c_maTrend    = trendDir ==  0                           ? color.new(color.orange,  0) :
               trendDir ==  1 and maTrend[1]  < maTrend ? color.new(C_GREEN,       0) :
               trendDir ==  1 and maTrend[1] >= maTrend ? color.new(C_GREENLIGHT,  0) :
               trendDir == -1 and maTrend[1]  < maTrend ? color.new(C_REDLIGHT,    0) :
               trendDir == -1 and maTrend[1] >= maTrend ? color.new(C_RED,         0) : na
c_ch         = trendDir ==  0                           ? color.new(color.orange, 75) :
               trendDir ==  1                           ? color.new(C_GREEN,      75) :
               trendDir == -1                           ? color.new(C_RED,        75) : na
c_slLineUp   = ta.rising (slLine, 1)
c_slLineDn   = ta.falling(slLine, 1)
c_slLine     = c_slLineUp ? na :
               c_slLineDn ? na :
               color.new(C_RED,         0)
c_barCol     = trendDir ==  0                   ? color.new(color.orange,  0) :
               trendDir ==  1 and open <= close ? color.new(C_GREEN,       0) :
               trendDir ==  1 and open >  close ? color.new(C_GREENLIGHT,  0) :
               trendDir == -1 and open >= close ? color.new(C_RED,         0) :
               trendDir == -1 and open <  close ? color.new(C_REDLIGHT,    0) :
               color.new(color.orange,  0)
//}
// ——————————— <plots> {
p_maFast1    = plot(
  maFast1,
  title      = 'EMA Fast 1',
  color      = c_emas,
  linewidth  = 1)
p_maFast2    = plot(
  maFast2,
  title      = 'EMA Fast 2',
  color      = c_emas,
  linewidth  = 2)
fill(
  p_maFast1, p_maFast2,
  title      = 'EMAs Fill',
  color      = c_maFill)
plot(
  maTrend,
  title      = 'SMA Trend',
  color      = c_maTrend,
  linewidth  = 3)
p_chTop      = plot(
  i_channelOn   ? rangeTop : na,
  title      = 'Top Channel',
  color      = c_maTrend,
  linewidth  = 1)
p_chBot      = plot(
  i_channelOn   ? rangeBot : na,
  title      = 'Bottom Channel',
  color      = c_maTrend,
  linewidth  = 1)
fill(
  p_chTop, p_chBot,
  title      = 'Channel',
  color      = c_ch)
plot(
  i_slOn and condition != 0 ? slLine : na,
  title      = 'Stop Loss Line',
  color      = c_slLine,
  linewidth  = 1,
  style      = plot.style_linebr)
//}
// ——————————— <alerts> {
plotshape(
  i_alertOn and longE ? high : na,
  title      = 'Long',
  text       = 'Long',
  textcolor  = color.white,
  color      = color.new(C_GREEN, 0),
  style      = shape.labelup,
  size       = size.normal,
  location   = location.belowbar)
plotshape(
  i_alertOn and shortE ? low : na,
  title      = 'Short',
  text       = 'Short',
  textcolor  = color.white,
  color      = color.new(C_RED, 0),
  style      = shape.labeldown,
  size       = size.normal,
  location   = location.abovebar)
plotshape(
  i_alertOn and (longX or shortX) ? close : na,
  title      = 'Close',
  text       = 'Close',
  textcolor  = color.new(color.yellow, 0),
  color      = color.new(color.yellow, 0),
  style      = shape.xcross,
  size       = size.small,
  location   = location.absolute)
//<stop loss>
plotshape(
  i_alertOn and (longSL or shortSL) ? slLine : na,
  title      = 'Stop Loss',
  text       = 'SL',
  textcolor  = color.new(color.yellow, 0),
  color      = color.new(color.yellow, 0),
  style      = shape.xcross,
  size       = size.small,
  location   = location.absolute)

plotshape(
  i_alertOn and i_goldenOn and GCross ? maTrend : na,
  title      = 'Golden Cross',
  text       = 'Golden\nCross',
  textcolor  = color.white,
  color      = color.new(color.orange, 0),
  style      = shape.labelup,
  size       = size.normal,
  location   = location.absolute)
plotshape(
  i_alertOn and i_goldenOn and DCross ? maTrend : na,
  title      = 'Death Cross',
  text       = 'Death\nCross',
  textcolor  = color.white,
  color      = color.new(color.orange, 0),
  style      = shape.labeldown,
  size       = size.normal,
  location   = location.absolute)

barcolor(i_barColOn ? c_barCol : na)
bgcolor(
  i_periodSw and not period ? color.new(color.gray, 90) : na,
  title      = 'Session')

alertcondition(
  longE or shortE or longX or shortX or longSL or shortSL,
  title      = "Any Alert",
  message    = "Any Alert")
alertcondition(
  longE,
  title      = "Buy",
  message    = "Buy")
alertcondition(
  shortE,
  title      = "Sell",
  message    = "Sell")
alertcondition(
  longX,
  title      = "Buy Close",
  message    = "Buy Close")
alertcondition(
  shortX,
  title      = "Sell Close",
  message    = "Sell Close")

alertcondition(
  longSL,
  title      = "Stop Loss Long",
  message    = "Stop Loss Long")
alertcondition(
  shortSL,
  title      = "Stop Loss Short",
  message    = "Stop Loss Short")
//}

Overview

Mix1: EMA Cross + Trend Channel [Gu5] calculates an ATR-based trend channel around the 200-period MA, which can optionally source data from a higher timeframe. The indicator identifies EMA crossovers and Golden Crosses directly on the price chart. Users can customize MA lengths, switch between SMA and EMA for the trend line, adjust channel width parameters, set time filters, and toggle visual features such as bar coloring and signal alerts.

Details

Published by

theonetrade on GitHub

Code credit

gu5tavo71 (Gustavo Cardelle), as written in the script's header

Draws

On the price chart

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.

Topics

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
MA Sourcesourceclosei_maSrc
EMA Fastint26i_maFast1
EMA Mediumint50i_maFast2
MA Trendint200i_maLen
MA TypestringO_MALEN2i_maLenSel
Select Higher Timeframetimeframei_htf
Channel Range Lengthfloat0.618i_rangeLen
■ Stop Loss On/Offboolfalsei_slOn
SL %float2.618i_sl
■ Period On/Offboolfalsei_periodSw
Start TimetimeO_STARTi_periodStar
End TimetimeO_ENDi_periodEnd
Show all 18 settings
SettingTypeDefaultVariable
Position TypestringO_POSSEL3i_posSel
Strategy TypestringO_TYPES2i_typeS
■ Bar Color On/Offbooltruei_barColOn
■ Alert On/Offbooltruei_alertOn
■ Channel Range On/Offboolfalsei_channelOn
■ Golden Cross On/Offboolfalsei_goldenOn
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 2 months ago · None stated GitHub repository of SPX 30M - Trading Chart

Ichimoku Cloud

by harryguiacorn
220 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 8 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 3 months ago · None stated GitHub repository of No-Lag MA Trend Levels

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers