Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (TipmyPip, AndrewAMD, Quad, aliswee, degenerate_762), 970 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
confused about order management #480646
06/23/20 06:43
06/23/20 06:43
Joined: Jun 2020
Posts: 5
P
pchen90 Offline OP
Newbie
pchen90  Offline OP
Newbie
P

Joined: Jun 2020
Posts: 5

Say I'm trying to write an algo with four different scenarios; each with its own entry, profit target and stop loss order settings.

pseudocode:

if condition1:
- go long immediately at market, set a stop loss order SLM points below entry price, set a profit take order PTM points above entry price

if condition 2:
- as above, but go short instead of long

if condition 3:

- submit a resting limit buy order at the current Ask price, set a stop loss order SLL points below entry price, set a profit take order PTL points above entry price

if condition 4:
- as above, but enter with a resting limit sell at the current Bid price


All the above are mutually exclusive. My reading of the relevant manual page (https://manual.zorro-project.com/buylong.htm) made me think I need to pass the static parameters directly to enterShort() or enterLong() when they're called but I'm having some issues with how I've done it below.

1) No trades seem to enter at market (have already determined condtion1 and condition2 are triggering correctly).
2) Logs seem to suggest stops are being trailed when I don't want them to be (log snippet below script)

Can anyone point me in the right direction? Should I be using a trade management function for this, or is the below roughly correct (with wrong syntax)?

Code

	// => Enter at market
	if (condition1) // Long Entry
	{
		enterLong(_lots,0,SLM,PTM);		
	}	
									
	else if (condition2) // Short Entry
	{

		enterShort(_lots,0,SLM,PTM);		
	}											
									
        // => Passive entry						
	else if (condition3)
	{

		enterLong(_lots,-_ticks,SLL,PTL);		
	}			
			
	else if (condition4) 
	{
		enterShort(_lots,-_ticks,SLL,PTL);	
	}
	
	



Trade logs - stops being trailed

[3269: Fri 14-01-03 15:30] -880 0 33/34 (163.07)
Enter 500 Long SPY Entry -0.025000 Stop 0.75000 TP 0.050000 at 15:30:00
(SPY::L) Long 500@163.04 Entry limit
(SPY::L) Entry limit 163.04 hit by 163.03 at 15:30:00
[SPY::L27033] Long 500@163.08 Risk 396 p at 15:30:00

[3270: Fri 14-01-03 15:31] -880 -18.63 33/35 (163.05)
Enter 500 Long SPY Entry -0.025000 Stop 0.75000 TP 0.050000 at 15:31:00
[SPY::L] Skipped (Max = 1)

[3271: Fri 14-01-03 15:32] -880 +1.36 34/34 (163.09)
Enter 500 Long SPY Entry -0.025000 Stop 0.75000 TP 0.050000 at 15:32:00
[SPY::L] Skipped (Max = 1)
[SPY::L27033] Trail 500@163.08 Stop 162.34 at 15:32:00

[3272: Fri 14-01-03 15:33] -880 +11.37 34/34 (163.11)
Enter 500 Long SPY Entry -0.025000 Stop 0.75000 TP 0.050000 at 15:33:00
[SPY::L] Skipped (Max = 1)
[SPY::L27033] Trail 500@163.08 Stop 162.36 at 15:33:00


Code





Re: confused about order management [Re: pchen90] #480647
06/23/20 07:46
06/23/20 07:46
Joined: May 2015
Posts: 390
Czech Republic
G
Grat Offline
Senior Member
Grat  Offline
Senior Member
G

Joined: May 2015
Posts: 390
Czech Republic
Try this:

MaxLong = MaxShort = 5; // don't open several trades

Re: confused about order management [Re: pchen90] #480649
06/23/20 12:04
06/23/20 12:04
Joined: Apr 2008
Posts: 585
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 585
Austria
When stops are trailed, you have set the Trail variable somewhere in your code. And if you want to enter at market, don't set the Entry variable.

Re: confused about order management [Re: pchen90] #480678
06/27/20 02:11
06/27/20 02:11
Joined: Jun 2020
Posts: 5
P
pchen90 Offline OP
Newbie
pchen90  Offline OP
Newbie
P

Joined: Jun 2020
Posts: 5
Thanks for the responses all! On a related question now I'm trying to create a more detailed trade log function to diagnose my algo's performance.

Say that I am working with 5-min bars. I want to know each time a resting limit order is filled in simulation (as either an entry or stop loss/profit target), what the high and low of that bar in which the simulated order was filled. Output should be to a csv file with columns identifying the time, bar number, trade type (entry/stop loss/profit target) and the OHLC prices of the bar.

However, it's not clear to me from the manual how order fill events are handled in simulated trade...

Should I be using a TMF outside the main run() function like this? I ran the below and couldn't even get it to print to the default logfile. Also - how do I get the actual fill price of the simulated trade from Entry/Stop/TakeProfit and not the price offset variable I provided as an argument?

Code

int ExtremeHitLog()
{
	if(TradeIsEntry) {
			string line = strf(
			  "Entry, %02i/%02i/%02i %02i:%02i, %.5f, %.5f, %.5f, %.5f\n",
			  day(),month(),year()%100,hour(),minute(),
			  priceOpen(),priceHigh(),priceLow(),priceClose());
		
			file_append("Data\\extremehits.csv",line);
		}
	

	//if(TradeIsStop)

	//if(TradeIsProfit)

   return 16; // trigger tmf at next event
}

Re: confused about order management [Re: pchen90] #480679
06/27/20 06:40
06/27/20 06:40
Joined: Apr 2008
Posts: 585
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 585
Austria
The idea is generally right, for finding out why it does not work, check the whole code and debug it with the watch function. Also read the troubleshooting page in the manual.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1