Scripting: Variables and Properties

Hi Guys,

Knowledge Base article Bar Variables and Properties describes how to have Bar variables (BAR=) in scripts listed in the Structure Panel Properties list for the Script.

It would be fabulous if this functionality could be extended to allow the setting of any user defined variable within a script that may need to changed to suit the market or the value for testing.

For example (I know this won’t work, but it suggests usage):

// Bar Offset 
#$BarOffset = 3;

// Price Offset;
#$PriceOffset = 0.01;

//Find Bar Price Offset above previous offset Bar
V1 = High();
V2 = If(V1 - V1[$BarOffset] > $PriceOffset,1,0);
V2

This would be a very useful capability to save having multiple scripts that are essentially the same except for the variable values.

Ever hopeful for improve functionality.

Cheers

Trevor

 

 

Hi Trevor

The issue is that our scripts perform vector processing. we do it that way to save you from looping through all the data. That makes it a little tricky with a static value like your PriceOffset.

If you want to use a static value, you just need to put it into a list first. You can do that with this function VARTOLIST(VAL=$PriceOffset). It is essentially what we do beneath the surface as pre-process step.

In regard to BarOffset, you just forgot to add the “OFFSET=”. It’s always best to build the script with a custom number first and then change that number to a variable.

This script works

// Bar Offset
#$BarOffset = 3;

// Price Offset;
#$PriceOffset = 0.01;

//Find Bar Price Offset above previous offset Bar
V1 = High();
V2 = If(V1 - OFFSET(V1, OFFSET=$BarOffset) > VARTOLIST(VAL=$PriceOffset),1,0);
V2

All the best

Mathew

Hi Mathew,

That’s great. In fact, it would be worth a Knowledge Base article.

Many thanks.

Cheers

Trevor

Hi Trevor, Hi Mathew,

I have read your post with great interest. Unfortunately I did not really understand the “logic” of the script. As far as I have understood the script it calculates the difference between the current high and the high three days ago and if this difference is greater than 0.01 you get the value “1” and if the value of the difference between the current high and the high three days ago is not greater than 0.01 you get the value “0”.

So the indicator moves between “0” and “1”. In this way the indicator tries to identify a short up- or downtrend. If the value is “1” we have a short uptrend and with a value of “0” we have a short downtrend. Is this correct?

Concerning the VARTOLIST function I have nothing found in the Knowledge Base. Is there a description available?

Thanks

Thomas

Hi Thomas,

My original script was not intended to do anything useful so far as market analysis is concerned, it was very simply intended to show a requirement for being able to have script variables listed as Script Properties that could then be user adjusted without having to use the Script Manager to change the script variable, which Mathew very ably demonstrated with my “useless” script. It however served its purpose, which was simply to find a way of setting script variables as Script Properties.

Here’s Mathew’s version of the script showing the the script variables in the SHOWBAR Properties:

20200422 Variable Property Test Script

And yes, it would be very helpful if VARTOLIST was included in the Functions List in Knowledge Base ID 714 “Formula Functions & General Interface”.

Cheers

Trevor

Hi Trevor,

thank you very much for you kind replay.

Regarding the scripting with bar variables, Darren had created a video that shows how to do that.

The link to the video is:

https://www.optuma.com/videos/scripting-with-bar-variables/

Perhaps the video is of some interest for you.

Thomas

Thanks Thomas, but I’d already seen the video.

Trevor