TradingView
chhagansinghmeena
30 אפר׳ 2023 16:24

Conceptive Price Moving Average [CSM] 

Nifty Bank IndexNSE

תיאור

The Conceptive Price Moving Average (CPMA) is a technical indicator designed to provide a more accurate moving average of the price by using the average of various price types, such as open, close, high, low, etc. The CPMA can help to smooth out the noise and provide a clearer picture of the overall trend by taking the average of the last 3 candles for each price type and then calculating the average of those averages.

To use the CPMA for generating buy/sell signals, you can look for crossovers of the CPMA and other commonly used moving averages, such as the 9-period EMA, 20-period EMA, 50-period EMA, 100-period EMA, and 200-period EMA, which are also plotted on the chart. When the CPMA crosses above a shorter-term moving average, such as the 9-period EMA or 20-period EMA, it can indicate a potential buy opportunity, while when the CPMA crosses below a shorter-term moving average, it can indicate a potential sell opportunity.

Based on my analysis of BankNifty and Nifty, I have found that the CPMA works best at a length of 21, showing good resistance and support for stocks. Therefore, I recommend using a length of 21 when using the CPMA for generating buy/sell signals.
תגובות
rajvardhan7744
//@version=5
strategy("CPMA Strategy", shorttitle="CPMA Strat", overlay=true)

// Define the length of the moving average
source = input(close, title="CMA Source")
length = input.int(21, title="CMA Length", minval=1)
length_09 = input.int(9, title="EMA 9", minval=1)
length_20 = input.int(20, title="EMA 20", minval=20)
length_50 = input.int(50, title="EMA 50", minval=50)
length_100 = input.int(100, title="EMA 100", minval=100)
length_200 = input.int(200, title="EMA 200", minval=200)

// Calculate the average of the last 3 candles for each price type
price_avg = ta.ema(source, length)
HL2_avg = ta.sma(hl2, length)
Open_avg = ta.ema(open, length)
High_avg = ta.sma(high, length)
Low_avg = ta.ema(low, length)
OHLC4_avg = ta.sma(ohlc4, length)
HLC3_avg = ta.ema(hlc3, length)
HLCC4_avg = ta.sma(hlcc4, length)

// Calculate the average of the price types
price_average = (price_avg + HL2_avg + Open_avg + High_avg + Low_avg + OHLC4_avg + HLC3_avg + HLCC4_avg) / 8
price_average := na(price_average[1]) ? price_average : price_average[1] + (source - price_average[1]) / (length * math.pow(source/price_average[1], 4))

ema9 = ta.ema(close, length_09)
ema20 = ta.ema(close, length_20)
ema50 = ta.ema(close, length_50)
ema100 = ta.ema(close, length_100)
ema200 = ta.ema(close, length_200)

// Plot the average on the chart
plot(price_average, color=color.blue, linewidth=2, title="CPMA")
plot(ema9, color=color.red, linewidth=1, title="EMA 9")
plot(ema20, color=color.green, linewidth=2, title="EMA 20")
plot(ema50, color=color.orange, linewidth=3, title="EMA 50")
plot(ema100, color=color.yellow, linewidth=4, title="EMA 100")
plot(ema200, color=color.white, linewidth=4, title="EMA 200")

// Generate Buy and Sell signals
strategy.entry("Buy", strategy.long, when=ta.crossover(price_average, ema9) or ta.crossover(price_average, ema20))
strategy.entry("Sell", strategy.short, when=ta.crossunder(price_average, ema9) or ta.crossunder(price_average, ema20))

// Exit signals based on longer-term moving averages
strategy.close("Buy", when=ta.crossunder(price_average, ema50) or ta.crossunder(price_average, ema100) or ta.crossunder(price_average, ema200))
strategy.close("Sell", when=ta.crossover(price_average, ema50) or ta.crossover(price_average, ema100) or ta.crossover(price_average, ema200))
עוד