Gamestudio Links
Zorro Links
Newest Posts
contractUpdate() is filtering if >2 rows
by mistery. 12/04/26 19:03
Removing outliers from files
by AndrewAMD. 12/02/26 15:26
SGT_FW
by Aku_Aku. 11/30/26 08:19
Experiences with cTrader
by JeyKey II. 11/27/26 09:04
make a complaint
by EW_bytes. 11/26/26 23:00
FXCM => AVA Trade Plugin???
by Martin_HH. 11/25/26 21:59
No connection to MT4
by Martin_HH. 11/23/26 06:38
MinMax function on History t6 file
by LucasJoshua. 11/21/26 14:28
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (mistery, AndrewAMD), 5,869 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EvanTJ, rht, MaliceTheMaker, Haitao_Ren, JimSimons
19250 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,150
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,150
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