modifyOrder (SDK Trading)
modifyOrder is a Fintechee API to modify a pending order(limit or stop).
modifyOrder(brokerName, accountId, orderId, symbolName, orderType, price, slippage, volume, takeProfit, stopLoss, comment)
EA SDK This function sends order to market. Phase (this API's scope): onTick | deinit
Kind: global function
Param | Type | Description |
---|---|---|
brokerName | string | broker name |
accountId | string | account ID |
orderId | string | order ID |
symbolName | string | symbol name |
orderType | number | order type(ORDER_TYPE.OP_BUY or OP_SELL or OP_BUYLIMIT or OP_SELLLIMIT or OP_BUYSTOP or OP_SELLSTOP) |
price | number | price(if the order is market order, price should be set by zero) |
slippage | number | always be 0(in this version, the trade will be opened by market price) |
volume | number | lots(100000 units per lot) |
takeProfit | number | take profit |
stopLoss | number | stop loss |
comment | string |
modifyOrder (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 = getPendingOrdersListLength(context)
for (var i = 0; i < length; i++) {
var pendingOrder = getPendingOrder(context, i)
if (pendingOrder != null) {
var orderId = getOrderId(pendingOrder)
var decision = Math.random()
if (decision < 1/6) {
// pending order(limit, go long) without take-profit, stop-loss
modifyOrder(brokerName, accountId, orderId, symbolName, ORDER_TYPE.OP_BUYLIMIT, ask-limitPrice, 0, volume, 0, 0, "")
} else if (decision < 1/3) {
// pending order(stop, go long) without take-profit, stop-loss
modifyOrder(brokerName, accountId, orderId, symbolName, ORDER_TYPE.OP_BUYSTOP, ask+limitPrice, 0, volume, 0, 0, "")
} else if (decision < 1/2) {
// pending order(limit, go long) with take-profit, stop-loss
modifyOrder(brokerName, accountId, orderId, symbolName, ORDER_TYPE.OP_BUYLIMIT, ask-limitPrice, 0, volume, ask+limitPrice, bid-3*stopPrice, "")
} else if (decision < 2/3) {
// pending order(stop, go long) with take-profit, stop-loss
modifyOrder(brokerName, accountId, orderId, symbolName, ORDER_TYPE.OP_BUYSTOP, ask+limitPrice, 0, volume, ask+3*limitPrice, bid-stopPrice, "")
} else if (decision < 5/6) {
// market order(go long) without take-profit, stop-loss
modifyOrder(brokerName, accountId, orderId, symbolName, ORDER_TYPE.OP_BUY, 0, 0, volume, 0, 0, "")
} else if (decision < 1) {
// market order(go long) with take-profit, stop-loss
modifyOrder(brokerName, accountId, orderId, symbolName, ORDER_TYPE.OP_BUY, 0, 0, volume, ask+limitPrice, bid-3*stopPrice, "")
}
}
}
})