Would like to modify a function Create Entry - who can help

Section for discussions related to indicators, use of indicators, and building of trading stategies using indicators.

Moderator: admin

Would like to modify a function Create Entry - who can help

Postby surfandturf » Mon Dec 17, 2012 6:51 pm

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
surfandturf
 
Posts: 25
Joined: Mon Jan 09, 2012 10:16 am

Re: Would like to modify a function Create Entry - who can help

Postby Ekaterina » Tue Dec 18, 2012 4:59 pm

Hi surfandturf ,

Firstly, I would like to adjust the funtion Create Entry of an existing program.


As I have understood, you need to create OCO order that consists of two Entry Orders, each Entry Order is created with Stop/Limit. Here you can find an example How to Create an OCO of Two Entry Orders with Stops and Limits Attached.

Can I just replace valuemap.Quantity = Amount * LotSize with valuemap:Quantity = (maxAsk-minBid)*factor*Lotsize


It is possible to set Quantity for each order. The most important thing is to follow the rules: The quantity is expressed in contracts and must be divisible by the value of the lot size (see baseUnitSize trading option in the following call: core.host:execute("getTradingProperty", ...)).

Bets regards,
Ekaterina
Ekaterina
 

Re: Would like to modify a function Create Entry - who can help

Postby surfandturf » Tue Dec 18, 2012 6:06 pm

Hello Ekaterina,
I managed today to add a individual quantity for each new order. Definitely not a professional solution. In the mean time, I also came to the conclusion that I need to use a OCO. I will try, if I understand the example...and ask again, if I do not get further. I am not a programmer, but have some kind of understanding.

Thanks
surfandturf
 
Posts: 25
Joined: Mon Jan 09, 2012 10:16 am


Return to Discussions

Who is online

Users browsing this forum: No registered users and 19 guests