Category Other  Published on 28/08/2024

Ctrader Strategie tester V1.13

Description

 *** Update after backtest   ***

Introduction to the cTrader Strategy Tester v1.12 Trading Robot 

The cTrader Strategy Tester v1.12 is an innovative trading robot designed to enhance trading strategies by integrating a multitude of indicators. Its primary objective is to allow traders to test and optimize various strategies by combining different technical analysis parameters.

One of the major advantages of this robot is its ability to export test parameters in CSV format. This feature simplifies result analysis and facilitates comparison between different strategies, offering increased flexibility and accuracy in the decision-making process.

Furthermore, the cTrader Strategy Tester v1.12 is an open-source and collaborative project. As such, it encourages active community participation to continuously improve its features and effectiveness. This collaborative approach allows for the incorporation of best practices and user suggestions to evolve the robot according to the real needs of traders.

In summary, the cTrader Strategy Tester v1.12 is a powerful and adaptable tool for traders looking to refine their strategies through detailed analysis and enriching community collaboration.

Full access is needed because we export CSV results. If you don’t want to use this feature, simply select "None" and disable the exporting process.

Indicators Needed For using it : 
1 . https://ctrader.com/algos/indicators/show/4484/

2. https://ctrader.com/algos/indicators/show/4485/

3. https://ctrader.com/algos/indicators/show/4486/

We are looking for all types of profiles interested in joining the adventure, so if you want to discuss this further, this is the place to do it : 

Telegram group : https://t.me/cTraderStrategyTesterProject

GitHub : https://github.com/YesOrNotCtrader/Ctrader-Stragegy-Tester-Project

 

Enjoy for Free =) 
Previous account here : https://ctrader.com/users/profile/70920
Contact telegram :  https://t.me/nimi012 


/* 
//// End backtest\\\

- Optimisation Fitness Check: X
- CSV Add winrate : X

*/
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.FullAccess)]
    public class CtraderStrategieTesterv11 : Robot
    {
        // DAYS TO TRADE 
        //--------------------------------Export--------------------------------------------------------------//
        [Parameter("Export Data to CSV ?", DefaultValue = true, Group = "===========================================================\nDATA EXPORT\n===========================================================")]
        public bool ExportData { get; set; }
        [Parameter("Data Folder", DefaultValue = "C:\\Users\\User\\Desktop", Group = "===========================================================\nDATA EXPORT\n===========================================================")]
        public string DataDir { get; set; }
        [Parameter("File Name", DefaultValue = EnumFileName.Account_Balance, Group = "===========================================================\nDATA EXPORT\n===========================================================")]
        public EnumFileName FileName { get; set; }
        public enum EnumFileName
        {
            Account_Balance,
            Profit_Factor,
            Drawdown,
            Drawup,
            Consecutive_Win,
            Consecutive_Loss,
        }
        [Parameter("Bars Or Ticks Method", DefaultValue = EnumTicksOrBarsCalculation.Bars, Group = "===========================================================\nMETHOD CALCULATION\n===========================================================")]
        public EnumTicksOrBarsCalculation TicksOrBarsMethod { get; set; }
        public enum EnumTicksOrBarsCalculation
        {
            Bars,
            Ticks
        }

        [Parameter("Monday", DefaultValue = true, Group = "===========================================================\nPERIOD SETTING\n===========================================================\nDay To Trade")]
        public bool Mon { get; set; }
        [Parameter("Tuesday", DefaultValue = true, Group = "===========================================================\nPERIOD SETTING\n===========================================================\nDay To Trade")]
        public bool Tue { get; set; }
        [Parameter("Wednesday", DefaultValue = true, Group = "===========================================================\nPERIOD SETTING\n===========================================================\nDay To Trade")]
        public bool Wed { get; set; }
        [Parameter("Thuesday", DefaultValue = true, Group = "===========================================================\nPERIOD SETTING\n===========================================================\nDay To Trade")]
        public bool Thu { get; set; }
        [Parameter("Friday", DefaultValue = true, Group = "===========================================================\nPERIOD SETTING\n===========================================================\nDay To Trade")]
        public bool Fri { get; set; }
        [Parameter("Saturday", DefaultValue = true, Group = "===========================================================\nPERIOD SETTING\n===========================================================\nDay To Trade")]
        public bool Sat { get; set; }
        [Parameter("Sunday", DefaultValue = true, Group = "===========================================================\nPERIOD SETTING\n===========================================================\nDay To Trade")]
        public bool Sun { get; set; }
        //Time TO TRADE 
        [Parameter("Trade Start Hour", DefaultValue = 0, Group = "Time To Trade")]
        public int StartHour { get; set; }
        [Parameter("Trade End Hour", DefaultValue = 24, Group = "Time To Trade")]
        public int EndHour { get; set; }

        //Risk TO TRADE 
        [Parameter("Type", DefaultValue = EnumSelectionRiskType.Perentage_Risk, Group = "===========================================================\nMONNEY MANNAGEMENT\n===========================================================")]
        public EnumSelectionRiskType SelectionRiskType { get; set; }
        public enum EnumSelectionRiskType
        {
            Fixed_Lot,
            Fixed_Volume,
            Perentage_Risk,
        }
        [Parameter("Value", DefaultValue = 1, Group = "===========================================================\nMONNEY MANNAGEMENT\n===========================================================", Step = 0.1)]
        public double RiskValue { get; set; }
        [Parameter("Max Spread ", DefaultValue = 2, Group = "===========================================================\nMONNEY MANNAGEMENT\n===========================================================", Step = 1)]
        public double SpreadMax { get; set; }
        [Parameter("Comission in Pips ", DefaultValue = 1, Group = "===========================================================\nMONNEY MANNAGEMENT\n===========================================================", Step = 0.5)]
        public double ComissionInPips { get; set; }

        [Parameter("Sleeping Strategie", DefaultValue = EnumSleepingStrategie.None, Group = "Sleeping Period")]
        public EnumSleepingStrategie SleepingStrategie { get; set; }
        public enum EnumSleepingStrategie
        {
            On_Loss,
            On_Win,
            On_All,
            None,
        }

        [Parameter("Time Frame Bars", DefaultValue = "Hour", Group = "Sleeping Period")]
        public TimeFrame SleepingPeriodTimeframe { get; set; }
        [Parameter("Numbers Bar To Open New Trade", DefaultValue = 1, Group = "Sleeping Period")]
        public int SleepingPeriodNbrsBars { get; set; }

        //INDICATOR 
        //Baseline Setting
        [Parameter("Time Frame", DefaultValue = "Hour", Group = "###########################################################\n###   STRATEGIE TESTER  #####################################\n###########################################################\n===========================================================\nBASELINE 1\n===========================================================")]
        public TimeFrame Baseline1TimeFrame { get; set; }
        [Parameter("Use it ?", DefaultValue = false, Group = "B1  => Indicator 1 parametter")]
        public bool Baseline1UseP1 { get; set; }
        [Parameter("     BaseLine Indicator", DefaultValue = CSTP_Indi_1Parametter.EnumIndiSelection.Simple_Moving_Average, Group = "B1  => Indicator 1 parametter")]
        public CSTP_Indi_1Parametter.EnumIndiSelection Baseline1IndiSelectionP1 { get; set; }
        [Parameter("     Value1", DefaultValue = 34, Group = "B1  => Indicator 1 parametter", Step = 1)]
        public double Baseline1Value1P1 { get; set; }
        [Parameter("     Signal Type", DefaultValue = EnumSignalOverUnderType.Over_Positive_Under_Negative, Group = "B1  => Indicator 1 parametter")]
        public EnumSignalOverUnderType Baseline1SignalTypeP1 { get; set; }
        public enum EnumSignalOverUnderType
        {
            Over_Positive_Under_Negative,
            Over_Negative_Under_Positive,
        }

        [Parameter("Use it ?", DefaultValue = true, Group = "B1  => Indicator 2 parametter")]
        public bool Baseline1UseP2 { get; set; }
        [Parameter("     BaseLine Indicator", DefaultValue = CSTP_Indi_2Parametter.EnumIndiSelection.SuperTrend, Group = "B1  => Indicator 2 parametter")]
        public CSTP_Indi_2Parametter.EnumIndiSelection Baseline1IndiSelectionP2 { get; set; }
        [Parameter("     Value1", DefaultValue = 55, Group = "B1  => Indicator 2 parametter", Step = 1)]
        public double Baseline1Value1P2 { get; set; }
        [Parameter("     Value2", DefaultValue = 10, Group = "B1  => Indicator 2 parametter", Step = 1)]
        public double Baseline1Value2P2 { get; set; }
        [Parameter("     Signal Type", DefaultValue = EnumSignalOverUnderType.Over_Positive_Under_Negative, Group = "B1  => Indicator 2 parametter")]
        public EnumSignalOverUnderType Baseline1SignalTypeP2 { get; set; }

        [Parameter("Use it ?", DefaultValue = false, Group = "B1  => Indicator 4 parametter")]
        public bool Baseline1UseP4 { get; set; }
        [Parameter("     BaseLine Indicator", DefaultValue = CSTP_Indi_4Parametter.EnumIndiSelection.Price_Volume_Trend, Group = "B1  => Indicator 4 parametter")]
        public CSTP_Indi_4Parametter.EnumIndiSelection Baseline1IndiSelectionP4 { get; set; }
        [Parameter("     Value1", DefaultValue = 55, Group = "B1  => Indicator 4 parametter", Step = 1)]
        public double Baseline1Value1P4 { get; set; }
        [Parameter("     Value2", DefaultValue = 55, Group = "B1  => Indicator 4 parametter", Step = 1)]
        public double Baseline1Value2P4 { get; set; }
        [Parameter("     Value3", DefaultValue = 55, Group = "B1  => Indicator 4 parametter", Step = 1)]
        public double Baseline1Value3P4 { get; set; }
        [Parameter("     Moving Average Type", DefaultValue = MovingAverageType.Simple, Group = "B1  => Indicator 4 parametter")]
        public MovingAverageType Baseline1MaTypeP4 { get; set; }
        [Parameter("     Signal Type", DefaultValue = EnumSignalDoubleOverUnderType.Over_Signal_Positive_Or_Under_Negative, Group = "B1  => Indicator 4 parametter")]
        public EnumSignalDoubleOverUnderType Baseline1SignalTypeP4 { get; set; }
        public enum EnumSignalDoubleOverUnderType
        {
            oO_1_Condition_Oo,
            __________________,
            Over_Level_Positive_Or_Under_Negative,
            Over_Level_Negative_Or_Under_Positive,
            Over_Signal_Positive_Or_Under_Negative,
            Over_Signal_Negative_Or_Under_Positive,

            Over_Level_Valid_Or_Under_Invalid,
            Over_Level_Invalid_Or_Under_Valid,
            Over_Signal_Valid_Or_Under_Invalid,
            Over_Signal_Invalid_Or_Under_Valid,
            _________________,
            oO_2_Condition_Oo,
            ___________________,
            Over_Level_And_Signal_Positive_Or_Under_Negative,
            Over_Level_And_Signal_Negative_Or_Under_Positive,
            Over_Level_And_Under_Signal_Positive_Or_Under_Level_And_Over_Signal_Negative,
            Over_Level_And_Under_Signal_Negative_Or_Under_Level_And_Over_Signal_Positive,
            Over_Level_And_Signal_Valid_Or_Under_Invalid,
            Over_Level_And_Signal_Invalid_Or_Under_Valid,
        }
        [Parameter("     Level Buy", DefaultValue = 50, Group = "B1  => Indicator 4 parametter", Step = 1)]
        public double Baseline1LevelBuyP4 { get; set; }
        [Parameter("     Level Sell", DefaultValue = 50, Group = "B1  => Indicator 4 parametter", Step = 1)]
        public double Baseline1LevelSellP4 { get; set; }

        //Entry Setting 
        [Parameter("Time Frame", DefaultValue = "Hour", Group = "\n===========================================================\nENTRY 1\n===========================================================")]
        public TimeFrame Entry1TimeFrame { get; set; }

        [Parameter("Use it ?", DefaultValue = false, Group = "E1  => Indicator 1 parametter")]
        public bool Entry1UseP1 { get; set; }
        [Parameter("     Entry Indicator", DefaultValue = CSTP_Indi_1Parametter.EnumIndiSelection.Simple_Moving_Average, Group = "E1  => Indicator 1 parametter")]
        public CSTP_Indi_1Parametter.EnumIndiSelection Entry1IndiSelectionP1 { get; set; }
        [Parameter("     Value1", DefaultValue = 13, Group = "E1  => Indicator 1 parametter", Step = 1)]
        public double Entry1Value1P1 { get; set; }
        [Parameter("     Signal Type", DefaultValue = EnumSignalCrossType.Cross_On_Signal, Group = "E1  => Indicator 1 parametter")]
        public EnumSignalCrossType Entry1SignalTypeP1 { get; set; }
        [Parameter("     LookBack Min", DefaultValue = 2, MinValue = 1, Group = "E1  => Indicator 1 parametter", Step = 1)]
        public int Entry1LookBackMinP1 { get; set; }

        [Parameter("Use it ?", DefaultValue = false, Group = "E1  => Indicator 2 parametter")]
        public bool Entry1UseP2 { get; set; }
        [Parameter("     BaseLine Indicator", DefaultValue = CSTP_Indi_2Parametter.EnumIndiSelection.SuperTrend, Group = "E1  => Indicator 2 parametter")]
        public CSTP_Indi_2Parametter.EnumIndiSelection Entry1IndiSelectionP2 { get; set; }
        [Parameter("     Value1", DefaultValue = 55, Group = "E1  => Indicator 2 parametter", Step = 1)]
        public double Entry1Value1P2 { get; set; }
        [Parameter("     Value2", DefaultValue = 10, Group = "E1  => Indicator 2 parametter", Step = 1)]
        public double Entry1Value2P2 { get; set; }
        [Parameter("     Signal Type", DefaultValue = EnumSignalCrossType.Cross_On_Signal, Group = "E1  => Indicator 2 parametter")]
        public EnumSignalCrossType Entry1SignalTypeP2 { get; set; }
        [Parameter("     LookBack Min", DefaultValue = 2, MinValue = 1, Group = "E1  => Indicator 2 parametter", Step = 1)]
        public int Entry1LookBackMinP2 { get; set; }

        [Parameter("Use it ?", DefaultValue = true, Group = "E1  => Indicator 4 parametter")]
        public bool Entry1UseP4 { get; set; }
        [Parameter("     Entry Indicator", DefaultValue = CSTP_Indi_4Parametter.EnumIndiSelection.Relative_Strength_Index, Group = "E1  => Indicator 4 parametter")]
        public CSTP_Indi_4Parametter.EnumIndiSelection Entry1IndiSelectionP4 { get; set; }
        [Parameter("     Value1", DefaultValue = 13, Group = "E1  => Indicator 4 parametter", Step = 1)]
        public double Entry1Value1P4 { get; set; }
        [Parameter("     Value2", DefaultValue = 1, Group = "E1  => Indicator 4 parametter", Step = 1)]
        public double Entry1Value2P4 { get; set; }
        [Parameter("     Value2", DefaultValue = 9, Group = "E1  => Indicator 4 parametter", Step = 1)]
        public double Entry1Value3P4 { get; set; }
        [Parameter("     Moving Average Type", DefaultValue = MovingAverageType.Simple, Group = "E1  => Indicator 4 parametter")]
        public MovingAverageType Entry1MaTypeP4 { get; set; }
        [Parameter("     Signal Type", DefaultValue = EnumSignalCrossType.Cross_On_Level, Group = "E1  => Indicator 4 parametter")]
        public EnumSignalCrossType Entry1SignalTypeP4 { get; set; }
        public enum EnumSignalCrossType
        {
            Cross_On_Level,
            Cross_On_Signal,
            Cross_On_Signal_And_Level,
            Cross_On_Level_And_Signal,
        }
        [Parameter("     Level Buy", DefaultValue = 30, Group = "E1  => Indicator 4 parametter", Step = 1)]
        public double Entry1LevelBuyP4 { get; set; }
        [Parameter("     Level Sell", DefaultValue = 70, Group = "E1  => Indicator 4 parametter", Step = 1)]
        public double Entry1LevelSellP4 { get; set; }
        [Parameter("     LookBack Min", DefaultValue = 1, MinValue = 1, Group = "E1  => Indicator 4 parametter", Step = 1)]
        public int Entry1LookBackMinP4 { get; set; }

        //Confirmation Setting
        [Parameter("Time Frame", DefaultValue = "Hour", Group = "\n===========================================================\nConfirmation 1\n===========================================================")]
        public TimeFrame Confirmation1TimeFrame { get; set; }

        [Parameter("Use it ?", DefaultValue = false, Group = "C1  => Indicator 1 parametter")]
        public bool Confirmation1UseP1 { get; set; }
        [Parameter("     BaseLine Indicator", DefaultValue = CSTP_Indi_1Parametter.EnumIndiSelection.Simple_Moving_Average, Group = "C1  => Indicator 1 parametter")]
        public CSTP_Indi_1Parametter.EnumIndiSelection Confirmation1IndiSelectionP1 { get; set; }
        [Parameter("     Value1", DefaultValue = 34, Group = "C1  => Indicator 1 parametter", Step = 1)]
        public double Confirmation1Value1P1 { get; set; }
        [Parameter("     Signal Type", DefaultValue = EnumSignalOverUnderType.Over_Positive_Under_Negative, Group = "C1  => Indicator 1 parametter")]
        public EnumSignalOverUnderType Confirmation1SignalTypeP1 { get; set; }

        [Parameter("Use it ?", DefaultValue = false, Group = "C1  => Indicator 2 parametter")]
        public bool Confirmation1UseP2 { get; set; }
        [Parameter("     BaseLine Indicator", DefaultValue = CSTP_Indi_2Parametter.EnumIndiSelection.SuperTrend, Group = "C1  => Indicator 2 parametter")]
        public CSTP_Indi_2Parametter.EnumIndiSelection Confirmation1IndiSelectionP2 { get; set; }
        [Parameter("     Value1", DefaultValue = 55, Group = "C1  => Indicator 2 parametter", Step = 1)]
        public double Confirmation1Value1P2 { get; set; }
        [Parameter("     Value2", DefaultValue = 10, Group = "C1  => Indicator 2 parametter", Step = 1)]
        public double Confirmation1Value2P2 { get; set; }
        [Parameter("     Signal Type", DefaultValue = EnumSignalOverUnderType.Over_Positive_Under_Negative, Group = "C1  => Indicator 2 parametter")]
        public EnumSignalOverUnderType Confirmation1SignalTypeP2 { get; set; }

        [Parameter("Use it ?", DefaultValue = false, Group = "C1  => Indicator 4 parametter")]
        public bool Confirmation1UseP4 { get; set; }
        [Parameter("     Entry Indicator", DefaultValue = CSTP_Indi_4Parametter.EnumIndiSelection.Price_Volume_Trend, Group = "C1  => Indicator 4 parametter")]
        public CSTP_Indi_4Parametter.EnumIndiSelection Confirmation1IndiSelectionP4 { get; set; }
        [Parameter("     Value1", DefaultValue = 26, Group = "C1  => Indicator 4 parametter", Step = 1)]
        public double Confirmation1Value1P4 { get; set; }
        [Parameter("     Value2", DefaultValue = 12, Group = "C1  => Indicator 4 parametter", Step = 1)]
        public double Confirmation1Value2P4 { get; set; }
        [Parameter("     Value3", DefaultValue = 9, Group = "C1  => Indicator 4 parametter", Step = 1)]
        public double Confirmation1Value3P4 { get; set; }
        [Parameter("     Moving Average Type", DefaultValue = MovingAverageType.Exponential, Group = "C1  => Indicator 4 parametter")]
        public MovingAverageType Confirmation1MaTypeP4 { get; set; }
        [Parameter("     Signal Type", DefaultValue = EnumSignalDoubleOverUnderType.Over_Level_And_Signal_Positive_Or_Under_Negative, Group = "C1  => Indicator 4 parametter")]
        public EnumSignalDoubleOverUnderType Confirmation1SignalTypeP4 { get; set; }
        [Parameter("     Level Buy", DefaultValue = 50, Group = "C1  => Indicator 4 parametter", Step = 1)]
        public double Confirmation1LevelBuyP4 { get; set; }
        [Parameter("     Level Sell", DefaultValue = 50, Group = "C1  => Indicator 4 parametter", Step = 1)]
        public double Confirmation1LevelSellP4 { get; set; }
        [Parameter("     LookBack Min", DefaultValue = 1, MinValue = 1, Group = "C1  => Indicator 4 parametter", Step = 1)]
        public int Confirmation1LookBackMinP4 { get; set; }

        //Volume Setting
        [Parameter("Time Frame", DefaultValue = "Hour", Group = "\n===========================================================\nVolume 1\n===========================================================")]
        public TimeFrame Volume1TimeFrame { get; set; }

        [Parameter("Use it ?", DefaultValue = false, Group = "V1  => Indicator 4 parametter")]
        public bool Volume1UseP4 { get; set; }
        [Parameter("     Entry Indicator", DefaultValue = CSTP_Indi_4Parametter.EnumIndiSelection.Price_Volume_Trend, Group = "V1  => Indicator 4 parametter")]
        public CSTP_Indi_4Parametter.EnumIndiSelection Volume1IndiSelectionP4 { get; set; }
        [Parameter("     Value1", DefaultValue = 26, Group = "V1  => Indicator 4 parametter", Step = 1)]
        public double Volume1Value1P4 { get; set; }
        [Parameter("     Value2", DefaultValue = 12, Group = "V1  => Indicator 4 parametter", Step = 1)]
        public double Volume1Value2P4 { get; set; }
        [Parameter("     Value2", DefaultValue = 9, Group = "V1  => Indicator 4 parametter", Step = 1)]
        public double Volume1Value3P4 { get; set; }
        [Parameter("     Moving Average Type", DefaultValue = MovingAverageType.Exponential, Group = "V1  => Indicator 4 parametter")]
        public MovingAverageType Volume1MaTypeP4 { get; set; }
        [Parameter("     Signal Type", DefaultValue = EnumSignalDoubleOverUnderType.Over_Signal_Positive_Or_Under_Negative, Group = "V1  => Indicator 4 parametter")]
        public EnumSignalDoubleOverUnderType Volume1SignalTypeP4 { get; set; }
        [Parameter("     Level Buy", DefaultValue = 50, Group = "V1  => Indicator 4 parametter", Step = 1)]
        public double Volume1LevelBuyP4 { get; set; }
        [Parameter("     Level Sell", DefaultValue = 50, Group = "V1  => Indicator 4 parametter", Step = 1)]
        public double Volume1LevelSellP4 { get; set; }
        [Parameter("     LookBack Min", DefaultValue = 1, MinValue = 1, Group = "V1  => Indicator 4 parametter", Step = 1)]
        public int Volume1LookBackMinP4 { get; set; }

        [Parameter("Use it ?", DefaultValue = false, Group = "V2  => Indicator 4 parametter")]
        public bool Volume2UseP4 { get; set; }
        [Parameter("     Entry Indicator", DefaultValue = CSTP_Indi_4Parametter.EnumIndiSelection.Price_Volume_Trend, Group = "V2  => Indicator 4 parametter")]
        public CSTP_Indi_4Parametter.EnumIndiSelection Volume2IndiSelectionP4 { get; set; }
        [Parameter("     Value1", DefaultValue = 26, Group = "V2  => Indicator 4 parametter", Step = 1)]
        public double Volume2Value1P4 { get; set; }
        [Parameter("     Value2", DefaultValue = 12, Group = "V2  => Indicator 4 parametter", Step = 1)]
        public double Volume2Value2P4 { get; set; }
        [Parameter("     Value2", DefaultValue = 9, Group = "V2  => Indicator 4 parametter", Step = 1)]
        public double Volume2Value3P4 { get; set; }
        [Parameter("     Moving Average Type", DefaultValue = MovingAverageType.Exponential, Group = "V2  => Indicator 4 parametter")]
        public MovingAverageType Volume2MaTypeP4 { get; set; }
        [Parameter("     Signal Type", DefaultValue = EnumSignalDoubleOverUnderType.Over_Signal_Positive_Or_Under_Negative, Group = "V2  => Indicator 4 parametter")]
        public EnumSignalDoubleOverUnderType Volume2SignalTypeP4 { get; set; }
        [Parameter("     Level Buy", DefaultValue = 50, Group = "V2  => Indicator 4 parametter", Step = 1)]
        public double Volume2LevelBuyP4 { get; set; }
        [Parameter("     Level Sell", DefaultValue = 50, Group = "V2  => Indicator 4 parametter", Step = 1)]
        public double Volume2LevelSellP4 { get; set; }
        [Parameter("     LookBack Min", DefaultValue = 1, MinValue = 1, Group = "V2  => Indicator 4 parametter", Step = 1)]
        public int Volume2LookBackMinP4 { get; set; }

        [Parameter("Use it ?", DefaultValue = false, Group = "V3  => Indicator 4 parametter")]
        public bool Volume3UseP4 { get; set; }
        [Parameter("     Entry Indicator", DefaultValue = CSTP_Indi_4Parametter.EnumIndiSelection.Price_Volume_Trend, Group = "V3  => Indicator 4 parametter")]
        public CSTP_Indi_4Parametter.EnumIndiSelection Volume3IndiSelectionP4 { get; set; }
        [Parameter("     Value1", DefaultValue = 26, Group = "V3  => Indicator 4 parametter", Step = 1)]
        public double Volume3Value1P4 { get; set; }
        [Parameter("     Value2", DefaultValue = 12, Group = "V3  => Indicator 4 parametter", Step = 1)]
        public double Volume3Value2P4 { get; set; }
        [Parameter("     Value2", DefaultValue = 9, Group = "V3  => Indicator 4 parametter", Step = 1)]
        public double Volume3Value3P4 { get; set; }
        [Parameter("     Moving Average Type", DefaultValue = MovingAverageType.Exponential, Group = "V3  => Indicator 4 parametter")]
        public MovingAverageType Volume3MaTypeP4 { get; set; }
        [Parameter("     Signal Type", DefaultValue = EnumSignalDoubleOverUnderType.Over_Signal_Positive_Or_Under_Negative, Group = "V3  => Indicator 4 parametter")]
        public EnumSignalDoubleOverUnderType Volume3SignalTypeP4 { get; set; }
        [Parameter("     Level Buy", DefaultValue = 50, Group = "V3  => Indicator 4 parametter", Step = 1)]
        public double Volume3LevelBuyP4 { get; set; }
        [Parameter("     Level Sell", DefaultValue = 50, Group = "V3  => Indicator 4 parametter", Step = 1)]
        public double Volume3LevelSellP4 { get; set; }
        [Parameter("     LookBack Min", DefaultValue = 1, MinValue = 1, Group = "V3  => Indicator 4 parametter", Step = 1)]
        public int Volume3LookBackMinP4 { get; set; }

        //Exit Setting
        [Parameter("Time Frame", DefaultValue = "Hour", Group = "\n===========================================================\nExit 1\n===========================================================")]
        public TimeFrame Exit1TimeFrame { get; set; }
        [Parameter("Stop Loss Type", DefaultValue = EnumExit1IndiType.Atr, Group = "Ex1  => Setting")]
        public EnumExit1IndiType Exit1IndiType { get; set; }
        public enum EnumExit1IndiType
        {
            Sl_TP_Fixed,
            Swing,
            Atr,
            Indicator_1_Parametter,
            Indicator_2_Parametters,
            Indicator_4_Parametters,
        }
        [Parameter("     SL Fixed / Period (Swing/Indicators)", DefaultValue = 10, Group = "Ex1  => Setting", Step = 1)]
        public double Sl { get; set; }
        [Parameter("     Multiplier", DefaultValue = 1.5, Group = "Ex1  => Setting", Step = 0.1)]
        public double SlMultiplier { get; set; }
        [Parameter("     RRR (0 = Disable)", DefaultValue = 2, Group = "Ex1  => Setting", Step = 0.1)]
        public double RRR { get; set; }

        [Parameter("Indicator 1 Parametter", DefaultValue = CSTP_Indi_1Parametter.EnumIndiSelection.Donchian_Middle, Group = "Ex1  => Stop Loss Calculation")]
        public CSTP_Indi_1Parametter.EnumIndiSelection Exit1CalculationSelectionP1 { get; set; }
        [Parameter("     Value1", DefaultValue = 55, Group = "Ex1  => Stop Loss Calculation", Step = 1)]
        public double Exit1CalculationValue1P1 { get; set; }
        [Parameter("Indicator 2 Parametter", DefaultValue = CSTP_Indi_2Parametter.EnumIndiSelection.SuperTrend, Group = "Ex1  => Stop Loss Calculation")]
        public CSTP_Indi_2Parametter.EnumIndiSelection Exit1CalculationSelectionP2 { get; set; }
        [Parameter("     Value1", DefaultValue = 13, Group = "Ex1  => Stop Loss Calculation", Step = 1)]
        public double Exit1CalculationValue1P2 { get; set; }
        [Parameter("     Value2", DefaultValue = 3, Group = "Ex1  => Stop Loss Calculation", Step = 1)]
        public double Exit1CalculationValue2P2 { get; set; }
        [Parameter("Indicator 3 Parametter", DefaultValue = CSTP_Indi_4Parametter.EnumIndiSelection.Average_True_Range, Group = "Ex1  => Stop Loss Calculation")]
        public CSTP_Indi_4Parametter.EnumIndiSelection Exit1CalculationSelectionP4 { get; set; }
        [Parameter("     Value1", DefaultValue = 13, Group = "Ex1  => Stop Loss Calculation", Step = 1)]
        public double Exit1CalculationValue1P4 { get; set; }
        [Parameter("     Value2", DefaultValue = 1, Group = "Ex1  => Stop Loss Calculation", Step = 1)]
        public double Exit1CalculationValue2P4 { get; set; }
        [Parameter("     Value3", DefaultValue = 1, Group = "Ex1  => Stop Loss Calculation", Step = 1)]
        public double Exit1CalculationValue3P4 { get; set; }
        [Parameter("     MaType", DefaultValue = MovingAverageType.Simple, Group = "Ex1  => Stop Loss Calculation")]
        public MovingAverageType Exit1CalculationMaTypeP4 { get; set; }

        [Parameter("Trailling Stop Type", DefaultValue = EnumExit1IndiTraillingType.Indicator_1_Parametter, Group = "Ex1  => Trailling Stop Setting")]
        public EnumExit1IndiTraillingType Exit1TraillingType { get; set; }
        public enum EnumExit1IndiTraillingType
        {
            Indicator_1_Parametter,
            Indicator_2_Parametters,
            Indicator_4_Parametters,
            Standard_Trailling_Stop,
            None,
        }

        [Parameter("     Start on RRR", DefaultValue = 0.3, Group = "Ex1  => Trailling Stop Setting", Step = 0.1)]
        public double Exit1TraillingStart { get; set; }
        [Parameter("Indicator 1 Parametter", DefaultValue = CSTP_Indi_1Parametter.EnumIndiSelection.Donchian_Middle, Group = "Ex1  => Trailling Stop Setting")]
        public CSTP_Indi_1Parametter.EnumIndiSelection Exit1TraillingSelectionP1 { get; set; }
        [Parameter("     Value1", DefaultValue = 55, Group = "Ex1  => Trailling Stop Setting", Step = 1)]
        public double Exit1TraillingValue1P1 { get; set; }
        [Parameter("Indicator 2 Parametter", DefaultValue = CSTP_Indi_2Parametter.EnumIndiSelection.SuperTrend, Group = "Ex1  => Trailling Stop Setting")]
        public CSTP_Indi_2Parametter.EnumIndiSelection Exit1TraillingSelectionP2 { get; set; }
        [Parameter("     Value1", DefaultValue = 13, Group = "Ex1  => Trailling Stop Setting", Step = 1)]
        public double Exit1TraillingValue1P2 { get; set; }
        [Parameter("     Value2", DefaultValue = 3, Group = "Ex1  => Trailling Stop Setting", Step = 1)]
        public double Exit1TraillingValue2P2 { get; set; }
        [Parameter("Indicator 3 Parametter", DefaultValue = CSTP_Indi_4Parametter.EnumIndiSelection.Average_True_Range, Group = "Ex1  => Trailling Stop Setting")]
        public CSTP_Indi_4Parametter.EnumIndiSelection Exit1TraillingSelectionP4 { get; set; }
        [Parameter("     Value1", DefaultValue = 13, Group = "Ex1  => Trailling Stop Setting", Step = 1)]
        public double Exit1TraillingValue1P4 { get; set; }
        [Parameter("     Value2", DefaultValue = 1, Group = "Ex1  => Trailling Stop Setting", Step = 1)]
        public double Exit1TraillingValue2P4 { get; set; }
        [Parameter("     Value3", DefaultValue = 1, Group = "Ex1  => Trailling Stop Setting", Step = 1)]
        public double Exit1TraillingValue3P4 { get; set; }
        [Parameter("     MaType", DefaultValue = MovingAverageType.Simple, Group = "Ex1  => Trailling Stop Setting")]
        public MovingAverageType Exit1TraillingMaTypeP4 { get; set; }


        //--------------------------------Optimisation--------------------------------------------------------------//
        [Parameter("Ratio Win / Loss", DefaultValue = false, Group = "============================================================================\nBACKTEST SETTING\n============================================================================\nGet Fitness Parametters")]
        public bool RatioWin { get; set; }
        [Parameter("Equity Drawdown Max", DefaultValue = false, Group = "============================================================================\nBACKTEST SETTING\n============================================================================\nGet Fitness Parametters")]
        public bool DrawdownEquityMax { get; set; }
        [Parameter("Balance Drawdown Max", DefaultValue = false, Group = "============================================================================\nBACKTEST SETTING\n============================================================================\nGet Fitness Parametters")]
        public bool DrawdownBalanceMax { get; set; }
        [Parameter("Ratio Profi Net", DefaultValue = false, Group = "============================================================================\nBACKTEST SETTING\n============================================================================\nGet Fitness Parametters")]
        public bool RatioProfiNet { get; set; }
        [Parameter("Ratio Tp/Sl", DefaultValue = false, Group = "============================================================================\nBACKTEST SETTING\n============================================================================\nGet Fitness Parametters")]
        public bool RatioTpSl { get; set; }
        [Parameter("Profit Factor", DefaultValue = false, Group = "============================================================================\nBACKTEST SETTING\n============================================================================\nGet Fitness Parametters")]
        public bool ProfitFactor { get; set; }
        [Parameter("K ratio Optimisation", DefaultValue = false, Group = "============================================================================\nBACKTEST SETTING\n============================================================================\nGet Fitness Parametters")]
        public bool Kratio { get; set; }
        [Parameter("PROM Optimisation", DefaultValue = false, Group = "============================================================================\nBACKTEST SETTING\n============================================================================\nGet Fitness Parametters")]
        public bool PROM { get; set; }




        //Init indicator
        private CSTP_Indi_1Parametter baseline1P1;
        private CSTP_Indi_2Parametter baseline1P2;
        private CSTP_Indi_4Parametter baseline1P4;

        private CSTP_Indi_1Parametter entry1P1;
        private CSTP_Indi_2Parametter entry1P2;
        private CSTP_Indi_4Parametter entry1P4;

        private CSTP_Indi_1Parametter confirmation1P1;
        private CSTP_Indi_2Parametter confirmation1P2;
        private CSTP_Indi_4Parametter confirmation1P4;

        private CSTP_Indi_4Parametter volume1P4;
        private CSTP_Indi_4Parametter volume2P4;
        private CSTP_Indi_4Parametter volume3P4;

        private CSTP_Indi_1Parametter exit1CalculationP1;
        private CSTP_Indi_2Parametter exit1CalculationP2;
        private CSTP_Indi_4Parametter exit1CalculationP4;

        private CSTP_Indi_1Parametter exit1TraillingP1;
        private CSTP_Indi_2Parametter exit1TraillingP2;
        private CSTP_Indi_4Parametter exit1TraillingP4;

        //SL Function
        private AverageTrueRange atr;
        private bool traillingSL;
        private double traillingSLStart;

        //Base Setting 
        private int barsBack;
        private string botNameLabelBuy;
        private string botNameLabelSell;


        //Sleep Setting 
        private Bars sleepBars;
        private DateTime startSleepPeriod;

        //Statistics Setting 
        private List<List<double>> positionStat;
        private double initialBalance;
        private double drawUpMax, drawDownMax;

        protected override void OnStart()
        {
            //Init indicator
            //baseline
            baseline1P1 = Indicators.GetIndicator<CSTP_Indi_1Parametter>(MarketData.GetBars(Baseline1TimeFrame), Baseline1IndiSelectionP1, Baseline1Value1P1);
            baseline1P2 = Indicators.GetIndicator<CSTP_Indi_2Parametter>(MarketData.GetBars(Baseline1TimeFrame), Baseline1IndiSelectionP2, Baseline1Value1P2, Baseline1Value2P2);
            baseline1P4 = Indicators.GetIndicator<CSTP_Indi_4Parametter>(MarketData.GetBars(Baseline1TimeFrame), Baseline1IndiSelectionP4, Baseline1Value1P4, Baseline1Value2P4, Baseline1Value3P4, Baseline1MaTypeP4);

            //entry                                                                                        
            entry1P1 = Indicators.GetIndicator<CSTP_Indi_1Parametter>(MarketData.GetBars(Entry1TimeFrame), Entry1IndiSelectionP1, Entry1Value1P1);
            entry1P2 = Indicators.GetIndicator<CSTP_Indi_2Parametter>(MarketData.GetBars(Entry1TimeFrame), Entry1IndiSelectionP2, Entry1Value1P2, Entry1Value2P2);
            entry1P4 = Indicators.GetIndicator<CSTP_Indi_4Parametter>(MarketData.GetBars(Entry1TimeFrame), Entry1IndiSelectionP4, Entry1Value1P4, Entry1Value2P4, Entry1Value3P4, Entry1MaTypeP4);

            //confirmation
            confirmation1P1 = Indicators.GetIndicator<CSTP_Indi_1Parametter>(MarketData.GetBars(Confirmation1TimeFrame), Confirmation1IndiSelectionP1, Confirmation1Value1P1);
            confirmation1P2 = Indicators.GetIndicator<CSTP_Indi_2Parametter>(MarketData.GetBars(Confirmation1TimeFrame), Confirmation1IndiSelectionP2, Confirmation1Value1P2, Confirmation1Value2P2);
            confirmation1P4 = Indicators.GetIndicator<CSTP_Indi_4Parametter>(MarketData.GetBars(Confirmation1TimeFrame), Confirmation1IndiSelectionP4, Confirmation1Value1P4, Confirmation1Value2P4, Confirmation1Value3P4, Confirmation1MaTypeP4);

            //volume
            volume1P4 = Indicators.GetIndicator<CSTP_Indi_4Parametter>(MarketData.GetBars(Volume1TimeFrame), Volume1IndiSelectionP4, Volume1Value1P4, Volume1Value2P4, Volume1Value3P4, Volume1MaTypeP4);
            volume2P4 = Indicators.GetIndicator<CSTP_Indi_4Parametter>(MarketData.GetBars(Volume1TimeFrame), Volume2IndiSelectionP4, Volume2Value1P4, Volume2Value2P4, Volume2Value3P4, Volume2MaTypeP4);
            volume3P4 = Indicators.GetIndicator<CSTP_Indi_4Parametter>(MarketData.GetBars(Volume1TimeFrame), Volume3IndiSelectionP4, Volume3Value1P4, Volume3Value2P4, Volume3Value3P4, Volume3MaTypeP4);

            //exit
            exit1CalculationP1 = Indicators.GetIndicator<CSTP_Indi_1Parametter>(MarketData.GetBars(Exit1TimeFrame), Exit1CalculationSelectionP1, Exit1CalculationValue1P1);
            exit1CalculationP2 = Indicators.GetIndicator<CSTP_Indi_2Parametter>(MarketData.GetBars(Exit1TimeFrame), Exit1CalculationSelectionP2, Exit1CalculationValue1P2, Exit1CalculationValue2P2);
            exit1CalculationP4 = Indicators.GetIndicator<CSTP_Indi_4Parametter>(MarketData.GetBars(Exit1TimeFrame), Exit1CalculationSelectionP4, Exit1CalculationValue1P4, Exit1CalculationValue2P4, Exit1CalculationValue3P4, Exit1CalculationMaTypeP4);

            exit1TraillingP1 = Indicators.GetIndicator<CSTP_Indi_1Parametter>(MarketData.GetBars(Exit1TimeFrame), Exit1TraillingSelectionP1, Exit1TraillingValue1P1);
            exit1TraillingP2 = Indicators.GetIndicator<CSTP_Indi_2Parametter>(MarketData.GetBars(Exit1TimeFrame), Exit1TraillingSelectionP2, Exit1TraillingValue1P2, Exit1TraillingValue2P2);
            exit1TraillingP4 = Indicators.GetIndicator<CSTP_Indi_4Parametter>(MarketData.GetBars(Exit1TimeFrame), Exit1TraillingSelectionP4, Exit1TraillingValue1P4, Exit1TraillingValue2P4, Exit1TraillingValue3P4, Exit1TraillingMaTypeP4);

            //exit1Supertrend = Indicators.GetIndicator<ST_SuperTrend>(MarketData.GetBars(Exit1TimeFrame), Exit1SuperTrendPeriod, Exit1SuperTrendPeriodMulti);

            //SL Function
            atr = Indicators.AverageTrueRange(MarketData.GetBars(Exit1TimeFrame), (int)Sl, MovingAverageType.Simple);
            traillingSL = false;
            traillingSLStart = 0.0;
            //Base Setting 
            barsBack = TicksOrBarsMethod == EnumTicksOrBarsCalculation.Ticks ? 0 : 1;
            botNameLabelBuy = SymbolName + " " + "ENTER BUY " + TimeFrame + " " + (Bars.OpenTimes.Last(0).ToLocalTime().ToString());
            botNameLabelSell = SymbolName + " " + "ENTER SELL " + TimeFrame + " " + (Bars.OpenTimes.Last(0).ToLocalTime().ToString());
            Positions.Closed += OnPositionsClosed;


            //Sleep Setting 
            sleepBars = MarketData.GetBars(SleepingPeriodTimeframe); //SleepingPeriodNbrsBars
            startSleepPeriod = Bars.OpenTimes.Last(0).ToLocalTime();

            //Statistics Setting 
            initialBalance = Account.Balance;
            positionStat = new List<List<double>>();
            drawUpMax = 0;
            drawDownMax = 0;

        }
        protected override void OnTick()
        {
            if ((Positions.FindAll(botNameLabelBuy, SymbolName).Length != 0 || Positions.FindAll(botNameLabelSell, SymbolName).Length != 0))
                GetDrawUpDrawDown();
            if (TicksOrBarsMethod == EnumTicksOrBarsCalculation.Ticks)
                Calulate();
        }
        protected override void OnBar()
        {
            if (TicksOrBarsMethod == EnumTicksOrBarsCalculation.Bars)
                Calulate();
        }
        private void Calulate()
        {
            //Check For position before enter -> possible to add parametter with multi position enter


            if (CheckEntryConditions() && Signal(TradeType.Buy) == 1)
                Open(TradeType.Buy, botNameLabelBuy);
            if (CheckEntryConditions() && Signal(TradeType.Sell) == -1)
                Open(TradeType.Sell, botNameLabelSell);

            // Exit
            if (Exit1TraillingType != EnumExit1IndiTraillingType.None)
            {
                //Check For Buy Position before Exit
                if (Positions.FindAll(botNameLabelBuy, SymbolName, TradeType.Buy).Length > 0)
                {
                    if (GetExit1(TradeType.Buy) == -1)
                        Close(TradeType.Buy, botNameLabelBuy);
                }
                //Check For Sell Position before Exit
                if (Positions.FindAll(botNameLabelSell, SymbolName, TradeType.Sell).Length > 0)
                {
                    if (GetExit1(TradeType.Sell) == 1)
                        Close(TradeType.Sell, botNameLabelSell);
                }
            }
        }
        private int Signal(TradeType tradeType)
        {
            // all function to get Signal Enter
            //Print((GetBasline1(tradeType)) + "    " + (GetEntry1(tradeType)) + "    " + (GetConfirmation1(tradeType)) + "    " + (GetVolume1(tradeType)));
            if ((GetBasline1(tradeType) == 1) && (GetEntry1(tradeType) == 1) && (GetConfirmation1(tradeType) == 1) && (GetVolume1(tradeType) == 1))
                return 1;

            else if ((GetBasline1(tradeType) == -1) && (GetEntry1(tradeType) == -1) && (GetConfirmation1(tradeType) == -1) && (GetVolume1(tradeType) == -1))
                return -1;

            else
                return 0;
        }
        private int GetBasline1(TradeType tradeType) // all indicator adding on baseline are implemented here
        {
            var resultBaseline1P = FunctionSignalUnderOver(tradeType, baseline1P1.Result, baseline1P1.Signal, Baseline1SignalTypeP1); // FunctionSignalUnderOver(DataSeries result, DataSeries Signal, EnumSignalOverUnderType signalOverUnder)
            var resultBaseline2P = FunctionSignalUnderOver(tradeType, baseline1P2.Result, baseline1P2.Signal, Baseline1SignalTypeP2); // FunctionSignalUnderOver(DataSeries result, DataSeries Signal, EnumSignalOverUnderType signalOverUnder)
            var resultBaseline4P = FunctionSignalDoubleSignalUnderOver(tradeType, baseline1P4.Result, baseline1P4.Signal, Baseline1SignalTypeP4, Baseline1LevelBuyP4, Baseline1LevelSellP4); // FunctionSignalDoubleSignalUnderOver(DataSeries result, DataSeries signal, EnumSignalDoubleOverUnderType signalOverUnder, double levelBuy, double levelSell)

            // without baseline
            if (!Baseline1UseP1 && !Baseline1UseP2 && !Baseline1UseP4 && tradeType == TradeType.Buy)
                return 1;
            else if (!Baseline1UseP1 && !Baseline1UseP2 && !Baseline1UseP4 && tradeType == TradeType.Sell)
                return -1;
            // with baseline
            else if ((!Baseline1UseP1 || resultBaseline1P == 1) && (!Baseline1UseP2 || resultBaseline2P == 1) && (!Baseline1UseP4 || resultBaseline4P == 1)) // add all variable with this sentence (exemple): (!Volume1MfiUse || resultMfi == 1)
                return 1;
            else if ((!Baseline1UseP1 || resultBaseline1P == -1) && (!Baseline1UseP2 || resultBaseline2P == -1) && (!Baseline1UseP4 || resultBaseline4P == -1))
                return -1;
            else
                return 0;
        }
        private int GetEntry1(TradeType tradeType) // all indicator adding on entry are implemented here
        {
            var resultEntry1P1 = FunctionSignalCrossEnter(tradeType, entry1P1.Result, entry1P1.Signal, Entry1SignalTypeP1, double.NaN, double.NaN, Entry1LookBackMinP1); //FunctionSignalCrossEnter(DataSeries result, DataSeries signal, EnumSignalCrossType signalOverUnder, double levelBuy, double levelSell, int lookBack)
            var resultEntry1P2 = FunctionSignalCrossEnter(tradeType, entry1P2.Result, entry1P2.Signal, Entry1SignalTypeP2, double.NaN, double.NaN, Entry1LookBackMinP2); //FunctionSignalCrossEnter(DataSeries result, DataSeries signal, EnumSignalCrossType signalOverUnder, double levelBuy, double levelSell, int lookBack)
            var resultEntry1P4 = FunctionSignalCrossEnter(tradeType, entry1P4.Result, entry1P4.Signal, Entry1SignalTypeP4, Entry1LevelBuyP4, Entry1LevelSellP4, Entry1LookBackMinP4); //FunctionSignalCrossEnter(DataSeries result, DataSeries signal, EnumSignalCrossType signalOverUnder, double levelBuy, double levelSell, int lookBack)
                                                                                                                                                                                      //Print(resultEntry1P4);
                                                                                                                                                                                      // without Entry
            if (!Entry1UseP1 && !Entry1UseP2 && !Entry1UseP4 && tradeType == TradeType.Buy)
                return 1;
            else if (!Entry1UseP1 && !Entry1UseP2 && !Entry1UseP4 && tradeType == TradeType.Sell)
                return -1;
            // with Entry
            else if ((!Entry1UseP1 || resultEntry1P1 == 1) && (!Entry1UseP2 || resultEntry1P2 == 1) && (!Entry1UseP4 || resultEntry1P4 == 1)) // add all variable with this sentence (exemple): (!Entry1RsiUse || resultRsi == 1)
                return 1;
            else if ((!Entry1UseP1 || resultEntry1P1 == -1) && (!Entry1UseP2 || resultEntry1P2 == -1) && (!Entry1UseP4 || resultEntry1P4 == -1))
                return -1;
            else
                return 0;
        }

        private int GetConfirmation1(TradeType tradeType) // all indicator adding on confirmation are implemented here
        {
            var resultConfirmation1P1 = FunctionSignalUnderOver(tradeType, confirmation1P1.Result, confirmation1P1.Signal, Confirmation1SignalTypeP1); // FunctionSignalUnderOver(DataSeries result, DataSeries Signal, EnumSignalOverUnderType signalOverUnder)
            var resultConfirmation1P2 = FunctionSignalUnderOver(tradeType, confirmation1P2.Result, confirmation1P2.Signal, Confirmation1SignalTypeP2); // FunctionSignalUnderOver(DataSeries result, DataSeries Signal, EnumSignalOverUnderType signalOverUnder)
            var resultConfirmation1P4 = FunctionSignalDoubleSignalUnderOver(tradeType, confirmation1P4.Result, confirmation1P4.Signal, Confirmation1SignalTypeP4, Confirmation1LevelBuyP4, Confirmation1LevelSellP4); //FunctionSignalCross(DataSeries result, DataSeries signal, EnumSignalCrossType signalOverUnder, double levelBuy, double levelSell, int lookBack)

            // without Condirmation
            if (!Confirmation1UseP1 && !Confirmation1UseP2 && !Confirmation1UseP4 && tradeType == TradeType.Buy)
                return 1;
            else if (!Confirmation1UseP1 && !Confirmation1UseP2 && !Confirmation1UseP4 && tradeType == TradeType.Sell) // without Condirmation
                return -1;
            // with Condirmation
            else if ((!Confirmation1UseP1 || resultConfirmation1P1 == 1) && (!Confirmation1UseP2 || resultConfirmation1P2 == 1) && (!Confirmation1UseP4 || resultConfirmation1P4 == 1)) // add all variable with this sentence : (!Confirmation1MacdUse || resultMacd == 1)
                return 1;
            else if ((!Confirmation1UseP1 || resultConfirmation1P1 == -1) && (!Confirmation1UseP2 || resultConfirmation1P2 == -1) && (!Confirmation1UseP4 || resultConfirmation1P4 == -1))
                return -1;
            else
                return 0;
        }

        private int GetVolume1(TradeType tradeType) // all indicator adding on volume are implemented here
        {
            var resultVolume1P4 = FunctionSignalDoubleSignalUnderOver(tradeType, volume1P4.Result, volume1P4.Signal, Volume1SignalTypeP4, Volume1LevelBuyP4, Volume1LevelSellP4); //FunctionSignalCross(DataSeries result, DataSeries signal, EnumSignalCrossType signalOverUnder, double levelBuy, double levelSell, int lookBack)
            var resultVolume2P4 = FunctionSignalDoubleSignalUnderOver(tradeType, volume2P4.Result, volume2P4.Signal, Volume2SignalTypeP4, Volume2LevelBuyP4, Volume2LevelSellP4); //FunctionSignalCross(DataSeries result, DataSeries signal, EnumSignalCrossType signalOverUnder, double levelBuy, double levelSell, int lookBack)
            var resultVolume3P4 = FunctionSignalDoubleSignalUnderOver(tradeType, volume3P4.Result, volume3P4.Signal, Volume3SignalTypeP4, Volume3LevelBuyP4, Volume3LevelSellP4); //FunctionSignalCross(DataSeries result, DataSeries signal, EnumSignalCrossType signalOverUnder, double levelBuy, double levelSell, int lookBack)

            // without Volume
            if (!Volume1UseP4 && !Volume2UseP4 && !Volume3UseP4 && tradeType == TradeType.Buy)
                return 1;
            else if (!Volume1UseP4 && !Volume2UseP4 && !Volume3UseP4 && tradeType == TradeType.Sell) // without Volume
                return -1;
            // with Volume
            else if ((!Volume1UseP4 || resultVolume1P4 == 1) && (!Volume2UseP4 || resultVolume2P4 == 1) && (!Volume3UseP4 || resultVolume3P4 == 1))  // add all variable with this sentence : (!Volume1MfiUse || resultMfi == 1)
                return 1;
            else if ((!Volume1UseP4 || resultVolume1P4 == -1) && (!Volume2UseP4 || resultVolume2P4 == -1) && (!Volume3UseP4 || resultVolume3P4 == -1))
                return -1;
            else
                return 0;
        }

        private int GetExit1(TradeType tradeType) // all indicator adding on exit are implemented here
        {
            traillingSL = traillingSL ? traillingSL : GetTraillingSL(tradeType);
            if (traillingSL)
            {
                if (Exit1TraillingType == EnumExit1IndiTraillingType.Indicator_1_Parametter)
                {
                    var resultExit1P1 = FunctionCross(exit1TraillingP1.Result, exit1TraillingP1.Signal);

                    //Print(Bars.OpenTimes.Last(0).ToLocalTime() + "  " + traillingSL + " " + GetTraillingSL(tradeType) + "   " + resultExit1P1);

                    if ((resultExit1P1 == 1) && tradeType == TradeType.Sell) // add all variable with this sentence : (!Volume1MfiUse || resultMfi == 1)
                        return 1;
                    else if ((resultExit1P1 == -1) && tradeType == TradeType.Buy)
                        return -1;
                    else
                        return 0;
                }
                if (Exit1TraillingType == EnumExit1IndiTraillingType.Indicator_2_Parametters)
                {
                    var resultExit1P2 = FunctionCross(exit1TraillingP2.Result, exit1TraillingP2.Signal);
                    if ((resultExit1P2 == 1) && tradeType == TradeType.Sell) // add all variable with this sentence : (!Volume1MfiUse || resultMfi == 1)
                        return 1;
                    else if ((resultExit1P2 == -1) && tradeType == TradeType.Buy)
                        return -1;
                    else
                        return 0;
                }
                if (Exit1TraillingType == EnumExit1IndiTraillingType.Indicator_4_Parametters)
                {
                    var resultExit1P2 = FunctionCross(exit1TraillingP4.Result, exit1TraillingP4.Signal);
                    if ((resultExit1P2 == 1) && tradeType == TradeType.Sell) // add all variable with this sentence : (!Volume1MfiUse || resultMfi == 1)
                        return 1;
                    else if ((resultExit1P2 == -1) && tradeType == TradeType.Buy)
                        return -1;
                    else
                        return 0;
                }
                else
                    return 0;
            }
            else // Get SL() -> Fixed SL or Swing Sl
                return 0;

        }

        // FUNCTION FOR SIGNAL -> need backtest and finding if other conditions need to be add
        // Confirmation Type Function
        private int FunctionSignalUnderOver(TradeType tradeType, DataSeries result, DataSeries Signal, EnumSignalOverUnderType signalOverUnder)
        {
            if (signalOverUnder == EnumSignalOverUnderType.Over_Positive_Under_Negative)
            {
                if (tradeType == TradeType.Buy && result.Last(barsBack) > Signal.Last(barsBack))
                    return 1;
                else if (tradeType == TradeType.Sell && result.Last(barsBack) < Signal.Last(barsBack))
                    return -1;
                else
                    return 0;
            }
            else // Over_Negative_Under_Positive
            {
                if (tradeType == TradeType.Buy && result.Last(barsBack) < Signal.Last(barsBack))
                    return 1;
                else if (tradeType == TradeType.Sell && result.Last(barsBack) > Signal.Last(barsBack))
                    return -1;
                else
                    return 0;
            }
        }
        // Confirmation Type Function
        private int FunctionSignalDoubleSignalUnderOver(TradeType tradeType, DataSeries result, DataSeries signal, EnumSignalDoubleOverUnderType signalOverUnder, double levelBuy, double levelSell)
        {
            if (signalOverUnder == EnumSignalDoubleOverUnderType.Over_Level_Positive_Or_Under_Negative)
            {
                if (tradeType == TradeType.Buy && result.Last(barsBack) > levelBuy)
                    return 1;
                else if (tradeType == TradeType.Sell && result.Last(barsBack) < levelSell)
                    return -1;
                else
                    return 0;
            }
            else if (signalOverUnder == EnumSignalDoubleOverUnderType.Over_Level_Negative_Or_Under_Positive)
            {
                if (tradeType == TradeType.Buy && result.Last(barsBack) < levelBuy)
                    return 1;
                else if (tradeType == TradeType.Sell && result.Last(barsBack) > levelSell)
                    return -1;
                else
                    return 0;
            }
            else if (signalOverUnder == EnumSignalDoubleOverUnderType.Over_Signal_Positive_Or_Under_Negative)
            {
                if (tradeType == TradeType.Buy && result.Last(barsBack) > signal.Last(barsBack))
                    return 1;
                else if (tradeType == TradeType.Sell && result.Last(barsBack) < signal.Last(barsBack))
                    return -1;
                else
                    return 0;
            }
            else if (signalOverUnder == EnumSignalDoubleOverUnderType.Over_Signal_Negative_Or_Under_Positive)
            {
                if (tradeType == TradeType.Buy && result.Last(barsBack) < signal.Last(barsBack))
                    return 1;
                else if (tradeType == TradeType.Sell && result.Last(barsBack) > signal.Last(barsBack))
                    return -1;
                else
                    return 0;
            }
            else if (signalOverUnder == EnumSignalDoubleOverUnderType.Over_Level_Valid_Or_Under_Invalid)
            {
                if (tradeType == TradeType.Buy && result.Last(barsBack) > levelBuy)
                    return 1;
                else if (tradeType == TradeType.Sell && result.Last(barsBack) > levelSell)
                    return -1;
                else
                    return 0;
            }
            else if (signalOverUnder == EnumSignalDoubleOverUnderType.Over_Level_Invalid_Or_Under_Valid)
            {
                if (tradeType == TradeType.Buy && result.Last(barsBack) < levelBuy)
                    return 1;
                else if (tradeType == TradeType.Sell && result.Last(barsBack) < levelSell)
                    return -1;
                else
                    return 0;
            }
            else if (signalOverUnder == EnumSignalDoubleOverUnderType.Over_Signal_Valid_Or_Under_Invalid)
            {
                if (tradeType == TradeType.Buy && result.Last(barsBack) > signal.Last(barsBack))
                    return 1;
                else if (tradeType == TradeType.Sell && result.Last(barsBack) > signal.Last(barsBack))
                    return -1;
                else
                    return 0;
            }
            else if (signalOverUnder == EnumSignalDoubleOverUnderType.Over_Signal_Invalid_Or_Under_Valid)
            {
                if (tradeType == TradeType.Buy && result.Last(barsBack) < signal.Last(barsBack))
                    return 1;
                else if (tradeType == TradeType.Sell && result.Last(barsBack) < signal.Last(barsBack))
                    return -1;
                else
                    return 0;
            }
            else if (signalOverUnder == EnumSignalDoubleOverUnderType.Over_Level_And_Signal_Positive_Or_Under_Negative)
            {
                if (tradeType == TradeType.Buy && result.Last(barsBack) > levelBuy && result.Last(barsBack) > signal.Last(barsBack))
                    return 1;
                else if (tradeType == TradeType.Sell && result.Last(barsBack) < levelSell && result.Last(barsBack) < signal.Last(barsBack))
                    return -1;
                else
                    return 0;
            }
            else if (signalOverUnder == EnumSignalDoubleOverUnderType.Over_Level_And_Signal_Negative_Or_Under_Positive)
            {
                if (tradeType == TradeType.Buy && result.Last(barsBack) < levelBuy && result.Last(barsBack) < signal.Last(barsBack))
                    return 1;
                else if (tradeType == TradeType.Sell && result.Last(barsBack) > levelSell && result.Last(barsBack) > signal.Last(barsBack))
                    return -1;
                else
                    return 0;
            }
            else if (signalOverUnder == EnumSignalDoubleOverUnderType.Over_Level_And_Under_Signal_Positive_Or_Under_Level_And_Over_Signal_Negative)
            {
                if (tradeType == TradeType.Buy && result.Last(barsBack) > levelBuy && result.Last(barsBack) < signal.Last(barsBack))
                    return 1;
                else if (tradeType == TradeType.Sell && result.Last(barsBack) < levelSell && result.Last(barsBack) > signal.Last(barsBack))
                    return -1;
                else
                    return 0;
            }
            else if (signalOverUnder == EnumSignalDoubleOverUnderType.Over_Level_And_Under_Signal_Negative_Or_Under_Level_And_Over_Signal_Positive)
            {
                if (tradeType == TradeType.Buy && result.Last(barsBack) < levelBuy && result.Last(barsBack) > signal.Last(barsBack))
                    return 1;
                else if (tradeType == TradeType.Sell && result.Last(barsBack) > levelSell && result.Last(barsBack) < signal.Last(barsBack))
                    return -1;
                else
                    return 0;
            }
            else if (signalOverUnder == EnumSignalDoubleOverUnderType.Over_Level_And_Signal_Valid_Or_Under_Invalid)
            {
                if (tradeType == TradeType.Buy && result.Last(barsBack) > levelBuy && result.Last(barsBack) > signal.Last(barsBack))
                    return 1;
                else if (tradeType == TradeType.Sell && result.Last(barsBack) > levelSell && result.Last(barsBack) > signal.Last(barsBack))
                    return -1;
                else
                    return 0;
            }
            else if (signalOverUnder == EnumSignalDoubleOverUnderType.Over_Level_And_Signal_Invalid_Or_Under_Valid)
            {
                if (tradeType == TradeType.Buy && result.Last(barsBack) < levelBuy && result.Last(barsBack) < signal.Last(barsBack))
                    return 1;
                else if (tradeType == TradeType.Sell && result.Last(barsBack) < levelSell && result.Last(barsBack) < signal.Last(barsBack))
                    return -1;
                else
                    return 0;
            }
            else
                return 0;
        }
        // Real Enter Type Function -> min and max for having possibility to find range period with Multiple signal (Maybe need a special function) it work but it's not good When I think about it. (result.Minimum(lookBack + 1) <= signal.Last(2) && result.Last(1) > signal.Last(1))
        private int FunctionSignalCrossEnter(TradeType tradeType, DataSeries result, DataSeries signal, EnumSignalCrossType signalOverUnder, double levelBuy, double levelSell, int lookBack)
        {
            if (signalOverUnder == EnumSignalCrossType.Cross_On_Level)
            {
                //Print(result.Minimum((lookBack + barsBack)) + "             " + Bars.OpenTimes.Last(0));
                if (tradeType == TradeType.Buy && GetMinimum(result, (lookBack + barsBack)) <= levelBuy && result.Last(barsBack) > levelBuy)
                    return 1;
                else if (tradeType == TradeType.Sell && GetMaximum(result, (lookBack + barsBack)) >= levelSell && result.Last(barsBack) < levelSell)
                    return -1;
                else
                    return 0;
            }
            else if (signalOverUnder == EnumSignalCrossType.Cross_On_Signal)
            {
                if (tradeType == TradeType.Buy && GetSignalLookbackBuy(result, signal, lookBack + barsBack) && result.Last(barsBack) > signal.Last(barsBack))
                    return 1;
                else if (tradeType == TradeType.Sell && GetSignalLookbackSell(result, signal, lookBack + barsBack) && result.Last(barsBack) < signal.Last(barsBack))
                    return -1;
                else
                    return 0;
            }
            else if (signalOverUnder == EnumSignalCrossType.Cross_On_Level_And_Signal)
            {
                if (tradeType == TradeType.Buy && GetMinimum(result, (lookBack + barsBack)) <= levelBuy && result.Last(barsBack) > levelBuy && result.Last(barsBack) > signal.Last(barsBack))
                    return 1;
                else if (tradeType == TradeType.Sell && GetMaximum(result, (lookBack + barsBack)) >= levelSell && result.Last(barsBack) < levelSell && result.Last(barsBack) < signal.Last(barsBack))
                    return -1;
                else
                    return 0;
            }
            else // Cross_On_Signal_And_Level
            {
                if (tradeType == TradeType.Buy && GetSignalLookbackBuy(result, signal, lookBack + barsBack) && result.Last(barsBack) > signal.Last(barsBack) && result.Last(barsBack) < levelBuy)
                    return 1;
                else if (tradeType == TradeType.Sell && GetSignalLookbackSell(result, signal, lookBack + barsBack) && result.Last(barsBack) < signal.Last(barsBack) && result.Last(barsBack) > levelSell)
                    return -1;
                else
                    return 0;
            }
        }
        private bool GetSignalLookbackBuy(DataSeries result, DataSeries signal, int lookBack)  // -> test if more faster than result.Maximum(lookBack +1)
        {
            for (int i = 1; i <= lookBack; i++)
            {
                if (result.Last(i) < signal.Last(i))
                    return true;

            }
            return false;
        }
        private bool GetSignalLookbackSell(DataSeries result, DataSeries signal, int lookBack)  // -> test if more faster than result.Maximum(lookBack +1)
        {
            for (int i = 1; i <= lookBack; i++)
            {
                if (result.Last(i) > signal.Last(i))
                    return true;
            }
            return false;
        }
        private double GetMaximum(DataSeries result, int lookBack)  // -> test if more faster than result.Maximum(lookBack +1)
        {
            var max = double.MinValue;
            for (int i = 1; i <= lookBack; i++)
                max = Math.Max(result.Last(i), max);
            return max;
        }
        private double GetMinimum(DataSeries result, int lookBack)  // -> test if more faster than result.Minimum(lookBack +1)
        {
            var min = double.MaxValue;
            for (int i = 1; i <= lookBack; i++)
                min = Math.Min(result.Last(i), min);
            return min;
        }

        // Exit Type Function
        private int FunctionCross(DataSeries result,

YE
YesOrNot2

Joined on 17.05.2024

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Ctrader Strategie Tester v1.13.algo
  • Rating: 0
  • Installs: 314
  • Modified: 31/08/2024 11:33
Comments
Log in to add a comment.
YE
YesOrNot2 · 2 months ago

correction line 921 max by min