Strategy Dev: mtCommon Library

Estimated reading time: 1 min

mtCommon (MachinaTrader Common) Library

The mtCommon Library needs to be imported and is cited as _mt. It can be used via any method of your strategy. It exposes a set of methods and helpers that can be used for defining parameters, managing storage, plotting and generating logs/output.

Defining and Retrieving parameters

This topic has a dedicated article:

Persistant Storage

Some strategies may require some data or state so that it is not lost when a Machina is stopped or when an instance is restarted. For this purpose we can use setVal to store data and getVal to read data from the persisted storage.

setVal

setVal takes 2 parameters, a unique name for the data to be stored and its value.
_mt.setVal(‘lastOperation’, userOp)

getVal

getVal takes a single parameter which is the unique name for the data to be retrieved from the storage.
userOp = _mt.getVal(‘lastOperation’)

Plotting

To plot on the chart during the execution, in this case, plotPoint is the helper to be used via the onTick method.

plotPoint

plotPoint takes 3 parameters, the name/label that will identify this indicator, the value for the current tick and the output color.
_mt.plotPoint(‘Fast’, taFast, ‘#80b3ff’)

Logging

The important information can be rendered to the logs returned to the user. For this, the logInfoP helper should to be used.

logInfoP

logInfoP takes a single parameter which is the string to report to the user.
    _mt.logInfoP(‘onInit called [‘ + STRAT_NAME + ‘ ‘ + VERSION + ‘]’)
Was this article helpful?
Dislike 0
Views: 96