Debugging using the Print() statement, where we write values or texts into the output, works very well, but in order to develop a better understanding about the processes in our scripts, we mainly use interactive live debugging in Visual Studio. This is the process of debugging while the script is running in AgenaTrader and we do live debugging of the status of our script in Visual Studio.
This offers the enormous advantage, that we can switch directly to our Visual Studio while executing the source code in AgenaTrader. So we have the opportunity to check and analyze various values of our variables in real time.
In order to be able to carry out our first live debugging, we need a script, ideally with a Print() statement and with one or more variables in AgenaScript, so that we can debug these variables interactively later.
Now make sure that your AgenaScript is saved and compile it in AgenaTrader. After successfully creating the new script, place the indicator on a chart in AgenaTrader. The results of the Print() statements are now displayed as usual in the AgenaTrader output window.
Now switch back to your Visual Studio and click on the left vertical bar at the level of your Print() statement. If you have clicked correctly, a red breakpoint will appear at which the execution will later be stopped while the script is still being executed and we can look at all the variables available at that point in time.
If we now reload the data in the chart or select a new instrument, it will not stop at our breakpoint because debugging is not yet activated for our script in Visual Studio. To enable interactive debugging, we click the Start button in Visual Studio.
After you click the Start button, Visual Studio will compile your script again and the debugging process will start. Now we update the data series in the chart in AgenaTrader or simply click on another instrument. Now we can immediately see that a yellow marker has now appeared at the red breakpoint. This means that we are now live in a debugging execution and can read the value of variables.
If you now place your mouse cursor exactly over a variable in the script (without clicking), the current value of the variable appears.
If you now click the function key F10, the yellow marking jumps to the next line, this means that we still have the debugging session active, but the program being executed has now taken another step in the algorithm. This means you can follow your entire source code line by line and control exactly how your variables change.
With F5 or the Next button you can cancel the current debugging process and the program will automatically continue to run normally until the red breakpoint is executed again.
When you’re done debugging and want to ignore all breakpoints in the current execution, you should click the Stop button, which is to the right of the Next button in Visual Studio.
Print() is great, but interactive live debugging is essential in your daily work as a script trader!