modifyTpSlOfTrade (SDK Trading)

modifyTpSlOfTrade is a Fintechee API to modify the take-profit or stop-loss of a open trade.

modifyTpSlOfTrade(brokerName, accountId, tradeId, takeProfit, stopLoss)

EA SDK This function modifies the take profit or stop loss of the specific open trade. Phase (this API's scope): onTick | deinit

Kind: global function

Param Type Description
brokerName string broker name
accountId string account ID
tradeId string trade ID
takeProfit number take profit
stopLoss number stop loss

modifyTpSlOfTrade (SDK Trading)

registerEA(
"test_api",
"An EA to test APIs",
[],
function (context) { // Init()
    var account = getAccount(context, 0)
	var brokerName = getBrokerNameOfAccount(account)
	var accountId = getAccountIdOfAccount(account)
	var symbolName = "EUR/USD"

	getQuotes (context, brokerName, accountId, symbolName)
},
function (context) { // Deinit()
},
function (context) { // OnTick()
    var account = getAccount(context, 0)
	var brokerName = getBrokerNameOfAccount(account)
	var accountId = getAccountIdOfAccount(account)
	var symbolName = "EUR/USD"

    var ask = getAsk(context, brokerName, accountId, symbolName)
	var bid = getBid(context, brokerName, accountId, symbolName)
	var limitPrice = 0.0003
	var stopPrice = 0.0003
	var volume = 0.01

    var length = getOpenTradesListLength(context)
    for (var i = 0; i < length; i++) {
        var openTrade = getOpenTrade(context, i)
        if (openTrade != null) {
            var tradeId = getTradeId(openTrade)

            var decision = Math.random()

            if (decision < 1/2) {
                // open trade without take-profit, stop-loss
            	modifyTpSlOfTrade(brokerName, accountId, tradeId, 0, 0)
            } else if (decision < 1) {
                // open trade with take-profit, stop-loss
            	modifyTpSlOfTrade(brokerName, accountId, tradeId, ask+limitPrice, bid-3*stopPrice)
            }
        }
    }
})