I am working on a project to identifying up and down trends using moving averages. I have seen on a web page the following chart. The special on this chart is that the moving average is colored according an existing up or down trend.
I want create also such a colored moving average.
Unfortunately I don’t know how to script this coloring. The code for the moving average would be something like the following:
MA(BARS=34, STYLE=Exponential, CALC=Close) TurnsDown
MA(BARS=34, STYLE=Exponential, CALC=Close) TurnsUp
But how is the coloring made? I want also use beside TurnsDown and TurnsUp a further “qualifier” to indicate a change in trend. That qualifier would be that the turn up or down of the moving average has to be at least 0.5 percent from the recent moving average high or low.
Any suggestion is welcome.
The majority of tools in Optuma have a Custom Colour scheme you can select via the tools properties. Once Custom is selected an area will be added to the Properties panel to add scripted criteria for each colour.
For your example you can set the default colour of the MA line to be red, then script the rules for the up colour:
MA(BARS=34, STYLE=Exponential, CALC=Close) IsUp
To add an extra rule where the colour is different when the MA turns back upwards and that the movement is greater than 0.5% you’d need the following script:
v1 = MA(BARS=34, STYLE=Exponential, CALC=Close);
v2 = ROC(v1, BARS=1) ;
v1 TurnsUp and v2 > 0.5
In the following example you can see the MA line will show Purple when this criteria is met, the rest of the time it’s blue / red.
thanks a lot. It is again so simple. I use the custom colour scheme a lot but came not to the idea to use it to colour the moving average.