I require some help with passing from Concept/Backtesting successfully to using it live. When I backtest, my orders gets created, deleted if their stop rate is hit before they become a trade and recreated when a new condition arise.
when I use it live using StrategyRunner, it just creates one entry order and exit the strategy. I am wondering why and maybe I require some code to signify to continue when en event occurs.
I have "simplified" bunch of code bellow to give a simple perspective of what it looks like.
gratitude in advance for the support
Guillaume
- Code: Select all
local arrId= 0;
local orders;orders={};
local activeOrder=false;
function ExtUpdate(id, source, period)
--Which remove the order if the Stop point hits before the entry target
if #orders > 0 and activeOrder then
$h!t(arrId, source, period);
else
--Some logics to create entry order
setEntry(...)
end
end
function setEntry(orderType, _BuySell, _rate, _rateStop, source, period, _mvaa)
-- Create new order (or to replace deleted)
local valuemap = core.valuemap();
valuemap.Command = "CreateOrder";
valuemap.OrderType = orderType;
valuemap.OfferID = OfferID;
valuemap.AcctID = Account;
valuemap.Rate = _rate;
valuemap.RateStop = _rateStop;
valuemap.BuySell = _BuySell;
local _qt = Amount * BaseSize;
valuemap.Quantity = _qt;
local success, msg;
ordering = true;
vTrace("executing EntryORder");
success, msg = terminal:execute(102, valuemap);
if not (success) then
terminal:alertMessage(instance.bid:instrument(), instance.bid[NOW], "R_FailedCreateLimitOrStop" .. ": " .. msg,
instance.bid:date(NOW));
end
end
function ExtAsyncOperationFinished(cookie, success, message, message1, message2)
--[...]
if cookie == 102 then -- OrderCreated
if success then
vTrace("New Order Created Succesfully ");
orderingContext = getCreatedEntryOrderId();
activeOrder = true;
--Saving info about the order
insert_new_order_to_Watch(arrId,...);
arrId = arrId+1;
end
end
end