Strategy · Pine Script v4 · On the chart

CDC Action Zone V.3 Test ++Position Size Fix+Float

by hasnocool· code credited to FlowerSeason

The CDC Action Zone V.3 Test strategy calculates fast and slow exponential moving averages to generate trend-following buy and sell signals.

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code339
Settings26inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

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

339 lines of Pine Script v4 from AZ V.3 Test ++Position Size Fix+Float.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

AZ V.3 Test ++Position Size Fix+Float.pine
// © FlowerSeason
// Original by piriya33 [CDC Action Zone V.3]
// Consult by InwCoin 
// This Strategy is public for free to pay my respects to my TEACHER.
//--------------//
// Core Concept //
//--------------//
// This Strategy is Base on EMA Cross
// But thing what make this strategy be different from original CDC Action Zone V.3 is "Position Size"
// Compound Profit & Not Compound Profit Strategy 
//-------------------------//
// Position Sizing Concept //
//-------------------------//
// Be real.Everyone know the key of survive in the Market is "Risk & Money Management" 
// So, How can we manage our Risk and Money?
// Yes, The key is " Make the Risk celling "
            ////////////////////////////////////
            //// (Risk% * 100) / Stoploss % ////
            ////////////////////////////////////
// How can we make the Risk celling?
// 1. Define your Risk Per Trade for you. (How much % money of your portfolio are you willing to pay for this trade?)
//    - Example -
//          - I Have 3,000$ in my portfolio. 
//          - I think i can take the risk per trade for my trade 2.5% of my portfolio. (75$)
//          - I calculate the Position Size of my trade to pay 2.5% of my portfolio when i need to stoploss. (75$)
//          - And then, I have 97.5% of my fund (2,925$) for fight in next trade.
//          - ***** So, I'll never lose a big money of my fund. And "SURVIVE" in long term. *****
// 2. Mark the "Entry Point" and "Stop Loss Point" 
//    - Example -
//          - I have a Entry Point at price 30,000 $  
//          - I Make the "Hard Stop" at previous low 11 Bar. (Hard Stop = When the price went lower from this point, We Sell this position without any pity)
//          - For example. I assume the previous low is 20,000$
//          - I Clac. the different % from Entry to Stoploss. (33%)
//          - ***** So, If the price went low from Entry Point -33%. I'll stop this position. *****
// 3. Calculate my position size.
            ////////////////////////////////////
            //// (Risk% * 100) / Stoploss % ////
            ////////////////////////////////////
//          - In the past 2 Example.
//          - We have Risk%      = 2.5% [75$]
//          - We have Stoploss%  = 33%    
//          - So, We clac.   >>   [(2.5 * 100) / 33]
//          - 7.575757       >>   7.5 % of my Portfolio
//          - 7.5 % of my Portfolio = 225 $
//          - ***** When my position [225$] Dropdown [33%] I'll lose [75$] for this trade and survive to fight in next trade. *****
//-------------------------//
// Compound Profit Concept //
//-------------------------//
// We calculate the base equity from [Fund + Profit] 
// Normal People use this.
//-----------------------------//
// Not Compound Profit Concept //
//-----------------------------//
// We calculate the base equity from [Fund Only] 
// If we have some profit. We use this profit for "Reserve" the loss in next trade.
//****************************************************************************//
//****************************************************************************//
//@version=4
strategy("CDC Action Zone V.3 Test ++Position Size Fix+Float", shorttitle="Action Zone V.3 + Position Sizing [Float],[Fix] Equity", overlay=true, precision = 4, initial_capital=3000, default_qty_type=strategy.cash, default_qty_value=10, currency=currency.USD, process_orders_on_close=true, pyramiding=0)
//****************************************************************************//
// CDC Action Zone is based on a simple EMA crossover 
// between [default] EMA12 and EMA26
// The zones are defined by the relative position of 
// price in relation to the two EMA lines
// Different zones can be use to activate / deactivate 
// other trading strategies
// The strategy can also be used on its own with 
// acceptable result, buy on the first green candle
// and sell on the first red candle
//****************************************************************************//
//****************************************************************************//
//=============================//
//   Define Money Management   //
//=============================//
SnowBall        = input(title="Profit+Fund = Gear Up [Float]", type=input.bool, defval=false) // Compound Profit Switch
ZeroRisk        = input(title="Only Fund = 0% Risk [Fix]", type=input.bool, defval=true)      // Not Compound Profit Switch
Risk_Per_Trade          = input(2.5, "% of Risk Per Trade") / 100                             // Risk% Per Trade Switch
//=============================//
// Define User Input Variables //
//=============================//
plotSig2sw       = input(title="Momentum based Buy/Sell Strategy ", type=input.bool, defval=true)
GreenRedStrategy = input(title="เขียว-แดง Long Strategy ", type=input.bool, defval=true)
xsrc             = input(title="Source Data",type=input.source, defval=close)
xprd1            = input(title="Fast EMA period", type=input.integer, defval=12)
xprd2            = input(title="Slow EMA period", type=input.integer, defval=26)
xsmooth          = input(title="Smoothing period (1 = no smoothing)", type=input.integer, defval=1)
fillSW           = input(title="Paint Bar Colors", type=input.bool, defval=true)
fastSW           = input(title="Show fast moving average line", type=input.bool, defval=true)
slowSW           = input(title="Show slow moving average line", type=input.bool, defval=true)
labelSwitch      =  input(title="Turn on assistive text", type=input.bool, defval=false)
plotSigsw        = input(title="Plot Buy/Sell Signals? ", type=input.bool, defval=true)
plotRibsw        = input(title="Plot Buy/Sell Ribbon", type=input.bool, defval=true)
plotRibbonPos    = input(title="Ribbon Position", options=["Top", "Bottom"], defval="Top")
xfixtf           = input(title="** Use Fixed time frame Mode (advanced) **", type=input.bool, defval=false)
xtf              = input(title="** Fix chart to which time frame ? **)", type=input.resolution, defval="D")
plotSig2lv       = input(title="Set signal threshold (higher = stricter)", type=input.integer, defval=1, minval=0, maxval=1)
//****************************************************************************//
//****************************************************************************//
//=======================//
// Calculate Action Zone //
//=======================//
xPrice = ema(xsrc,xsmooth)
FastMA = xfixtf ?
     ema(
         security(syminfo.ticker,
             xtf,
             ema(xsrc,xprd1)),
         xsmooth):
     ema(xPrice,xprd1)
SlowMA = xfixtf ?
     ema(
         security(syminfo.ticker,
             xtf,
             ema(xsrc,xprd2)),
         xsmooth):
     ema(xPrice,xprd2)
Bull = FastMA > SlowMA
Bear = FastMA < SlowMA
//****************************************************************************//
//====================//
// Define Color Zones //
//====================//
Green  = Bull and xPrice>FastMA // Buy
Blue   = Bear and xPrice>FastMA and xPrice>SlowMA //Pre Buy 2
LBlue  = Bear and xPrice>FastMA and xPrice<SlowMA //Pre Buy 1
Red    = Bear and xPrice < FastMA // Sell
Orange = Bull and xPrice < FastMA and xPrice < SlowMA // Pre Sell 2
Yellow = Bull and xPrice < FastMA and xPrice > SlowMA // Pre Sell 1
//****************************************************************************//
//========================//
// Display color on chart //
//========================//
bColor = Green ? color.green : 
     Blue ? color.blue : 
     LBlue ? color.aqua : 
     Red ? color.red : 
     Orange ? color.orange : 
     Yellow ? color.yellow : 
     color.black
barcolor(color=fillSW? bColor : na)
//****************************************************************************//
//==================//
// Display MA lines //
//==================//
FastL      = plot(fastSW ? FastMA : na,"Fast EMA",color=color.red)
SlowL      = plot(slowSW ? SlowMA : na,"Slow EMA",color=color.blue)
fillcolor  = Bull ? color.green : Bear ? color.red : color.black
fill(FastL,SlowL,fillcolor)
//****************************************************************************//
// Define Buy and Sell condition
// This is only for thebasic usage of CDC Actionzone (EMA Crossover) 
// ie. Buy on first green bar and sell on first red bar
buycond  = Green and Green[1]==0
sellcond = Red and Red[1]==0
bullish  = barssince(buycond) < barssince(sellcond)
bearish  = barssince(sellcond) < barssince(buycond)
buy      = bearish[1]and buycond
sell     = bullish[1] and sellcond
bColor_BullBear = bullish ? color.green : bearish ? color.red : color.black
//****************************************************************************//
//==================================//
// Plot Buy and Sell point on chart //
//==================================//
plotshape(plotSigsw ? buy : na,
     style=shape.circle,
     title = "Buy Signal",
     location = location.belowbar,
     color = color.green)
plotshape(plotSigsw ? sell : na,
     style=shape.circle,
     title = "Sell Signal",
     location=location.abovebar,
     color = color.red)
// Display Buy/Sell Ribbon
plotshape(plotRibsw ? plotRibbonPos == "Top" ? close : na : na,
     style=shape.square,
     title = "Buy/Sell Ribbon", 
     location = location.top, 
     color = bColor_BullBear)
     
plotshape(plotRibsw ? plotRibbonPos == "Bottom" ? close : na : na,
     style=shape.square,
     title = "Buy/Sell Ribbon", 
     location = location.bottom, 
     color = bColor_BullBear)
    
//****************************************************************************//
//=======//
// Label //
//=======//
labelstyle = close>SlowMA ? label.style_labeldown : label.style_labelup
labelyloc = close>SlowMA ? yloc.abovebar : yloc.belowbar
labeltcolor = buy? color.black : 
     sell ? color.white :
     close > close[1] ? color.green : 
     color.red
labelbgcolor = buy ? color.green : sell ? color.red : color.silver
labeltext = buy ? "BUY next bar\n" : sell ? "SELL next bar\n" : " "
trendText = bullish ? "bullish" : bearish ? "bearish" : "sideways"
l1 = label.new(bar_index,na,
     text=labeltext+syminfo.ticker + " "+tostring(close) + " " + syminfo.currency + "\n currently in a " + trendText + " trend \n" ,
     color = labelbgcolor, 
     textcolor=labeltcolor, 
     yloc=labelyloc, 
     style=labelstyle)
label.delete(labelSwitch ? l1[1] : l1)
//____________________________________________________________________________//
//____________________________________________________________________________//
// Momentum Signal using StochRSI //
// Adds a momentum based signal following trends to the script
// Default is hidden, only use with caution
// Parameters for STOCH RSI is hard-coded to avoid cluttering the input screen further
// If you need to change anything, make a copy of the code and change it.
// Inputs are commented out, to enable them comment out the hard coded variables first!
// fixed inputs //
smoothK  = 3
smoothD  = 3
RSIlen   = 14
STOlen   = 14
SRsrc    = close
OSlevel  = 30
OBlevel  = 70
// User inputs // // COMMENT ABOVE VARIABLES FIRST!! 
// smoothK = input(3,"StochRSI smooth K",type=input.integer,minval=1)
// smoothD = input(3,"StochRSI smooth D",type=input.integer,minval=1)
// RSIlen = input(14,"RSI length",type=input.integer,minval=1)
// STOlen = input(14,"Stochastic length",type=input.integer,minval=1)
// SRsrc = input(close,"Source for StochasticRSI",type=input.source)
// OSlevel = input(30,"Oversold Threshold",type=input.float,minval=0.00)
// OBlevel = input(70,"Oversold Threshold",type=input.float,minval=0.00)
// calculations //
rsi1  = rsi(SRsrc,RSIlen)
k     = sma(stoch(rsi1,rsi1,rsi1,STOlen),smoothK)
d     = sma(k,smoothD)
// storsiBuySig =  if bullish
//     if (d < OSlevel and crossover(k,d))
//         3
//     else if crossover(k,OSlevel)
//         2
//     else if d > OSlevel and crossover(k,d)
//         1
//     else
//         0
// else
//     0
storsiBuySig = iff(bullish,
                     iff(d < OSlevel and crossover(k,d),
                         2,
                         iff(d > OSlevel and crossover(k,d),
                             1,
                             0)),
                     0)
storsiSellSig = iff(bearish,
                     iff(d > OBlevel and crossunder(k,d),
                         2,
                         iff(d < OBlevel and crossunder(k,d),
                             1,
                             0)),
                     0)
BuyMomentum = iff(bullish,
                     iff(d < OSlevel and crossover(k,d),
                         2,
                         iff(d > OSlevel and crossover(k,d),
                             1,
                             0)),
                     0)
SellMomentum   = iff(bearish,
                     iff(d > OBlevel and crossunder(k,d),
                         2,
                         iff(d < OBlevel and crossunder(k,d),
                             1,
                             0)),
                     0)
//****************************************************************************//
// === BACKTEST RANGE === //
use_date_range = input(true)
FromYear  = input(defval = 2018, title = "From Year", minval = 1950)
FromMonth = input(defval = 1, title = "From Month", minval = 1)
FromDay   = input(defval = 1, title = "From Day", minval = 1)
ToYear    = input(defval = 9999, title = "To Year", minval = 1950)
ToMonth   = input(defval = 1, title = "To Month", minval = 1)
ToDay     = input(defval = 1, title = "To Day", minval = 1)
in_date_range = use_date_range ? (time > timestamp(FromYear, FromMonth, FromDay, 00, 00)) and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59)) : true
//stopLoss = (price * stop_loss_percent / 100 / leverage) / syminfo.mintick
//****************************************************************************//
//****************************************************************************//
//////////////////////////////////////////////
//    define strategy entry / exit          //
//////////////////////////////////////////////
// Equity Monitor
var initialCapital_A = ( strategy.initial_capital + strategy.netprofit + strategy.openprofit )  // Compound Profit 
initialCapital_B     = ( strategy.initial_capital + strategy.netprofit + strategy.openprofit )  // Not Compound Profit 
// LONG CONDITIONS
Select_Long_Condition_1       = (  Bull and xPrice > FastMA  ) and (GreenRedStrategy == true)    // Buy when color bar = GREEN
Open_Long_Condition           = (( Select_Long_Condition_1 )) and strategy.opentrades == 0
//****************************************************************************//
// STOP LOSS
float longSL = na
longSL := Open_Long_Condition ? lowest(low, 11)[1] : longSL[1]                                   // This is Hard Stop
//****************************************************************************//
// TAKE PROFIT
Long_Entry_Price   = close
Diff_OPEN_to_SL    = abs(Long_Entry_Price - longSL)                                              // Clac. the different price for find the [Stoploss %]
// Exit CONDITIONS
Select_TakeProfit_Condition_1       = ( Red and Red[1]==0 )                                      // Sell when color bar = RED
Exit_Long_Condition                 = (( Select_TakeProfit_Condition_1 )) 
Position_Value_USD_A      = initialCapital_A * Risk_Per_Trade / ( Diff_OPEN_to_SL / Long_Entry_Price )   // Compound Profit
Position_Value_USD_B      = initialCapital_B * Risk_Per_Trade / ( Diff_OPEN_to_SL / Long_Entry_Price )   // Not Compound Profit
Real_Position_Size_A        = Position_Value_USD_A / Long_Entry_Price                                    // Compound Profit
Real_Position_Size_B        = Position_Value_USD_B / Long_Entry_Price                                    // Not Compound Profit
//****************************************************************************//
// POSITION SIZE CAP
Not_Over_Size_A       = ( Real_Position_Size_A * xPrice ) < initialCapital_A    // Compound Profit
Over_Size_A           = ( Real_Position_Size_A * xPrice ) > initialCapital_A    // Compound Profit
Not_Over_Size_B       = ( Real_Position_Size_B * xPrice ) < initialCapital_B    // Not Compound Profit
Over_Size_B           = ( Real_Position_Size_B * xPrice ) > initialCapital_B    // Not Compound Profit
//****************************************************************************//
// ENTRY/EXIT
if ( Open_Long_Condition ) and ( in_date_range ) and ( Not_Over_Size_A ) and ( ZeroRisk == 1 )    // Compound Profit
    strategy.entry( "LONG", strategy.long, qty= Real_Position_Size_A )
if ( Open_Long_Condition ) and ( in_date_range ) and ( Not_Over_Size_B ) and ( SnowBall == 1 )    // Not Compound Profit
    strategy.entry( "LONG", strategy.long, qty= Real_Position_Size_B )
if ( Open_Long_Condition ) and ( in_date_range ) and ( Over_Size_A ) and ( ZeroRisk == 1 )        // Compound Profit
    strategy.entry( "LONG", strategy.long, qty= initialCapital_A / Long_Entry_Price ) 
if ( Open_Long_Condition ) and ( in_date_range ) and ( Over_Size_B ) and ( SnowBall == 1 )        // Not Compound Profit
    strategy.entry( "LONG", strategy.long, qty= initialCapital_B / Long_Entry_Price ) 
if ( Exit_Long_Condition ) and in_date_range
    strategy.close(  "LONG"  ) 
//****************************************************************************//
//****************************************************************************//
// PLOT STOP LOSS
longPlotSL = strategy.opentrades > 0 and strategy.position_size > 0 ? longSL : na
plot(longPlotSL, title='LONG STOP LOSS', linewidth=3, style=plot.style_linebr, color=color.red)
// PLOT BUY MORE
plotshape(plotSig2sw ? storsiBuySig > plotSig2lv ? storsiBuySig : na : na, "Buy more signals", style=shape.triangleup, location=location.bottom, color = color.teal)
plotshape(plotSig2sw ? storsiSellSig > plotSig2lv ? storsiSellSig : na : na, "Sell more signals", style=shape.triangledown, location=location.bottom, color = color.orange)
//****************************************************************************//
//****************************************************************************//
Expand (480 lines)

Overview

CDC Action Zone V.3 Test ++Position Size Fix+Float plots EMA lines, custom bar colors, buy and sell labels, and a visual ribbon directly on the main price chart. The strategy executes trades based on EMA crossovers with customizable position sizing calculations for fixed or compounding risk management. Users can adjust period lengths, momentum thresholds, fixed timeframes, and backtest date ranges. The strategy defaults to exiting on opposing signals without a built-in fixed stop loss order.

Details

Published by

hasnocool on GitHub

Code credit

FlowerSeason, as written in the script's header

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Trend, Oscillators & momentum, Moving averages

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
Profit+Fund = Gear Up [Float]boolfalseSnowBall
Only Fund = 0% Risk [Fix]booltrueZeroRisk
% of Risk Per Tradefloat2.5Risk_Per_Trade
Momentum based Buy/Sell Strategy booltrueplotSig2sw
เขียว-แดง Long Strategy booltrueGreenRedStrategy
Source Datasourceclosexsrc
Fast EMA periodint12xprd1
Slow EMA periodint26xprd2
Smoothing period (1 = no smoothing)int1xsmooth
Paint Bar ColorsbooltruefillSW
Show fast moving average linebooltruefastSW
Show slow moving average linebooltrueslowSW
Show all 26 settings
SettingTypeDefaultVariable
Turn on assistive textboolfalselabelSwitch
Plot Buy/Sell Signals? booltrueplotSigsw
Plot Buy/Sell RibbonbooltrueplotRibsw
Ribbon PositionstringTopplotRibbonPos
** Use Fixed time frame Mode (advanced) **boolfalsexfixtf
** Fix chart to which time frame ? **)timeframeDxtf
Set signal threshold (higher = stricter)int1plotSig2lv
use_date_rangebooltrueuse_date_range
From Yearint2018FromYear
From Monthint1FromMonth
From Dayint1FromDay
To Yearint9999ToYear
To Monthint1ToMonth
To Dayint1ToDay
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

This strategy combines Arnaud Legoux Moving Average percentage price change calculations with an adaptive Gaussian Moving Average to generate trend-following signals. Long and short entries are triggered when the ALMA change calculation crosses above or below

Strategy v5 Moving averagesOscillators & momentum
Updated 6 weeks ago · None stated GitHub repository of ESM2024 - ALMA Smoothed Gaussian Moving Average
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

SMA RSI Strategy

by PythonForForex
64 stars

This strategy evaluates simple moving averages and the Relative Strength Index to generate trading signals. It calculates a 10-period SMA, a 30-period SMA, and a 14-period RSI. Long positions are entered when the fast SMA crosses above the slow SMA while RSI i

Strategy v5 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of SMA RSI Strategy

Momentum Rider DAILY FINAL

by greenpeas007
58 stars

This strategy combines exponential moving averages (EMA 9, 21, 50), RSI, MACD, and Supertrend indicators to enter long positions. It triggers trades using six dynamic setups based on momentum breakouts, EMA crossovers, and pullbacks. Position sizing is compute

Strategy v6 TrendOscillators & momentum Repaints
Updated 4 months ago · Custom licence GitHub repository of Momentum Rider DAILY FINAL

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