Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, TedMar, dr_panther), 1,049 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 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: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

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