May 17, 2022

5 4

Are any Building Blocks better than the other ? Can we find better blocks for our settings, for our instruments and timeframe ? V2

1/ What’s new in this version ?

  • We have now Building Blocks name instead of the variables name. it is easier to understand which building blocks is more efficient in Out Of Sample period.
  • The Code analyzes the Entry and Exit signal.
  • This new snippet analyzes the blocks per signal name. You can now choose by name the signal you want to analyze.
  • By choosing the name of the signal, you can select an Entry signal or an Exit signal, a Long or a Short signal to analyze
  • This is really practical if you are templating, you may have multiple signals with different name. You can enter the name of the signal of your template
  • We usually use this snippet with only Entry position, Long Or Short only to have clarity in the results , however it is not always possible when you are templating. Your template may have Long and Short, Entry indicator and exit indicator. This snippet allow you to do stats per signal.
  • You can add two trading signals or more from your template, or do only one signal analysis.
  • You can expand this snippet to any StrategyQuant metrics. Actually, there are 10 metrics available.
  • This snippet can create a portfolio of trades from your OOS filter selection in the last Databank. Then you can see the Out Of Sample results in StrategyQuant results tab.
  • This snippet creates a statistic for each databanks, and a list of Building Blocks fitting the criteria in folder  ‘C:\temp\
  • this snippet writes a ‘random groups for each databanks , to have a more precise selection for the next period Out Of Sample.

2/ How to install it 

  • in the CodeEditor : ImportSQExtension RankStratsParameters 15052022 V2 04”  (and “SQExtension_SortinoRatio” if it is not already installed in your SQX)
  • Compile
  • Restart SQX
  • (see video attached, “1 Snippets installation”)
  • Create a folder C:\Temp\
  • Create the directories as described on the picture below , C:\Temp\Results P1  etc.  (you can unzip the files “Directories.rar” in “C:\Temp” to help you)

  • Import Custom project  “I 1176 Bouillant Research Custom Project EURUSD Ent 1i Ex 1i I”   (It will create your strategies)
  • Import Custom project  “I 1177 Bouillant Analysis Custom Project”                                        (it will analyze your strategies if you have more than 20000 strategies in your project)
  • Import Custom project  “I 1177 Bouillant Analysis Plus Custom Project”                                (it will analyze your strategies if you have less than 20000 strategies in your project)

 

3/ How can we test the Building Blocks ?

One way is to create strategies in a Custom Analysis and analyze the Long Entry, Short Entry, Long Exit, Short Exit from their Out Of Sample results in another custom analysis:

The Custom project  “I 1176 Bouillant Research Custom Project EURUSD Ent 1i Ex 1i I” will create your strategies, and the Custom project  “I 1177 Bouillant Analysis Custom Project” will analyze your strategies.

It is working as follows : (Schema.docx)

 

 

4/ Are any Building blocks better than the others ?

On the results of 3 Instruments, over 21 years Out Of Sample total, I found that some Building Blocks are much better than other :

if you open the attached file “Results sorted by NetProfit of P1 R“,  (you can watch the attached video “2 Are Block Better than the other“)

You can see on “Results1″ that some Building blocks have a net profit of 4959 $ per year and on “Results2other Building block have a loss of -4977 $

 

 

Yes, some building blocks give more profit than other, it depends on your instrument, your strategy

Don’t forget that few blocks can confuse your results.

 

5/ How do we run the snippet on One Databank?

You just need to

  • add a Custom Analysis Task to your Custom Project
  • select “RankStrategiesParameters” in the drop box
  • select the source Databank (P1R in this example)
  • run the task
  • Enter 1 as number of DataBanks in the first input box
  • Then enter 10 as a minimum number of Strategies per Building blocks (More is better, this depends on the number of strategies available in yor databank)

(You can see the “3 How to run the snippets on Single DataBank” attached video as well)

 

 

 

6/ Can we go further, analyzing multiple Databanks ? Selecting the best Building Blocks of one Cross Validation period and applying to the next period ?

 

Thanks to Mark and the Coding Sessions, this snippet can read multiple Databanks .

If you select multiple Databanks, it will analyze them, one by one, and select the Building blocks based on your criteria.

 

7/ How do we run the snippets on multiple databanks ?

 

I created a Workflow Example, you can download it : “I 1172 USDCHF H1 10YP1”   (I attached a video “4 How to run the snippets on Multiple DataBanks“)

Its In Sample Period is 10 Years, the Out of Sample Period is one year . It is H1.

The Workflow is over 7 periods of one year. This snippets is adjusted for 7 databanks : (You can adjust it)

input = JOptionPane.showInputDialog("Enter the Number Of DataBanks");		                        														// Possible Option
NbDataBanks = Integer.parseInt(input);	
if (NbDataBanks < 1) {NbDataBanks = 1;}
if (NbDataBanks > 7) {NbDataBanks = 7;}

 

For your Workflow, you can change the Databank Name as well :

String DatabankName1 = "P1 R";										// If you are working on Multiple DataBanks, you have to set the Number of Databank Here, the name of the Databanks here
String DatabankName2 = "P2 R";										// If you are working on Multiple DataBanks, you have to set the Number of Databank Here, the name of the Databanks here
String DatabankName3 = "P3 R";										// If you are working on Multiple DataBanks, you have to set the Number of Databank Here, the name of the Databanks here
String DatabankName4 = "P4 R";										// If you are working on Multiple DataBanks, you have to set the Number of Databank Here, the name of the Databanks here
String DatabankName5 = "P5 R";										// If you are working on Multiple DataBanks, you have to set the Number of Databank Here, the name of the Databanks here
String DatabankName6 = "P6 R";										// If you are working on Multiple DataBanks, you have to set the Number of Databank Here, the name of the Databanks here
String DatabankName7 = "P7 R";										// If you are working on Multiple DataBanks, you have to set the Number of Databank Here, the name of the Databanks here
String DatabankName8 = "P8 R";										// If you are working on Multiple DataBanks, you have to set the Number of Databank Here, the name of the Databanks here
String DatabankName9 = "P9 R";										// If you are working on Multiple DataBanks, you have to set the Number of Databank Here, the name of the Databanks here
String DatabankName10 = "P10 R";									// If you are working on Multiple DataBanks, you have to set the Number of Databank Here, the name of the Databanks here
String DatabankName11 = "P11 R";									// If you are working on Multiple DataBanks, you have to set the Number of Databank Here, the name of the Databanks here
String DatabankName12 = "P12 R";									// If you are working on Multiple DataBanks, you have to set the Number of Databank Here, the name of the Databanks here

The Custom analysis is a the last task.

 

For this workflow :          (I attached a video “4 How to run the snippets on Multiple DataBanks”)

  • Your enter 7 as the number of DataBanks
  • Your enter 10 as the minimum Strategies per Building blocks
  • Your enter 1, because you want a portfolio of CV trades based on your blocks selection criteria
  • You enter the criteria , 2 for Net Profit
  • You enter the amount above which your building blocks are acceptable.

 

8/ Can it improve the results ?

At the end of this process, this snippet is creating a portfolio in the last Databanks. We can have a global view of all the Out Of Sample periods trades

In this test, I was able to get Out Of Sample improvements on two instruments, and avoid the loss of 2020, please watch the attached video “5 Some Results

EURUSD without Blocks filter :

CHFUSD without Blocks filter :

EURUSD with Blocks filter :

CHFUSD with Blocks filter :

 

My only criteria was net profit only , but what about Sharpe Ratio ? and Ulcer index ? What would happen if we select Net profit and sharpe ratio ?

Until now, I filtered the strategies only by Block name, what would be the results if we was searching each period from a Random Group with precise settings in each blocks. The results would certainly be even better.

We can do more testing with other metrics. We have 10 metrics available in the snippet, and we can add more. The snippet is easy develop and to adjust.

StrategyQuant have plenty of helpful metrics. It is precise and reliable, made for traders. It is easy to develop with the help of the coding sessions and the community members.

The snippets are a good way unite developers and traders, an idea of one can help many. Please share your snippets because it is helping the community members.

 

 

9/ The Snippet Code :

 

Overview of the code :

You can collapse the code by #Region to have an overview of the code :

 

package SQ.CustomAnalysis;

import com.strategyquant.lib.*;
import java.util.ArrayList;
import com.strategyquant.datalib.*;
import com.strategyquant.tradinglib.*;
import com.strategyquant.tradinglib.PlTypes;
import com.strategyquant.tradinglib.project.ProjectEngine;
import com.strategyquant.tradinglib.results.SpecialValues;
import com.strategyquant.datalib.TradingException;
import com.strategyquant.lib.SQTime;
import com.strategyquant.lib.ValuesMap;
import com.strategyquant.lib.XMLUtil;
import java.util.Arrays;
import java.util.Collections;
import java.lang.String;
import com.strategyquant.tradinglib.results.stats.comparator.OrderComparatorByOpenTime;
import SQ.Utils.Bouillant;
import com.strategyquant.lib.L;
import com.strategyquant.tradinglib.optimization.WalkForwardMatrixResult;
import com.strategyquant.lib.ValuesMap;
import java.io.File;  							
import java.io.BufferedWriter;
import java.io.IOException;  					
import java.io.FileWriter;   					
import java.util.Scanner;  						
import javax.swing.JOptionPane;    				
import java.io.FileNotFoundException;  			
import java.io.*;
import org.jdom2.*;
import org.jdom2.output.*;
import org.jdom2.Element;
import org.jdom2.input.SAXBuilder;
import org.jdom2.Document;
import java.io.StringReader;
import java.util.*;
import java.io.IOException;
import org.jdom2.Attribute;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import com.google.common.base.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.Duration;
import java.time.Instant;
import java.sql.Timestamp;

// Created in France by Emmanuel Bouillant-Evrard for the StrategyQuantX Community :)
public class RankStratsParametersV1 extends CustomAnalysisMethod 
{
    public static final Logger Log = LoggerFactory.getLogger(RankStratsParametersV1.class);

    static Boolean DebugMode = false; // false : Off, true : on 
    static FileWriter FilterWriterTmp ;

    public RankStratsParametersV1() 
    {
        super("RankStrategiesParameters", TYPE_PROCESS_DATABANK);
    }
    
    @Override
    public boolean filterStrategy(String project, String task, String databankName, ResultsGroup rg) throws Exception 
    {
        return true;
    }

    @Override
    public ArrayList<ResultsGroup> processDatabank(String project, String task, String databankName, ArrayList<ResultsGroup> databankRG) throws Exception 
    {
        try 
        {
            //#region ********************************************************* Init1  *************************************************************************************************
                // ArrayList where we store stratgies 
                ArrayList<ResultsGroup> newDatabankContents = new ArrayList<ResultsGroup>();
                // create new ResultsGroup for our new portfolio
                ResultsGroup portfolioRG = new ResultsGroup("Filtered portfolio");																	//("Filtered portfolio "+ "of "+ databankName);
                // get OrderList from new portfolio (empty so far),
                // we will insert WF orders there
                OrdersList portfolioOrdersList = portfolioRG.orders();
                Databank databank1 = ProjectEngine.get(project).getDatabanks().get(databankName);
                String LongEntrySignal= "LongEntrySignal";																							// if you are templating, you enter the name of your signal here 
                String ShortEntrySignal= "ShortEntrySignal";																						// if you are templating, you enter the name of your signal here 
                String LongExitSignal= "LongExitSignal";																							// if you are templating, you enter the name of your signal here 
                String ShortExitSignal= "ShortExitSignal";																							// if you are templating, you enter the name of your signal here 

                String stratMetric1= "ProfitFactor";
                String stratMetric2 = "NetProfit";
                String stratMetric3 = "SharpeRatio";
                String stratMetric4 = "UlcerIndex";
                String stratMetric5 = "SortinoRatio";
                String stratMetric6 = "WinningPct";
                String stratMetric7 = "ReturnDDRatio";
                String stratMetric8 = "RExpectancy";
                String stratMetric9 = "AnnualPctReturnDDRatio";
                String stratMetric10 = "Drawdown";
                String stratMetric11 = "NumberOfTrades";
                
                int NewOrderForPortefolio = 0;
                int SortType = 1;                  								 	// SortType
                int AscDesc = 1; 												 	// automatically set by the switch bellow 
                int AboveUnder = 1;     		  								 	// automatically set by the switch bellow 
                int AboveUnder2 = 1;     		  								 	// automatically set by the switch bellow 
                int NbDataBanks = 1; 												// Are you working on One Databank only or on Multiple DataBanks. 
                String DatabankName1 = "P1 R";										// If you are working on Multiple DataBanks, enter the name of the Databanks here
                String DatabankName2 = "P2 R";										// If you are working on Multiple DataBanks, enter the name of the Databanks here
                String DatabankName3 = "P3 R";										// If you are working on Multiple DataBanks, enter the name of the Databanks here
                String DatabankName4 = "P4 R";										// If you are working on Multiple DataBanks, enter the name of the Databanks here
                String DatabankName5 = "P5 R";										// If you are working on Multiple DataBanks, enter the name of the Databanks here
                String DatabankName6 = "P6 R";										// If you are working on Multiple DataBanks, enter the name of the Databanks here
                String DatabankName7 = "P7 R";										// If you are working on Multiple DataBanks, enter the name of the Databanks here
                String DatabankName8 = "P8 R";										// If you are working on Multiple DataBanks, enter the name of the Databanks here
                String DatabankName9 = "P9 R";										// If you are working on Multiple DataBanks, enter the name of the Databanks here
                String DatabankName10 = "P10 R";									// If you are working on Multiple DataBanks, enter the name of the Databanks here
                String DatabankName11 = "P11 R";									// If you are working on Multiple DataBanks, enter the name of the Databanks here
                String DatabankName12 = "P12 R";									// If you are working on Multiple DataBanks, enter the name of the Databanks here
                String DatabankName13 = "All DB";									// If you are working on Multiple DataBanks, enter the name of the Databanks here
                int breakdownLevelMax = 50;                                       	// Level Max of Block breakdown in a Strategy, must be < 100
                Element AllGroups = new Element("Groups");							// Groups of All group generated
                boolean randomID = false; 											// Generate a random ID for each group, or keep the same ID each time to avoid redoing a the template
                boolean outputXmlStrategyFile = false;								// Output Strategy File
                boolean outputPortfolio = true;										// Output a portfolio of trade filtered by block name only.
                boolean NbTotalOnNbTradeOrNbStrategies = false;						// The minimum is based on the Total Strategies (false), or on the Total of Trades from all strategies (true)
                int NbOrdersperPortfolioMax = 100000;								// Some Portfolio may have to much trades, we have to limit them otherwise it may takes to much time to save the portfolio (hours)
             	Timestamp timestamp1 = new Timestamp(System.currentTimeMillis());
                Instant instant1 = timestamp1.toInstant();
            //#endregion

            //#region ********************************************************* Settings & Dialog Box input ***************************************************************************
                String OutputPath1 = "C:\\Temp\\";              				//  OutputPath !!!!!!!!!!!!!  IMPORTANT !!!!!!!!!!!!!! Must be set, it depend on the installation of the computer !!!!!!!!!!!!!!!!!!!!!!!!!

                NbDataBanks = 1;										     	// Are you working on One Databank only or on Multiple DataBanks. If you are working on Multiple DataBanks, you have to set the Number of Databank Here, the name of the Databanks on Line 114 - 132 
                String input;													// To hold String input.
                input1: do                                                      // (forward : without do) 
                {     												
                    input = (String)JOptionPane.showInputDialog(null, "How many DataBanks are you analysing ? (Databanks P1 to DataBank P?)", "Analysis Settings", JOptionPane.QUESTION_MESSAGE, null, null, 7);		                        											// Possible Option
                    if (Strings.isNullOrEmpty(input)){ continue  input1;}		// (forward : break instead of continue)                                                       					 // or (input == null || input.trim().isEmpty())
                    break input1;											 	// (forward : without break
                }while(true);
                NbDataBanks = Integer.parseInt(input);							// Convert the String input to an int.
                if (NbDataBanks < 1) {NbDataBanks = 1;}
                if (NbDataBanks > 12) {NbDataBanks = 12;}						// For the moment I am using 12 Databanks max in my custom project, you can add more databanks in the code if necessary
                NbDataBanks = NbDataBanks + 1; 									// I am adding 1, for the "All DB" databank, this last Databank is giving the global stats results of all DataBanks  

                int minimum = 10;												// This is the Number of strategies minimum using a block indicator. more is better . However this depend on the number of strategies you have in the databanks, more is better and more reliable statistics.
                input2: do
                {
                    input =   (String)JOptionPane.showInputDialog(null,"Enter the minimum number of strategies for a Building block to be selected (More may be better)", "Analysis Settings", JOptionPane.QUESTION_MESSAGE, null, null, 10);		                           																// Possible Option
                    if (Strings.isNullOrEmpty(input)){ continue  input2;}
                    break input2;
                }while(true);
                minimum = Integer.parseInt(input);								// Convert the String input to an int.
                if (minimum <= 0) { minimum = 1 ; }
                int minimumXml = minimum; //3;									// This is the Number of strategies minimum using a block indicator. more is better . However this depend on the number of strategies you have in the databanks, more is better and more reliable statistics.

                int IsOos = 2;													// We always choose 2 : Out of sample because only OOS is important, I kept the rest as an option, you can activate the next 4 line if you need option (1) InSample Stats, (3) Full Sample Stats
                int LongShort = 3;
                int OosSimulationOverPreviousBlockFilter = 0;
                int ChoiceFilterNextOOS = 0;    
                int ChoiceFilterNextOOS2 = 0;     																													
                double MinimumLevelFilterNextOOS = 0; 
                double MinimumLevelFilterNextOOS2 = 0; 
                double MinimumLevelFilterRandomGroups = 0;   

                if (NbDataBanks > 1)
                {
                    OosSimulationOverPreviousBlockFilter = 1;
                    input4: do
                    {
                        input =  (String)JOptionPane.showInputDialog(null,"Do you want a PortFolio of Multiple Cross-Validation Period ?    (0) No, (1) Yes", "PortFolio creation" , JOptionPane.QUESTION_MESSAGE, null, null, 1);                				// Possible Option
                        if (Strings.isNullOrEmpty(input)){ continue  input4;}
                        break input4;
                    }while(true);
                    OosSimulationOverPreviousBlockFilter = Integer.parseInt(input);																										// Convert the String input to an int.
                    if (OosSimulationOverPreviousBlockFilter < 0) {OosSimulationOverPreviousBlockFilter = 0;}
                    if (OosSimulationOverPreviousBlockFilter > 1) {OosSimulationOverPreviousBlockFilter = 1;}
                    
                    if (OosSimulationOverPreviousBlockFilter == 1)
                    {
                        NbOrdersperPortfolioMax = 400000;								// Some Portfolio may have to much trades, we have to limit them otherwise it may takes to much time to save the portfolio (hours)
                        input11: do                                                      // (forward : without do) 
                        {     												
                            input = (String)JOptionPane.showInputDialog(null,"Enter the maximum of trades per PortFolio (500000 max, more will slow the analysis), if the maximum is exceeded, it will create several portfolios in the databanks ", "PortFolio creation Settings", JOptionPane.QUESTION_MESSAGE, null, null, NbOrdersperPortfolioMax );		                        											// Possible Option
                            if (Strings.isNullOrEmpty(input)){ continue  input11;}		// (forward : break instead of continue)                                                       					 // or (input == null || input.trim().isEmpty())
                            break input11;											 	// (forward : without break
                        }while(true);
                        NbOrdersperPortfolioMax = Integer.parseInt(input);				// Convert the String input to an int.
                        if (NbOrdersperPortfolioMax < 1) {NbOrdersperPortfolioMax = 1;}
                        if (NbOrdersperPortfolioMax > 600000) {NbOrdersperPortfolioMax = 600000;}	

                        ChoiceFilterNextOOS = 2; 
                        input5: do
                        {    																																							// 2 :  NetProfit is selected 
                            input =  (String)JOptionPane.showInputDialog(null,"Select a filter to filter each OOS period : (0)None, (1)ProfitFactor,(2)NetProfit,(3)SharpeRatio,(4)UlcerIndex,(5)SortinoRatio,(6)WinningPct,(7)ReturnDDRatio,(8)RExpectancy,(9)AnnualPctReturnDDRatio,(10)Drawdown", "PortFolio creation Settings" , JOptionPane.QUESTION_MESSAGE, null, null,2);
                            if (Strings.isNullOrEmpty(input)){ continue  input5;}
                            break input5;
                        }while(true);
                        ChoiceFilterNextOOS = Integer.parseInt(input);						// Convert the String input to an int.
                        if (ChoiceFilterNextOOS < 0) {ChoiceFilterNextOOS = 0;}
                        if (ChoiceFilterNextOOS > 10) {ChoiceFilterNextOOS = 10;}

                        if (ChoiceFilterNextOOS != 0)
                        {
                            MinimumLevelFilterNextOOS = 1000;         																													// 1000 profit minimum selected for the next CV/OOS period 
                            MinimumLevelFilterNextOOS2 = 1000;         																													// 1000 profit minimum selected for the next CV/OOS period 

                            if (ChoiceFilterNextOOS != 0){
                                input6: do
                                { 
                                    input =  (String)JOptionPane.showInputDialog(null,"Enter the minimum or maximum for this filter", "Filter Settings", JOptionPane.QUESTION_MESSAGE, null, null,2000);															
                                    if (Strings.isNullOrEmpty(input)){ continue  input6;}
                                    break input6;
                                }while(true);			
                                MinimumLevelFilterNextOOS = Double.parseDouble(input);																										// Convert the String input to a double.
                            }

                            ChoiceFilterNextOOS2 = 0; 
                            MinimumLevelFilterRandomGroups = MinimumLevelFilterNextOOS;     //1000;         																												// 1000 profit minimum selected for the next CV/OOS period 
                        }
                    }
                }
            //#endregion

            for(int DatabanksNumber = 1; DatabanksNumber <= NbDataBanks; DatabanksNumber++) 	                 																		// For each DataBanks                                                              													 
            {
                for(int SignalType = 1; SignalType <= 2; SignalType++) 	  																												// Select "Entry signal" or "Exit Signal"                                                                                 													 
                {
                    //#region  ******************************************************** Loading Databanks **************************************************************************************
                        if (NbDataBanks > 1)
                        {
                            switch (DatabanksNumber) 
                            {
                                case 1:
                                    databank1 = ProjectEngine.get(project).getDatabanks().get(DatabankName1);																			// Enter here your dataBank Name instead of "P1 R"
                                    break;
                                case 2:
                                    databank1 = ProjectEngine.get(project).getDatabanks().get(DatabankName2);																			// Enter here your dataBank Name
                                    break;
                                case 3:
                                    databank1 = ProjectEngine.get(project).getDatabanks().get(DatabankName3);																			// Enter here your dataBank Name
                                    break;
                                case 4:
                                    databank1 = ProjectEngine.get(project).getDatabanks().get(DatabankName4);																			// Enter here your dataBank Name
                                    break;
                                case 5:
                                    databank1 = ProjectEngine.get(project).getDatabanks().get(DatabankName5);																			// Enter here your dataBank Name
                                    break;
                                case 6:
                                    databank1 = ProjectEngine.get(project).getDatabanks().get(DatabankName6);																			// Enter here your dataBank Name
                                    break;
                                case 7:
                                    databank1 = ProjectEngine.get(project).getDatabanks().get(DatabankName7);																			// Enter here your dataBank Name
                                    break;
                                case 8:
                                    databank1 = ProjectEngine.get(project).getDatabanks().get(DatabankName8);																			// Enter here your dataBank Name
                                    break;	
                                case 9:
                                    databank1 = ProjectEngine.get(project).getDatabanks().get(DatabankName9);																			// Enter here your dataBank Name
                                    break;	
                                case 10:
                                    databank1 = ProjectEngine.get(project).getDatabanks().get(DatabankName10);																			// Enter here your dataBank Name
                                    break;		
                                case 11:
                                    databank1 = ProjectEngine.get(project).getDatabanks().get(DatabankName11);																			// Enter here your dataBank Name
                                    break;	
                                case 12:
                                    databank1 = ProjectEngine.get(project).getDatabanks().get(DatabankName12);																			// Enter here your dataBank Name
                                    break;
                            }
                            if (DatabanksNumber == NbDataBanks) 																														// All Databanks, to have a general stats of all the building blocks
                            {
                                databank1 = ProjectEngine.get(project).getDatabanks().get(DatabankName13);																			
                            }
                            databankName = databank1.getName();
                            databankRG = databank1.getRecords();
                        }

                        if (DebugMode){
                        FileWriter FilterWriterTmp = new FileWriter(OutputPath1 + "Test of "+ databankName + ".xml" , true);
                        FilterWriterTmp.write(databankName+"\r\n");
                        FilterWriterTmp.write("databankRG.size() " +String.valueOf(databankRG.size())+"\r\n");
                        FilterWriterTmp.close();}

                    //#endregion	

                    //#region ********************************************************* Init2  *************************************************************************************************
                        int counter = 0;
                        String [] arrays1 = new String[100000];         											    																// 0 : variable name
                        String [] arrays1XmlLong = new String[100000];         											    															// 0 : Xml Building Blocks 
                        String [] arrays1XmlShort = new String[100000];         											    														// 0 : Xml Building Blocks 
                    
                        Element [] arrays1XmlLongb = new Element[100000];         											   														 	// 0 : Xml Building Blocks 
                        Element [] arrays1XmlShortb = new Element[100000];         											    														// 0 : Xml Building Blocks 

                        double [][] arrays2 = new double[100000][12];    																												// 0 : Nb , 1 : Total Profit Factor, 2 : NetProfit, 3 : SharpeRatio, 4 : UlcerIndex, 6 : etc.
                        double [][] arrays2Long = new double[100000][12];    																											// 0 : Nb , 1 : Total Profit Factor, 2 : NetProfit, 3 : SharpeRatio, 4 : UlcerIndex, 6 : etc.
                        double [][] arrays2Short = new double[100000][12];    																											// 0 : Nb , 1 : Total Profit Factor, 2 : NetProfit, 3 : SharpeRatio, 4 : UlcerIndex, 6 : etc.
                        double [][] arrays2LongXml = new double[100000][12];    																										// 0 : Nb , 1 : Total Profit Factor, 2 : NetProfit, 3 : SharpeRatio, 4 : UlcerIndex, 6 : etc.
                        double [][] arrays2ShortXml = new double[100000][12];    																										// 0 : Nb , 1 : Total Profit Factor, 2 : NetProfit, 3 : SharpeRatio, 4 : UlcerIndex, 6 : etc.
                        String [] arrays2LongXmlName = new String[100000]; 
                        String [] arrays2ShortXmlName = new String[100000]; 

                        String [] arraysFilterEntryLong = new String[100000];         										   																	// 0 : variable filtered name
                        String [] arraysFilterEntryShort = new String[100000];         										   																	// 0 : variable filtered name
                        String [] arraysFilterExitLong = new String[100000];         										   																	// 0 : variable filtered name
                        String [] arraysFilterExitShort = new String[100000];         										   																	// 0 : variable filtered name

                        int NbNameEntryLong = 0; 
                        int NbNameEntryShort = 0; 
                        int NbNameExitLong = 0; 
                        int NbNameExitShort = 0; 

                        Double[][] stats = new Double[databankRG.size()][11];
                        Double[][] statsLong = new Double[databankRG.size()][11];
                        Double[][] statsShort = new Double[databankRG.size()][11];
                        String[] statsStr = new String[databankRG.size()];
                        String[][]statsStr2 = new String[databankRG.size()][];
                        String[][]statsStr2XmlLong = new String[databankRG.size()][];
                        String[][]statsStr2XmlShort = new String[databankRG.size()][];
                        List<Element>[] statsStr2XmlLongb = new List[databankRG.size()];
                        for (int i = 0; i < databankRG.size(); i++)
                        {
                            statsStr2XmlLongb[i] = new ArrayList<Element>();
                        }
                        List<Element>[] statsStr2XmlShortb = new List[databankRG.size()];
                        for (int i = 0; i < databankRG.size(); i++)
                        {
                            statsStr2XmlShortb[i] = new ArrayList<Element>();
                        }

                        File myObj;
                        File FilterFile;
                        File FilterFile2;
                        File FilterFileLong;
                        File FilterFile2Long;
                        File FilterFileShort;
                        File FilterFile2Short;
                        File FilterFileExitLong;
                        File FilterFileExitShort;
                    //#endregion

                    //#region ********** loop through strategies in databank and assign the variable to 2 Arrays : stats for stratMetric and statsStr2 for the variable name ******************* 
                        counter = 0;
                        for(ResultsGroup strategyRG : databankRG) 																														// Read each values strategy from the databank
                        {
                            Result mainResult = strategyRG.subResult( strategyRG.getMainResultKey());
                            if(mainResult==null) break;

                            String strName = strategyRG.getName();
                            if(strName.startsWith("Filtered portfolio")) 
                            {
                                continue;
                            }

                            SQStats	statsFull = mainResult.stats(Directions.Both,PlTypes.Money, SampleTypes.FullSample);
                            SQStats	statsFullLong = mainResult.stats(Directions.Long,PlTypes.Money, SampleTypes.FullSample);
                            SQStats	statsFullShort = mainResult.stats(Directions.Short,PlTypes.Money, SampleTypes.FullSample);
                            if (LongShort == 1)
                            {
                                if (IsOos == 1 )
                                {
                                    statsFull = mainResult.stats(Directions.Long,PlTypes.Money, SampleTypes.InSample);
                                }
                                else if (IsOos == 2 )
                                {
                                    statsFull = mainResult.stats(Directions.Long,PlTypes.Money, SampleTypes.OutOfSample);
                                }
                                else
                                {
                                    statsFull = mainResult.stats(Directions.Long,PlTypes.Money, SampleTypes.FullSample);
                                }
                            }
                            else if (LongShort == 2)
                            {
                                if (IsOos == 1 )
                                {
                                    statsFull = mainResult.stats(Directions.Short,PlTypes.Money, SampleTypes.InSample);
                                }
                                else if (IsOos == 2 )
                                {
                                    statsFull = mainResult.stats(Directions.Short,PlTypes.Money, SampleTypes.OutOfSample);
                                }
                                else
                                {
                                    statsFull = mainResult.stats(Directions.Short,PlTypes.Money, SampleTypes.FullSample);
                                }
                            }
                            else if (LongShort == 3)
                            {
                                if (IsOos == 1 )
                                {
                                    statsFull = mainResult.stats(Directions.Both,PlTypes.Money, SampleTypes.InSample);
                                    statsFullLong = mainResult.stats(Directions.Long,PlTypes.Money, SampleTypes.InSample);
                                    statsFullShort = mainResult.stats(Directions.Short,PlTypes.Money, SampleTypes.InSample);
                                }
                                else if (IsOos == 2 )
                                {
                                    statsFull = mainResult.stats(Directions.Both,PlTypes.Money, SampleTypes.OutOfSample);
                                    statsFullLong = mainResult.stats(Directions.Long,PlTypes.Money, SampleTypes.OutOfSample);
                                    statsFullShort = mainResult.stats(Directions.Short,PlTypes.Money, SampleTypes.OutOfSample);
                                }
                                else
                                {
                                    statsFull = mainResult.stats(Directions.Both,PlTypes.Money, SampleTypes.FullSample);
                                    statsFullLong = mainResult.stats(Directions.Long,PlTypes.Money, SampleTypes.FullSample);
                                    statsFullShort = mainResult.stats(Directions.Short,PlTypes.Money, SampleTypes.FullSample);
                                }
                            }

                            if(statsFull == null) break;

                            stats[counter][0]  = statsFull.getDouble(stratMetric1);
                            stats[counter][1] = statsFull.getDouble(stratMetric2);
                            stats[counter][2] = statsFull.getDouble(stratMetric3);
                            stats[counter][3] = statsFull.getDouble(stratMetric4);
                            stats[counter][4] = statsFull.getDouble(stratMetric5);
                            stats[counter][5] = statsFull.getDouble(stratMetric6);
                            stats[counter][6] = statsFull.getDouble(stratMetric7);
                            stats[counter][7] = statsFull.getDouble(stratMetric8);
                            stats[counter][8] = statsFull.getDouble(stratMetric9);
                            stats[counter][9] = statsFull.getDouble(stratMetric10);
                            stats[counter][10] = statsFull.getDouble(stratMetric11);

                            if (LongShort == 3 && statsFullLong != null)
                            {
                                statsLong[counter][0]  = statsFullLong.getDouble(stratMetric1);
                                statsLong[counter][1] = statsFullLong.getDouble(stratMetric2);
                                statsLong[counter][2] = statsFullLong.getDouble(stratMetric3);
                                statsLong[counter][3] = statsFullLong.getDouble(stratMetric4);
                                statsLong[counter][4] = statsFullLong.getDouble(stratMetric5);
                                statsLong[counter][5] = statsFullLong.getDouble(stratMetric6);
                                statsLong[counter][6] = statsFullLong.getDouble(stratMetric7);
                                statsLong[counter][7] = statsFullLong.getDouble(stratMetric8);
                                statsLong[counter][8] = statsFullLong.getDouble(stratMetric9);
                                statsLong[counter][9] = statsFullLong.getDouble(stratMetric10);
                                statsLong[counter][10] = statsFullLong.getDouble(stratMetric11);
                            }

                            if (LongShort == 3 && statsFullShort != null)
                            {
                                statsShort[counter][0]  = statsFullShort.getDouble(stratMetric1);
                                statsShort[counter][1] = statsFullShort.getDouble(stratMetric2);
                                statsShort[counter][2] = statsFullShort.getDouble(stratMetric3);
                                statsShort[counter][3] = statsFullShort.getDouble(stratMetric4);
                                statsShort[counter][4] = statsFullShort.getDouble(stratMetric5);
                                statsShort[counter][5] = statsFullShort.getDouble(stratMetric6);
                                statsShort[counter][6] = statsFullShort.getDouble(stratMetric7);
                                statsShort[counter][7] = statsFullShort.getDouble(stratMetric8);
                                statsShort[counter][8] = statsFullShort.getDouble(stratMetric9);
                                statsShort[counter][9] = statsFullShort.getDouble(stratMetric10);
                                statsShort[counter][10] = statsFullShort.getDouble(stratMetric11);
                            }

                            //#region ********************************************************* V2 now , we are searching the Building Blocks Name from a Trading signal ******************
                            String BuildingBlocksName1 = "";
                            String BuildingBlocksName2 = "";
                            String BuildingBlocksName3 = "";
                            String BuildingBlocksName4 = "";
                            Bouillant BouilltParaObj1 = new Bouillant();
                            Bouillant BouilltParaObj2 = new Bouillant();
                            Bouillant BouilltParaObj3 = new Bouillant();
                            Bouillant BouilltParaObj4 = new Bouillant();

                            if (SignalType == 1)
                            {
                                try 
                                {
                                    BuildingBlocksName1 = BouilltParaObj1.toBuildingBlocksName(strategyRG, false, LongEntrySignal, 50);						    // We are searching the Building Blocks from a trading signal.   50 : to have a general view of larger blocks (build with two  blocks) like (("IsRising") || ("IsFalling") || ("IsLowerCount") || ("IsGreaterCount") || ("IsLower") || ("IsLowerOrEqual") || ("IsGreater") || ("IsGreaterOrEqual") || ("CrossesAbove") || ("CrossesBelow")
                                    BuildingBlocksName2 = BouilltParaObj2.toBuildingBlocksName(strategyRG, false, ShortEntrySignal, 50);						// We are searching the Building Blocks from a trading signal
                                    BuildingBlocksName3 = BouilltParaObj1.toBuildingBlocksName(strategyRG, false, LongEntrySignal, 100);						// We are searching the Building Blocks from a trading signal.   100 : to have a details of the smallest basic blocks
                                    BuildingBlocksName4 = BouilltParaObj2.toBuildingBlocksName(strategyRG, false, ShortEntrySignal, 100);						// We are searching the Building Blocks from a trading signal
                                } catch (Exception e){}
                            }
                            else if (SignalType == 2)
                            {
                                try 
                                {
                                    BuildingBlocksName1 = BouilltParaObj1.toBuildingBlocksName(strategyRG, false, LongExitSignal, 50);
                                    BuildingBlocksName2 = BouilltParaObj2.toBuildingBlocksName(strategyRG, false, ShortExitSignal, 50);
                                    BuildingBlocksName3 = BouilltParaObj1.toBuildingBlocksName(strategyRG, false, LongExitSignal, 100);
                                    BuildingBlocksName4 = BouilltParaObj2.toBuildingBlocksName(strategyRG, false, ShortExitSignal, 100);
                                } catch (Exception e){}
                            }

                            if (!BuildingBlocksName1.equals("") && !BuildingBlocksName2.equals(""))
                            {
                                statsStr[counter] = BuildingBlocksName1 + "," + BuildingBlocksName2 + "," + BuildingBlocksName3 + "," + BuildingBlocksName4;
                            }
                            else if (!BuildingBlocksName1.equals(""))
                            {
                                statsStr[counter] = BuildingBlocksName1 + "," + BuildingBlocksName3;
                            }
                            else if (!BuildingBlocksName2.equals(""))
                            {
                                statsStr[counter] = BuildingBlocksName2 + "," + BuildingBlocksName4;
                            }
                            if (DebugMode){
                            FilterWriterTmp = new FileWriter(OutputPath1 + "Test of "+ databankName + ".xml" , true);
                            FilterWriterTmp.write(String.valueOf(counter) + statsStr[counter]+"\r\n");
                            FilterWriterTmp.close();}
                            String [] myArray;
                            String text1 = "";
                            text1 = statsStr[counter];
                            if (text1 == null) 
                            {
                                statsStr2[counter] = new String[]{""} ;
                                counter++;
                                continue; 
                            }                         																																					// V2
                            myArray = text1.split(",");
                            statsStr2[counter] = myArray ;
                            //#endregion

                            //#region ********************************************************* V2 now , we are searching the Building Blocks XML from a Trading signal ******************

                            String[] BuildingBlocksXML1b = new String[1];
                            String[] BuildingBlocksXML2b = new String[1];
                            BouilltParaObj1 = new Bouillant();
                            BouilltParaObj2 = new Bouillant();

                            if (SignalType == 1)
                            {
                                try 
                                {
                                    BuildingBlocksXML1b = BouilltParaObj1.toBuildingBlocksXml2(strategyRG, false, LongEntrySignal, breakdownLevelMax);      								// read the string of the Element
                                    BuildingBlocksXML2b = BouilltParaObj2.toBuildingBlocksXml2(strategyRG, false, ShortEntrySignal, breakdownLevelMax);
                                } catch (Exception e){}

                            }
                            else if (SignalType == 2)
                            {
                                try 
                                {
                                    BuildingBlocksXML1b = BouilltParaObj1.toBuildingBlocksXml2(strategyRG, false, LongExitSignal, breakdownLevelMax);      								// read the string of the Element
                                    BuildingBlocksXML2b = BouilltParaObj2.toBuildingBlocksXml2(strategyRG, false, ShortExitSignal, breakdownLevelMax);
                                } catch (Exception e){}
                            }

                            statsStr2XmlLong[counter] = BuildingBlocksXML1b;
                            statsStr2XmlShort[counter] = BuildingBlocksXML2b;


                            ArrayList<Element> BuildingBlocksXML1c = new ArrayList<Element>();
                            ArrayList<Element> BuildingBlocksXML2c = new ArrayList<Element>();
                            BouilltParaObj1 = new Bouillant();
                            BouilltParaObj2 = new Bouillant();


                            if (SignalType == 1)
                            {
                                try 
                                {
                                    BuildingBlocksXML1c = BouilltParaObj1.toBuildingBlocksXml3(strategyRG, false, LongEntrySignal, breakdownLevelMax);									// read the Element
                                    BuildingBlocksXML2c  = BouilltParaObj2.toBuildingBlocksXml3(strategyRG, false, ShortEntrySignal, breakdownLevelMax);
                                } catch (Exception e){}
                            }
                            else if (SignalType == 2)
                            {
                                try 
                                {
                                    BuildingBlocksXML1c = BouilltParaObj1.toBuildingBlocksXml3(strategyRG, false, LongExitSignal, breakdownLevelMax);									// read the Element
                                    BuildingBlocksXML2c  = BouilltParaObj2.toBuildingBlocksXml3(strategyRG, false, ShortExitSignal, breakdownLevelMax);
                                } catch (Exception e){}
                            }

                            statsStr2XmlLongb[counter] = BuildingBlocksXML1c;
                            statsStr2XmlShortb[counter] = BuildingBlocksXML2c;
                            counter++;
                        }
                        if (DebugMode){
                        FilterWriterTmp = new FileWriter(OutputPath1 + "Test of "+ databankName + ".xml" , true);
                        FilterWriterTmp.write("counter " + String.valueOf(counter)+"\r\n");
                        FilterWriterTmp.close();}
                    //#endregion
                    
                    //#endregion
            
                    //#region ********************************************************* Assign each values to array arrays1, arrays2, arrays2Long, arrays2Short *******************************
                    int NbVariable = 0 ;
                    int IndexVariableTrouvé = 0 ;																	
                    for(int i1 = 0; i1 < counter; i1++) 																																			// For each strategies
                    {
                        if (statsStr2[i1] == null) 
                        {
                            if (DebugMode){
                            FilterWriterTmp = new FileWriter(OutputPath1 + "Test of "+ databankName + ".xml" , true);
                            FilterWriterTmp.write("statsStr2[i1] == null   \r\n");
                            FilterWriterTmp.close();}
                            continue;
                        }                      	// V2
                        for(int i2 = 0; i2 < statsStr2[i1].length; i2 += 1)   				//+= 2 V1																								// For each  variables 
                        {
                                                                                                                                                                                                    // Search among existing variables
                            IndexVariableTrouvé = -1;
                            for(int i3 = 0; i3 < NbVariable; i3++)                                                  																				// Search in arrays1, to check if the variable exist already
                            {
                                if (arrays1[i3].equals(statsStr2[i1][i2].trim()))
                                {
                                    IndexVariableTrouvé = i3;
                                    break;
                                }
                            }
                            
                            if (IndexVariableTrouvé == -1 && NbVariable < arrays1.length)																											// if it is a new variable, we add it to the list
                            {
                                arrays1[NbVariable] =  statsStr2[i1][i2].trim();
                                IndexVariableTrouvé = NbVariable;
                                NbVariable+=1;
                            }
                            if (IndexVariableTrouvé != -1)
                            {
                                arrays2[IndexVariableTrouvé][0] += 1;
                                arrays2[IndexVariableTrouvé][1] += stats[i1][0];
                                arrays2[IndexVariableTrouvé][2] += stats[i1][1];
                                arrays2[IndexVariableTrouvé][3] += stats[i1][2];
                                arrays2[IndexVariableTrouvé][4] += stats[i1][3];
                                arrays2[IndexVariableTrouvé][5] += stats[i1][4];
                                arrays2[IndexVariableTrouvé][6] += stats[i1][5];
                                arrays2[IndexVariableTrouvé][7] += stats[i1][6];
                                arrays2[IndexVariableTrouvé][8] += stats[i1][7];
                                arrays2[IndexVariableTrouvé][9] += stats[i1][8];
                                arrays2[IndexVariableTrouvé][10] += stats[i1][9];
                                arrays2[IndexVariableTrouvé][11] += stats[i1][10];
                            }
                            if (LongShort == 3 && (statsLong[i1][1] != 0 || statsLong[i1][2] != 0 || statsLong[i1][3] != 0))
                            {
                                arrays2Long[IndexVariableTrouvé][0] += 1;
                                arrays2Long[IndexVariableTrouvé][1] += statsLong[i1][0];
                                arrays2Long[IndexVariableTrouvé][2] += statsLong[i1][1];
                                arrays2Long[IndexVariableTrouvé][3] += statsLong[i1][2];
                                arrays2Long[IndexVariableTrouvé][4] += statsLong[i1][3];
                                arrays2Long[IndexVariableTrouvé][5] += statsLong[i1][4];
                                arrays2Long[IndexVariableTrouvé][6] += statsLong[i1][5];
                                arrays2Long[IndexVariableTrouvé][7] += statsLong[i1][6];
                                arrays2Long[IndexVariableTrouvé][8] += statsLong[i1][7];
                                arrays2Long[IndexVariableTrouvé][9] += statsLong[i1][8];
                                arrays2Long[IndexVariableTrouvé][10] += statsLong[i1][9];
                                arrays2Long[IndexVariableTrouvé][11] += statsLong[i1][10];
                            }
                            if (LongShort == 3 && (statsShort[i1][1] != 0 || statsLong[i1][2] != 0 || statsLong[i1][3] != 0))
                            {
                                arrays2Short[IndexVariableTrouvé][0] += 1;
                                arrays2Short[IndexVariableTrouvé][1] += statsShort[i1][0];
                                arrays2Short[IndexVariableTrouvé][2] += statsShort[i1][1];
                                arrays2Short[IndexVariableTrouvé][3] += statsShort[i1][2];
                                arrays2Short[IndexVariableTrouvé][4] += statsShort[i1][3];
                                arrays2Short[IndexVariableTrouvé][5] += statsShort[i1][4];
                                arrays2Short[IndexVariableTrouvé][6] += statsShort[i1][5];
                                arrays2Short[IndexVariableTrouvé][7] += statsShort[i1][6];
                                arrays2Short[IndexVariableTrouvé][8] += statsShort[i1][7];
                                arrays2Short[IndexVariableTrouvé][9] += statsShort[i1][8];
                                arrays2Short[IndexVariableTrouvé][10] += statsShort[i1][9];
                                arrays2Short[IndexVariableTrouvé][11] += statsShort[i1][10];
                            }
                        }
                    }
                    if (DebugMode){
                    FilterWriterTmp = new FileWriter(OutputPath1 + "Test of "+ databankName + ".xml" , true);
                    FilterWriterTmp.write(String.valueOf(NbVariable)+"\r\n");
                    FilterWriterTmp.close();

                    FilterWriterTmp = new FileWriter(OutputPath1 + "Test of "+ databankName + ".xml" , true);
                    FilterWriterTmp.write(String.valueOf(arrays1XmlLong.length)+"\r\n");
                    FilterWriterTmp.close();

                    FilterWriterTmp = new FileWriter(OutputPath1 + "Test of "+ databankName + ".xml" , true);
                    FilterWriterTmp.write(String.valueOf(arrays1XmlShort.length)+"\r\n");
                    FilterWriterTmp.close();}
                    //#endregion

                    //#region ********************************************************* Assign each values to array arrays1Xml, arrays2Xml, arrays2LongXml, arrays2ShortXml *******************************
                    int NbVariableXmlLong = 0 ;
                    IndexVariableTrouvé = 0 ;	
                    String String10 = ""; 
                    String String20 = ""; 
                    String Param1 = "";            
                    String Param2 = "";  																
                    for(int i1 = 0; i1 < counter; i1++) 																																			// For each strategies
                    {

                        if (statsStr2XmlLong[i1] == null) 
                        {
                            if (DebugMode){
                            FilterWriterTmp = new FileWriter(OutputPath1 + "Test of "+ databankName + ".xml" , true);
                            FilterWriterTmp.write("statsStr2XmlLong[i1] == null  " + String.valueOf(i1) +  "\r\n");
                            FilterWriterTmp.close();}
                            continue; 
                        } 
                        
                        for(int i2 = 0; i2 < statsStr2XmlLong[i1].length; i2 += 1)   				//+= 2 V1																						// For each  variables 
                        {
                                                                                                                                                                                                    // Search among existing variables
                            IndexVariableTrouvé = -1;
                            for(int i3 = 0; i3 < NbVariableXmlLong; i3++)                                                 																			// Search in arrays1Xml, to check if the variable exist already
                            {
                                if (statsStr2XmlLong[i1][i2] != null)
                                {
                                    Element element1 =  arrays1XmlLongb[i3];
                                    String10 = element1.getAttributeValue("name"); 
                                    Element element2 = statsStr2XmlLongb[i1].get(i2);
                                    String20 = element2.getAttributeValue("name"); 
                                    
                                    if (String10 != null && String20 != null)
                                    {
                                        if (String10.equals(String20))																																		// if it is the same Building blocks name
                                        {
                                            Element element1Copy = (Element)element1.clone();
                                            element1Copy.detach();
                                            String test4 = "" ;   
                                            List<Element> paramElems2  = element1Copy.getChildren(); 

                                            for (int i4 = 0; i4 < paramElems2.size(); i4++) 
                                            {
                                                Element element5 = paramElems2.get(i4);
                                                String elParamKey3 = element5.getAttributeValue("key");					    																				// the name
                                                String elParamVariable3 = element5.getAttributeValue("variable");					    																	// the variable
                                                String gid = element5.getAttributeValue("gid");					    																						// the gid

                                                if (gid != null)
                                                {
                                                    if (elParamKey3.startsWith("#"))																														// && elParamVariable3=="true"
                                                    {
                                                        element5.setAttribute("gid","0");
                                                    }
                                                }
                                            }
                                            Element element2Copy = (Element)element2.clone();
                                            element2Copy.detach();
                                            test4 = "" ;   
                                            paramElems2  = element2Copy.getChildren(); 

                                            for (int i4 = 0; i4 < paramElems2.size(); i4++) 
                                            {
                                                Element element5 = paramElems2.get(i4);
                                                String elParamKey3 = element5.getAttributeValue("key");					    																				// the name
                                                String elParamVariable3 = element5.getAttributeValue("variable");					    																	// the variable
                                                String gid = element5.getAttributeValue("gid");					    																						// the gid

                                                if (gid != null)
                                                {
                                                    if (elParamKey3.startsWith("#"))																														// && elParamVariable3=="true"
                                                    {
                                                        element5.setAttribute("gid","0");
                                                    }
                                                }
                                            }

                                            Element element3 = element1Copy.getChild("Param");
                                            Element element4 = element2Copy.getChild("Param");
                                            Param1 = XMLUtil.elementToString(element3);
                                            Param2 = XMLUtil.elementToString(element4);

                                            if (Param1 != null && Param2 != null){
                                            if (Param1.equals(Param2) && IndexVariableTrouvé == -1)																																		// if it is the same parameter in each Building blocks name
                                            {
                                                IndexVariableTrouvé = i3;
                                            }}
                                            arrays2LongXml[i3][0] += 1;                                                 																												// Modif V 2.01
                                            arrays2LongXml[i3][1] += statsLong[i1][0];                                                 																									// Modif V 2.01
                                            arrays2LongXml[i3][2] += statsLong[i1][1];
                                            arrays2LongXml[i3][3] += statsLong[i1][2];
                                            arrays2LongXml[i3][4] += statsLong[i1][3];
                                            arrays2LongXml[i3][5] += statsLong[i1][4];
                                            arrays2LongXml[i3][6] += statsLong[i1][5];
                                            arrays2LongXml[i3][7] += statsLong[i1][6];
                                            arrays2LongXml[i3][8] += statsLong[i1][7];
                                            arrays2LongXml[i3][9] += statsLong[i1][8];
                                            arrays2LongXml[i3][10] += statsLong[i1][9];
                                            arrays2LongXml[i3][11] += statsLong[i1][10];
                                        }
                                    }
                                }
                            }

                            if (statsStr2XmlLong[i1][i2] != null && statsStr2XmlLongb[i1].get(i2) != null){
                            if (IndexVariableTrouvé == -1 && NbVariableXmlLong < arrays1XmlLong.length)																								// if it is a new variable, we add it to the list
                            {
                                arrays1XmlLong[NbVariableXmlLong] =  statsStr2XmlLong[i1][i2].trim();
                                arrays1XmlLongb[NbVariableXmlLong] = statsStr2XmlLongb[i1].get(i2);
                                IndexVariableTrouvé = NbVariableXmlLong;
                                NbVariableXmlLong+=1;
                            }
                            if (IndexVariableTrouvé != -1)
                            {
                                arrays2LongXml[IndexVariableTrouvé][0] += 1;
                                arrays2LongXml[IndexVariableTrouvé][1] += statsLong[i1][0];
                                arrays2LongXml[IndexVariableTrouvé][2] += statsLong[i1][1];
                                arrays2LongXml[IndexVariableTrouvé][3] += statsLong[i1][2];
                                arrays2LongXml[IndexVariableTrouvé][4] += statsLong[i1][3];
                                arrays2LongXml[IndexVariableTrouvé][5] += statsLong[i1][4];
                                arrays2LongXml[IndexVariableTrouvé][6] += statsLong[i1][5];
                                arrays2LongXml[IndexVariableTrouvé][7] += statsLong[i1][6];
                                arrays2LongXml[IndexVariableTrouvé][8] += statsLong[i1][7];
                                arrays2LongXml[IndexVariableTrouvé][9] += statsLong[i1][8];
                                arrays2LongXml[IndexVariableTrouvé][10] += statsLong[i1][9];
                                arrays2LongXml[IndexVariableTrouvé][11] += statsLong[i1][10];
                                arrays2LongXmlName[IndexVariableTrouvé] = String20; 
                            }}
                        }
                    }

                    int NbVariableXmlShort = 0 ;
                    IndexVariableTrouvé = 0 ;																	
                    for(int i1 = 0; i1 < counter; i1++) 																																			// For each strategies
                    {
                        if (statsStr2XmlShort[i1] == null) 
                        {
                            if (DebugMode){
                            FilterWriterTmp = new FileWriter(OutputPath1 + "Test of "+ databankName + ".xml" , true);
                            FilterWriterTmp.write("statsStr2XmlShort[i1] == null  " + String.valueOf(i1) +  "\r\n");
                            FilterWriterTmp.close();}
                            continue;
                        }                      	// V2
                        for(int i2 = 0; i2 < statsStr2XmlShort[i1].length; i2 += 1)   				//+= 2 V1																						// For each  variables 
                        {
                                                                                                                                                                                                    // Search among existing variables
                            IndexVariableTrouvé = -1;
                            for(int i3 = 0; i3 < NbVariableXmlShort; i3++)                                                  																		// Search in arrays1Xml, to check if the variable exist already
                            {
                                if (statsStr2XmlShort[i1][i2] != null)
                                {
                                    Element element1 =  arrays1XmlShortb[i3];
                                    String10 = element1.getAttributeValue("name"); 
                                    Element element2 = statsStr2XmlShortb[i1].get(i2);
                                    String20 = element2.getAttributeValue("name"); 
                                    
                                    if (String10 != null && String20 != null)
                                    {
                                        if (String10.equals(String20))																																	// if it is the same Building blocks name
                                        {
                                            Element element1Copy = (Element)element1.clone();
                                            element1Copy.detach();
                                            String test4 = "" ;   
                                            List<Element> paramElems2  = element1Copy.getChildren(); 

                                            for (int i4 = 0; i4 < paramElems2.size(); i4++) 
                                            {
                                                Element element5 = paramElems2.get(i4);
                                                String elParamKey3 = element5.getAttributeValue("key");					    																				// the name
                                                String elParamVariable3 = element5.getAttributeValue("variable");					    																	// the variable
                                                String gid = element5.getAttributeValue("gid");					    																						// the gid

                                                if (gid != null)
                                                {
                                                    if (elParamKey3.startsWith("#"))																														// && elParamVariable3=="true"
                                                    {
                                                        element5.setAttribute("gid","0");
                                                    }
                                                }
                                            }
                                            Element element2Copy = (Element)element2.clone();
                                            element2Copy.detach();
                                            test4 = "" ;   
                                            paramElems2  = element2Copy.getChildren(); 

                                            for (int i4 = 0; i4 < paramElems2.size(); i4++) 
                                            {
                                                Element element5 = paramElems2.get(i4);
                                                String elParamKey3 = element5.getAttributeValue("key");					    																				// the name
                                                String elParamVariable3 = element5.getAttributeValue("variable");					    																	// the variable
                                                String gid = element5.getAttributeValue("gid");					    																						// the gid

                                                if (gid != null)
                                                {
                                                    if (elParamKey3.startsWith("#"))																														// && elParamVariable3=="true"
                                                    {
                                                        element5.setAttribute("gid","0");
                                                    }
                                                }
                                            }

                                            Element element3 = element1Copy.getChild("Param");
                                            Element element4 = element2Copy.getChild("Param");
                                            Param1 = XMLUtil.elementToString(element3);
                                            Param2 = XMLUtil.elementToString(element4);

                                            if (Param1 != null && Param2 != null){
                                            if (Param1.equals(Param2) && IndexVariableTrouvé == -1)																																		// if it is the same parameter in each Building blocks name
                                            {
                                                IndexVariableTrouvé = i3;
                                                ////break;                                                 																																// Modif V 2.01
                                            }}
                                            arrays2ShortXml[i3][0] += 1;                                                 																												// Modif V 2.01
                                            arrays2ShortXml[i3][1] += statsShort[i1][0];                                                 																								// Modif V 2.01
                                            arrays2ShortXml[i3][2] += statsShort[i1][1];
                                            arrays2ShortXml[i3][3] += statsShort[i1][2];
                                            arrays2ShortXml[i3][4] += statsShort[i1][3];
                                            arrays2ShortXml[i3][5] += statsShort[i1][4];
                                            arrays2ShortXml[i3][6] += statsShort[i1][5];
                                            arrays2ShortXml[i3][7] += statsShort[i1][6];
                                            arrays2ShortXml[i3][8] += statsShort[i1][7];
                                            arrays2ShortXml[i3][9] += statsShort[i1][8];
                                            arrays2ShortXml[i3][10] += statsShort[i1][9];
                                            arrays2ShortXml[i3][11] += statsShort[i1][10];
                                        }
                                    }
                                }
                                /*if (arrays1XmlShort[i3].equals(statsStr2XmlShort[i1][i2].trim()))
                                {
                                    IndexVariableTrouvé = i3;
                                    break;
                                }}*/
                            }

                            if (statsStr2XmlShort[i1][i2] != null && statsStr2XmlShortb[i1].get(i2) != null){
                            if (IndexVariableTrouvé == -1 && NbVariableXmlShort < arrays1XmlShort.length)																																// if it is a new variable, we add it to the list
                            {
                                arrays1XmlShort[NbVariableXmlShort] =  statsStr2XmlShort[i1][i2].trim();
                                arrays1XmlShortb[NbVariableXmlShort] = statsStr2XmlShortb[i1].get(i2);
                                IndexVariableTrouvé = NbVariableXmlShort;
                                NbVariableXmlShort+=1;
                            }
                            if (IndexVariableTrouvé != -1)
                            {
                                arrays2ShortXml[IndexVariableTrouvé][0] += 1;
                                arrays2ShortXml[IndexVariableTrouvé][1] += statsShort[i1][0];
                                arrays2ShortXml[IndexVariableTrouvé][2] += statsShort[i1][1];
                                arrays2ShortXml[IndexVariableTrouvé][3] += statsShort[i1][2];
                                arrays2ShortXml[IndexVariableTrouvé][4] += statsShort[i1][3];
                                arrays2ShortXml[IndexVariableTrouvé][5] += statsShort[i1][4];
                                arrays2ShortXml[IndexVariableTrouvé][6] += statsShort[i1][5];
                                arrays2ShortXml[IndexVariableTrouvé][7] += statsShort[i1][6];
                                arrays2ShortXml[IndexVariableTrouvé][8] += statsShort[i1][7];
                                arrays2ShortXml[IndexVariableTrouvé][9] += statsShort[i1][8];
                                arrays2ShortXml[IndexVariableTrouvé][10] += statsShort[i1][9];
                                arrays2ShortXml[IndexVariableTrouvé][11] += statsShort[i1][10];
                                arrays2ShortXmlName[IndexVariableTrouvé] = String20; 
                            }}
                        }
                    }
                    if (DebugMode){
                    FilterWriterTmp = new FileWriter(OutputPath1 + "Test of "+ databankName + ".xml" , true);
                    FilterWriterTmp.write(String.valueOf(NbVariableXmlLong)+"\r\n");
                    FilterWriterTmp.close();
                    FilterWriterTmp = new FileWriter(OutputPath1 + "Test of "+ databankName + ".xml" , true);
                    FilterWriterTmp.write(String.valueOf(NbVariableXmlShort)+"\r\n");
                    FilterWriterTmp.close();}
                    //#endregion
                    
                    //#region  ******************************************************** OosSimulationOverPreviousBlockFilter ******************************************************************

                    if (DatabanksNumber != 1 && OosSimulationOverPreviousBlockFilter == 1 && SignalType == 1 &&  DatabanksNumber < NbDataBanks && outputPortfolio)  								// We are doing a portfolio only on the Entry, excluding All DB 														// if filter file already exist 
                    {
                        //#region  ************************************************************************ Read previous  Filter ********************************************************************
                        FilterFileLong = new File(OutputPath1+"Entry Long Filter File.txt"); 
                        FilterFileShort = new File(OutputPath1+"Entry Short Filter File.txt"); 
                        FilterFileExitLong = new File(OutputPath1+"Exit Long Filter File.txt"); 
                        FilterFileExitShort = new File(OutputPath1+"Exit Short Filter File.txt"); 

                        arraysFilterEntryLong = new String[100000];         										   																	// 0 : variable filtered name
                        arraysFilterEntryShort = new String[100000];         										   																	// 0 : variable filtered name
                        arraysFilterExitLong = new String[100000];         										   																	// 0 : variable filtered name
                        arraysFilterExitShort = new String[100000];         										   																	// 0 : variable filtered name

                        NbNameEntryLong = 0; 
                        NbNameEntryShort = 0; 
                        NbNameExitLong = 0; 
                        NbNameExitShort = 0; 

                        if (FilterFileLong.exists())
                        {
                            Scanner myFilterReaderEntryLong = new Scanner(FilterFileLong);
                            while (myFilterReaderEntryLong.hasNextLine()) 
                            {
                                String data = myFilterReaderEntryLong.nextLine();
                                arraysFilterEntryLong[NbNameEntryLong] = data;
                                NbNameEntryLong +=1;
                            }
                            myFilterReaderEntryLong.close();
                        }
                        if (FilterFileShort.exists())
                        {
                            Scanner myFilterReaderEntryShort = new Scanner(FilterFileShort);
                            while (myFilterReaderEntryShort.hasNextLine()) 
                            {
                                String data = myFilterReaderEntryShort.nextLine();
                                arraysFilterEntryShort[NbNameEntryShort] = data;
                                NbNameEntryShort +=1;
                            }
                            myFilterReaderEntryShort.close();
                        }
                        if (FilterFileExitLong.exists())
                        {
                            Scanner myFilterReaderExitLong = new Scanner(FilterFileExitLong);
                            while (myFilterReaderExitLong.hasNextLine()) 
                            {
                                String data = myFilterReaderExitLong.nextLine();
                                arraysFilterExitLong[NbNameExitLong] = data;
                                NbNameExitLong +=1;
                            }
                            myFilterReaderExitLong.close();
                        }
                        if (FilterFileExitShort.exists())
                        {
                            Scanner myFilterReaderExitShort = new Scanner(FilterFileExitShort);
                            while (myFilterReaderExitShort.hasNextLine()) 
                            {
                                String data = myFilterReaderExitShort.nextLine();
                                arraysFilterExitShort[NbNameExitShort] = data;
                                NbNameExitShort +=1;
                            }
                            myFilterReaderExitShort.close();
                        }

                        int counter2 = 0;
                        for(ResultsGroup strategyRG : databankRG) 																																		// For each Strategy
                        {
                            // skip strategies whose name starts with "Filtered portfolio"
                            // this will ensure that we'll ignore our portfolios created
                            // in previous runs
                            String strName = strategyRG.getName();

                            if(strName.startsWith("Filtered portfolio")) 
                            {
                                continue;
                            }
                            Result mainResult = strategyRG.subResult(strategyRG.getMainResultKey());                        // Main
                            if(mainResult==null) break;

                            // **************************************** Read the Strategy Stats, check if it must be filtered *************************************
                            int StrategyFilteredEntryLong = 0;
                            int StrategyFilteredEntryShort = 0;
                            int StrategyFilteredExitLong = 0;
                            int StrategyFilteredExitShort = 0;
                            
                            if (statsStr2[counter2] == null) 
                            {
                                counter2 += 1;
                                continue; 
                            }                          // V2

                            //loops1:
                            for(int i2 = 0; i2 < statsStr2[counter2].length; i2 += 1) 				// += 2	V1																							// For each variables from this strategy, Search among existing variables in arraysFilter
                            {
                                for(int i3 = 0; i3 < NbNameEntryLong; i3++)                                                  																					// Search in arraysFilter, to check if the variable exist already
                                {
                                    if (arraysFilterEntryLong[i3].equals(statsStr2[counter2][i2].trim()))																										// if a variable exist in the Arrayfilter, we will add it to the portfolio
                                    {
                                        StrategyFilteredEntryLong = 1;
                                    }
                                }
                                for(int i3 = 0; i3 < NbNameEntryShort; i3++)                                                  																					// Search in arraysFilter, to check if the variable exist already
                                {
                                    if (arraysFilterEntryShort[i3].equals(statsStr2[counter2][i2].trim()))																										// if a variable exist in the Arrayfilter, we will add it to the portfolio
                                    {
                                        StrategyFilteredEntryShort = 1;
                                    }
                                }
                                for(int i3 = 0; i3 < NbNameExitLong; i3++)                                                  																					// Search in arraysFilter, to check if the variable exist already
                                {
                                    if (arraysFilterExitLong[i3].equals(statsStr2[counter2][i2].trim()))																										// if a variable exist in the Arrayfilter, we will add it to the portfolio
                                    {
                                        StrategyFilteredExitLong = 1;
                                    }
                                }
                                for(int i3 = 0; i3 < NbNameExitShort; i3++)                                                  																					// Search in arraysFilter, to check if the variable exist already
                                {
                                    if (arraysFilterExitShort[i3].equals(statsStr2[counter2][i2].trim()))																										// if a variable exist in the Arrayfilter, we will add it to the portfolio
                                    {
                                        StrategyFilteredExitShort = 1;
                                    }
                                }
                            }
                            counter2 += 1;
                            // ************************************************************************************************************************************

                            String wfResultKey = strategyRG.getMainResultKey();                                           																			//wfResult.getResultKey();
                            // we'll name the new subresult as "StrategyName "+ "existing WF result name"
                            String newSubResultKey = String.format("%s-%s", databankName + " " + strategyRG.getName(), wfResultKey);
                        
                            // clone settings to use them in the new result
                            SettingsMap settingsMapCopy =  mainResult.getSettings().clone();                                 																		//wfResult.getSettings().clone();
                            // create new result that will be added to the portfolio
                            Result wfResultCopied = new Result(newSubResultKey, portfolioRG, settingsMapCopy);

                            if (FilterFileLong.exists() && FilterFileExitLong.exists() && StrategyFilteredEntryLong == 1 && StrategyFilteredExitLong == 1)       // ||StrategyFiltered != 1 																												// a variable exist in the Arrayfilter, we will add it to the portfolio														
                            {
                                // copy WF orders from original strategy to new results group
                                OrdersList filteredOL = strategyRG.orders().filterWithClone(wfResultKey, Directions.Long , SampleTypes.OutOfSample);														// SampleTypes.OutOfSample
                                OrdersList filteredOLShort = strategyRG.orders().filterWithClone(wfResultKey, Directions.Short , SampleTypes.OutOfSample);														// SampleTypes.OutOfSample
                                //fdebug("Debug ", "filteredOL.size : "+	filteredOL.size() );	
                                if (filteredOL != null)
                                {
                                    for(int i = 0; i < filteredOL.size(); i++) 
                                    {
                                        if (portfolioOrdersList.size() <= NbOrdersperPortfolioMax)
                                        {
                                            Order order = filteredOL.get(i);
                                            
                                            // change setup name to match the new result name in the new portfolio
                                            order.SetupName = newSubResultKey;
                                            order.IsInPortfolio = 1;
                                            // add the order to the portfolio OrdersList
                                            portfolioOrdersList.add(order);
                                            NewOrderForPortefolio = 1;
                                        }
                                    }
                                    // copy also symbol definitions from old strategy
                                    // this is needed for proper calculation of PL and metrics

                                    if (filteredOLShort == null)
                                    {
                                        if (filteredOL.size() > 0)
                                        {
                                            portfolioRG.addSubresult(newSubResultKey, settingsMapCopy, wfResultCopied);
                                            portfolioRG.symbols().add(strategyRG.symbols());
                                        }
                                    }
                                    else
                                    {
                                        if (filteredOL.size() > 0 && (filteredOLShort.size() == 0  || StrategyFilteredEntryShort == 0 || StrategyFilteredExitShort == 0 || !FilterFileShort.exists() || !FilterFileExitShort.exists()))
                                        {
                                            portfolioRG.addSubresult(newSubResultKey, settingsMapCopy, wfResultCopied);
                                            portfolioRG.symbols().add(strategyRG.symbols());
                                        }
                                    }
                                }
                            }

                            if (FilterFileShort.exists() && FilterFileExitShort.exists() && StrategyFilteredEntryShort == 1 && StrategyFilteredExitShort == 1)       // ||StrategyFiltered != 1 																												// a variable exist in the Arrayfilter, we will add it to the portfolio														
                            {
                                // copy WF orders from original strategy to new results group
                                OrdersList filteredOL = strategyRG.orders().filterWithClone(wfResultKey, Directions.Short, SampleTypes.OutOfSample);														// SampleTypes.OutOfSample
                                //fdebug("Debug ", "filteredOL.size : "+	filteredOL.size() );	
                                if (filteredOL != null)
                                {
                                    for(int i = 0; i < filteredOL.size(); i++) 
                                    {
                                        if (portfolioOrdersList.size() <= NbOrdersperPortfolioMax)
                                        {
                                            Order order = filteredOL.get(i);
                                            // change setup name to match the new result name in the new portfolio
                                            order.SetupName = newSubResultKey;
                                            order.IsInPortfolio = 1;
                                            // add the order to the portfolio OrdersList
                                            portfolioOrdersList.add(order);
                                            NewOrderForPortefolio = 1;
                                        }
                                    }
                                    // copy also symbol definitions from old strategy
                                    // this is needed for proper calculation of PL and metrics
                                    if (filteredOL.size() > 0)
                                    {
                                        portfolioRG.addSubresult(newSubResultKey, settingsMapCopy, wfResultCopied);
                                        portfolioRG.symbols().add(strategyRG.symbols());
                                    }
                                }
                            }
                        }

                        if (portfolioOrdersList.size() >= NbOrdersperPortfolioMax || DatabanksNumber == (NbDataBanks - 1))																												// if the numboer of order is more than NbOrdersperPortfolioMax, we close the portfolio and create a new one
                        {
                            createPortfolioResult(portfolioRG);
                            //portfolioRG.computeAllStats();                                              // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! a remettre 
                            Databank databank = ProjectEngine.get(project).getDatabanks().get(databankName);
                            databank.add(portfolioRG, true);

                            Timestamp timestamp2 = new Timestamp(System.currentTimeMillis());
                            Instant instant2 = timestamp2.toInstant();
                            Duration between = Duration.between(instant1, instant2);
                            long seconds = between.getSeconds();
                            long absoluteResult = between.abs().toMinutes();

                            if (absoluteResult > 45)      																																		// if it takes more than 45 minutes to create a portfolio, then SQX ask if you want to continue save portfolio
                            {
                                OosSimulationOverPreviousBlockFilter = 1;
                                input12: do
                                {
                                    input = JOptionPane.showInputDialog("Do you want to continue to create Results on PortFolio of Multiple Cross-Validation Period ?    (0) No, (1) Yes",1);                				// Possible Option
                                    if (Strings.isNullOrEmpty(input)){ continue  input12;}
                                    break input12;
                                }while(true);
                                OosSimulationOverPreviousBlockFilter = Integer.parseInt(input);																										// Convert the String input to an int.
                                if (OosSimulationOverPreviousBlockFilter < 0) {OosSimulationOverPreviousBlockFilter = 0;}
                                if (OosSimulationOverPreviousBlockFilter > 1) {OosSimulationOverPreviousBlockFilter = 1;}
                            }
                            timestamp1 = new Timestamp(System.currentTimeMillis());
                            instant1 = timestamp1.toInstant();

                            // ******************************************************************************************
                            if (DatabanksNumber != (NbDataBanks - 1))
                            {
                                // create new ResultsGroup for our new portfolio
                                portfolioRG = new ResultsGroup("Filtered portfolio");																									//("Filtered portfolio "+ "of "+ databankName);
                                // get OrderList from new portfolio (empty so far),
                                // we will insert WF orders there
                                portfolioOrdersList = portfolioRG.orders();
                            }
                        }
                        //#endregion
                    }
                    //#endregion

                    //#region ********************************************************* OutPut File For each SortType by : (1)ProfitFactor,(2)NetProfit,(3)SharpeRatio,(4)UlcerIndex,(5)SortinoRatio,(6)WinningPct,(7)ReturnDDRatio,(8)RExpectancy,(9)AnnualPctReturnDDRatio,(10)Drawdown" *******************************
                    for(SortType = 1; SortType <= 10; SortType++) 															// 
                    {
                        //#region  ************************************************************************ File Name ************************************************************************
                            String StringTemp = "";
                            switch (SortType) 
                            {
                                case 1:
                                    StringTemp = stratMetric1; 
                                    AscDesc = 1;																					// "Enter Sort : (1) From Highest To Lowest , (2) From Lowest To Highest"
                                    AboveUnder = 1;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 2:
                                    StringTemp = stratMetric2;
                                    AscDesc = 1; 																					// "Enter Sort : (1) From Highest To Lowest , (2) From Lowest To Highest"
                                    AboveUnder = 1;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 3:
                                    StringTemp = stratMetric3; 
                                    AscDesc = 1;																					// "Enter Sort : (1) From Highest To Lowest , (2) From Lowest To Highest"
                                    AboveUnder = 1;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 4:
                                    StringTemp = stratMetric4; 
                                    AscDesc = 2;																					// "Enter Sort : (1) From Highest To Lowest , (2) From Lowest To Highest"
                                    AboveUnder = 2;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 5:
                                    StringTemp = stratMetric5; 
                                    AscDesc = 1;																					// "Enter Sort : (1) From Highest To Lowest , (2) From Lowest To Highest"
                                    AboveUnder = 1;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 6:
                                    StringTemp = stratMetric6;
                                    AscDesc = 1; 																					// "Enter Sort : (1) From Highest To Lowest , (2) From Lowest To Highest"
                                    AboveUnder = 1;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 7:
                                    StringTemp = stratMetric7; 
                                    AscDesc = 1;																					// "Enter Sort : (1) From Highest To Lowest , (2) From Lowest To Highest"
                                    AboveUnder = 1;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 8:
                                    StringTemp = stratMetric8; 
                                    AscDesc = 1;																					// "Enter Sort : (1) From Highest To Lowest , (2) From Lowest To Highest"
                                    AboveUnder = 1;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 9:
                                    StringTemp = stratMetric9; 
                                    AscDesc = 1;																					// "Enter Sort : (1) From Highest To Lowest , (2) From Lowest To Highest"
                                    AboveUnder = 1;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 10:
                                    StringTemp = stratMetric10; 
                                    AscDesc = 2;																					// "Enter Sort : (1) From Highest To Lowest , (2) From Lowest To Highest"
                                    AboveUnder = 2;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                            }
                            if (ChoiceFilterNextOOS == 0) {AboveUnder = 1;}
                            switch (ChoiceFilterNextOOS2) 
                            {
                                case 0:
                                    AboveUnder2 = 1;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 1:
                                    AboveUnder2 = 1;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 2:
                                    AboveUnder2 = 1;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 3:
                                    AboveUnder2 = 1;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 4:
                                    AboveUnder2 = 2;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 5:
                                    AboveUnder2 = 1;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 6:
                                    AboveUnder2 = 1;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 7:
                                    AboveUnder2 = 1;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 8:
                                    AboveUnder2 = 1;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 9:
                                    AboveUnder2 = 1;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                                case 10:
                                    AboveUnder2 = 2;																					// "Enter Above/Under the limit : (1) Above , (2) Under"
                                    break;
                            }

                            
                            String OutputPath = "";
                            if (SignalType == 1)
                            {
                                OutputPath = OutputPath1+"Entry Results sorted by " + StringTemp + " of "+ databankName + ".txt";  	//  OutputPath
                            }
                            else if (SignalType == 2)
                            {
                                OutputPath = OutputPath1+"Exit Results sorted by " + StringTemp + " of "+ databankName + ".txt";  	//  OutputPath
                            }
                        //#endregion
                        
                        //#region  ************************************************************************ Sort the best value of the arrays1, depending on SortType ************************
                        for(int i1 = 0; i1 < NbVariable; i1++) 																// for each Variables
                        {
                            for(int i2 = i1 + 1; i2 < NbVariable; i2++) 													// Pour chaque Variables
                            {
                                if (AscDesc==1)																				// Sort from higher to lower
                                {
                                    if ((SortType == 1 && arrays2[i2][1] / arrays2[i2][0] > arrays2[i1][1] / arrays2[i1][0]) || (SortType == 2 && arrays2[i2][2] / arrays2[i2][0] > arrays2[i1][2] / arrays2[i1][0]) || (SortType == 3 && arrays2[i2][3] / arrays2[i2][0] > arrays2[i1][3] / arrays2[i1][0]) || (SortType == 4 && arrays2[i2][4] / arrays2[i2][0] > arrays2[i1][4] / arrays2[i1][0]) || (SortType == 5 && arrays2[i2][5] / arrays2[i2][0] > arrays2[i1][5] / arrays2[i1][0]) || (SortType == 6 && arrays2[i2][6] / arrays2[i2][0] > arrays2[i1][6] / arrays2[i1][0]) || (SortType == 7 && arrays2[i2][7] / arrays2[i2][0] > arrays2[i1][7] / arrays2[i1][0]) || (SortType == 8 && arrays2[i2][8] / arrays2[i2][0] > arrays2[i1][8] / arrays2[i1][0]) || (SortType == 9 && arrays2[i2][9] / arrays2[i2][0] > arrays2[i1][9] / arrays2[i1][0]) || (SortType == 10 && arrays2[i2][10] / arrays2[i2][0] > arrays2[i1][10] / arrays2[i1][0]))
                                    {
                                        String StringTemp0 = arrays1[i1];
                                        double DoubleTemp0 = arrays2[i1][0];
                                        double DoubleTemp1 = arrays2[i1][1];
                                        double DoubleTemp2 = arrays2[i1][2];
                                        double DoubleTemp3 = arrays2[i1][3];
                                        double DoubleTemp4 = arrays2[i1][4];
                                        double DoubleTemp5 = arrays2[i1][5];
                                        double DoubleTemp6 = arrays2[i1][6];
                                        double DoubleTemp7 = arrays2[i1][7];
                                        double DoubleTemp8 = arrays2[i1][8];
                                        double DoubleTemp9 = arrays2[i1][9];
                                        double DoubleTemp10 = arrays2[i1][10];
                                        double DoubleTemp11 = arrays2[i1][11];


                                        arrays1[i1] = arrays1[i2];
                                        arrays2[i1][0] = arrays2[i2][0];
                                        arrays2[i1][1] =  arrays2[i2][1];
                                        arrays2[i1][2] =  arrays2[i2][2];
                                        arrays2[i1][3] =  arrays2[i2][3];
                                        arrays2[i1][4] =  arrays2[i2][4];
                                        arrays2[i1][5] =  arrays2[i2][5];
                                        arrays2[i1][6] =  arrays2[i2][6];
                                        arrays2[i1][7] =  arrays2[i2][7];
                                        arrays2[i1][8] =  arrays2[i2][8];
                                        arrays2[i1][9] =  arrays2[i2][9];
                                        arrays2[i1][10] =  arrays2[i2][10];
                                        arrays2[i1][11] =  arrays2[i2][11];


                                        arrays1[i2] = StringTemp0;
                                        arrays2[i2][0] = DoubleTemp0;
                                        arrays2[i2][1] = DoubleTemp1;
                                        arrays2[i2][2] = DoubleTemp2;
                                        arrays2[i2][3] = DoubleTemp3;
                                        arrays2[i2][4] = DoubleTemp4;
                                        arrays2[i2][5] = DoubleTemp5;
                                        arrays2[i2][6] = DoubleTemp6;
                                        arrays2[i2][7] = DoubleTemp7;
                                        arrays2[i2][8] = DoubleTemp8;
                                        arrays2[i2][9] = DoubleTemp9;
                                        arrays2[i2][10] = DoubleTemp10;
                                        arrays2[i2][11] = DoubleTemp11;

                                        if (LongShort == 3)
                                        {
                                            DoubleTemp0 = arrays2Long[i1][0];
                                            DoubleTemp1 = arrays2Long[i1][1];
                                            DoubleTemp2 = arrays2Long[i1][2];
                                            DoubleTemp3 = arrays2Long[i1][3];
                                            DoubleTemp4 = arrays2Long[i1][4];
                                            DoubleTemp5 = arrays2Long[i1][5];
                                            DoubleTemp6 = arrays2Long[i1][6];
                                            DoubleTemp7 = arrays2Long[i1][7];
                                            DoubleTemp8 = arrays2Long[i1][8];
                                            DoubleTemp9 = arrays2Long[i1][9];
                                            DoubleTemp10 = arrays2Long[i1][10];
                                            DoubleTemp11 = arrays2Long[i1][11];

                                            arrays2Long[i1][0] = arrays2Long[i2][0];
                                            arrays2Long[i1][1] =  arrays2Long[i2][1];
                                            arrays2Long[i1][2] =  arrays2Long[i2][2];
                                            arrays2Long[i1][3] =  arrays2Long[i2][3];
                                            arrays2Long[i1][4] =  arrays2Long[i2][4];
                                            arrays2Long[i1][5] =  arrays2Long[i2][5];
                                            arrays2Long[i1][6] =  arrays2Long[i2][6];
                                            arrays2Long[i1][7] =  arrays2Long[i2][7];
                                            arrays2Long[i1][8] =  arrays2Long[i2][8];
                                            arrays2Long[i1][9] =  arrays2Long[i2][9];
                                            arrays2Long[i1][10] =  arrays2Long[i2][10];
                                            arrays2Long[i1][11] =  arrays2Long[i2][11];

                                            arrays2Long[i2][0] = DoubleTemp0;
                                            arrays2Long[i2][1] = DoubleTemp1;
                                            arrays2Long[i2][2] = DoubleTemp2;
                                            arrays2Long[i2][3] = DoubleTemp3;
                                            arrays2Long[i2][4] = DoubleTemp4;
                                            arrays2Long[i2][5] = DoubleTemp5;
                                            arrays2Long[i2][6] = DoubleTemp6;
                                            arrays2Long[i2][7] = DoubleTemp7;
                                            arrays2Long[i2][8] = DoubleTemp8;
                                            arrays2Long[i2][9] = DoubleTemp9;
                                            arrays2Long[i2][10] = DoubleTemp10;
                                            arrays2Long[i2][11] = DoubleTemp11;

                                            DoubleTemp0 = arrays2Short[i1][0];
                                            DoubleTemp1 = arrays2Short[i1][1];
                                            DoubleTemp2 = arrays2Short[i1][2];
                                            DoubleTemp3 = arrays2Short[i1][3];
                                            DoubleTemp4 = arrays2Short[i1][4];
                                            DoubleTemp5 = arrays2Short[i1][5];
                                            DoubleTemp6 = arrays2Short[i1][6];
                                            DoubleTemp7 = arrays2Short[i1][7];
                                            DoubleTemp8 = arrays2Short[i1][8];
                                            DoubleTemp9 = arrays2Short[i1][9];
                                            DoubleTemp10 = arrays2Short[i1][10];
                                            DoubleTemp11 = arrays2Short[i1][11];

                                            arrays2Short[i1][0] = arrays2Short[i2][0];
                                            arrays2Short[i1][1] =  arrays2Short[i2][1];
                                            arrays2Short[i1][2] =  arrays2Short[i2][2];
                                            arrays2Short[i1][3] =  arrays2Short[i2][3];
                                            arrays2Short[i1][4] =  arrays2Short[i2][4];
                                            arrays2Short[i1][5] =  arrays2Short[i2][5];
                                            arrays2Short[i1][6] =  arrays2Short[i2][6];
                                            arrays2Short[i1][7] =  arrays2Short[i2][7];
                                            arrays2Short[i1][8] =  arrays2Short[i2][8];
                                            arrays2Short[i1][9] =  arrays2Short[i2][9];
                                            arrays2Short[i1][10] =  arrays2Short[i2][10];
                                            arrays2Short[i1][11] =  arrays2Short[i2][11];

                                            arrays2Short[i2][0] = DoubleTemp0;
                                            arrays2Short[i2][1] = DoubleTemp1;
                                            arrays2Short[i2][2] = DoubleTemp2;
                                            arrays2Short[i2][3] = DoubleTemp3;
                                            arrays2Short[i2][4] = DoubleTemp4;
                                            arrays2Short[i2][5] = DoubleTemp5;
                                            arrays2Short[i2][6] = DoubleTemp6;
                                            arrays2Short[i2][7] = DoubleTemp7;
                                            arrays2Short[i2][8] = DoubleTemp8;
                                            arrays2Short[i2][9] = DoubleTemp9;
                                            arrays2Short[i2][10] = DoubleTemp10;
                                            arrays2Short[i2][11] = DoubleTemp11;
                                        }
                                    }
                                }
                                if (AscDesc == 2)																			// Sort from lower to Higher
                                {
                                    if ((SortType == 1 && arrays2[i2][1] / arrays2[i2][0] < arrays2[i1][1] / arrays2[i1][0]) || (SortType == 2 && arrays2[i2][2] / arrays2[i2][0] < arrays2[i1][2] / arrays2[i1][0]) || (SortType == 3 && arrays2[i2][3] / arrays2[i2][0] < arrays2[i1][3] / arrays2[i1][0]) || (SortType == 4 && arrays2[i2][4] / arrays2[i2][0] < arrays2[i1][4] / arrays2[i1][0]) || (SortType == 5 && arrays2[i2][5] / arrays2[i2][0] < arrays2[i1][5] / arrays2[i1][0]) || (SortType == 6 && arrays2[i2][6] / arrays2[i2][0] < arrays2[i1][6] / arrays2[i1][0]) || (SortType == 7 && arrays2[i2][7] / arrays2[i2][0] < arrays2[i1][7] / arrays2[i1][0]) || (SortType == 8 && arrays2[i2][8] / arrays2[i2][0] < arrays2[i1][8] / arrays2[i1][0]) || (SortType == 9 && arrays2[i2][9] / arrays2[i2][0] < arrays2[i1][9] / arrays2[i1][0]) || (SortType == 10 && arrays2[i2][10] / arrays2[i2][0] < arrays2[i1][10] / arrays2[i1][0]))
                                    {
                                        String StringTemp0 = arrays1[i1];
                                        double DoubleTemp0 = arrays2[i1][0];
                                        double DoubleTemp1 = arrays2[i1][1];
                                        double DoubleTemp2 = arrays2[i1][2];
                                        double DoubleTemp3 = arrays2[i1][3];
                                        double DoubleTemp4 = arrays2[i1][4];

                                        double DoubleTemp5 = arrays2[i1][5];
                                        double DoubleTemp6 = arrays2[i1][6];
                                        double DoubleTemp7 = arrays2[i1][7];
                                        double DoubleTemp8 = arrays2[i1][8];
                                        double DoubleTemp9 = arrays2[i1][9];
                                        double DoubleTemp10 = arrays2[i1][10];
                                        double DoubleTemp11 = arrays2[i1][11];


                                        arrays1[i1] = arrays1[i2];
                                        arrays2[i1][0] = arrays2[i2][0];
                                        arrays2[i1][1] =  arrays2[i2][1];
                                        arrays2[i1][2] =  arrays2[i2][2];
                                        arrays2[i1][3] =  arrays2[i2][3];
                                        arrays2[i1][4] =  arrays2[i2][4];

                                        arrays2[i1][5] =  arrays2[i2][5];
                                        arrays2[i1][6] =  arrays2[i2][6];
                                        arrays2[i1][7] =  arrays2[i2][7];
                                        arrays2[i1][8] =  arrays2[i2][8];
                                        arrays2[i1][9] =  arrays2[i2][9];
                                        arrays2[i1][10] =  arrays2[i2][10];
                                        arrays2[i1][11] =  arrays2[i2][11];


                                        arrays1[i2] = StringTemp0;
                                        arrays2[i2][0] = DoubleTemp0;
                                        arrays2[i2][1] = DoubleTemp1;
                                        arrays2[i2][2] = DoubleTemp2;
                                        arrays2[i2][3] = DoubleTemp3;
                                        arrays2[i2][4] = DoubleTemp4;

                                        arrays2[i2][5] = DoubleTemp5;
                                        arrays2[i2][6] = DoubleTemp6;
                                        arrays2[i2][7] = DoubleTemp7;
                                        arrays2[i2][8] = DoubleTemp8;
                                        arrays2[i2][9] = DoubleTemp9;
                                        arrays2[i2][10] = DoubleTemp10;
                                        arrays2[i2][11] = DoubleTemp11;

                                        if (LongShort == 3)
                                        {
                                            DoubleTemp0 = arrays2Long[i1][0];
                                            DoubleTemp1 = arrays2Long[i1][1];
                                            DoubleTemp2 = arrays2Long[i1][2];
                                            DoubleTemp3 = arrays2Long[i1][3];
                                            DoubleTemp4 = arrays2Long[i1][4];
                                            DoubleTemp5 = arrays2Long[i1][5];
                                            DoubleTemp6 = arrays2Long[i1][6];
                                            DoubleTemp7 = arrays2Long[i1][7];
                                            DoubleTemp8 = arrays2Long[i1][8];
                                            DoubleTemp9 = arrays2Long[i1][9];
                                            DoubleTemp10 = arrays2Long[i1][10];
                                            DoubleTemp11 = arrays2Long[i1][11];

                                            arrays2Long[i1][0] = arrays2Long[i2][0];
                                            arrays2Long[i1][1] =  arrays2Long[i2][1];
                                            arrays2Long[i1][2] =  arrays2Long[i2][2];
                                            arrays2Long[i1][3] =  arrays2Long[i2][3];
                                            arrays2Long[i1][4] =  arrays2Long[i2][4];
                                            arrays2Long[i1][5] =  arrays2Long[i2][5];
                                            arrays2Long[i1][6] =  arrays2Long[i2][6];
                                            arrays2Long[i1][7] =  arrays2Long[i2][7];
                                            arrays2Long[i1][8] =  arrays2Long[i2][8];
                                            arrays2Long[i1][9] =  arrays2Long[i2][9];
                                            arrays2Long[i1][10] =  arrays2Long[i2][10];
                                            arrays2Long[i1][11] =  arrays2Long[i2][11];

                                            arrays2Long[i2][0] = DoubleTemp0;
                                            arrays2Long[i2][1] = DoubleTemp1;
                                            arrays2Long[i2][2] = DoubleTemp2;
                                            arrays2Long[i2][3] = DoubleTemp3;
                                            arrays2Long[i2][4] = DoubleTemp4;
                                            arrays2Long[i2][5] = DoubleTemp5;
                                            arrays2Long[i2][6] = DoubleTemp6;
                                            arrays2Long[i2][7] = DoubleTemp7;
                                            arrays2Long[i2][8] = DoubleTemp8;
                                            arrays2Long[i2][9] = DoubleTemp9;
                                            arrays2Long[i2][10] = DoubleTemp10;
                                            arrays2Long[i2][11] = DoubleTemp11;

                                            DoubleTemp0 = arrays2Short[i1][0];
                                            DoubleTemp1 = arrays2Short[i1][1];
                                            DoubleTemp2 = arrays2Short[i1][2];
                                            DoubleTemp3 = arrays2Short[i1][3];
                                            DoubleTemp4 = arrays2Short[i1][4];
                                            DoubleTemp5 = arrays2Short[i1][5];
                                            DoubleTemp6 = arrays2Short[i1][6];
                                            DoubleTemp7 = arrays2Short[i1][7];
                                            DoubleTemp8 = arrays2Short[i1][8];
                                            DoubleTemp9 = arrays2Short[i1][9];
                                            DoubleTemp10 = arrays2Short[i1][10];
                                            DoubleTemp11 = arrays2Short[i1][11];

                                            arrays2Short[i1][0] = arrays2Short[i2][0];
                                            arrays2Short[i1][1] =  arrays2Short[i2][1];
                                            arrays2Short[i1][2] =  arrays2Short[i2][2];
                                            arrays2Short[i1][3] =  arrays2Short[i2][3];
                                            arrays2Short[i1][4] =  arrays2Short[i2][4];
                                            arrays2Short[i1][5] =  arrays2Short[i2][5];
                                            arrays2Short[i1][6] =  arrays2Short[i2][6];
                                            arrays2Short[i1][7] =  arrays2Short[i2][7];
                                            arrays2Short[i1][8] =  arrays2Short[i2][8];
                                            arrays2Short[i1][9] =  arrays2Short[i2][9];
                                            arrays2Short[i1][10] =  arrays2Short[i2][10];
                                            arrays2Short[i1][11] =  arrays2Short[i2][11];

                                            arrays2Short[i2][0] = DoubleTemp0;
                                            arrays2Short[i2][1] = DoubleTemp1;
                                            arrays2Short[i2][2] = DoubleTemp2;
                                            arrays2Short[i2][3] = DoubleTemp3;
                                            arrays2Short[i2][4] = DoubleTemp4;
                                            arrays2Short[i2][5] = DoubleTemp5;
                                            arrays2Short[i2][6] = DoubleTemp6;
                                            arrays2Short[i2][7] = DoubleTemp7;
                                            arrays2Short[i2][8] = DoubleTemp8;
                                            arrays2Short[i2][9] = DoubleTemp9;
                                            arrays2Short[i2][10] = DoubleTemp10;
                                            arrays2Short[i2][11] = DoubleTemp11;
                                        }
                                    }
                                }
                            }
                        }
                        //#endregion
                        
                        //#region  ************************************************************************ Sort the best value of the arrays1Xml, depending on SortType *********************
                        for(int i1 = 0; i1 < NbVariableXmlLong; i1++) 																// for each Variables
                        {
                            for(int i2 = i1 + 1; i2 < NbVariableXmlLong; i2++) 														// for each Variables
                            {
                                if (AscDesc==1)																						// Sort from higher to lower
                                {
                                    if ((SortType == 1 && arrays2LongXml[i2][1] / arrays2LongXml[i2][0] > arrays2LongXml[i1][1] / arrays2LongXml[i1][0]) || (SortType == 2 && arrays2LongXml[i2][2] / arrays2LongXml[i2][0] > arrays2LongXml[i1][2] / arrays2LongXml[i1][0]) || (SortType == 3 && arrays2LongXml[i2][3] / arrays2LongXml[i2][0] > arrays2LongXml[i1][3] / arrays2LongXml[i1][0]) || (SortType == 4 && arrays2LongXml[i2][4] / arrays2LongXml[i2][0] > arrays2LongXml[i1][4] / arrays2LongXml[i1][0]) || (SortType == 5 && arrays2LongXml[i2][5] / arrays2LongXml[i2][0] > arrays2LongXml[i1][5] / arrays2LongXml[i1][0]) || (SortType == 6 && arrays2LongXml[i2][6] / arrays2LongXml[i2][0] > arrays2LongXml[i1][6] / arrays2LongXml[i1][0]) || (SortType == 7 && arrays2LongXml[i2][7] / arrays2LongXml[i2][0] > arrays2LongXml[i1][7] / arrays2LongXml[i1][0]) || (SortType == 8 && arrays2LongXml[i2][8] / arrays2LongXml[i2][0] > arrays2LongXml[i1][8] / arrays2LongXml[i1][0]) || (SortType == 9 && arrays2LongXml[i2][9] / arrays2LongXml[i2][0] > arrays2LongXml[i1][9] / arrays2LongXml[i1][0]) || (SortType == 10 && arrays2LongXml[i2][10] / arrays2LongXml[i2][0] > arrays2LongXml[i1][10] / arrays2LongXml[i1][0]))
                                    {
                                        Element Element0 = arrays1XmlLongb[i1];
                                        String StringTemp0 = arrays1XmlLong[i1];
                                        String StringTemp0b = arrays2LongXmlName[i1];
                                        double DoubleTemp0 = arrays2LongXml[i1][0];
                                        double DoubleTemp1 = arrays2LongXml[i1][1];
                                        double DoubleTemp2 = arrays2LongXml[i1][2];
                                        double DoubleTemp3 = arrays2LongXml[i1][3];
                                        double DoubleTemp4 = arrays2LongXml[i1][4];
                                        double DoubleTemp5 = arrays2LongXml[i1][5];
                                        double DoubleTemp6 = arrays2LongXml[i1][6];
                                        double DoubleTemp7 = arrays2LongXml[i1][7];
                                        double DoubleTemp8 = arrays2LongXml[i1][8];
                                        double DoubleTemp9 = arrays2LongXml[i1][9];
                                        double DoubleTemp10 = arrays2LongXml[i1][10];
                                        double DoubleTemp11 = arrays2LongXml[i1][11];


                                        arrays1XmlLongb[i1] = arrays1XmlLongb[i2];
                                        arrays1XmlLong[i1] = arrays1XmlLong[i2];
                                        arrays2LongXmlName[i1] = arrays2LongXmlName[i2];
                                        arrays2LongXml[i1][0] = arrays2LongXml[i2][0];
                                        arrays2LongXml[i1][1] =  arrays2LongXml[i2][1];
                                        arrays2LongXml[i1][2] =  arrays2LongXml[i2][2];
                                        arrays2LongXml[i1][3] =  arrays2LongXml[i2][3];
                                        arrays2LongXml[i1][4] =  arrays2LongXml[i2][4];
                                        arrays2LongXml[i1][5] =  arrays2LongXml[i2][5];
                                        arrays2LongXml[i1][6] =  arrays2LongXml[i2][6];
                                        arrays2LongXml[i1][7] =  arrays2LongXml[i2][7];
                                        arrays2LongXml[i1][8] =  arrays2LongXml[i2][8];
                                        arrays2LongXml[i1][9] =  arrays2LongXml[i2][9];
                                        arrays2LongXml[i1][10] =  arrays2LongXml[i2][10];
                                        arrays2LongXml[i1][11] =  arrays2LongXml[i2][11];


                                        arrays1XmlLongb[i2] = Element0;
                                        arrays1XmlLong[i2] = StringTemp0;
                                        arrays2LongXmlName[i2] = StringTemp0b;
                                        arrays2LongXml[i2][0] = DoubleTemp0;
                                        arrays2LongXml[i2][1] = DoubleTemp1;
                                        arrays2LongXml[i2][2] = DoubleTemp2;
                                        arrays2LongXml[i2][3] = DoubleTemp3;
                                        arrays2LongXml[i2][4] = DoubleTemp4;
                                        arrays2LongXml[i2][5] = DoubleTemp5;
                                        arrays2LongXml[i2][6] = DoubleTemp6;
                                        arrays2LongXml[i2][7] = DoubleTemp7;
                                        arrays2LongXml[i2][8] = DoubleTemp8;
                                        arrays2LongXml[i2][9] = DoubleTemp9;
                                        arrays2LongXml[i2][10] = DoubleTemp10;
                                        arrays2LongXml[i2][11] = DoubleTemp11;
                                    }
                                }
                                if (AscDesc == 2)																			// Sort from lower to Higher
                                {
                                    if ((SortType == 1 && arrays2LongXml[i2][1] / arrays2LongXml[i2][0] < arrays2LongXml[i1][1] / arrays2LongXml[i1][0]) || (SortType == 2 && arrays2LongXml[i2][2] / arrays2LongXml[i2][0] < arrays2LongXml[i1][2] / arrays2LongXml[i1][0]) || (SortType == 3 && arrays2LongXml[i2][3] / arrays2LongXml[i2][0] < arrays2LongXml[i1][3] / arrays2LongXml[i1][0]) || (SortType == 4 && arrays2LongXml[i2][4] / arrays2LongXml[i2][0] < arrays2LongXml[i1][4] / arrays2LongXml[i1][0]) || (SortType == 5 && arrays2LongXml[i2][5] / arrays2LongXml[i2][0] < arrays2LongXml[i1][5] / arrays2LongXml[i1][0]) || (SortType == 6 && arrays2LongXml[i2][6] / arrays2LongXml[i2][0] < arrays2LongXml[i1][6] / arrays2LongXml[i1][0]) || (SortType == 7 && arrays2LongXml[i2][7] / arrays2LongXml[i2][0] < arrays2LongXml[i1][7] / arrays2LongXml[i1][0]) || (SortType == 8 && arrays2LongXml[i2][8] / arrays2LongXml[i2][0] < arrays2LongXml[i1][8] / arrays2LongXml[i1][0]) || (SortType == 9 && arrays2LongXml[i2][9] / arrays2LongXml[i2][0] < arrays2LongXml[i1][9] / arrays2LongXml[i1][0]) || (SortType == 10 && arrays2LongXml[i2][10] / arrays2LongXml[i2][0] < arrays2LongXml[i1][10] / arrays2LongXml[i1][0]))
                                    {
                                        Element Element0 = arrays1XmlLongb[i1];
                                        String StringTemp0 = arrays1XmlLong[i1];
                                        String StringTemp0b = arrays2LongXmlName[i1];
                                        double DoubleTemp0 = arrays2LongXml[i1][0];
                                        double DoubleTemp1 = arrays2LongXml[i1][1];
                                        double DoubleTemp2 = arrays2LongXml[i1][2];
                                        double DoubleTemp3 = arrays2LongXml[i1][3];
                                        double DoubleTemp4 = arrays2LongXml[i1][4];

                                        double DoubleTemp5 = arrays2LongXml[i1][5];
                                        double DoubleTemp6 = arrays2LongXml[i1][6];
                                        double DoubleTemp7 = arrays2LongXml[i1][7];
                                        double DoubleTemp8 = arrays2LongXml[i1][8];
                                        double DoubleTemp9 = arrays2LongXml[i1][9];
                                        double DoubleTemp10 = arrays2LongXml[i1][10];
                                        double DoubleTemp11 = arrays2LongXml[i1][11];


                                        arrays1XmlLongb[i1] = arrays1XmlLongb[i2];
                                        arrays1XmlLong[i1] = arrays1XmlLong[i2];
                                        arrays2LongXmlName[i1] = arrays2LongXmlName[i2];
                                        arrays2LongXml[i1][0] = arrays2LongXml[i2][0];
                                        arrays2LongXml[i1][1] =  arrays2LongXml[i2][1];
                                        arrays2LongXml[i1][2] =  arrays2LongXml[i2][2];
                                        arrays2LongXml[i1][3] =  arrays2LongXml[i2][3];
                                        arrays2LongXml[i1][4] =  arrays2LongXml[i2][4];

                                        arrays2LongXml[i1][5] =  arrays2LongXml[i2][5];
                                        arrays2LongXml[i1][6] =  arrays2LongXml[i2][6];
                                        arrays2LongXml[i1][7] =  arrays2LongXml[i2][7];
                                        arrays2LongXml[i1][8] =  arrays2LongXml[i2][8];
                                        arrays2LongXml[i1][9] =  arrays2LongXml[i2][9];
                                        arrays2LongXml[i1][10] =  arrays2LongXml[i2][10];
                                        arrays2LongXml[i1][11] =  arrays2LongXml[i2][11];

                                        arrays1XmlLongb[i2] = Element0;
                                        arrays1XmlLong[i2] = StringTemp0;
                                        arrays2LongXmlName[i2] = StringTemp0b;
                                        arrays2LongXml[i2][0] = DoubleTemp0;
                                        arrays2LongXml[i2][1] = DoubleTemp1;
                                        arrays2LongXml[i2][2] = DoubleTemp2;
                                        arrays2LongXml[i2][3] = DoubleTemp3;
                                        arrays2LongXml[i2][4] = DoubleTemp4;

                                        arrays2LongXml[i2][5] = DoubleTemp5;
                                        arrays2LongXml[i2][6] = DoubleTemp6;
                                        arrays2LongXml[i2][7] = DoubleTemp7;
                                        arrays2LongXml[i2][8] = DoubleTemp8;
                                        arrays2LongXml[i2][9] = DoubleTemp9;
                                        arrays2LongXml[i2][10] = DoubleTemp10;
                                        arrays2LongXml[i2][11] = DoubleTemp11;
                        
                                    }
                                }
                            }
                        }
                        for(int i1 = 0; i1 < NbVariableXmlShort; i1++) 																// for each Variables
                        {
                            for(int i2 = i1 + 1; i2 < NbVariableXmlShort; i2++) 														// for each Variables
                            {
                                if (AscDesc==1)																						// Sort from higher to lower
                                {
                                    if ((SortType == 1 && arrays2ShortXml[i2][1] / arrays2ShortXml[i2][0] > arrays2ShortXml[i1][1] / arrays2ShortXml[i1][0]) || (SortType == 2 && arrays2ShortXml[i2][2] / arrays2ShortXml[i2][0] > arrays2ShortXml[i1][2] / arrays2ShortXml[i1][0]) || (SortType == 3 && arrays2ShortXml[i2][3] / arrays2ShortXml[i2][0] > arrays2ShortXml[i1][3] / arrays2ShortXml[i1][0]) || (SortType == 4 && arrays2ShortXml[i2][4] / arrays2ShortXml[i2][0] > arrays2ShortXml[i1][4] / arrays2ShortXml[i1][0]) || (SortType == 5 && arrays2ShortXml[i2][5] / arrays2ShortXml[i2][0] > arrays2ShortXml[i1][5] / arrays2ShortXml[i1][0]) || (SortType == 6 && arrays2ShortXml[i2][6] / arrays2ShortXml[i2][0] > arrays2ShortXml[i1][6] / arrays2ShortXml[i1][0]) || (SortType == 7 && arrays2ShortXml[i2][7] / arrays2ShortXml[i2][0] > arrays2ShortXml[i1][7] / arrays2ShortXml[i1][0]) || (SortType == 8 && arrays2ShortXml[i2][8] / arrays2ShortXml[i2][0] > arrays2ShortXml[i1][8] / arrays2ShortXml[i1][0]) || (SortType == 9 && arrays2ShortXml[i2][9] / arrays2ShortXml[i2][0] > arrays2ShortXml[i1][9] / arrays2ShortXml[i1][0]) || (SortType == 10 && arrays2ShortXml[i2][10] / arrays2ShortXml[i2][0] > arrays2ShortXml[i1][10] / arrays2ShortXml[i1][0]))
                                    {
                                        Element Element0 = arrays1XmlShortb[i1];
                                        String StringTemp0 = arrays1XmlShort[i1];
                                        String StringTemp0b = arrays2ShortXmlName[i1];
                                        double DoubleTemp0 = arrays2ShortXml[i1][0];
                                        double DoubleTemp1 = arrays2ShortXml[i1][1];
                                        double DoubleTemp2 = arrays2ShortXml[i1][2];
                                        double DoubleTemp3 = arrays2ShortXml[i1][3];
                                        double DoubleTemp4 = arrays2ShortXml[i1][4];
                                        double DoubleTemp5 = arrays2ShortXml[i1][5];
                                        double DoubleTemp6 = arrays2ShortXml[i1][6];
                                        double DoubleTemp7 = arrays2ShortXml[i1][7];
                                        double DoubleTemp8 = arrays2ShortXml[i1][8];
                                        double DoubleTemp9 = arrays2ShortXml[i1][9];
                                        double DoubleTemp10 = arrays2ShortXml[i1][10];
                                        double DoubleTemp11 = arrays2ShortXml[i1][11];

                                        arrays1XmlShortb[i1] = arrays1XmlShortb[i2];
                                        arrays1XmlShort[i1] = arrays1XmlShort[i2];
                                        arrays2ShortXmlName[i1] = arrays2ShortXmlName[i2];
                                        arrays2ShortXml[i1][0] = arrays2ShortXml[i2][0];
                                        arrays2ShortXml[i1][1] =  arrays2ShortXml[i2][1];
                                        arrays2ShortXml[i1][2] =  arrays2ShortXml[i2][2];
                                        arrays2ShortXml[i1][3] =  arrays2ShortXml[i2][3];
                                        arrays2ShortXml[i1][4] =  arrays2ShortXml[i2][4];
                                        arrays2ShortXml[i1][5] =  arrays2ShortXml[i2][5];
                                        arrays2ShortXml[i1][6] =  arrays2ShortXml[i2][6];
                                        arrays2ShortXml[i1][7] =  arrays2ShortXml[i2][7];
                                        arrays2ShortXml[i1][8] =  arrays2ShortXml[i2][8];
                                        arrays2ShortXml[i1][9] =  arrays2ShortXml[i2][9];
                                        arrays2ShortXml[i1][10] =  arrays2ShortXml[i2][10];
                                        arrays2ShortXml[i1][11] =  arrays2ShortXml[i2][11];

                                        arrays1XmlShortb[i2] = Element0;
                                        arrays1XmlShort[i2] = StringTemp0;
                                        arrays2ShortXmlName[i2] = StringTemp0b;
                                        arrays2ShortXml[i2][0] = DoubleTemp0;
                                        arrays2ShortXml[i2][1] = DoubleTemp1;
                                        arrays2ShortXml[i2][2] = DoubleTemp2;
                                        arrays2ShortXml[i2][3] = DoubleTemp3;
                                        arrays2ShortXml[i2][4] = DoubleTemp4;
                                        arrays2ShortXml[i2][5] = DoubleTemp5;
                                        arrays2ShortXml[i2][6] = DoubleTemp6;
                                        arrays2ShortXml[i2][7] = DoubleTemp7;
                                        arrays2ShortXml[i2][8] = DoubleTemp8;
                                        arrays2ShortXml[i2][9] = DoubleTemp9;
                                        arrays2ShortXml[i2][10] = DoubleTemp10;
                                        arrays2ShortXml[i2][11] = DoubleTemp11;
                                    }
                                }
                                if (AscDesc == 2)																			// Sort from lower to Higher
                                {
                                    if ((SortType == 1 && arrays2ShortXml[i2][1] / arrays2ShortXml[i2][0] < arrays2ShortXml[i1][1] / arrays2ShortXml[i1][0]) || (SortType == 2 && arrays2ShortXml[i2][2] / arrays2ShortXml[i2][0] < arrays2ShortXml[i1][2] / arrays2ShortXml[i1][0]) || (SortType == 3 && arrays2ShortXml[i2][3] / arrays2ShortXml[i2][0] < arrays2ShortXml[i1][3] / arrays2ShortXml[i1][0]) || (SortType == 4 && arrays2ShortXml[i2][4] / arrays2ShortXml[i2][0] < arrays2ShortXml[i1][4] / arrays2ShortXml[i1][0]) || (SortType == 5 && arrays2ShortXml[i2][5] / arrays2ShortXml[i2][0] < arrays2ShortXml[i1][5] / arrays2ShortXml[i1][0]) || (SortType == 6 && arrays2ShortXml[i2][6] / arrays2ShortXml[i2][0] < arrays2ShortXml[i1][6] / arrays2ShortXml[i1][0]) || (SortType == 7 && arrays2ShortXml[i2][7] / arrays2ShortXml[i2][0] < arrays2ShortXml[i1][7] / arrays2ShortXml[i1][0]) || (SortType == 8 && arrays2ShortXml[i2][8] / arrays2ShortXml[i2][0] < arrays2ShortXml[i1][8] / arrays2ShortXml[i1][0]) || (SortType == 9 && arrays2ShortXml[i2][9] / arrays2ShortXml[i2][0] < arrays2ShortXml[i1][9] / arrays2ShortXml[i1][0]) || (SortType == 10 && arrays2ShortXml[i2][10] / arrays2ShortXml[i2][0] < arrays2ShortXml[i1][10] / arrays2ShortXml[i1][0]))
                                    {
                                        Element Element0 = arrays1XmlShortb[i1];
                                        String StringTemp0 = arrays1XmlShort[i1];
                                        String StringTemp0b = arrays2ShortXmlName[i1];
                                        double DoubleTemp0 = arrays2ShortXml[i1][0];
                                        double DoubleTemp1 = arrays2ShortXml[i1][1];
                                        double DoubleTemp2 = arrays2ShortXml[i1][2];
                                        double DoubleTemp3 = arrays2ShortXml[i1][3];
                                        double DoubleTemp4 = arrays2ShortXml[i1][4];

                                        double DoubleTemp5 = arrays2ShortXml[i1][5];
                                        double DoubleTemp6 = arrays2ShortXml[i1][6];
                                        double DoubleTemp7 = arrays2ShortXml[i1][7];
                                        double DoubleTemp8 = arrays2ShortXml[i1][8];
                                        double DoubleTemp9 = arrays2ShortXml[i1][9];
                                        double DoubleTemp10 = arrays2ShortXml[i1][10];
                                        double DoubleTemp11 = arrays2ShortXml[i1][11];

                                        arrays1XmlShortb[i1] = arrays1XmlShortb[i2];
                                        arrays1XmlShort[i1] = arrays1XmlShort[i2];
                                        arrays2ShortXmlName[i1] = arrays2ShortXmlName[i2];
                                        arrays2ShortXml[i1][0] = arrays2ShortXml[i2][0];
                                        arrays2ShortXml[i1][1] =  arrays2ShortXml[i2][1];
                                        arrays2ShortXml[i1][2] =  arrays2ShortXml[i2][2];
                                        arrays2ShortXml[i1][3] =  arrays2ShortXml[i2][3];
                                        arrays2ShortXml[i1][4] =  arrays2ShortXml[i2][4];

                                        arrays2ShortXml[i1][5] =  arrays2ShortXml[i2][5];
                                        arrays2ShortXml[i1][6] =  arrays2ShortXml[i2][6];
                                        arrays2ShortXml[i1][7] =  arrays2ShortXml[i2][7];
                                        arrays2ShortXml[i1][8] =  arrays2ShortXml[i2][8];
                                        arrays2ShortXml[i1][9] =  arrays2ShortXml[i2][9];
                                        arrays2ShortXml[i1][10] =  arrays2ShortXml[i2][10];
                                        arrays2ShortXml[i1][11] =  arrays2ShortXml[i2][11];

                                        arrays1XmlShortb[i2] = Element0;
                                        arrays1XmlShort[i2] = StringTemp0;
                                        arrays2ShortXmlName[i2] = StringTemp0b;
                                        arrays2ShortXml[i2][0] = DoubleTemp0;
                                        arrays2ShortXml[i2][1] = DoubleTemp1;
                                        arrays2ShortXml[i2][2] = DoubleTemp2;
                                        arrays2ShortXml[i2][3] = DoubleTemp3;
                                        arrays2ShortXml[i2][4] = DoubleTemp4;

                                        arrays2ShortXml[i2][5] = DoubleTemp5;
                                        arrays2ShortXml[i2][6] = DoubleTemp6;
                                        arrays2ShortXml[i2][7] = DoubleTemp7;
                                        arrays2ShortXml[i2][8] = DoubleTemp8;
                                        arrays2ShortXml[i2][9] = DoubleTemp9;
                                        arrays2ShortXml[i2][10] = DoubleTemp10;
                                        arrays2ShortXml[i2][11] = DoubleTemp11;
                                    }
                                }
                            }
                        }
                        //#endregion

                        //#region  ************************************************************************ File Output : results of this period and Filter for the next period **************

                            // #region **************************************************************** OUTPUT file compleat StrategyXML *****************************************************
                            if (outputXmlStrategyFile)
                            {
                                FileWriter FilterWriter4 = new FileWriter("temp.xml" , true);
                                for(ResultsGroup strategyRG : databankRG) 														// Read each values strategy from the databank
                                {
                                    Result mainResult = strategyRG.subResult( strategyRG.getMainResultKey());
                                    if(mainResult == null) break;

                                    String strName = strategyRG.getName();
                                    if(strName.startsWith("Filtered portfolio")) 
                                    {
                                        continue;
                                    }
                                    Bouillant BouilltParaObj1 = new Bouillant();
                                    Bouillant BouilltParaObj2 = new Bouillant();
                                    FilterWriter4 = new FileWriter(OutputPath1 + databankName + " Bull "  + strName+  ".txt" , true);
                                    String BuildingBlocksName1 = BouilltParaObj1.toXMLStrategyString(strategyRG, false);
                                    FilterWriter4.write(BuildingBlocksName1);
                                    FilterWriter4.close();

                                    FilterWriter4 = new FileWriter(OutputPath1 + databankName + " Bear "  + strName+  ".txt" , true);
                                    BuildingBlocksName1 = BouilltParaObj2.toXMLStrategyString(strategyRG, false);	
                                    FilterWriter4.write(BuildingBlocksName1);
                                    FilterWriter4.close();
                                }
                            }
                            //#endregion

                            // #region **************************************************************** File Output **************************************************************************

                            //File myObj;// = new File(OutputPath); 
                            /*if (myObj.exists())																					// Delete previous file
                            {
                                if (myObj.delete()) 
                                { 
                                    System.out.println("Deleted the file: " + myObj.getName());
                                } 
                                else 
                                {
                                    System.out.println("Failed to delete the file.");
                                } 
                            }*/

                            FileWriter FilterWriter = new FileWriter("temp1.txt" , true);
                            FileWriter FilterWriter2 = new FileWriter("temp2.txt" , true);

                            FileWriter FilterWriterLong = new FileWriter("temp3.txt" , true);
                            FileWriter FilterWriter2Long = new FileWriter("temp4.txt" , true);

                            FileWriter FilterWriterShort = new FileWriter("temp5.txt" , true);
                            FileWriter FilterWriter2Short = new FileWriter("temp6.txt" , true);


                            File theDir = new File(OutputPath1);																	// Creation of directory if the path does not exist
                            if (!theDir.exists()) theDir.mkdirs();																	// Creation of directory if the path does not exist

                            myObj = new File(OutputPath);     																		// Specify the Path and filename
                            if (!myObj.exists())
                            {
                                if (myObj.createNewFile()) 
                                {
                                    System.out.println("File created: " + myObj.getName());
                                }
                                else 
                                {
                                    System.out.println("File already exists.");
                                }
                            }

                            FileWriter myWriter = new FileWriter(OutputPath , true);
                            if (ChoiceFilterNextOOS == SortType)								      								// OutPut Filter for the next period
                            {
                                if (SignalType == 1)
                                {
                                    FilterFile = new File(OutputPath1+"Entry Filter File.txt"); 
                                    if (FilterFile.exists()){FilterFile.delete();}
                                    FilterFile.createNewFile();
                                    FilterWriter = new FileWriter(OutputPath1 + "Entry Filter File.txt" , true);

                                    FilterFile2 = new File(OutputPath1+"Entry Filter File of " + databankName + ".txt");  
                                    if (FilterFile2.exists()){FilterFile2.delete();}
                                    FilterFile2.createNewFile();
                                    FilterWriter2 = new FileWriter(OutputPath1 + "Entry Filter File of " + databankName + ".txt" , true);

                                    FilterFileLong = new File(OutputPath1+"Entry Long Filter File.txt"); 
                                    if (FilterFileLong.exists()){FilterFileLong.delete();}
                                    FilterFileLong.createNewFile();
                                    FilterWriterLong = new FileWriter(OutputPath1 + "Entry Long Filter File.txt" , true);

                                    FilterFile2Long = new File(OutputPath1+"Entry Long Filter File of " + databankName + ".txt");  
                                    if (FilterFile2Long.exists()){FilterFile2Long.delete();}
                                    FilterFile2Long.createNewFile();
                                    FilterWriter2Long = new FileWriter(OutputPath1 + "Entry Long Filter File of " + databankName + ".txt" , true);

                                    FilterFileShort = new File(OutputPath1+"Entry Short Filter File.txt"); 
                                    if (FilterFileShort.exists()){FilterFileShort.delete();}
                                    FilterFileShort.createNewFile();
                                    FilterWriterShort = new FileWriter(OutputPath1 + "Entry Short Filter File.txt" , true);

                                    FilterFile2Short = new File(OutputPath1+"Entry Short Filter File of " + databankName + ".txt");  
                                    if (FilterFile2Short.exists()){FilterFile2Short.delete();}
                                    FilterFile2Short.createNewFile();
                                    FilterWriter2Short = new FileWriter(OutputPath1 + "Entry Short Filter File of " + databankName + ".txt" , true);
                                }
                                else if (SignalType == 2)
                                {
                                    FilterFile = new File(OutputPath1+"Exit Filter File.txt"); 
                                    if (FilterFile.exists()){FilterFile.delete();}
                                    FilterFile.createNewFile();
                                    FilterWriter = new FileWriter(OutputPath1 + "Exit Filter File.txt" , true);
                                    
                                    FilterFile2 = new File(OutputPath1+"Exit Filter File of " + databankName + ".txt");  
                                    if (FilterFile2.exists()){FilterFile2.delete();}
                                    FilterFile2.createNewFile();
                                    FilterWriter2 = new FileWriter(OutputPath1 + "Exit Filter File of " + databankName + ".txt" , true);
                                    
                                    FilterFileLong = new File(OutputPath1+"Exit Long Filter File.txt"); 
                                    if (FilterFileLong.exists()){FilterFileLong.delete();}
                                    FilterFileLong.createNewFile();
                                    FilterWriterLong = new FileWriter(OutputPath1 + "Exit Long Filter File.txt" , true);

                                    FilterFile2Long = new File(OutputPath1+"Exit Long Filter File of " + databankName + ".txt");  
                                    if (FilterFile2Long.exists()){FilterFile2Long.delete();}
                                    FilterFile2Long.createNewFile();
                                    FilterWriter2Long = new FileWriter(OutputPath1 + "Exit Long Filter File of " + databankName + ".txt" , true);

                                    FilterFileShort = new File(OutputPath1+"Exit Short Filter File.txt"); 
                                    if (FilterFileShort.exists()){FilterFileShort.delete();}
                                    FilterFileShort.createNewFile();
                                    FilterWriterShort = new FileWriter(OutputPath1 + "Exit Short Filter File.txt" , true);

                                    FilterFile2Short = new File(OutputPath1+"Exit Short Filter File of " + databankName + ".txt");  
                                    if (FilterFile2Short.exists()){FilterFile2Short.delete();}
                                    FilterFile2Short.createNewFile();
                                    FilterWriter2Short = new FileWriter(OutputPath1 + "Exit Short Filter File of " + databankName + ".txt" , true);
                                }
                            }

                            myWriter.write("\r\n");
                            myWriter.write("Minimum : " + String.format("%10d",minimum) + "  IsOos :  " + String.format("%10d",IsOos) + "  LongShort :  " + String.format("%10d",LongShort) + "  SortType :  " + String.format("%10d",SortType) + "\r\n");
                            myWriter.write("\r\n");
                            for(int i1 = 0; i1 < NbVariable; i1++) 																	// For each Variables
                            {
                                if ((arrays2[i1][0] >= minimum && !NbTotalOnNbTradeOrNbStrategies) || (arrays2[i1][11] >= minimum && NbTotalOnNbTradeOrNbStrategies))  											// s.substring(0, Math.min(s.length(), 10))
                                {
                                    String s = arrays1[i1];
                                    s = s.substring(0, Math.min(s.length(), 50));
                                    myWriter.write("Block Name : " + String.format("%-50s", s) + "\t" + "Total Strategies : " + String.format("%10.0f",arrays2[i1][0])  + "\t"  + stratMetric1 + " : " + String.format("%10.3f",(arrays2[i1][1] / arrays2[i1][0]))+ "\t"  + stratMetric2 + " : " + String.format("%15.3f",(arrays2[i1][2] / arrays2[i1][0])) + "\t"  + stratMetric3 + " : " + String.format("%10.3f",(arrays2[i1][3] / arrays2[i1][0])) + "\t"  + stratMetric4 + " : " + String.format("%10.3f",(arrays2[i1][4] / arrays2[i1][0]))+ "\t"  + stratMetric5 + " : " + String.format("%10.3f",(arrays2[i1][5] / arrays2[i1][0]))+ "\t"  + stratMetric6 + " : " + String.format("%10.3f",(arrays2[i1][6] / arrays2[i1][0]))+ "\t"  + stratMetric7 + " : " + String.format("%10.3f",(arrays2[i1][7] / arrays2[i1][0]))+ "\t"  + stratMetric8 + " : " + String.format("%10.3f",(arrays2[i1][8] / arrays2[i1][0]))+ "\t"  + stratMetric9 + " : " + String.format("%10.3f",(arrays2[i1][9] / arrays2[i1][0]))+ "\t"  + stratMetric10 + " : " + String.format("%10.3f",(arrays2[i1][10] / arrays2[i1][0]))+ "\r\n");
                                    if (ChoiceFilterNextOOS == SortType)								      							// OutPut Filter for the next period
                                    {
                                        if (AboveUnder == 1)
                                        {
                                            if (ChoiceFilterNextOOS == 0 || (ChoiceFilterNextOOS == 1 && (arrays2[i1][1] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 2 && (arrays2[i1][2] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS) || (ChoiceFilterNextOOS == 3 && (arrays2[i1][3] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 4 && (arrays2[i1][4] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 5 && (arrays2[i1][5] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS)  ||(ChoiceFilterNextOOS == 6 && (arrays2[i1][6] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 7 && (arrays2[i1][7] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 8 && (arrays2[i1][8] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 9 && (arrays2[i1][9] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 10 && (arrays2[i1][10] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS))
                                            {
                                                if (AboveUnder2 == 1)
                                                {
                                                    if (ChoiceFilterNextOOS2 == 0 || (ChoiceFilterNextOOS2 == 1 && (arrays2[i1][1] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 2 && (arrays2[i1][2] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 3 && (arrays2[i1][3] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 4 && (arrays2[i1][4] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 5 && (arrays2[i1][5] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2)  ||(ChoiceFilterNextOOS2 == 6 && (arrays2[i1][6] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 7 && (arrays2[i1][7] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 8 && (arrays2[i1][8] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 9 && (arrays2[i1][9] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 10 && (arrays2[i1][10] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2))
                                                    {
                                                        FilterWriter.write(arrays1[i1] + "\r\n");
                                                        FilterWriter2.write(arrays1[i1] + "\r\n");
                                                    }
                                                }
                                                if (AboveUnder2 == 2)
                                                {
                                                    if (ChoiceFilterNextOOS2 == 0 || (ChoiceFilterNextOOS2 == 1 && (arrays2[i1][1] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 2 && (arrays2[i1][2] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 3 && (arrays2[i1][3] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 4 && (arrays2[i1][4] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 5 && (arrays2[i1][5] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2)  ||(ChoiceFilterNextOOS2 == 6 && (arrays2[i1][6] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 7 && (arrays2[i1][7] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 8 && (arrays2[i1][8] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 9 && (arrays2[i1][9] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 10 && (arrays2[i1][10] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2))
                                                    {
                                                        FilterWriter.write(arrays1[i1] + "\r\n");
                                                        FilterWriter2.write(arrays1[i1] + "\r\n");
                                                    }
                                                }
                                            }
                                        }
                                        if (AboveUnder == 2)
                                        {
                                            if (ChoiceFilterNextOOS == 0 || (ChoiceFilterNextOOS == 1 && (arrays2[i1][1] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 2 && (arrays2[i1][2] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS) || (ChoiceFilterNextOOS == 3 && (arrays2[i1][3] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 4 && (arrays2[i1][4] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 5 && (arrays2[i1][5] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS)  ||(ChoiceFilterNextOOS == 6 && (arrays2[i1][6] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 7 && (arrays2[i1][7] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 8 && (arrays2[i1][8] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 9 && (arrays2[i1][9] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 10 && (arrays2[i1][10] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS))
                                            {
                                                if (AboveUnder2 == 1)
                                                {
                                                    if (ChoiceFilterNextOOS2 == 0 || (ChoiceFilterNextOOS2 == 1 && (arrays2[i1][1] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 2 && (arrays2[i1][2] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 3 && (arrays2[i1][3] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 4 && (arrays2[i1][4] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 5 && (arrays2[i1][5] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2)  ||(ChoiceFilterNextOOS2 == 6 && (arrays2[i1][6] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 7 && (arrays2[i1][7] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 8 && (arrays2[i1][8] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 9 && (arrays2[i1][9] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 10 && (arrays2[i1][10] / arrays2[i1][0]) >= MinimumLevelFilterNextOOS2))
                                                    {
                                                        FilterWriter.write(arrays1[i1] + "\r\n");
                                                        FilterWriter2.write(arrays1[i1] + "\r\n");
                                                    }
                                                }
                                                if (AboveUnder2 == 2)
                                                {
                                                    if (ChoiceFilterNextOOS2 == 0 || (ChoiceFilterNextOOS2 == 1 && (arrays2[i1][1] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 2 && (arrays2[i1][2] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 3 && (arrays2[i1][3] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 4 && (arrays2[i1][4] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 5 && (arrays2[i1][5] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2)  ||(ChoiceFilterNextOOS2 == 6 && (arrays2[i1][6] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 7 && (arrays2[i1][7] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 8 && (arrays2[i1][8] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 9 && (arrays2[i1][9] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 10 && (arrays2[i1][10] / arrays2[i1][0]) <= MinimumLevelFilterNextOOS2))
                                                    {
                                                        FilterWriter.write(arrays1[i1] + "\r\n");
                                                        FilterWriter2.write(arrays1[i1] + "\r\n");
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            //#endregion
                        
                            //#region ***************************************************************** Long and Short stats results *********************************************************
                            if (LongShort == 3)                                                                                        		
                            {
                                myWriter.write("\r\n");
                                myWriter.write("\r\n");
                                myWriter.write("Details Full, Long, Short : \r\n");
                                myWriter.write("\r\n");
                                for(int i1 = 0; i1 < NbVariable; i1++) 																										// For each Variables
                                {
                                    if ((arrays2[i1][0] > minimum  && !NbTotalOnNbTradeOrNbStrategies) || (arrays2[i1][11] >= minimum && NbTotalOnNbTradeOrNbStrategies)) 
                                    {
                                        double stratMetricLongDbl1;
                                        if (arrays2Long[i1][0] > 0)	{stratMetricLongDbl1 = (arrays2Long[i1][1] / arrays2Long[i1][0]);}
                                        else {stratMetricLongDbl1 = 0;}
                                        double stratMetricShortDbl1;
                                        if (arrays2Short[i1][0] > 0) {stratMetricShortDbl1 = (arrays2Short[i1][1] / arrays2Short[i1][0]);}
                                        else{stratMetricShortDbl1 = 0;}
                                        double stratMetricLongDbl2;
                                        if (arrays2Long[i1][0] > 0)	{stratMetricLongDbl2 = (arrays2Long[i1][2] / arrays2Long[i1][0]);}
                                        else {stratMetricLongDbl2 = 0;}
                                        double stratMetricShortDbl2;
                                        if (arrays2Short[i1][0] > 0) {stratMetricShortDbl2 = (arrays2Short[i1][2] / arrays2Short[i1][0]);}
                                        else{stratMetricShortDbl2 = 0;}
                                        double stratMetricLongDbl3;
                                        if (arrays2Long[i1][0] > 0)	{stratMetricLongDbl3 = (arrays2Long[i1][3] / arrays2Long[i1][0]);}
                                        else {stratMetricLongDbl3 = 0;}
                                        double stratMetricShortDbl3;
                                        if (arrays2Short[i1][0] > 0) {stratMetricShortDbl3 = (arrays2Short[i1][3] / arrays2Short[i1][0]);}
                                        else{stratMetricShortDbl3 = 0;}
                                        double stratMetricLongDbl4;
                                        if (arrays2Long[i1][0] > 0)	{stratMetricLongDbl4 = (arrays2Long[i1][4] / arrays2Long[i1][0]);}
                                        else {stratMetricLongDbl4 = 0;}
                                        double stratMetricShortDbl4;
                                        if (arrays2Short[i1][0] > 0) {stratMetricShortDbl4 = (arrays2Short[i1][4] / arrays2Short[i1][0]);}
                                        else{stratMetricShortDbl4 = 0;}
                                        double stratMetricLongDbl5;
                                        if (arrays2Long[i1][0] > 0)	{stratMetricLongDbl5 = (arrays2Long[i1][5] / arrays2Long[i1][0]);}
                                        else {stratMetricLongDbl5 = 0;}
                                        double stratMetricShortDbl5;
                                        if (arrays2Short[i1][0] > 0) {stratMetricShortDbl5 = (arrays2Short[i1][5] / arrays2Short[i1][0]);}
                                        else{stratMetricShortDbl5 = 0;}
                                        double stratMetricLongDbl6;
                                        if (arrays2Long[i1][0] > 0)	{stratMetricLongDbl6 = (arrays2Long[i1][6] / arrays2Long[i1][0]);}
                                        else {stratMetricLongDbl6 = 0;}
                                        double stratMetricShortDbl6;
                                        if (arrays2Short[i1][0] > 0) {stratMetricShortDbl6 = (arrays2Short[i1][6] / arrays2Short[i1][0]);}
                                        else{stratMetricShortDbl6 = 0;}
                                        double stratMetricLongDbl7;
                                        if (arrays2Long[i1][0] > 0)	{stratMetricLongDbl7 = (arrays2Long[i1][7] / arrays2Long[i1][0]);}
                                        else {stratMetricLongDbl7 = 0;}
                                        double stratMetricShortDbl7;
                                        if (arrays2Short[i1][0] > 0) {stratMetricShortDbl7 = (arrays2Short[i1][7] / arrays2Short[i1][0]);}
                                        else{stratMetricShortDbl7 = 0;}
                                        double stratMetricLongDbl8;
                                        if (arrays2Long[i1][0] > 0)	{stratMetricLongDbl8 = (arrays2Long[i1][8] / arrays2Long[i1][0]);}
                                        else {stratMetricLongDbl8 = 0;}
                                        double stratMetricShortDbl8;
                                        if (arrays2Short[i1][0] > 0) {stratMetricShortDbl8 = (arrays2Short[i1][8] / arrays2Short[i1][0]);}
                                        else{stratMetricShortDbl8 = 0;}
                                        double stratMetricLongDbl9;
                                        if (arrays2Long[i1][0] > 0)	{stratMetricLongDbl9 = (arrays2Long[i1][9] / arrays2Long[i1][0]);}
                                        else {stratMetricLongDbl9 = 0;}
                                        double stratMetricShortDbl9;
                                        if (arrays2Short[i1][0] > 0) {stratMetricShortDbl9 = (arrays2Short[i1][9] / arrays2Short[i1][0]);}
                                        else{stratMetricShortDbl9 = 0;}
                                        double stratMetricLongDbl10;
                                        if (arrays2Long[i1][0] > 0)	{stratMetricLongDbl10 = (arrays2Long[i1][10] / arrays2Long[i1][0]);}
                                        else {stratMetricLongDbl10 = 0;}
                                        double stratMetricShortDbl10;
                                        if (arrays2Short[i1][0] > 0) {stratMetricShortDbl10 = (arrays2Short[i1][10] / arrays2Short[i1][0]);}
                                        else{stratMetricShortDbl10 = 0;}
                                        String s = arrays1[i1];
                                        s = s.substring(0, Math.min(s.length(), 50));
                                        
                                        myWriter.write("Block Name : " + String.format("%-50s", s) + "\t" + "Total Strategies : " + String.format("%10.0f",arrays2[i1][0]) + "\t"+ String.format("%10.0f",arrays2Long[i1][0])+ "\t" + String.format("%10.0f",arrays2Short[i1][0])+ "\t"  + stratMetric1 + " : " + String.format("%10.3f",(arrays2[i1][1] / arrays2[i1][0]))+ "\t"  + String.format("%10.3f",stratMetricLongDbl1)+ "\t"+ String.format("%10.3f",stratMetricShortDbl1)+ "\t"+ stratMetric2 + " : " + String.format("%15.3f",(arrays2[i1][2] / arrays2[i1][0]))+ "\t"+ String.format("%15.3f",stratMetricLongDbl2)+ "\t"+ String.format("%15.3f",stratMetricShortDbl2)+ "\t"  + stratMetric3 + " : " + String.format("%10.3f",(arrays2[i1][3] / arrays2[i1][0])) + "\t" + String.format("%10.3f",stratMetricLongDbl3)+ "\t" + String.format("%10.3f",stratMetricShortDbl3)+ "\t"  + stratMetric4 + " : " + String.format("%10.3f",(arrays2[i1][4] / arrays2[i1][0]))+ "\t" + String.format("%10.3f",stratMetricLongDbl4)+ "\t"+ String.format("%10.3f",stratMetricShortDbl4)+ "\t" + stratMetric5 + " : " + String.format("%10.3f",(arrays2[i1][5] / arrays2[i1][0]))+ "\t"  + String.format("%10.3f",stratMetricLongDbl5)+ "\t" + String.format("%10.3f",stratMetricShortDbl5)+ "\t" + stratMetric6 + " : " + String.format("%10.3f",(arrays2[i1][6] / arrays2[i1][0]))+ "\t"  + String.format("%10.3f",stratMetricLongDbl6)+ "\t" + String.format("%10.3f",stratMetricShortDbl6)+ "\t" + stratMetric7 + " : " + String.format("%10.3f",(arrays2[i1][7] / arrays2[i1][0]))+ "\t" + String.format("%10.3f",stratMetricLongDbl7)+ "\t"+ String.format("%10.3f",stratMetricShortDbl7)+ "\t" + stratMetric8 + " : " + String.format("%10.3f",(arrays2[i1][8] / arrays2[i1][0]))+ "\t" + String.format("%10.3f",stratMetricLongDbl8) + "\t"+ String.format("%10.3f",stratMetricShortDbl8)+ "\t"+ stratMetric9 + " : " + String.format("%10.3f",(arrays2[i1][9] / arrays2[i1][0]))+ "\t" + String.format("%10.3f",stratMetricLongDbl9)+ "\t"+ String.format("%10.3f",stratMetricShortDbl9)+ "\t" + stratMetric10 + " : " + String.format("%10.3f",(arrays2[i1][10] / arrays2[i1][0]))+ "\t" + String.format("%10.3f",stratMetricLongDbl10)+ "\t" + String.format("%10.3f",stratMetricShortDbl10)+ "\r\n");
                                    }
                                }
                            }
                            
                            for(int i1 = 0; i1 < NbVariable; i1++) 																										// For each Variables Long
                            {
                                if (ChoiceFilterNextOOS == SortType && ((arrays2Long[i1][0] > minimum  && !NbTotalOnNbTradeOrNbStrategies) || (arrays2Long[i1][11] >= minimum && NbTotalOnNbTradeOrNbStrategies))) 
                                {
                                    if (AboveUnder == 1)
                                    {
                                        if (ChoiceFilterNextOOS == 0 || (ChoiceFilterNextOOS == 1 && (arrays2Long[i1][1] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 2 && (arrays2Long[i1][2] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS) || (ChoiceFilterNextOOS == 3 && (arrays2Long[i1][3] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 4 && (arrays2Long[i1][4] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 5 && (arrays2Long[i1][5] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS)  ||(ChoiceFilterNextOOS == 6 && (arrays2Long[i1][6] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 7 && (arrays2Long[i1][7] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 8 && (arrays2Long[i1][8] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 9 && (arrays2Long[i1][9] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 10 && (arrays2Long[i1][10] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS))
                                        {
                                            if (AboveUnder2 == 1)
                                            {
                                                if (ChoiceFilterNextOOS2 == 0 || (ChoiceFilterNextOOS2 == 1 && (arrays2Long[i1][1] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 2 && (arrays2Long[i1][2] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 3 && (arrays2Long[i1][3] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 4 && (arrays2Long[i1][4] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 5 && (arrays2Long[i1][5] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2)  ||(ChoiceFilterNextOOS2 == 6 && (arrays2Long[i1][6] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 7 && (arrays2Long[i1][7] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 8 && (arrays2Long[i1][8] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 9 && (arrays2Long[i1][9] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 10 && (arrays2Long[i1][10] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2))
                                                {
                                                    FilterWriterLong.write(arrays1[i1] + "\r\n");
                                                    FilterWriter2Long.write(arrays1[i1] + "\r\n");
                                                }
                                            }
                                            if (AboveUnder2 == 2)
                                            {
                                                if (ChoiceFilterNextOOS2 == 0 || (ChoiceFilterNextOOS2 == 1 && (arrays2Long[i1][1] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 2 && (arrays2Long[i1][2] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 3 && (arrays2Long[i1][3] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 4 && (arrays2Long[i1][4] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 5 && (arrays2Long[i1][5] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2)  ||(ChoiceFilterNextOOS2 == 6 && (arrays2Long[i1][6] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 7 && (arrays2Long[i1][7] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 8 && (arrays2Long[i1][8] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 9 && (arrays2Long[i1][9] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 10 && (arrays2Long[i1][10] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2))
                                                {
                                                    FilterWriterLong.write(arrays1[i1] + "\r\n");
                                                    FilterWriter2Long.write(arrays1[i1] + "\r\n");
                                                }
                                            }
                                        }
                                    }
                                    if (AboveUnder == 2)
                                    {
                                        if (ChoiceFilterNextOOS == 0 || (ChoiceFilterNextOOS == 1 && (arrays2Long[i1][1] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 2 && (arrays2Long[i1][2] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS) || (ChoiceFilterNextOOS == 3 && (arrays2Long[i1][3] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 4 && (arrays2Long[i1][4] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 5 && (arrays2Long[i1][5] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS)  ||(ChoiceFilterNextOOS == 6 && (arrays2Long[i1][6] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 7 && (arrays2Long[i1][7] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 8 && (arrays2Long[i1][8] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 9 && (arrays2Long[i1][9] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 10 && (arrays2Long[i1][10] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS))
                                        {
                                            if (AboveUnder2 == 1)
                                            {
                                                if (ChoiceFilterNextOOS2 == 0 || (ChoiceFilterNextOOS2 == 1 && (arrays2Long[i1][1] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 2 && (arrays2Long[i1][2] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 3 && (arrays2Long[i1][3] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 4 && (arrays2Long[i1][4] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 5 && (arrays2Long[i1][5] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2)  ||(ChoiceFilterNextOOS2 == 6 && (arrays2Long[i1][6] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 7 && (arrays2Long[i1][7] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 8 && (arrays2Long[i1][8] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 9 && (arrays2Long[i1][9] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 10 && (arrays2Long[i1][10] / arrays2Long[i1][0]) >= MinimumLevelFilterNextOOS2))
                                                {
                                                    FilterWriterLong.write(arrays1[i1] + "\r\n");
                                                    FilterWriter2Long.write(arrays1[i1] + "\r\n");
                                                }
                                            }
                                            if (AboveUnder2 == 2)
                                            {
                                                if (ChoiceFilterNextOOS2 == 0 || (ChoiceFilterNextOOS2 == 1 && (arrays2Long[i1][1] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 2 && (arrays2Long[i1][2] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 3 && (arrays2Long[i1][3] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 4 && (arrays2Long[i1][4] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 5 && (arrays2Long[i1][5] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2)  ||(ChoiceFilterNextOOS2 == 6 && (arrays2Long[i1][6] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 7 && (arrays2Long[i1][7] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 8 && (arrays2Long[i1][8] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 9 && (arrays2Long[i1][9] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 10 && (arrays2Long[i1][10] / arrays2Long[i1][0]) <= MinimumLevelFilterNextOOS2))
                                                {
                                                    FilterWriterLong.write(arrays1[i1] + "\r\n");
                                                    FilterWriter2Long.write(arrays1[i1] + "\r\n");
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            for(int i1 = 0; i1 < NbVariable; i1++) 																										// For each Variables Short
                            {
                                if (ChoiceFilterNextOOS == SortType && ((arrays2Short[i1][0] > minimum  && !NbTotalOnNbTradeOrNbStrategies) || (arrays2Short[i1][11] >= minimum && NbTotalOnNbTradeOrNbStrategies))) 
                                {
                                    if (AboveUnder == 1)
                                    {
                                        if (ChoiceFilterNextOOS == 0 || (ChoiceFilterNextOOS == 1 && (arrays2Short[i1][1] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 2 && (arrays2Short[i1][2] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS) || (ChoiceFilterNextOOS == 3 && (arrays2Short[i1][3] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 4 && (arrays2Short[i1][4] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 5 && (arrays2Short[i1][5] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS)  ||(ChoiceFilterNextOOS == 6 && (arrays2Short[i1][6] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 7 && (arrays2Short[i1][7] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 8 && (arrays2Short[i1][8] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 9 && (arrays2Short[i1][9] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 10 && (arrays2Short[i1][10] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS))
                                        {
                                            if (AboveUnder2 == 1)
                                            {
                                                if (ChoiceFilterNextOOS2 == 0 || (ChoiceFilterNextOOS2 == 1 && (arrays2Short[i1][1] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 2 && (arrays2Short[i1][2] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 3 && (arrays2Short[i1][3] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 4 && (arrays2Short[i1][4] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 5 && (arrays2Short[i1][5] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2)  ||(ChoiceFilterNextOOS2 == 6 && (arrays2Short[i1][6] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 7 && (arrays2Short[i1][7] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 8 && (arrays2Short[i1][8] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 9 && (arrays2Short[i1][9] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 10 && (arrays2Short[i1][10] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2))
                                                {
                                                    FilterWriterShort.write(arrays1[i1] + "\r\n");
                                                    FilterWriter2Short.write(arrays1[i1] + "\r\n");
                                                }
                                            }
                                            if (AboveUnder2 == 2)
                                            {
                                                if (ChoiceFilterNextOOS2 == 0 || (ChoiceFilterNextOOS2 == 1 && (arrays2Short[i1][1] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 2 && (arrays2Short[i1][2] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 3 && (arrays2Short[i1][3] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 4 && (arrays2Short[i1][4] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 5 && (arrays2Short[i1][5] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2)  ||(ChoiceFilterNextOOS2 == 6 && (arrays2Short[i1][6] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 7 && (arrays2Short[i1][7] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 8 && (arrays2Short[i1][8] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 9 && (arrays2Short[i1][9] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 10 && (arrays2Short[i1][10] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2))
                                                {
                                                    FilterWriterShort.write(arrays1[i1] + "\r\n");
                                                    FilterWriter2Short.write(arrays1[i1] + "\r\n");
                                                }
                                            }
                                        }
                                    }
                                    if (AboveUnder == 2)
                                    {
                                        if (ChoiceFilterNextOOS == 0 || (ChoiceFilterNextOOS == 1 && (arrays2Short[i1][1] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 2 && (arrays2Short[i1][2] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS) || (ChoiceFilterNextOOS == 3 && (arrays2Short[i1][3] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 4 && (arrays2Short[i1][4] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 5 && (arrays2Short[i1][5] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS)  ||(ChoiceFilterNextOOS == 6 && (arrays2Short[i1][6] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 7 && (arrays2Short[i1][7] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 8 && (arrays2Short[i1][8] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 9 && (arrays2Short[i1][9] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS) ||(ChoiceFilterNextOOS == 10 && (arrays2Short[i1][10] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS))
                                        {
                                            if (AboveUnder2 == 1)
                                            {
                                                if (ChoiceFilterNextOOS2 == 0 || (ChoiceFilterNextOOS2 == 1 && (arrays2Short[i1][1] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 2 && (arrays2Short[i1][2] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 3 && (arrays2Short[i1][3] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 4 && (arrays2Short[i1][4] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 5 && (arrays2Short[i1][5] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2)  ||(ChoiceFilterNextOOS2 == 6 && (arrays2Short[i1][6] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 7 && (arrays2Short[i1][7] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 8 && (arrays2Short[i1][8] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 9 && (arrays2Short[i1][9] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 10 && (arrays2Short[i1][10] / arrays2Short[i1][0]) >= MinimumLevelFilterNextOOS2))
                                                {
                                                    FilterWriterShort.write(arrays1[i1] + "\r\n");
                                                    FilterWriter2Short.write(arrays1[i1] + "\r\n");
                                                }
                                            }
                                            if (AboveUnder2 == 2)
                                            {
                                                if (ChoiceFilterNextOOS2 == 0 || (ChoiceFilterNextOOS2 == 1 && (arrays2Short[i1][1] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 2 && (arrays2Short[i1][2] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 3 && (arrays2Short[i1][3] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 4 && (arrays2Short[i1][4] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 5 && (arrays2Short[i1][5] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2)  ||(ChoiceFilterNextOOS2 == 6 && (arrays2Short[i1][6] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 7 && (arrays2Short[i1][7] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 8 && (arrays2Short[i1][8] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2) ||(ChoiceFilterNextOOS2 == 9 && (arrays2Short[i1][9] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2) || (ChoiceFilterNextOOS2 == 10 && (arrays2Short[i1][10] / arrays2Short[i1][0]) <= MinimumLevelFilterNextOOS2))
                                                {
                                                    FilterWriterShort.write(arrays1[i1] + "\r\n");
                                                    FilterWriter2Short.write(arrays1[i1] + "\r\n");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            FilterWriter.close();
                            FilterWriter2.close();
                            FilterWriterLong.close();
                            FilterWriter2Long.close();
                            FilterWriterShort.close();
                            FilterWriter2Short.close();
                            myWriter.close();
                            //#endregion

                            if (ChoiceFilterNextOOS == SortType)								      										
                            {
                                //#region ************************************************************* Random groups Long *******************************************************************
                                // For more information :  https://strategyquant.com/doc/strategyquant/random-groups/
                                Element Groups = new Element("Groups");
                                //org.jdom2.Document document = new Document(Groups);
                                Element Group = new Element("Group");

                                Attribute classe1 = new Attribute("id", getRandomHexString(32));    											// "CB8DA07A5CE85161657363670D57E4F0"
                                if (!randomID)																									// New random ID implied creating a new template in SQX each time for each new group, keeping the same ID implied keeping the same template in SQX without templating each time
                                {
                                    if (SignalType == 1)
                                    {
                                        switch (DatabanksNumber) 
                                        {
                                            case 1:
                                                classe1 = new Attribute("id", "9d9e22d91aaf4f9fad70f9856c2e81b3"); 
                                                break;
                                            case 2:
                                                classe1 = new Attribute("id", "bfd879fe4e0ee8c570a86c58a5551b9d"); 
                                                break;
                                            case 3:
                                                classe1 = new Attribute("id", "beecd1bb4434e7fe989488a946d5dc27"); 
                                                break;
                                            case 4:
                                                classe1 = new Attribute("id", "6a3bf97cc5a1ee0bf50119e385564c7d"); 
                                                break;
                                            case 5:
                                                classe1 = new Attribute("id", "95513b562c9602e9cdce33bee6b1644a"); 
                                                break;
                                            case 6:
                                                classe1 = new Attribute("id", "b5116a5d5688b526d2233da87f41f1c6"); 
                                                break;
                                            case 7:
                                                classe1 = new Attribute("id", "5705a12577d02f13ac6dfc72c1052cc9"); 
                                                break;
                                            case 8:
                                                classe1 = new Attribute("id", "345be09fca86a21ffeba530f649f5273"); 
                                                break;
                                            case 9:
                                                classe1 = new Attribute("id", "b9ed4aa8e4dbcbd9e850db1f234c9c82"); 
                                                break;
                                            case 10:
                                                classe1 = new Attribute("id", "7e477b9830d0dd05fc536a38af7c4eaa"); 
                                                break;
                                        }
                                    }
                                    if (SignalType == 2)
                                    {
                                        switch (DatabanksNumber) 
                                        {
                                            case 1:
                                                classe1 = new Attribute("id", "427176d0bff1335714ca4a14601c6997"); 
                                                break;
                                            case 2:
                                                classe1 = new Attribute("id", "9de42ef34ef44dbaf27e23429ddabdb0"); 
                                                break;
                                            case 3:
                                                classe1 = new Attribute("id", "2a1f686ae08fa4e79412d845eaeb5fb9"); 
                                                break;
                                            case 4:
                                                classe1 = new Attribute("id", "11ac56869c057b9694c0fd24b5f6a1cd"); 
                                                break;
                                            case 5:
                                                classe1 = new Attribute("id", "a3f7d13df13a1f0f6752ff37da9d9547"); 
                                                break;
                                            case 6:
                                                classe1 = new Attribute("id", "305c6f6e3efae11e57ac7ee3bf711da1"); 
                                                break;
                                            case 7:
                                                classe1 = new Attribute("id", "a36d8820e37009bde4e7353530ac43e5"); 
                                                break;
                                            case 8:
                                                classe1 = new Attribute("id", "21fd93a085af7bcd8487714e5dd895f2"); 
                                                break;
                                            case 9:
                                                classe1 = new Attribute("id", "3bb2af23e3010a56dbe7ebb95a087e90"); 
                                                break;
                                            case 10:
                                                classe1 = new Attribute("id", "61259b9234d37c79c6b7494c9e42b725"); 
                                                break;
                                        }
                                    }
                                }

                                Group.setAttribute(classe1);
                                Attribute classe2 = new Attribute("name","Long " + databankName);
                                if (SignalType == 1)
                                {
                                    classe2 = new Attribute("name","Entry Long " + databankName);
                                }
                                else if (SignalType == 2)
                                {
                                    classe2 = new Attribute("name","Exit Long " + databankName);
                                }
                                Group.setAttribute(classe2);
                                Attribute classe3 = new Attribute("type","Conditions");    
                                Group.setAttribute(classe3);
                                Attribute classe4 = new Attribute("category","No category");
                                Group.setAttribute(classe4);

                                for(int i1 = 0; i1 < NbVariableXmlLong; i1++) 																	// For each Variables
                                {
                                    if ((arrays2LongXml[i1][0] >= minimumXml && !NbTotalOnNbTradeOrNbStrategies) || (arrays2LongXml[i1][11] >= minimumXml && NbTotalOnNbTradeOrNbStrategies)) 
                                    {
                                        if (ChoiceFilterNextOOS == SortType)								      								// OutPut Filter for the next period
                                        {
                                            if (AboveUnder == 1)
                                            {
                                                if ((ChoiceFilterNextOOS == 1 && (arrays2LongXml[i1][1] / arrays2LongXml[i1][0]) >= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 2 && (arrays2LongXml[i1][2] / arrays2LongXml[i1][0]) >= MinimumLevelFilterRandomGroups) || (ChoiceFilterNextOOS == 3 && (arrays2LongXml[i1][3] / arrays2LongXml[i1][0]) >= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 4 && (arrays2LongXml[i1][4] / arrays2LongXml[i1][0]) >= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 5 && (arrays2LongXml[i1][5] / arrays2LongXml[i1][0]) >= MinimumLevelFilterRandomGroups)  ||(ChoiceFilterNextOOS == 6 && (arrays2LongXml[i1][6] / arrays2LongXml[i1][0]) >= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 7 && (arrays2LongXml[i1][7] / arrays2LongXml[i1][0]) >= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 8 && (arrays2LongXml[i1][8] / arrays2LongXml[i1][0]) >= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 9 && (arrays2LongXml[i1][9] / arrays2LongXml[i1][0]) >= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 10 && (arrays2LongXml[i1][10] / arrays2LongXml[i1][0]) >= MinimumLevelFilterRandomGroups))
                                                {
                                                    Element elemCopy = (Element)arrays1XmlLongb[i1].clone();
                                                    elemCopy.detach();
                                                    Group.addContent(elemCopy);
                                                }
                                            }
                                            if (AboveUnder == 2)
                                            {
                                                if ((ChoiceFilterNextOOS == 1 && (arrays2LongXml[i1][1] / arrays2LongXml[i1][0]) <= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 2 && (arrays2LongXml[i1][2] / arrays2LongXml[i1][0]) <= MinimumLevelFilterRandomGroups) || (ChoiceFilterNextOOS == 3 && (arrays2LongXml[i1][3] / arrays2LongXml[i1][0]) <= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 4 && (arrays2LongXml[i1][4] / arrays2LongXml[i1][0]) <= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 5 && (arrays2LongXml[i1][5] / arrays2LongXml[i1][0]) <= MinimumLevelFilterRandomGroups)  ||(ChoiceFilterNextOOS == 6 && (arrays2LongXml[i1][6] / arrays2LongXml[i1][0]) <= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 7 && (arrays2LongXml[i1][7] / arrays2LongXml[i1][0]) <= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 8 && (arrays2LongXml[i1][8] / arrays2LongXml[i1][0]) <= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 9 && (arrays2LongXml[i1][9] / arrays2LongXml[i1][0]) <= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 10 && (arrays2LongXml[i1][10] / arrays2LongXml[i1][0]) <= MinimumLevelFilterRandomGroups))
                                                {
                                                    Element elemCopy = (Element)arrays1XmlLongb[i1].clone();
                                                    elemCopy.detach();
                                                    Group.addContent(elemCopy);	
                                                }
                                            }
                                        }
                                    }
                                }

                                Groups.addContent(Group);
                                Element GroupCopy = (Element)Group.clone();
                                if (DatabanksNumber < NbDataBanks){AllGroups.addContent(GroupCopy);}
                                String String1 = XMLUtil.elementToString(Groups);
                                if (SignalType == 1)
                                {
                                    FileWriter FilterWriter4 = new FileWriter(OutputPath1 + "Entry Long Building Blocks File sorted by " + StringTemp  +" Of "+ databankName + ".xml" , true);
                                    FilterWriter4.write(String1);
                                    FilterWriter4.close();
                                }
                                else if (SignalType == 2)
                                {
                                    FileWriter FilterWriter4 = new FileWriter(OutputPath1 + "Exit Long Building Blocks File sorted by " + StringTemp  +" Of "+ databankName + ".xml" , true);
                                    FilterWriter4.write(String1);
                                    FilterWriter4.close();
                                }

                                // #endregion 

                                //#region ************************************************************* Random groups Short ******************************************************************

                                Groups = new Element("Groups");
                                //document = new Document(Groups);
                                Group = new Element("Group");

                                classe1 = new Attribute("id", getRandomHexString(32));    																	// "CB8DA07A5CE85161657363670D57E4F0"
                                if (!randomID)																												// New random ID implied creating a new template in SQX each time for each new group, keeping the same ID implied keeping the same template in SQX without templating each time
                                {
                                    if (SignalType == 1)
                                    {
                                        switch (DatabanksNumber) 
                                        {
                                            case 1:
                                                classe1 = new Attribute("id", "982d6384fb01c950cd929869976e1a3a"); 
                                                break;
                                            case 2:
                                                classe1 = new Attribute("id", "4b7900eab6c9f657154dacc7bd2b78a0"); 
                                                break;
                                            case 3:
                                                classe1 = new Attribute("id", "36cd9ad64366fa7de45a4ed9a9a51786"); 
                                                break;
                                            case 4:
                                                classe1 = new Attribute("id", "877f3d7389a85ccba12e836ce861cde7"); 
                                                break;
                                            case 5:
                                                classe1 = new Attribute("id", "7f4818235ec22d997581b3f49bc6d945"); 
                                                break;
                                            case 6:
                                                classe1 = new Attribute("id", "10bde31afc740bb669fbeb7c4b162d97"); 
                                                break;
                                            case 7:
                                                classe1 = new Attribute("id", "c767b466d0beab44418018dc6c3b284f"); 
                                                break;
                                            case 8:
                                                classe1 = new Attribute("id", "8822e445c98a4b3d6bf834f7825c9b73"); 
                                                break;
                                            case 9:
                                                classe1 = new Attribute("id", "25a1bdfbb7029e8bf8832feb4cb8be16"); 
                                                break;
                                            case 10:
                                                classe1 = new Attribute("id", "f4dbcc342a7dc4f2fc0641d7c872f64e"); 
                                                break;
                                        }
                                    }
                                    if (SignalType == 2)
                                    {
                                        switch (DatabanksNumber) 
                                        {
                                            case 1:
                                                classe1 = new Attribute("id", "ccfc79fe76a7851fab39aa2d21adf04f"); 
                                                break;
                                            case 2:
                                                classe1 = new Attribute("id", "a39104f571d7f22357c5445bb1f4052c"); 
                                                break;
                                            case 3:
                                                classe1 = new Attribute("id", "c255d39c891949e25db5caa879958947"); 
                                                break;
                                            case 4:
                                                classe1 = new Attribute("id", "7fe22382d77a84ee41bbdc525ec57063"); 
                                                break;
                                            case 5:
                                                classe1 = new Attribute("id", "d6cabb3158f08f6aa2d0710dc8acea39"); 
                                                break;
                                            case 6:
                                                classe1 = new Attribute("id", "d849523fe05f4045ed78f29254e38299"); 
                                                break;
                                            case 7:
                                                classe1 = new Attribute("id", "478fe992bff80299e463b57f3db82516"); 
                                                break;
                                            case 8:
                                                classe1 = new Attribute("id", "ec554eb2ce6d2f4425df95d91d5e0328"); 
                                                break;
                                            case 9:
                                                classe1 = new Attribute("id", "f52644d1abac82f45aa80a997aef5f5d"); 
                                                break;
                                            case 10:
                                                classe1 = new Attribute("id", "a3bc2c45b41e6bef9c673db19081b1b3"); 
                                                break;
                                        }
                                    }
                                }
                                Group.setAttribute(classe1);
                                classe2 = new Attribute("name", "Short " + databankName);
                                if (SignalType == 1)
                                {
                                    classe2 = new Attribute("name","Entry Short " + databankName);
                                }
                                else if (SignalType == 2)
                                {
                                    classe2 = new Attribute("name","Exit Short " + databankName);
                                }
                                Group.setAttribute(classe2);
                                classe3 = new Attribute("type","Conditions");    
                                Group.setAttribute(classe3);
                                classe4 = new Attribute("category","No category");
                                Group.setAttribute(classe4);

                                for(int i1 = 0; i1 < NbVariableXmlShort; i1++) 																	// For each Variables
                                {
                                    if ((arrays2ShortXml[i1][0] >= minimumXml && !NbTotalOnNbTradeOrNbStrategies) || (arrays2ShortXml[i1][11] >= minimumXml && NbTotalOnNbTradeOrNbStrategies))
                                    {
                                        if (ChoiceFilterNextOOS == SortType)								      								// OutPut Filter for the next period
                                        {
                                            if (AboveUnder == 1)
                                            {
                                                if ((ChoiceFilterNextOOS == 1 && (arrays2ShortXml[i1][1] / arrays2ShortXml[i1][0]) >= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 2 && (arrays2ShortXml[i1][2] / arrays2ShortXml[i1][0]) >= MinimumLevelFilterRandomGroups) || (ChoiceFilterNextOOS == 3 && (arrays2ShortXml[i1][3] / arrays2ShortXml[i1][0]) >= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 4 && (arrays2ShortXml[i1][4] / arrays2ShortXml[i1][0]) >= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 5 && (arrays2ShortXml[i1][5] / arrays2ShortXml[i1][0]) >= MinimumLevelFilterRandomGroups)  ||(ChoiceFilterNextOOS == 6 && (arrays2ShortXml[i1][6] / arrays2ShortXml[i1][0]) >= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 7 && (arrays2ShortXml[i1][7] / arrays2ShortXml[i1][0]) >= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 8 && (arrays2ShortXml[i1][8] / arrays2ShortXml[i1][0]) >= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 9 && (arrays2ShortXml[i1][9] / arrays2ShortXml[i1][0]) >= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 10 && (arrays2ShortXml[i1][10] / arrays2ShortXml[i1][0]) >= MinimumLevelFilterRandomGroups))
                                                {
                                                    Element elemCopy = (Element)arrays1XmlShortb[i1].clone();
                                                    elemCopy.detach();
                                                    Group.addContent(elemCopy);
                                                }
                                            }
                                            if (AboveUnder == 2)
                                            {
                                                if ((ChoiceFilterNextOOS == 1 && (arrays2ShortXml[i1][1] / arrays2ShortXml[i1][0]) <= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 2 && (arrays2ShortXml[i1][2] / arrays2ShortXml[i1][0]) <= MinimumLevelFilterRandomGroups) || (ChoiceFilterNextOOS == 3 && (arrays2ShortXml[i1][3] / arrays2ShortXml[i1][0]) <= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 4 && (arrays2ShortXml[i1][4] / arrays2ShortXml[i1][0]) <= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 5 && (arrays2ShortXml[i1][5] / arrays2ShortXml[i1][0]) <= MinimumLevelFilterRandomGroups)  ||(ChoiceFilterNextOOS == 6 && (arrays2ShortXml[i1][6] / arrays2ShortXml[i1][0]) <= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 7 && (arrays2ShortXml[i1][7] / arrays2ShortXml[i1][0]) <= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 8 && (arrays2ShortXml[i1][8] / arrays2ShortXml[i1][0]) <= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 9 && (arrays2ShortXml[i1][9] / arrays2ShortXml[i1][0]) <= MinimumLevelFilterRandomGroups) ||(ChoiceFilterNextOOS == 10 && (arrays2ShortXml[i1][10] / arrays2ShortXml[i1][0]) <= MinimumLevelFilterRandomGroups))
                                                {
                                                    Element elemCopy = (Element)arrays1XmlShortb[i1].clone();
                                                    elemCopy.detach();
                                                    Group.addContent(elemCopy);	
                                                }
                                            }
                                        }
                                    }
                                }

                                Groups.addContent(Group);
                                GroupCopy = (Element)Group.clone();
                                if (DatabanksNumber < NbDataBanks){AllGroups.addContent(GroupCopy);}
                                String1 = XMLUtil.elementToString(Groups);

                                if (SignalType == 1)
                                {
                                    FileWriter FilterWriter4 = new FileWriter(OutputPath1 + "Entry Short Building Blocks File sorted by " + StringTemp  +" Of "+ databankName + ".xml" , true);
                                    FilterWriter4.write(String1);
                                    FilterWriter4.close();
                                }
                                else if (SignalType == 2)
                                {
                                    FileWriter FilterWriter4 = new FileWriter(OutputPath1 + "Exit Short Building Blocks File sorted by " + StringTemp  +" Of "+ databankName + ".xml" , true);
                                    FilterWriter4.write(String1);
                                    FilterWriter4.close();
                                }
                                // #endregion 
                            }
                        //#endregion
                    }
                    //#endregion
                
                    if (DatabanksNumber == (NbDataBanks - 1) && SignalType == 2)
                    {
                        FileWriter FilterWriter4 = new FileWriter(OutputPath1 + "All Building Blocks File.xml" , true);
                        String String100 = XMLUtil.elementToString(AllGroups);
                        FilterWriter4.write(String100);
                        FilterWriter4.close();
                    }
                }
            }
            return databankRG;  
        }
        catch (Exception e) 																																																			//IOException
        {
            Log.error("Error RankStratsParametersV1", e);
            return databankRG;  
        }
    }

       //------------------------------------------------------------------------
    /**
     * creates a Portfolio result from all the existing sub-results in the ResultsGroup
     * This is function from standard SQ library, with only exception that this works
     * also on WF results - standard ResultsGroup.createPortfolioResult()
     * ignores WF results when creating portfolio.
     *
     * @param portfolioRG
     * @throws Exception
     */
    public void createPortfolioResult(ResultsGroup portfolioRG) throws Exception 
    {
        Result firstResult = null;
        String tf = null;
        int resultsInPortfolio = 0;
        // go through all existing sub-results and get their initial capital and from-to dates
        for(String existingResultKey : portfolioRG.getResultKeys()) {
            Result result = portfolioRG.subResult(existingResultKey);
            resultsInPortfolio++;
            if(firstResult == null) {
                firstResult = result;
            }
        }
        if(resultsInPortfolio <= 1) 
        {
            throw new Exception("ResultGroup doesn't contain more Results, cannot create a portfolio!");
        }
        if(firstResult == null) 
        {
            throw new Exception("No Result in ResultGroup to create portfolio!");
        }
        SettingsMap settings = firstResult.getSettings();
        Result portfolioResult = new Result(ResultsGroup.Portfolio, portfolioRG, settings);
        portfolioRG.removeSubresult(ResultsGroup.Portfolio, true);
        portfolioRG.addSubresult(ResultsGroup.Portfolio, settings, portfolioResult);
        portfolioRG.specialValues().setString(SpecialValues.Symbol, ResultsGroup.Portfolio);
        portfolioRG.specialValues().setString(SpecialValues.Timeframe, "N/A");
        // for portfolio sort orders by their open time
        OrdersList ordersList = portfolioRG.orders();
        ordersList.sort(new OrderComparatorByOpenTime());
        // compute all metrics on the portfolio
        portfolioResult.computeAllStats(portfolioRG.specialValues(), portfolioRG.getOOS());
    }

    /** create random string for group ID
    * @param numchars
    */ 
    private String getRandomHexString(int numchars)
    {
        Random r = new Random();
        StringBuffer sb = new StringBuffer();
        while(sb.length() < numchars)
        {
           sb.append(Integer.toHexString(r.nextInt()));
          //  sb.append(Integer.toHexString(r.nextInt()));
        }

        return sb.toString().substring(0, numchars);
    }
    // Sources: 
    // https://strategyquant.com/doc/programming-for-sq/changing-strategy-parameters-programmatically/
    // https://strategyquant.com/doc/programming-for-sq/viewing-and-changing-strategy-parameters-version-2/


    // https://strategyquant.com/doc/programming-for-sq/working-with-resultsgroup/
    // https://strategyquant.com/doc/programming-for-sq/example-per-strategy-custom-analysis/
    // https://strategyquant.com/doc/programming-for-sq/save-databank-results-to-db/
    // https://strategyquant.com/sqxapi/com/strategyquant/tradinglib/Databank.html
    // http://www.jdom.org/docs/apidocs/org/jdom2/Element.html
    // https://strategyquant.com/doc/strategyquant/random-groups/
    // https://stackoverflow.com/questions/2430782/alternative-to-a-goto-statement-in-java
    // https://stackoverflow.com/questions/14721397/checking-if-a-string-is-empty-or-null-in-java
    // https://ecomputernotes.com/java/swing/joptionpane

}

 

 

 

Sources :

My name is Emmanuel Bouillant-Evrard, Engineer specialized in Finance. I worked in Research and Development in Finance in USA, Canada and France for 24 years.

 

 

 

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Michael47x
Michael47x
May 19, 2022 12:44 pm

Why would I not build once i.e., P1 Long, P1 Short into db P1 and then use that as base for each P1-P7 sliding retest?

Michael47x
Michael47x
May 19, 2022 10:17 pm

So, I competed my 1st run, taking the top 5 results Entry/Exit, jumping over to Algo Wizard to create separate Random groups for each…. Dude, I’m excited again.
-thank you