Steps in making a script
VAI scripts are an easy but powerful way of creating your own indicators and systems. It’s like cooking a meal, each section or ingredient would work on its own but together, it makes the whole script or dish better. The more complex your meal is, the more different ingredients you’ll need.
However, you’ll still need to learn the syntax and primitives that we use, Excel users will find a lot of the syntax and operators familiar. If you’re unsure what’s the primitive for an indicator, example moving average, you can use the search function in the Knowledge Base. Now, I think we’re ready to run through what ingredients you need to add one by one.
Step 1 – Setting up the variables
Firstly, you’ll need to set up your variables, in this context, the indicators and settings that you’ll be using. For this example, we’ll be using a 10 and 50 period simple moving average. You can write it as follows:
Set abc = sma(close,10)
Set xyz = sma(close,50)
(you can change abc to whatever you want to rename the variable to)
Step 2 – Creating the conditions
After setting up the variables, you’ll need to tell the system what to do with them. In the same example, we’ll tell the system to buy and sell whenever 2 moving averages crosses each other.
Set Bullish = crossover(abc,xyz)
Set Bearish = crossover(xyz,abc)
Step 3 – Plotting the indicators and buy/sell signals in the chart
You can plot all the variables you make in the chart, all the different settings can be found in the Knowledge Base.
//To plot the indicators
//To plot the trading signals
Step 4 – Adding a command to make it readable for back testing
You’ll need to insert a command at the bottom so that the back tester would know what your buy and sell variables are, in this case, its:
And that’s it! We’re done with the basics, easy peasy!