Hi,
I would like to know how to remove entry orders. My strategy is currently creating some of them but after some candles are not longer valid so I want to delete them.
Thanks in advance
Sergio.
Moderator: admin
-- variables
local createOrderCookie = 103; -- cookie for create order command
local editStopOrderCookie = 104; -- cookie for edit stop order command
local aOrderID;
local mTradeId = nil;
function checkForTrade()
local tradesTable = core.host:findTable("trades");
local aTradeRow = tradesTable:find("OpenOrderID",aOrderID);
if aTradeRow ~= nil then
mTradeId = aTradeRow.TradeID;
end
end
function changeStopOrder()
local tradesTable = core.host:findTable("trades"); -- find trades table
local aTradeRow = tradesTable:find("TradeID",mTradeId); -- find row for trade with ID=mTradeId
if aTradeRow ~= nil then
if aTradeRow.StopOrderID ~= nil then
local valuemap = core.valuemap();
valuemap.Command = "EditOrder";
valuemap.OrderID = aTradeRow.StopOrderID; -- for limit order you should replace it with aTradeRow.LimitOrderID
..................................
terminal:execute(editStopOrderCookie, valuemap);
else
core.host:trace("There is no stop order for the selected trade");
end
end
end
-- variables
local createOrderCookie = 103; -- cookie for create order command
local editStopOrderCookie = 104; -- Cookie for edit stop order command
local aOrderID;
local mTradeId = nil;
function Update()
checkForTrade(); -- This function will check if trade created from our entry order with ID=aOrderID is exist
if mTradeId ~= nil then
changeStopOrder();
end
end
-- function for creating order
function CreateOrder()
valuemap = core.valuemap();
................................
terminal:execute(createOrderCookie, valuemap);
end
function changeStopOrder()
local tradesTable = core.host:findTable("trades"); -- find trades table
local aTradeRow = tradesTable:find("TradeID",mTradeId); -- find row for trade with ID=mTradeId
if aTradeRow ~= nil then
if aTradeRow.StopOrderID ~= nil then
local valuemap = core.valuemap();
valuemap.Command = "EditOrder";
valuemap.OrderID = aTradeRow.StopOrderID; -- for limit order you should replace it with aTradeRow.LimitOrderID
..................................
terminal:execute(editStopOrderCookie, valuemap);
else
core.host:trace("There is no stop order for the selected trade");
end
end
end
function checkForTrade()
local tradesTable = core.host:findTable("trades");
local aTradeRow = tradesTable:find("OpenOrderID",aOrderID);
if aTradeRow ~= nil then
mTradeId = aTradeRow.TradeID;
end
end
function AsyncOperationFinished(cookie, success, message)
if cookie == createOrderCookie and success then
aOrderID = message;
end
if cookie == editStopOrderCookie then
if success then
core.host:trace("Stop order is changed successfully");
else
core.host:trace("An error occured while editing stop order: "..message);
end
end
end
function changeStopOrder(stopValue)
local tradesTable = core.host:findTable("trades"); -- find trades table
local aTradeRow = tradesTable:find("TradeID",mTradeId); -- find row for trade with ID=mTradeId
if aTradeRow ~= nil then
if aTradeRow.StopOrderID ~= nil then
local valuemap = core.valuemap();
valuemap.AcctID = Account;
valuemap.Command = "EditOrder";
valuemap.OrderID = aTradeRow.StopOrderID;
valuemap.Rate = stopValue;
terminal:execute(editStopOrderCookie, valuemap);
else
core.host:trace("There is no stop order for the selected trade");
end
end
end
function changeLimitOrder(limitValue)
local tradesTable = core.host:findTable("trades"); -- find trades table
local aTradeRow = tradesTable:find("TradeID",mTradeId); -- find row for trade with ID=mTradeId
if aTradeRow ~= nil then
if aTradeRow.LimitOrderID ~= nil then
local valuemap = core.valuemap();
valuemap.AcctID = Account;
valuemap.Command = "EditOrder";
valuemap.OrderID = aTradeRow.LimitOrderID;
valuemap.Rate = limitValue;
terminal:execute(editLimitOrderCookie, valuemap);
else
core.host:trace("There is no limit order for the selected trade");
end
end
end
Return to Indicator Development
Users browsing this forum: No registered users and 29 guests