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
3 registered members (Edgar_Herrera, VoroneTZ, Akow), 973 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
Setting TradeStopLimit and TradeTrailLimit #460394
06/29/16 00:33
06/29/16 00:33
Joined: Jun 2016
Posts: 33
NC
C
Cstyle Offline OP
Newbie
Cstyle  Offline OP
Newbie
C

Joined: Jun 2016
Posts: 33
NC
I'm trying to write a simple strategy which starts to trail only after the trade is profitable. I'm using a TMF with TradeStopLimit and TradeTrailLimit, but it is not behaving as I would expect:

Code:
#include <profile.c>

int TrailWhenProfitable()
{
	static bool TrailInitiated;
	
 	if(NumOpenLong > 0 )
	{
	
			if (priceClose() > TradePriceOpen + (2 * ATR(100)) && TrailInitiated == false)
				{
					TradeStopLimit = TradePriceOpen;
					TradeTrailLimit =  TradePriceOpen + ATR(100);
					TrailInitiated = true;
					printf("  TradeStopLimit = %.3f,  TradeTrailLimit = %.3f", TradeStopLimit, TradeTrailLimit);
					printf("  ATR = %.3f,  priceClose = %.3f", ATR(100), priceClose());
					printf("  TradePriceOpen = %.3f,  TradePriceClose = %.3f", TradePriceOpen, TradePriceClose);
					
				}
	}
	else 
		TrailInitiated = false;
   	
   	
   return 0;
   		
}

function run()
{
	StartDate = 2009;
	EndDate = 2016; 	
	LookBack = 500;
	set(LOGFILE); // log all trades
	set(TICKS);  // normally needed for TMF

	vars Price = series(price());
	vars Trend = series(LowPass(Price,500));
	

  	
	if(valley(Trend) && NumOpenLong == 0) 
	{
		enterLong(TrailWhenProfitable);
	}
	
  
}



The values being written to the log for TradeStopLimit and TradeTrailLimit via printf also don't seem right. What am I doing wrong?

Thanks!

Last edited by Cstyle; 07/01/16 22:31.
Re: Setting TradeStopLimit and TradeTrailLimit [Re: Cstyle] #460395
06/29/16 00:37
06/29/16 00:37
Joined: Jun 2016
Posts: 33
NC
C
Cstyle Offline OP
Newbie
Cstyle  Offline OP
Newbie
C

Joined: Jun 2016
Posts: 33
NC
Also, the forum is removing all of the tabs from my code, making it more difficult to read. All of the code is left justified, no indentation. What is the correct way to post code so that this doesn't happen?

Thanks!

Re: Setting TradeStopLimit and TradeTrailLimit [Re: Cstyle] #460426
06/30/16 12:09
06/30/16 12:09
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
It's [code], not [quote].

Re: Setting TradeStopLimit and TradeTrailLimit [Re: jcl] #460430
06/30/16 15:45
06/30/16 15:45
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline
Serious User
DdlV  Offline
Serious User
D

Joined: Jun 2013
Posts: 1,609
Hi Cstyle. A couple of thoughts:

When looking for help (in any forum), things like "The values being written" are too vague. Much better to also post the log or a snippet showing the values, bar where they occurred, etc., as well as why the values "don't seem right".

Re. the code, take a look at TradePriceClose vs. priceClose().

HTH.

Re: Setting TradeStopLimit and TradeTrailLimit [Re: jcl] #460434
06/30/16 16:40
06/30/16 16:40
Joined: Jun 2016
Posts: 33
NC
C
Cstyle Offline OP
Newbie
Cstyle  Offline OP
Newbie
C

Joined: Jun 2016
Posts: 33
NC
Originally Posted By: jcl
It's [code], not [quote].


Perfect. I fixed my original post. Thanks!

Re: Setting TradeStopLimit and TradeTrailLimit [Re: DdlV] #460461
07/01/16 22:43
07/01/16 22:43
Joined: Jun 2016
Posts: 33
NC
C
Cstyle Offline OP
Newbie
Cstyle  Offline OP
Newbie
C

Joined: Jun 2016
Posts: 33
NC
Originally Posted By: DdlV
Hi Cstyle. A couple of thoughts:

When looking for help (in any forum), things like "The values being written" are too vague. Much better to also post the log or a snippet showing the values, bar where they occurred, etc., as well as why the values "don't seem right".

Re. the code, take a look at TradePriceClose vs. priceClose().

HTH.


DdlV, I swapped out TradePriceClose with priceClose, and updated the code in my post above. The strategy behaves the same, ie. not the way I would expect.

Here are the values in the log file that don't seem right:

Quote:
[NAS100::L6901] Long 1@1393 at 17:00

[1270: Thu 07.05.09 18:00] +0 +0 1/0
[1271: Thu 07.05.09 19:00] +0 +0 1/0
[1272: Thu 07.05.09 20:00] +0 +0 1/0
[1273: Thu 07.05.09 21:00] +0 +0 1/0
[1274: Thu 07.05.09 22:00] +0 +0 1/0
[1275: Thu 07.05.09 23:00] +0 +0 1/0
[1276: Fri 08.05.09 00:00] +0 +1 1/0
[1277: Fri 08.05.09 01:00] +0 +1 1/0
[1278: Fri 08.05.09 02:00] +0 +1 1/0
[1279: Fri 08.05.09 03:00] +0 +1 1/0 TradeStopLimit = 73151834298078158000000.000, TradeTrailLimit = 0.000 ATR = 6.676, priceClose = 1407.000 TradePriceOpen = 75262725486622238000000.000, TradePriceClose = 0.000
[NAS100::L6901] Trail 1@1393 Stop 1394 at 03:450


priceClose and ATR look fine in the log file. (Note that the asset is NAS100 using the data available from the zorro website.) All other values do not look right.

Why is TradePriceOpen so high? Shouldn't it be set to 1393?

Why is TradeTrailLimit set to 0? If TradePriceOpen is a huge number and I'm setting TradeTrailLimit equal to TradePriceOpen plus ATR, shouldn't TradeTrailLimit equal the huge number plus 6.676?

Again, thanks so much for your help!

Re: Setting TradeStopLimit and TradeTrailLimit [Re: Cstyle] #460462
07/01/16 23:10
07/01/16 23:10
Joined: Jun 2016
Posts: 33
NC
C
Cstyle Offline OP
Newbie
Cstyle  Offline OP
Newbie
C

Joined: Jun 2016
Posts: 33
NC
Looks like I just needed to typecast them to (var) so that they would print correctly. Problem solved!

Last edited by Cstyle; 07/01/16 23:11.

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1