Gamestudio Links
Zorro Links
Newest Posts
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
Release 2.68 replacement of the .par format
by Martin_HH. 09/23/25 20:48
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 18,161 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Optimize Error 040 while limiting concurrent trades #460864
07/18/16 00:10
07/18/16 00:10
Joined: Jul 2016
Posts: 4
G
GHRouge Offline OP
Guest
GHRouge  Offline OP
Guest
G

Joined: Jul 2016
Posts: 4
Hi,
I've been coming across a lot of Error 040s due to the way I've tried to implement a method to limit the total amount of trades that a strategy can execute.
Here is an example of what's happening. There is only 1 optimize call:

Code:
function ABC();{    // Trading strategy 1
   algo("ABC:L")

   // Maximum Trade Limiter
   var total;
   for(current_trades) total++;
   if (total >= 4) return;

   Stop = 3 * ATR(10);
   Trail = optimize(1,1,6) * ATR(10);

   ... <strategy code> ...
}

function run(){
   set(PARAMETERS);
   
   while(algo(loop("ABC",...))){
      if(algo == "ABC") ABC();
      if(algo == "...") ...
      ...
   }
}


I have narrowed down the issue to the trade limiting lines. Commenting them out will result in an optimization without Error 040.
Does anyone have a suggestion for a better way to limit the number of trades an algo places without causing these errors?
Thanks!

Re: Optimize Error 040 while limiting concurrent trades [Re: GHRouge] #460868
07/18/16 10:49
07/18/16 10:49
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline
User
MatPed  Offline
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
Hi,
why did not use NumOpenLong/Short and simplify the code?
I do not like that loop and I think you forgot to init the total to 0.
Why did you use a var counter and not a int one?

my 2 cents

Re: Optimize Error 040 while limiting concurrent trades [Re: MatPed] #460870
07/18/16 12:12
07/18/16 12:12
Joined: Jul 2000
Posts: 28,022
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,022
Frankfurt
Aside from that, here's a bug:

if (total >= 4) return;

This is a classical Error 040 since you sometimes optimize Trail, sometimes not.

Re: Optimize Error 040 while limiting concurrent trades [Re: jcl] #460973
07/21/16 19:50
07/21/16 19:50
Joined: Jul 2016
Posts: 4
G
GHRouge Offline OP
Guest
GHRouge  Offline OP
Guest
G

Joined: Jul 2016
Posts: 4
Thank you both, I appreciate the feedback. Still a novice on these matters =)


Moderated by  Petra 

Gamestudio download | 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