8.0 Recommended trade

Indicators can use the UDI.setRecommendedTrade() function to set a "recommended trade", signalled to the user by a lightning-bolt icon next to the name of the indicator on the chart. Clicking on the icon then fills the recommendation into the chart's deal ticket, ready for placement.

Note: this functionality is not available in older versions of the platform. To avoid run-time errors, you should check for its availability before trying to use it:

if (UDI.setRecommendedTrade) {

// Function(ality) is available…

}

You can pass three types of parameter to UDI.setRecommendedTrade():

Null. Hides the icon.

An empty object, {}. Icon is visible, but disabled and greyed-out.

A partial or full trading definition.

A trading definition is fundamentally the same as the parameter for SendOrder() in the Figaro framework. The major difference is that UDIs do not have access to the Sway.OrderTypes enumeration. You specify the order type using the textual name from the enumeration, such as "SELL_LIMIT", rather than a constant such as Sway.OrderTypes.SELL_LIMIT. For example:

UDI.setRecommendedTrade({

tradingAction: "SELL_LIMIT",

openPrice: 1.07,

sl: 1.08,

tp: 1.06,

comment: "My indicator"

});

Although your definition should always include a tradingAction, all the properties of the definition are optional rather than compulsory. The deal ticket will only update with the properties which you include. For example, if you do not include a tp then the take-profit field in the deal ticket will be unchanged, and will continue to use/show any previous value set by the user. Therefore, if you specifically want to recommend an order with no take-profit, you should set tp:0 rather than omitting the tp property.

Your definition can use all the derived properties which are accepted by SendOrder(). For example, you can use the following to set the stop-loss at 20 pips from the entry price, varying tick by tick while the deal ticket is open:

UDI.setRecommendedTrade({

tradingAction: "BUY",

sl: {pips: 20},

tp: 0

});

It is up to you whether you set a trading volume in your definition, or whether you omit it and leave the volume at the most recent value set by the user. If you do set a trading volume then it is most common to use a risk-based value (in combination with a stop-loss), rather than an absolute quantity. For example, volume: {equityPercent: 1}.

Last updated