Look at the image and will find that the close order rate exceeds the low and high rate of bar. It is very strange. Isn't the rate inside the bar? Same thing happened on the open order rate, too.
Why did this happen?
Here below is my code:
- Code: Select all
-- enter into the specified direction
function MarketOrder(BuySell)
valuemap = core.valuemap();
valuemap.Command = "CreateOrder";
valuemap.OrderType = "OM";
valuemap.OfferID = OfferID;
valuemap.AcctID = Account;
valuemap.Quantity = Amount * BaseSize;
valuemap.BuySell = BuySell;
if IsNeedTrailing then
valuemap.TrailStepStop = (IsNeedDynamicTrailing and 1 or TrailingStop);
end
if (not CanClose) and (instance.parameters.SetStop or instance.parameters.SetLimit) then
valuemap.EntryLimitStop = 'Y'
end
success, msg = terminal:execute(200, valuemap);
if not(success) then
terminal:alertMessage(instance.bid:instrument(), instance.bid[instance.bid:size() - 1], "Open order failed" .. msg, instance.bid:date(instance.bid:size() - 1));
return false, msg;
end
return true, msg;
end
- Code: Select all
function closeOrder(TradeID)
enum = core.host:findTable("trades"):enumerator();
row = enum:next();
while row ~= nil do
if row.TradeID == TradeID and
row.AccountID == Account then
-- close trades immediatelly if we can close
local valuemap = core.valuemap();
valuemap.Command = "CreateOrder";
valuemap.OrderType = "CM";
valuemap.OfferID = row.OfferID;
valuemap.AcctID = Account;
valuemap.Quantity = row.Lot;
valuemap.TradeID = row.TradeID;
if row.BS == "B" then
valuemap.BuySell = "S";
else
valuemap.BuySell = "B";
end
local success, msg = terminal:execute(200, valuemap);
if not (success) then
core.host:trace("current order close order failed:");
else
core.host:trace("current order close order success");
end
end
row = enum:next();
end
end