Conditional Script


I have written a script to colour code chart bars but wish to enhance it so if I select a daily chart, it uses value A for MA and if it is a weekly chart, it uses value B for MA.

The existing script uses value A for MA regardless if I am selecting Daily or Weekly charts.

I have looked but unable to find a Chart function to specify which timeframe my chart is using to use a conditional or IF statement.

Would be greatly appreciated if anybody has any tips or sample code I can look at that would help me accomplish this?




Hi George,

It’s not possible to make a script conditional on the chart timeframe being used. However, it is possible to use scripts calculated on data from different time frames from the chart.

For example, on this daily chart the red bars are when the weekly RSI(10) is above 70:



Hi George,

Further to Darren’s previous reply, I believe it maybe possible to setup a script which takes time frame into account. (This script requires the latest build of Optuma 64bit V1.2).

Here is an example:

TF = BARDATE() - BARDATE(OFFSET=1); $a = IF(TF == 7, 10,50) ; CLOSE() CrossesAbove MA(BARS=$a)
In the above example the script will use a 10SMA for Weekly charts (ie when the BARDATE difference (TF) between consecutive bars is 7), and a 50SMA for any other time frame (when the value of TF is anything other than 7). You maybe able to use a similar script to achieve the result you are after.