May 4, 2021 at 1:26 am #63741Dan
- Topics: 1
- Replies: 0
- Posts: 1
I am looking to build an indicator that references two securities.
A percent rate of change, weekly for 4 time periods of CPER (US) minus percent rate of change, weekly for 4 time periods of GLD (US)
If CPER is greater than GLD, even if both are negative, this should still be a positive number.
The values could be a positive or negative number
I would like it plotted as an indicator in two ways:
1.Multi-plot shading…….can these values be plotted, something like a Kuomo Cloud?
If CPER percent change is greater than GLD, then the cloud would be green; if CPER percent change is less than GLD, then the cloud would be red
The cloud would be expand/contract based on values of percent ROC minus percent ROC
2. Green or red ribbon
Here, there would be no values, simply….the ribbon would be green if CPER percent ROC > GLD percent ROC
or red, if GLD percent ROC > CPER percent ROC
Also, to show how the coding is different for weekly values as opposed to daily, can I see:
ROC based on daily charts, with a ROC of 30 days?
ThanksMay 4, 2021 at 11:00 am #63752Matthew
- Topics: 5
- Replies: 521
- Posts: 526
There are actually two scripts that would be needed to do this. One to set the value and one to control the colour.
As we are only working with a single value (the difference between the two ROCs) a shaded ribbon does not really work well. A shaded zone usually needs two reference points, so i have used a Histogram in my example. If you were planning to have the individual ROC values as plots on the script as well as the change, a ribbon may work, what i’ve provided below should give you the foundation you need to build the display style you are after.
The script to find the ROC variation between the two codes would be:12345678910//Set Source Codes on a Weekly Time frameDATA1 = GETDATA(CODE=CPER:US, TIMEFRAME=1 Week) ;DATA2 = GETDATA(CODE=GLD:US, TIMEFRAME=1 Week);//Find 4 Week Rate of Change % for both CodesV1 = ROC(DATA1, BARS=4) ;V2 = ROC(DATA2, BARS=4) ;//Plot Variation between the two ROC valuesV1 - V2
Applied using a Show View, the Plot Style needs to be set to Histogram and the Colour scheme set to Custom. This will allow us to setup the second script to control the colour so that the bars are green whenever the ROC for CPER is higher than that of GLD.12345678910//Set Source Codes on a Weekly Time frameDATA1 = GETDATA(CODE=CPER:US, TIMEFRAME=1 Week) ;DATA2 = GETDATA(CODE=GLD:US, TIMEFRAME=1 Week);//Find 4 Week Rate of Change % for both CodesV1 = ROC(DATA1, BARS=4) ;V2 = ROC(DATA2, BARS=4) ;//Plot Variation between the two ROC valuesV1 - V2
Set the colour for this script to be green and the default colour to be red, and it will display the expected result.
I’ve attached a workbook sample you can reference.
Regarding the time frame and ROC periods, these can be changed in the script. Time frames via the Data1 and Data2 variables, and the ROC period via the V1 and V2 variables.
- You must be logged in to reply to this topic.