OrderLimit blocks SET_WAIT?

Posted By: Cheulmen

OrderLimit blocks SET_WAIT? - 05/10/18 22:53

I’m trying to do a script that buys a couple of assets that are inside a loop, adjusting the price continuously thanks to a TMF, but I’m not getting the behavior that I need: I want that each Bar and for each asset, one long order is inserted into the order book, with a bid slightly over the last bid (something like priceClose() - 0.9*Spread;) Then, each 60 seconds, if the trade hasn’t been filled the script should cancel the remaining unfilled, and reopen the remaining with a price adjusted again to the last bid. The problem is that I found only two ways to do this, each one with its own problems:

1.- If I use OrderLimit, the script inserts the order for one pair, and then it is blocked. It doesn’t inserts the second order for the other pair until SET_WAIT. So at any moment I have only one open trade, not two. Even the “Server” field in the Zorro window, where the timestamp is shown, is frozen with the time of the first order until it times out.
2.- If I use Entry, the problem here is that I want the order immediately sent, I don’t want to wait before a new price that matches with my limit arrives in a tick(). I just want the order sent to the order book each Bar.

Also, I don’t want to use OrderDelay because I don’t want to wait x seconds to enter the trade, but at the same time I need some way to control the duration of the trade trying to be filled. Right now, when the order is cancelled because it hasn’t been filled after SET_WAIT, it enters into the TMF. Then, OrderDelay waits some seconds to enter the trade again, but I want the order sent immediately, and after 60 seconds without being filled, cancelled and opened again and so on. I want my orders in the order book, not in Zorro's memory waiting to be sent.

This is the simplified code:

Click to reveal..
int tmf()
{
if(is(TRADEMODE) && TradeIsMissed) { //enters here after SET_TIME seconds
if(!TradeIsOpen) {
if(TradeIsLong)
OrderLimit = priceClose() - (Spread*0.9);
else
OrderLimit = priceClose()+(Spread*0.9);
return 2+16;
} else {
if(TradeIsLong)
{
OrderLimit = priceClose()+(Spread*0.9);
printf("n%s TradeIsLong", datetime());
}
else
OrderLimit = priceClose()-(Spread*0.9);
return 1+16;
}
}
else
return 16;
}

void run()
{
set(PARAMETERS|LOGFILE|PRELOAD|TICKS);
if(is(INITRUN)) brokerCommand(SET_WAIT,60*1000); //wait 60 secs before trying to reopen

BarPeriod = 30;

while(asset(loop("EUR/USD","AUD/USD")))
{
LotAmount=1;
Lots=20;

OrderLimit = priceClose() - 0.9*Spread; // Option 1: this blocks
//Entry = (priceClose() - 0.9*Spread)*(-1); //Option 2: this doesn’t send the orders immediately

enterLong(tmf);
}
}

So, is it possible to use OrderLimit & SET_WAIT but without that “blocking” behaviour? When I use it I can’t open two trades at the same time.
Posted By: jcl

Re: OrderLimit blocks SET_WAIT? - 05/14/18 08:37

This is possible, but must be supported by the broker plugin. BrokerBuy2 must then immediately return the order ID and set the fill amount to zero. This is a function only recently added, so it's not yet supported by the current plugins.

http://manual.zorro-project.com/brokerplugin.htm
© 2024 lite-C Forums