Volume Based Buy & Sell Momentum
Forums › ProRealTime English forum › ProBuilder support › Volume Based Buy & Sell Momentum
- This topic has 8 replies, 3 voices, and was last updated 1 month ago by
bruces.
-
-
01/19/2025 at 8:28 AM #242797This is a TradingView Pinescript Indicator that I would like to run on ProRealTime in a separate pane and be able to adjust the EMA length please:study(title=”Volume Based Buy and Sell Momentum by 2tm”, shorttitle=”VBSM”)EMA_Len = input(25, title=”Lenth”, minval=1)xROC = roc(close, 1)nRes1 = iff(volume < volume[1], nz(nRes1[1], 0) + xROC, nz(nRes1[1], 0))nRes2 = iff(volume > volume[1], nz(nRes2[1], 0) + xROC, nz(nRes2[1], 0))nRes3 = nRes1 + nRes2nResEMA3 = sma(nRes1, EMA_Len) + sma(nRes2, EMA_Len)PNVI = plot(nRes3, color=blue, title=”PVI + NVI”)PEMA = plot(nResEMA3, color=red, title=”EMA”)pCol = nRes3 > nResEMA3 ? blue : redfill (PNVI, PEMA, pCol)01/20/2025 at 12:43 PM #242845
Hi, here you have the code translated:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849// Parameter declarationEMALen = 25 // Adjustable EMA length set by the user// Calculation variablesxROC = ROC[1](Close) // Rate of Change of the closing price// Ensure enough bars exist for EMA calculationIF BarIndex > EMALen THEN// Calculate nRes1 based on decreasing volumeIF Volume < Volume[1] THENnRes1 = nRes1[1] + xROCELSEnRes1 = nRes1[1]ENDIF// Calculate nRes2 based on increasing volumeIF Volume > Volume[1] THENnRes2 = nRes2[1] + xROCELSEnRes2 = nRes2[1]ENDIF// Combine results to compute nRes3nRes3 = nRes1 + nRes2 // Combine nRes1 and nRes2 to compute the main indicator// Calculate EMA (Exponential Moving Average) of the accumulatorsnResEMA1 = Average[EMALen](nRes1)nResEMA2 = Average[EMALen](nRes2)nResEMA3 = nResEMA1 + nResEMA2 // Combine the EMAs of nRes1 and nRes2 to get the total EMA// Determine fill color based on the relationship between nRes3 and nResEMA3IF nRes3 > nResEMA3 THENr = 0g = 0b = 255ELSEr = 255g = 0b = 0ENDIF// Draw the shaded area between nRes3 and nResEMA3 with the calculated colorColorBetween(nRes3, nResEMA3, r, g, b, 30)ENDIF// Return the results on the chartRETURN nRes3 AS "PVI+NVI" COLOURED("blue"), nResEMA3 AS "EMA" COLOURED("red")01/20/2025 at 11:48 PM #242894Ivan, Thank you, Thank you Thank you.
Perfect – Very grateful
Would it be possible to include the option to paint the EMA line completely red as it is now OR green if Rate of Change is > zero and Red if ROC is < zero and black if ROC = zero? Not necessary on the other line, just the EMA.
Hope that is not pushing the boundaries too much.
Thyank you
Bruce
01/21/2025 at 9:14 AM #242899No problem. Here you have it
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364// Parameter declarationEMALen = 25 // Adjustable EMA length set by the user// Calculation variablesxROC = ROC[1](Close) // Rate of Change of the closing price// Ensure enough bars exist for EMA calculationIF BarIndex > EMALen THEN// Calculate nRes1 based on decreasing volumeIF Volume < Volume[1] THENnRes1 = nRes1[1] + xROCELSEnRes1 = nRes1[1]ENDIF// Calculate nRes2 based on increasing volumeIF Volume > Volume[1] THENnRes2 = nRes2[1] + xROCELSEnRes2 = nRes2[1]ENDIF// Combine results to compute nRes3nRes3 = nRes1 + nRes2 // Combine nRes1 and nRes2 to compute the main indicator// Calculate EMA (Exponential Moving Average) of the accumulatorsnResEMA1 = Average[EMALen](nRes1)nResEMA2 = Average[EMALen](nRes2)nResEMA3 = nResEMA1 + nResEMA2 // Combine the EMAs of nRes1 and nRes2 to get the total EMA// Determine fill color based on the relationship between nRes3 and nResEMA3IF nRes3 > nResEMA3 THENr = 0g = 0b = 255ELSEr = 255g = 0b = 0ENDIF// Draw the shaded area between nRes3 and nResEMA3 with the calculated colorColorBetween(nRes3, nResEMA3, r, g, b, 30)// Determine EMA color based on ROCif xROC > 0 thenr1=0g1=255b1=0elsif xROC < 0 thenr1=255g1=0b1=0elser1=0g1=0b1=0endifENDIF// Return the results on the chartRETURN nRes3 AS "PVI+NVI" COLOURED("blue"), nResEMA3 AS "EMA" COLOURED(r1,g1,b1)01/21/2025 at 11:53 AM #24290801/21/2025 at 3:44 PM #242925Hi,
Do you mean like this…?
Volume Based & Sell Momentum123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566DefParam DrawOnLastBarOnly=true// Parameter declarationEMALen = 25 // Adjustable EMA length set by the user// Calculation variablesxROC = ROC[1](Close) // Rate of Change of the closing price// Ensure enough bars exist for EMA calculationIF BarIndex > EMALen THEN// Calculate nRes1 based on decreasing volumeIF Volume < Volume[1] THENnRes1 = nRes1 + xROCELSEnRes1 = nRes1ENDIF// Calculate nRes2 based on increasing volumeIF Volume > Volume[1] THENnRes2 = nRes2 + xROCELSEnRes2 = nRes2ENDIF// Combine results to compute nRes3nRes3 = nRes1 + nRes2 // Combine nRes1 and nRes2 to compute the main indicator// Calculate EMA (Exponential Moving Average) of the accumulatorsnResEMA1 = Average[EMALen,1](nRes1)nResEMA2 = Average[EMALen,1](nRes2)nResEMA3 = nResEMA1 + nResEMA2 // Combine the EMAs of nRes1 and nRes2 to get the total EMA// Determine fill color based on the relationship between nRes3 and nResEMA3IF nRes3 > nResEMA3 THENr = 0g = 0b = 255ELSEr = 255g = 0b = 0ENDIF// Draw the shaded area between nRes3 and nResEMA3 with the calculated colorColorBetween(nRes3, nResEMA3, r, g, b, 30)EndIfEMAROC=ROC[1](nResEMA3)If EMAROC>0 thenr=0g=255b=0ElsIf EMAROC<0 thenr=255g=0b=0Elser=0g=0b=0EndIf// Return the results on the chartRETURN nRes3 AS "PVI+NVI" COLOURED("blue"), nResEMA3 AS "EMA" COLOURED(r,g,b)1 user thanked author for this post.
01/23/2025 at 7:58 AM #242973Hi Ivan, Apologies for delay in getting back to you.
I think the green (up trend) and red (down trend) of the EMA is now painting correctly on the EMA line on the chart, based on the slope of the EMA – see Pane 4 on attached chart. However, the plot of the EMA in the latest iteration of the code doesn’t look correct.
I’ve attached a screen shot of the PRT chart showing:
Pane 1 – Price Candles
Pane 2 – Version 1 of the VBSM converted from Tradingview, without alternate color plots on EMA (weren’t asked for at the time)
Pane 3 – Version 2 showing alternate color plots on EMA, but color coding incorrectly based on the trend/slope of the PVI+NVI line and not the EMA line
Pane 4 – Version 3 (and latest) showing alternate color plots on EMA, correctly based on the slope of the EMA line, but with incorrect EMA plot.The plot of the EMA in latest version (Pane 4) is different to the previous two plots. The plots in Panes 2 and 3 are correct as I have compared them to the plot of the original indicator in Tradingview.
So grateful for your work to date and wondering if you could have a look at for me please and resolve? That will be all that is required then thank you.
Thank you
Bruce
01/23/2025 at 11:02 AM #242978In the first two versions, the “EMA” was calculated as a “Simple Moving Average.”
See, for example, line 28 in the first and second versions:nResEMA1=Average[EMALen](nRes1)
Here, a “Simple Moving Average” was used for the calculation…
I changed this in the third version, where the calculation was correctly done using EMA’s instead of SMA’s.
This explains the difference compared to the first two versions…
1 user thanked author for this post.
01/23/2025 at 12:18 PM #242989 -
AuthorPosts
Find exclusive trading pro-tools on