Python Tool
Overview
Python is a popular programming language that now has limited support within Optuma (from versions 2.0 and later).
Requirements
There are a number of prerequisites that must be met before the Python tool will display:
- You need an Active Trader Services (or higher) subscription with Optuma
- You must have a version of Python 3.10 or above installed. Download the latest free version from here.
- Python must be added to your Windows Path (this option is provided as part of the standard Python installation).
Note
If you already have Python installed and it is not part of the Windows Path you can set it up manually using the process outlined here.
Once all prerequisites have been met you will have access to the Python tool in Optuma.
Using the Python Tool
Right-click on the chart, go to the Tool (spanner) icon, and search for Python. Left-click on the option that is found in the list.
The tool will be added to the chart (but will display not plots by default). On the left-side Actions panel click the Create New Python Script option.
A pop-up window will appear where you can enter in a new name for the script.
Enter a name and press Ok and the Python editor will appear.
The Python (.py) tool files created are stored in your Documents/Optuma/Local/Python Scripts folder.
Example Python Script
The following is an example Python script you can use in Optuma…
import Tool
from datetime import datetime
def Init():
global bars,date,list,real
Tool.Props.Name = 'My Tool'
Tool.Props.Hint = 'My Tool Hint [REAL]'
Tool.Props.PlotColor = 0x0000ff #BBGGRR
bars= Tool.AddInteger('BARS', 'Bars', 12)
date= Tool.AddDate('DATE','Date', 1545730073)
list= Tool.AddList('LIST','List','One|Two|Three')
real= Tool.AddReal('REAL','Real',23.5)
timestamp = 1545730073
dt_object = datetime.fromtimestamp(timestamp)
print("dt_object =", dt_object)
def Process(start, end):
real.Value = real.value + 1
m = Tool.RunScript('MA(BARS='+str(bars.value)+', STYLE=Simple, CALC=Close)', Tool.Source)
print(date.Value)
for i in range(start, end):
Tool.DataOut.Row(i).close = m.Row(i).close
def OnPropertyChange(var):
print(var.Name)
print(var.Value)
Once the code has been saved, go to the Actions panel of the Python tool again and click the Reprocess Python Script action. Any time you wish to adjust the script, click the Edit Python Script in the same Actions panel.
Selecting an Existing Python Script
To access a Python script you have already coded, apply the Python tool to the chart. Go to the left side Properties panel and you will see a Drop Down selector called Python File.
From here you can select all previously created Python scripts for use in Optuma.
Python Tool Properties
Tool Name: This allows you to adjust the name of the tool, as it’s displayed in the Structure Panel.
Python File: Use this drop-down to select the Python Script file you want to display on the chart.
Note
Any user-controlled properties you have set up in the Python code (a date selector for example) will appear in this section.
Plot Style: Adjusts the display style of the Python tools default plot. There are 6 options available: Line, Dot, Histogram, Step, Shaded, Shaded Step.
Line Style: When Line is selected as the Plot Style, the Line Style property allows you to adjust the type of line displayed. There are 8 options available: Solid, Dots, Dash, Dash Dots, Long Dash, Long Dash Dot, Long Dash Dot Dot, Stippled.
Line Width: This allows you to adjust the width of the Python Tools default line. Moving the slider bar to the right increases the thickness of the line.
Colour Scheme: This allows you to select the colour scheme being used by the Python Tools default plot. Single Colour, Copy Colours from Price Chart, Positive / Negative, and Custom options are available.
Line Colour: This allows you to adjust the colour of the Python Tools default line.
Tool Transparency: Use this slider bar to adjust the transparency of the tool. Moving the slider to the left will increase the transparency of the tool.
Visible: Un-tick this checkbox to hide the tool from the chart.
Show in Price Scale: When selected the Python Tools plot lines value(s) will be displayed in the Price Scale.
Lock Tool: When enabled this tool can’t be deleted from the chart or have any properties adjusted.