Re-execute a failed Market order?

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

Moderator: admin

Re-execute a failed Market order?

Postby Stance » Sun Jun 05, 2016 8:34 pm

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,
Stance
FXCodeBase: Initiate
 
Posts: 141
Joined: Mon Jun 01, 2015 4:34 pm

Re: Re-execute a failed Market order?

Postby Stance » Mon Jun 06, 2016 12:06 am

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

Stance
FXCodeBase: Initiate
 
Posts: 141
Joined: Mon Jun 01, 2015 4:34 pm

Re: Re-execute a failed Market order?

Postby Julia CJ » Tue Jun 07, 2016 2:04 am

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.
Julia CJ
 

Re: Re-execute a failed Market order?

Postby Stance » Tue Jun 07, 2016 7:13 am

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.
Stance
FXCodeBase: Initiate
 
Posts: 141
Joined: Mon Jun 01, 2015 4:34 pm

Re: Re-execute a failed Market order?

Postby Julia CJ » Fri Jun 10, 2016 8:22 am

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.
Julia CJ
 

Re: Re-execute a failed Market order?

Postby cnikitopoulos94 » Wed Dec 07, 2016 1:38 am

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
cnikitopoulos94
 
Posts: 47
Joined: Sat Sep 12, 2015 8:10 am


Return to Discussions

Who is online

Users browsing this forum: No registered users and 5 guests