Optimize Error 040 while limiting concurrent trades

Posted By: GHRouge

Optimize Error 040 while limiting concurrent trades - 07/18/16 00:10

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!
Posted By: MatPed

Re: Optimize Error 040 while limiting concurrent trades - 07/18/16 10:49

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
Posted By: jcl

Re: Optimize Error 040 while limiting concurrent trades - 07/18/16 12:12

Aside from that, here's a bug:

if (total >= 4) return;

This is a classical Error 040 since you sometimes optimize Trail, sometimes not.
Posted By: GHRouge

Re: Optimize Error 040 while limiting concurrent trades - 07/21/16 19:50

Thank you both, I appreciate the feedback. Still a novice on these matters =)
© 2024 lite-C Forums