I have two questions, where I need help.
Firstly, I would like to adjust the funtion Create Entry of an existing program. Currently, it generates a buy and sell order (hedging, I have a non FIFO account), by choice you can add a fixed limit for both orders. Now, I would like that, if one order is hit, that the other order is cancelled, but a stop is created at the entry price of the cancelled order to protect the now open order. The function exit will now close when Limit is hit or other conditions are met. How can I adjust the existing funtion without changing too much?
Secondly, I would like to calculate the Limit for each trade individually and within the program. I would like to use a percentage of the difference between maxAsk and minBid. Can I just replace valuemap.Quantity = Amount * LotSize with valuemap:Quantity = (maxAsk-minBid)*factor*Lotsize
Who can help me here? What is the right and easiest approach, and how is it done.
Thanks a lot
Programming Code Extract
function Entry()
terminal:alertMessage(instance.bid:instrument(), instance.bid[instance.bid:size() - 1], "Entry", instance.bid:date(instance.bid:size() - 1));
local maxAsk, minBid;
maxAsk = mathex.max(AskH1.high, AskH1:size() - MM + 1, AskH1:size() - 1);
minBid = mathex.min(BidH1.low, BidH1:size() - MM + 1, BidH1:size() - 1);
CreateEntry(maxAsk + AskH1:pipSize() * 0, "B");
CreateEntry(minBid - BidH1:pipSize() * 0, "S");
end
function CreateEntry(rate, side)
local valuemap = core.valuemap();
valuemap.Command = "CreateOrder";
valuemap.OrderType = "SE";
valuemap.OfferID = OfferID;
valuemap.AcctID = AccountID;
valuemap.Quantity = Amount * LotSize;
valuemap.Rate = rate;
valuemap.BuySell = side;
valuemap.CustomID = CustomID;
if side == "B" then
valuemap.PegPriceOffsetPipsLimit = ProfitTarget;
else
valuemap.PegPriceOffsetPipsLimit = -ProfitTarget;
end
valuemap.PegTypeLimit = "M";
success, message = terminal:execute(100, valuemap);
if not success then
terminal:alertMessage(instance.bid:instrument(), instance.bid[instance.bid:size() - 1], "Creating entry order failed:" .. message, instance.bid:date(instance.bid:size() - 1));
end
end