Hi,
I try to modify the function MarketOrder(BuySell) to make an Entry Order at a specified price.
I modified the orderType like this :
valuemap.OrderType = "O";
I add the valuemap.Rate number like this (for exemple) :
valuemap.Rate = 1.112;
But unfortunaltely that didn't work because when the entry order is executed in FXCM, the Rate of the order is the current price and not my specified price.
Could someone help me to solve this problem ?
Here under is the complete function (exemple for EURUSD) :
function MarketOrder(BuySell)
local valuemap, success, msg;
valuemap = core.valuemap();
valuemap.Command = "CreateOrder";
valuemap.OrderType = "O"; -- modified for an entry order
valuemap.OfferID = Offer;
valuemap.AcctID = Account;
valuemap.Quantity = Amount * BaseSize;
valuemap.BuySell = BuySell;
valuemap.CustomID = CustomID;
valuemap.Rate = 1.112; -- added to specify the price level
-- add stop/limit
valuemap.PegTypeStop = "O";
if SetStop then
if BuySell == "B" then
valuemap.PegPriceOffsetPipsStop = -Stop;
else
valuemap.PegPriceOffsetPipsStop = Stop;
end
end
if TrailingStop then
valuemap.TrailStepStop = 1;
end
valuemap.PegTypeLimit = "O";
if SetLimit then
if BuySell == "B" then
valuemap.PegPriceOffsetPipsLimit = Limit;
else
valuemap.PegPriceOffsetPipsLimit = -Limit;
end
end
if (not CanClose) 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;
end
return true;
end