Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (MadJack, AndrewAMD, Quad), 540 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
OrderLimit blocks SET_WAIT? #472654
05/10/18 22:53
05/10/18 22:53
Joined: Nov 2017
Posts: 34
C
Cheulmen Offline OP
Newbie
Cheulmen  Offline OP
Newbie
C

Joined: Nov 2017
Posts: 34
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.

Re: OrderLimit blocks SET_WAIT? [Re: Cheulmen] #472685
05/14/18 08:37
05/14/18 08:37
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
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


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1