Permutations using booleans

 

Hi all, 

I have written an ichimoku trading expert to place buy and sell trades when certain criteria are met.

After deriving all of the individual variables using copy buffers, I use the following code to trigger the buy signal:

	     if(tenkanSen > kijunSen
               && tenkanSen-1 < Kijunsen-1
	       && tenkanSen > senkouSpanA
               && tenkanSen > senkouSpanB
               && SenkouSpanA26 > SenkouSpanB26
               && ChikouSpan26 > senkouSpanA26
               && ChikouSpan26 > senkouSpanB26
               && ClosePrice > senkouSpanA
               && ClosePrice > senkouSpanB)
              {//Place Buy position
	       }

I now want to backtest and optimise the strategy. So I want the option to turn each condition on and off using a boolean to be able to run the optimiser and establish which combination of conditions gives me the best result. 

I have set up the booleans as below:

input group "+--- Buy condition inputs ---+"
input bool tenkan_above_kijun = true;
input bool tenkan_above_senkouA = true; 
input bool tenkan_above_senkouB = true;
input bool SenkouA_above_SenkouB = true;
input bool Chikou_above_SenkouA26 = true;
input bool Chikou_above_SenkouB26 = true;
input bool CloseP_above_senkouA = true; 
input bool CloseP_above_senkouB = true;

Each boolean can either be true or false and there are 8 conditions that this can apply to. 

This means that there are 256 different combinations to test. Except coding all of the 256 conditions individually I don't know how to automate this process. 

I have found this thread on mql5: //https://www.mql5.com/en/forum/146999 but don't understand how to apply it to my situation.

Your help would be much appreciated.


Thanks, 


Blue

Code to generate permutations
Code to generate permutations
  • 2013.09.21
  • www.mql5.com
In order to generate different combinations, I believe I need to work with permutations...
 
This is basically like counting in binary numbers:

128/64/32/16/8/4/2/1

00000000 = 0
00000001 = 1
00000010 = 2
00000011 = 2+1 =3
00000100 = 4
00000101 = 4+1 = 5
00000110 = 4+2 = 6
00000111 = 4+2+1 = 7
00001000 = 8 and so on and so on
00001001
00001010
00001011
00001100
00001101
00001110
00001111
00010000
00010001
00010010
00010011
00010100
00010101
00010110
...
etc.

So basically if you can translate a running index from 0 to 255 into binary numbers then you done have the permutation already. But I would have to look into how to exactly do that myself.

Then you could put the decimal places together as a string of a number and as such also take it apart. Or maybe you find a more practical approach with a bool array[8].
 
Cpt.blue.lemon: So I want the option to turn each condition on and off using a boolean to be able to run the optimiser and establish which combination of conditions gives me the best result. 

You are overthinking it; just do it.

             if( (!tenkan_above_kijun || tenkanSen > kijunSen)
               && tenkanSen-1 < Kijunsen-1
               && (!tenkan_above_senkouA || tenkanSen > senkouSpanA)
               && (!tenkan_above_senkouB  || tenkanSen > senkouSpanB)
               && (!SenkouA_above_SenkouB  || SenkouSpanA26 > SenkouSpanB26)
               && (!Chikou_above_SenkouA26  || ChikouSpan26 > senkouSpanA26)
               && (!Chikou_above_SenkouB26  || ChikouSpan26 > senkouSpanB26)
               && (!CloseP_above_senkouA  || ClosePrice > senkouSpanA)
               && (!CloseP_above_senkouB  || ClosePrice > senkouSpanB) )
              {//Place Buy position
               }
 

Hi all, 


Only just finding the time to get back round to this. I'll give your comments a try.


Thanks, 


B

 
  1. X-1 < Y-1 is the same as X < Y
         if(tenkanSen > kijunSen
         && tenkanSen-1 < Kijunsen-1
    That condition will never be true.
         if(tenkanSen > kijunSen
         && tenkanSen < Kijunsen

    Perhaps you meant the previous value, not one less.

  2. Do you really have two variables ("kijuSen" and "Kijunsen") or did you just post code that does not even compile?