Seasonal Indicator
Forums › ProRealTime English forum › ProBuilder support › Seasonal Indicator
- This topic has 2 replies, 2 voices, and was last updated 5 years ago by Hasardeur.
-
-
10/22/2019 at 9:51 PM #110909
Hi All,
i would like to ask for a code assistance.
The attached code shows the seasonal behaviour
– quantity of up /down weeks from year to year in % (Histogram 1=100%)
– price percentage of the up /down weeks in %
– SumUp percentage of Price changing from Jan to Dec.- I would like to know how to code the vertical line shown 52 weeks ago from todays date without showing the vertival lines to the left.
How to eliminate the additional vertical lines to the left? - Is it possible to change the background colour all 3 monthy repeating every year.
For example:
2018, Jan-Mar= dark green, Apr-Jun=mid green, Jul-Sep=light green, Okt-Dec= yellow
2019, Jan-Mar= dark green, Apr-Jun=mid green, Jul-Sep=light green, Okt-Dec= yellow
– How is it possible to eliminate the fix variable of 2018 at the if loop at the beginning?
Many thanks for your support in advance.
Best RegardsHasardeur
Seasonal Indicator123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263// monthly1 = false (in weekly chart=false, in monthly chart=true) // variable boolean// LookbackYear s= 4SumTot= 0SumPos= 0SumNeg= 0//AvgTot= 0nPos = 0nNeg = 0Pb = 0LookBackYears= MAX(1, MIN(LookBackYears, 25))IF monthly1 THENt= 12 // look back period for monthly chartELSEt= 52 // look back period for monthly chartENDIFIF Year >= 2018 THENFOR m=0 TO LookBackYears DOREM cslculate positive/Negative months/weeksi= m*tSumTot= SumTot + (close[i]-open[i])/open[i]*100 // SumUp all (+/-) percentageIF (close[i]-open[i]) > 0 THENnPos= nPos+1 // SumUp positive months/weeksSumPos= SumPos + (close[i]-open[i])/open[i]*100 // SumUp positive price percentageELSEnNeg= nNeg-1 // SumUp positive months/weeksSumNeg= SumNeg + (Close[i]-Open[i])/open[i]*100 // SumUp negative price percentageENDIFNEXTREM calculate averagenYears= (LookBackYears+1)If Year[1]<Year ThenAvgTot= 0ELSEAvgTot= AvgTot + SumTot/nYearsEndif// total average price of pos/neg months/weeksIF (nPos/nYears) > 0.5 THENPb= nPos/nYears // percentage of pos monts/weeks (+1=100%)Avg= SumPos/nYears // average price of pos months/weeksELSIF (nPos/nYears) < 0.5 THENPb= nNeg/nYears // percentage of neg monts/weeks (-1=100%)Avg= SumNeg/nYears // average price of neg months/weeksELSEPb= 0Avg= SumTot/nYears //average price of 50% pos/neg months/weeksENDIFIf date > today-t ThenDRAWVLINE(barindex-t) // vertical line at 0NE look back perid (t) month/week from today on (last bar at the right)ENDIFFor u=1 to t DOIf month = u THENBACKGROUNDCOLOR(255/12*u, 255, 055/12*u,100) // background coloour (should canging all 3 month)ENDIFNEXTENDIFReturn Pb STYLE(histogram) as "Qty +/- [%]", Avg coloured(0, 0, 255) as "Price +/- [%]", AvgTot coloured(0, 0, 255) STYLE(line, 2) as "SumUp Price/Year [%]"10/23/2019 at 3:06 PM #110940Here is the modified code. I changed the vertical line color to red, because it was not clearly visible on a yellow background.
You can now choose the first year for the indicator to begin to be plotted in history with the StartYear variable.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384defparam drawonlastbaronly=truemonthly1 = 0 //(in weekly chart=false, in monthly chart=true) // variable booleanLookbackYears= 4 //FirstYear = 2016 //first year to plotSumTot= 0SumPos= 0SumNeg= 0//AvgTot= 0nPos = 0nNeg = 0Pb = 0LookBackYears= MAX(1, MIN(LookBackYears, 25))IF monthly1 THENt= 12 // look back period for monthly chartELSEt= 52 // look back period for monthly chartENDIFIF Year >= FirstYear THENFOR m=0 TO LookBackYears DOREM cslculate positive/Negative months/weeksi= m*tSumTot= SumTot + (close[i]-open[i])/open[i]*100 // SumUp all (+/-) percentageIF (close[i]-open[i]) > 0 THENnPos= nPos+1 // SumUp positive months/weeksSumPos= SumPos + (close[i]-open[i])/open[i]*100 // SumUp positive price percentageELSEnNeg= nNeg-1 // SumUp positive months/weeksSumNeg= SumNeg + (Close[i]-Open[i])/open[i]*100 // SumUp negative price percentageENDIFNEXTREM calculate averagenYears= (LookBackYears+1)If Year[1]<Year ThenAvgTot= 0ELSEAvgTot= AvgTot + SumTot/nYearsEndif// total average price of pos/neg months/weeksIF (nPos/nYears) > 0.5 THENPb= nPos/nYears // percentage of pos monts/weeks (+1=100%)Avg= SumPos/nYears // average price of pos months/weeksELSIF (nPos/nYears) < 0.5 THENPb= nNeg/nYears // percentage of neg monts/weeks (-1=100%)Avg= SumNeg/nYears // average price of neg months/weeksELSEPb= 0Avg= SumTot/nYears //average price of 50% pos/neg months/weeksENDIFIf date > today-t ThenDRAWVLINE(barindex-t) coloured(255,0,0) // vertical line at 0NE look back perid (t) month/week from today on (last bar at the right)ENDIF//For u=1 to t DO//If month = u THEN//BACKGROUNDCOLOR(255/12*u, 255, 055/12*u,100) // background coloour (should canging all 3 month)//ENDIF//NEXTif month>=1 and month<=3 thenr=0g=100b=0elsif month>=4 and month<=6 thenr=154g=205b=50elsif month>=7 and month<=9 thenr=202g=255b=112elser=255g=255b=0endifbackgroundcolor(r,g,b)ENDIFReturn Pb STYLE(histogram) as "Qty +/- [%]", Avg coloured(0, 0, 255) as "Price +/- [%]", AvgTot coloured(0, 0, 255) STYLE(line, 2) as "SumUp Price/Year [%]"1 user thanked author for this post.
10/24/2019 at 9:37 AM #111036 - I would like to know how to code the vertical line shown 52 weeks ago from todays date without showing the vertival lines to the left.
-
AuthorPosts
Find exclusive trading pro-tools on