Strategy · Pine Script v5 · On the chart

Xsodus CDC ActionZone V3

by xsodus

This strategy calculates fast and slow exponential moving averages to execute trend-following trades based on CDC ActionZone logic.

View on GitHub

GitHub stars5on the repository
Pine versionv5runs as is
Lines of code132
Settings10inputs
LicenceMIT
Last update2 weeks ago11 Oct 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 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

132 lines of Pine Script v5 from xsodus-cdc-strategy.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

xsodus-cdc-strategy.pine
// SPDX-License-Identifier: MIT
// © xsodus
// Added Labels and alert conditions and other quality of life feature

// This script was implemented based on CDC ActionZone indicator (by Piriya)
// The concept is to send a buy signal if fast EMA crosses over slow EMA and send a sell signal when the slow EMA crosses over fast EMA.
// In which, we call trend following strategy. 

//@version=5
strategy('Xsodus CDC ActionZone V3', overlay=true)

sourceData = input(title='Source Data', defval=close)
smoothPeriod = input(title='Smoothing period (1 = no smoothing)', defval=1)
startDate = input.time(title='Start Date', defval=timestamp('2018-01-01T00:00+07:00'))
endDate = input.time(title='End Date', defval=timestamp('9999-01-01T00:00+07:00'))

fastEMAInput = input(title='Fast EMA period', defval=12)
slowEMAInput = input(title='Slow EMA period', defval=26)

isLongStrategy = input(title='Long Position Strategy', defval=true)
enableStopLoss = input(title='Enable stop loss', defval=true)
enableTrailingStop = input(title='Enable trailing stop', defval=false)
stopLossPercentage = input.float(title='Stop loss %', defval=20) * 0.01


xPrice = ta.ema(sourceData, smoothPeriod)

emaFast = ta.ema(sourceData, fastEMAInput)
emaSlow = ta.ema(sourceData, slowEMAInput)

lastPrice = sourceData[1]

var isOrdered = false
// Calculate stop loss price condition.
var positionStopPrice = 0.0

long = emaFast > emaSlow
short = emaFast < emaSlow

// price bar colors
Green = long and xPrice > emaFast  // Buy
Blue = short and xPrice > emaFast and xPrice > emaSlow  //Pre Buy 2
LBlue = short and xPrice > emaFast and xPrice < emaSlow  //Pre Buy 1

Red = short and xPrice < emaFast  // Sell
Orange = long and xPrice < emaFast and xPrice < emaSlow  // Pre Sell 2
Yellow = long and xPrice < emaFast and xPrice > emaSlow  // Pre Sell 1


// Buy if the fast EMA is higer than slow EMA and current histrogram MACD is higer than 0
buy = long
sell = short

bColor = Green ? color.green : Blue ? color.blue : LBlue ? color.aqua : Red ? color.red : Orange ? color.orange : Yellow ? color.yellow : color.black
barcolor(bColor)

//****************************************************************************//
// Display MA lines

FastL = plot(emaFast, 'Fast EMA', color=color.new(color.red, 0))
SlowL = plot(emaSlow, 'Slow EMA', color=color.new(color.blue, 0))
fillcolor = long ? color.green : short ? color.red : color.black
fill(FastL, SlowL, fillcolor, transp=90)


plot(emaFast, title='Fast EMA', color=color.new(color.green, 0), linewidth=3)
plot(emaSlow, title='Slow EMA', color=color.new(color.red, 0), linewidth=3)



strategyName = isLongStrategy ? 'Long' : 'Short'
shouldOpenPosition = isLongStrategy ? buy : sell
shouldClosePosition = not shouldOpenPosition
mainStrategy = isLongStrategy ? strategy.long : strategy.short
hasClosePos = false
hasExitPos = false

// Update open position status
if time > startDate and time < endDate and isOrdered == false and strategy.position_size == 0
    isOrdered := shouldOpenPosition
    if isLongStrategy
        strategy.order(strategyName, strategy.long, when=shouldOpenPosition)
    else
        strategy.order(strategyName, strategy.short, when=shouldOpenPosition)


// Update stop loss status
if strategy.opentrades > 0 and enableStopLoss
    if enableTrailingStop and strategy.position_avg_price < lastPrice
        if isLongStrategy
            positionStopPrice := lastPrice * (1 - stopLossPercentage)
            positionStopPrice
        else
            positionStopPrice := lastPrice * (1 + stopLossPercentage)
            positionStopPrice
    if not enableTrailingStop
        if isLongStrategy
            positionStopPrice := strategy.position_avg_price * (1 - stopLossPercentage)
            positionStopPrice
        else
            positionStopPrice := strategy.position_avg_price * (1 + stopLossPercentage)
            positionStopPrice

if strategy.opentrades > 0 and enableStopLoss and positionStopPrice > 0.0
    hasExitPos = true
    strategy.exit(strategyName, stop=positionStopPrice)

// Update close position status
if strategy.opentrades > 0
    hasClosePos = true
    strategy.close(strategyName, when=shouldClosePosition)

// Reset flag for opening a new order
if strategy.opentrades == 0 and shouldClosePosition
    isOrdered := false
    positionStopPrice := 0.0
    positionStopPrice

// Debug in data window
plotchar(sourceData[0], 'Current Price', '', location=location.top)
plotchar(lastPrice, 'Last Bar Price', '', location=location.top)
plotchar(positionStopPrice, 'Current Stop Loss Price', '', location=location.top)

plotchar(buy, 'buy', '', location=location.top)
plotchar(sell, 'sell', '', location=location.top)
plotchar(shouldOpenPosition, 'Should open position', '', location=location.top)
plotchar(shouldClosePosition, 'Should close position', '', location=location.top)
plotchar(isOrdered, 'isOrdered', '', location=location.top)

plotchar(hasClosePos, 'hasClosePos', '', location=location.top)
plotchar(hasExitPos, 'hasExitPos', '', location=location.top)
plotchar(strategy.opentrades, 'position count', '', location=location.top)

Overview

Xsodus CDC ActionZone V3 colors price bars across six conditions depending on price position relative to the fast and slow EMAs. Entries occur when the fast EMA crosses the slow EMA within a defined date range, trading either long or short. Positions are managed using a percentage-based stop loss with an optional trailing stop. Key settings allow users to adjust EMA lengths, bar smoothing, and risk parameters directly on the price chart.

Details

Published by

xsodus on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Moving averages

Markets

Crypto

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

pinescript

Settings

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

SettingTypeDefaultVariable
Source DatasourceclosesourceData
Smoothing period (1 = no smoothing)int1smoothPeriod
Start Datetimetimestamp('2018-01-01T00:00+07:00')startDate
End Datetimetimestamp('9999-01-01T00:00+07:00')endDate
Fast EMA periodint12fastEMAInput
Slow EMA periodint26slowEMAInput
Long Position StrategybooltrueisLongStrategy
Enable stop lossbooltrueenableStopLoss
Enable trailing stopboolfalseenableTrailingStop
Stop loss %float20stopLossPercentage
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

Doge SMA

by hackingthemarkets
474 stars

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

Strategy v4 TrendMoving averages
Updated 4 years ago · None stated GitHub repository of Doge SMA

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

Strategy v6 TrendMoving averages
Updated today · AGPL-3.0 GitHub repository of Forven S01508 — Simple EMA20/50 Cross
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
257 stars

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

Strategy v5 TrendSupport & resistance Repaints
Updated 6 weeks ago · None stated GitHub repository of 30s - ES 1m Strategy Candle Bar

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