Page 1 of 1

Re-execute a failed Market order?

PostPosted: Sun Jun 05, 2016 8:34 pm
by Stance
Hi,

Sometimes a market order would fail - not sure why - but is there a way of re-executing the failed market order?

I don't want the strategy to wait for the next period where the condition is matched again, but I want it to straight away re-execute the failed order.

Thankyou,

Re: Re-execute a failed Market order?

PostPosted: Mon Jun 06, 2016 12:06 am
by Stance
Will doing this to force the order again work?


-- enter into the specified direction
function enter(BuySell)
-- do not enter if position in the specified direction already exists
if tradesCount(BuySell) >= MaxNumberOfPosition
or ((tradesCount(nil)) >= MaxNumberOfPositionInAnyDirection)
then
return true;
end

-- send the alert after the checks to see if we can trade.
if (BuySell == "S") then
Signal ("Sell Signal");
else
Signal ("Buy Signal");
end

return MarketOrder(BuySell);
end

-- enter into the specified direction
function MarketOrder(BuySell)
local valuemap, success, msg;
valuemap = core.valuemap();

valuemap.Command = "CreateOrder";
valuemap.OrderType = "OM";
valuemap.OfferID = Offer;
valuemap.AcctID = Account;
valuemap.Quantity = Amount * BaseSize;
valuemap.BuySell = BuySell;
valuemap.CustomID = CustomID;

-- 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

MarketOrder(BuySell);
end

return true;
end


Re: Re-execute a failed Market order?

PostPosted: Tue Jun 07, 2016 2:04 am
by Julia CJ
Hi Stance,

I think the chance of order revival is the smallest. All market conditions should be the same as they were in its previous executing.

Re: Re-execute a failed Market order?

PostPosted: Tue Jun 07, 2016 7:13 am
by Stance
Julia CJ wrote:Hi Stance,

I think the chance of order revival is the smallest. All market conditions should be the same as they were in its previous executing.


What do you mean? My strategy puts in a market order, but sometimes it would fail either because due to lost of network or server is busy. So I want it to re-execute again.

At the moment, when I see it fails, then I have to manually put one in.

Re: Re-execute a failed Market order?

PostPosted: Fri Jun 10, 2016 8:22 am
by Julia CJ
Hi Stance,

TS is blocked in the execution time of lua code. Therefore, while the code is executing, the conditions are not changed, according to the the validity of order that is verified in terminal:execute.
If terminal:execute returns the error, there is not a necessity to call the order with the same parameters. It will return the error again.

Re: Re-execute a failed Market order?

PostPosted: Wed Dec 07, 2016 1:38 am
by cnikitopoulos94
In theory, there is a way Stance.

However, it would take a lot of coding and complications (imo).

The best way to have this fixed is by changing the sources of your indicator, having them accessed through the same stream you have them connected too atm, while it is being refreshed by a whole other timeframe.

I.E.

If (not(haveTrades(nil)) and <Market Condition> then
BUY()
.

So basically <Market Condition> is being attatched to a source which refreshes by the <period> amount (TimeFrame) so you would need to find a way to have it being refreshed by a smaller timeframe and rechecking your conditions by the second, so if it didn't capture when period closed tick will refresh period as soon as next opens because it refreshed the conditions and met the timeframe you choose.

So then at 4:00:00 it was suppose to buy, but now it did it at 4:00:01