New to Python on Optuma - Setup and code to get the data to run a backtest

Hi everyone,
new to Optuma; I would like to import a python code to perform a backtest.
After having right-clicked, and having named the new file, I would like to understand how I can get the closing data using the below code. Are thay stored in an array so that I can use them as a time series?

import Tool

#Init function gets called once when tool is applied/loaded
def Init():
Tool.Props.Name = "ABCD.2 "

#Process function gets called when applied/loaded or when new data is received

#start, end are the start and end+1 indexes of the source data list.
def Process(start, end):
for i in range(start, end):
Tool.DataOut.Row(i).Close = Tool.Source.Row(i).close


Besides, Trying to run the script above, we get the following error, as the Tool module has not been found.

Traceback (most recent call last):

File [\mydoc.intranet.servizi \Optuma\Local\Python Scripts\ABCD.2 .py](file://mydoc.intranet.servizi%20/Optuma/Local/Python%20Scripts/, line 1, in
import Tool
ModuleNotFoundError: No module named ‘Tool’

Thanks in advance


It looks like you might be trying to run the default Python script in the editor, unfortunately, it doesn’t work that way, the editor is only used to edit the script not run it.

To run the script you need to save the Python script in the editor and click the Reproces Python Script action in Optuma.

To get the data into a Python array, you can add it to a python array in the for loop using Tool.Source.Row(i).close as the value to add.

Once you get the function working you can use it as the entry or exit script in a backtest using the backtest module.