My problem "microsoft.visualstudio.windows.forms" could not be found help me to solve this

Created at 14 Feb 2021, 05:07
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
ogima.515@gmail.com's avatar

ogima.515@gmail.com

Joined 23.08.2017

My problem "microsoft.visualstudio.windows.forms" could not be found help me to solve this
14 Feb 2021, 05:07


I have this problem.Can anyone help me.


@ogima.515@gmail.com
Replies

PanagiotisCharalampous
15 Feb 2021, 09:20

Hi there,

Can you share the cBot code that is causing this problem?

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

ogima.515@gmail.com
18 Feb 2021, 11:07 ( Updated at: 18 Feb 2021, 11:18 )

This my cod have problem


          
       
        
           
   


@ogima.515@gmail.com

ogima.515@gmail.com
18 Feb 2021, 11:08

This my cod have problem

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System.Windows.Forms;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class OgimacBotv10 : Robot
    {
        int lockaccount = 0;

        [Parameter("Lot Size", DefaultValue = 0.01, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        [Parameter("Solves Periods", DefaultValue = 48)]
        public int SolvesPeriods { get; set; }

        [Parameter("TP (Pips)", DefaultValue = 10.0, MinValue = 0, Step = 1)]
        public double TP { get; set; }

        [Parameter("SL (Pips)", DefaultValue = 0.0, MinValue = 0, Step = 1)]
        public double SL { get; set; }

        [Parameter("Profit Multiplier", DefaultValue = 15.0, MinValue = 0, Step = 1)]
        public double pf { get; set; }

        [Parameter("Max Spread", DefaultValue = 100.0, MinValue = 0, Step = 1)]
        public double Spread { get; set; }

        [Parameter("Use Trend for Open Positions", DefaultValue = false)]
        public bool TrendEnabled { get; set; }

        [Parameter("Pending Buy", DefaultValue = false)]
        public bool B_orderEnabled { get; set; }

        [Parameter("Pending Sell", DefaultValue = false)]
        public bool S_orderEnabled { get; set; }

        [Parameter("Pending Trend", DefaultValue = false)]
        public bool t_orderEnabled { get; set; }

        [Parameter("Number of Buy Stop Positions", DefaultValue = 2, MinValue = 0, Step = 1)]
        public int BS_order { get; set; }

        [Parameter("Number of Sell Stop Positions", DefaultValue = 2, MinValue = 0, Step = 1)]
        public int SS_order { get; set; }

        [Parameter("Number of Buy Limit Positions", DefaultValue = 2, MinValue = 0, Step = 1)]
        public int BL_order { get; set; }

        [Parameter("Number of Sell Limit Positions", DefaultValue = 2, MinValue = 0, Step = 1)]
        public int SL_order { get; set; }

        [Parameter("First Gap (Pips)", DefaultValue = 2.0, MinValue = 0, Step = 1)]
        public double FG { get; set; }

        [Parameter("Gap Between Positions and TP (Pips)", DefaultValue = 2.0, MinValue = 0, Step = 1)]
        public double GBP { get; set; }

        [Parameter("Distance for Move (Pips)", DefaultValue = 10.0, MinValue = 0, Step = 1)]
        public double DM { get; set; }

        [Parameter("Max Open Positions", DefaultValue = 1, MinValue = 0, Step = 1)]
        public int MaxOrder { get; set; }

        [Parameter("Open Distance Mode", DefaultValue = false)]
        public bool Open_DM { get; set; }

        [Parameter("Open 1", DefaultValue = false)]
        public bool Open1 { get; set; }

        [Parameter("Open 2", DefaultValue = true)]
        public bool Open2 { get; set; }

        [Parameter("Open 3", DefaultValue = false)]
        public bool Open3 { get; set; }

        [Parameter("Close 1", DefaultValue = false)]
        public bool Close1 { get; set; }

        [Parameter("Close 2", DefaultValue = true)]
        public bool Close2 { get; set; }

        [Parameter("Close 3", DefaultValue = false)]
        public bool Close3 { get; set; }

        [Parameter("Close 4", DefaultValue = false)]
        public bool Close4 { get; set; }

        [Parameter("Close Buy Re", DefaultValue = false)]
        public bool Close_BuyRe { get; set; }

        [Parameter("Close Buy Fo", DefaultValue = false)]
        public bool Close_BuyFo { get; set; }

        [Parameter("Close Sell Fo", DefaultValue = false)]
        public bool Close_SellFo { get; set; }

        [Parameter("Close Buy&Sell Fo", DefaultValue = false)]
        public bool Close_BuySellFo { get; set; }

        [Parameter("Close Buy Re&Fo", DefaultValue = false)]
        public bool Close_BuyReFo { get; set; }


        [Parameter("Reversal", DefaultValue = false)]
        public bool ReversalEnabled { get; set; }

        [Parameter("TrendFollow", DefaultValue = false)]
        public bool TrendFollowEnabled { get; set; }

        [Parameter("Max UpRe 1", DefaultValue = 10, MinValue = 0, Step = 1)]
        public int MaxUpReversal1 { get; set; }

        [Parameter("Max UpRe 2", DefaultValue = 10, MinValue = 0, Step = 1)]
        public int MaxUpReversal2 { get; set; }

        [Parameter("Max UpRe 3", DefaultValue = 10, MinValue = 0, Step = 1)]
        public int MaxUpReversal3 { get; set; }

        [Parameter("Max UpRe 4", DefaultValue = 10, MinValue = 0, Step = 1)]
        public int MaxUpReversal4 { get; set; }

        [Parameter("Max UpRe 5", DefaultValue = 10, MinValue = 0, Step = 1)]
        public int MaxUpReversal5 { get; set; }

        [Parameter("Max DownRe 1", DefaultValue = 30, MinValue = 0, Step = 1)]
        public int MaxDownReversal1 { get; set; }

        [Parameter("Max DownRe 2", DefaultValue = 30, MinValue = 0, Step = 1)]
        public int MaxDownReversal2 { get; set; }

        [Parameter("Max DownRe 3", DefaultValue = 30, MinValue = 0, Step = 1)]
        public int MaxDownReversal3 { get; set; }

        [Parameter("Max DownRe 4", DefaultValue = 30, MinValue = 0, Step = 1)]
        public int MaxDownReversal4 { get; set; }

        [Parameter("Max UpTF 1", DefaultValue = 50, MinValue = 0, Step = 1)]
        public int MaxUpTrendFollow1 { get; set; }

        [Parameter("Max UpTF 2", DefaultValue = 50, MinValue = 0, Step = 1)]
        public int MaxUpTrendFollow2 { get; set; }

        [Parameter("Max UpTF 3", DefaultValue = 50, MinValue = 0, Step = 1)]
        public int MaxUpTrendFollow3 { get; set; }

        [Parameter("Max UpTF 4", DefaultValue = 50, MinValue = 0, Step = 1)]
        public int MaxUpTrendFollow4 { get; set; }

        [Parameter("Max UpTF 5", DefaultValue = 50, MinValue = 0, Step = 1)]
        public int MaxUpTrendFollow5 { get; set; }

        [Parameter("Max DownTF 1", DefaultValue = 50, MinValue = 0, Step = 1)]
        public int MaxDownTrendFollow1 { get; set; }

        [Parameter("Max DownTF 2", DefaultValue = 50, MinValue = 0, Step = 1)]
        public int MaxDownTrendFollow2 { get; set; }

        [Parameter("Max DownTF 3", DefaultValue = 50, MinValue = 0, Step = 1)]
        public int MaxDownTrendFollow3 { get; set; }

        [Parameter("Max DownTF 4", DefaultValue = 50, MinValue = 0, Step = 1)]
        public int MaxDownTrendFollow4 { get; set; }

        [Parameter("Max DownTF 5", DefaultValue = 50, MinValue = 0, Step = 1)]
        public int MaxDownTrendFollow5 { get; set; }

        [Parameter("LSM for UpRe 1", DefaultValue = 1.5, MinValue = 0, Step = 1)]
        public double Lot_up_r1 { get; set; }

        [Parameter("LSM for UpRe 2", DefaultValue = 0.5, MinValue = 0, Step = 1)]
        public double Lot_up_r2 { get; set; }

        [Parameter("LSM for UpRe 3", DefaultValue = 0.5, MinValue = 0, Step = 1)]
        public double Lot_up_r3 { get; set; }

        [Parameter("LSM for UpRe 4", DefaultValue = 0, MinValue = 0, Step = 1)]
        public double Lot_up_r4 { get; set; }

        [Parameter("LSM for UpRe 5", DefaultValue = 0, MinValue = 0, Step = 1)]
        public double Lot_up_r5 { get; set; }

        [Parameter("LSM for DownRe 1", DefaultValue = 1.5, MinValue = 0, Step = 1)]
        public double Lot_down_r1 { get; set; }

        [Parameter("LSM for DownRe 2", DefaultValue = 0.5, MinValue = 0, Step = 1)]
        public double Lot_down_r2 { get; set; }

        [Parameter("LSM for DownRe 3", DefaultValue = 0.5, MinValue = 0, Step = 1)]
        public double Lot_down_r3 { get; set; }

        [Parameter("LSM for DownRe 4", DefaultValue = 0, MinValue = 0, Step = 1)]
        public double Lot_down_r4 { get; set; }

        [Parameter("LSM for UpTF 1", DefaultValue = 1.5, MinValue = 0, Step = 1)]
        public double Lot_up_f1 { get; set; }

        [Parameter("LSM for UpTF 2", DefaultValue = 0.5, MinValue = 0, Step = 1)]
        public double Lot_up_f2 { get; set; }

        [Parameter("LSM for UpTF 3", DefaultValue = 0.5, MinValue = 0, Step = 1)]
        public double Lot_up_f3 { get; set; }

        [Parameter("LSM for UpTF 4", DefaultValue = 0.5, MinValue = 0, Step = 1)]
        public double Lot_up_f4 { get; set; }

        [Parameter("LSM for UpTF 5", DefaultValue = 0.5, MinValue = 0, Step = 1)]
        public double Lot_up_f5 { get; set; }

        [Parameter("LSM for DownTF 1", DefaultValue = 1.5, MinValue = 0, Step = 1)]
        public double Lot_down_f1 { get; set; }

        [Parameter("LSM for DownTF 2", DefaultValue = 0.5, MinValue = 0, Step = 1)]
        public double Lot_down_f2 { get; set; }

        [Parameter("LSM for DownTF 3", DefaultValue = 0.5, MinValue = 0, Step = 1)]
        public double Lot_down_f3 { get; set; }

        [Parameter("LSM for DownTF 4", DefaultValue = 0.5, MinValue = 0, Step = 1)]
        public double Lot_down_f4 { get; set; }

        [Parameter("LSM for DownTF 5", DefaultValue = 0.5, MinValue = 0, Step = 1)]
        public double Lot_down_f5 { get; set; }

        [Parameter("Upper Demand Zone", DefaultValue = 0.0, MinValue = 0, Step = 1)]
        public double UpperDemandZone { get; set; }

        [Parameter("Lower Demand Zone", DefaultValue = 0.0, MinValue = 0, Step = 1)]
        public double LowerDemandZone { get; set; }

        [Parameter("Upper Supply Zone", DefaultValue = 0.0, MinValue = 0, Step = 1)]
        public double UpperSupplyZone { get; set; }

        [Parameter("Lower Supply Zone", DefaultValue = 0.0, MinValue = 0, Step = 1)]
        public double LowerSupplyZone { get; set; }

        [Parameter("Move SL to Break Even Enabled for Trend Follow Position", DefaultValue = false)]
        public bool BeEnabled { get; set; }

        [Parameter("Move SL to Break Even Enabled for Trend Reversal Position", DefaultValue = false)]
        public bool BeEnabled2 { get; set; }

        [Parameter("Add Pips", DefaultValue = 5)]
        public double AddPips { get; set; }

        [Parameter("Trigger when gaining pips", DefaultValue = 10)]
        public double BePips { get; set; }

        [Parameter("Monday trade Enabled", DefaultValue = true)]
        public bool MondayEnabled { get; set; }

        [Parameter("Tuesday trade Enabled", DefaultValue = true)]
        public bool TuesdayEnabled { get; set; }

        [Parameter("Wednesday trade Enabled", DefaultValue = true)]
        public bool WednesdayEnabled { get; set; }

        [Parameter("Thursday trade Enabled", DefaultValue = true)]
        public bool ThursdayEnabled { get; set; }

        [Parameter("Friday trade Enabled", DefaultValue = true)]
        public bool FridayEnabled { get; set; }

        [Parameter("Timer Enabled", DefaultValue = false)]
        public bool TimerEnabled { get; set; }

        [Parameter("Start Hour", DefaultValue = 10.0)]
        public double StartTime { get; set; }

        [Parameter("Start Minute", DefaultValue = 30.0)]
        public double StartTimeMinute { get; set; }

        [Parameter("Stop Hour", DefaultValue = 12.0)]
        public double StopTime { get; set; }

        [Parameter("Stop Minute", DefaultValue = 30.0)]
        public double StopTimeMinute { get; set; }

        [Parameter("ID of TF1", DefaultValue = 10.0, MinValue = 0, Step = 1)]
        public double IDTF1 { get; set; }

        [Parameter("ID of TF2", DefaultValue = 10.0, MinValue = 0, Step = 1)]
        public double IDTF2 { get; set; }

        [Parameter("ID of TF3", DefaultValue = 10.0, MinValue = 0, Step = 1)]
        public double IDTF3 { get; set; }

        [Parameter("ID of TF4", DefaultValue = 10.0, MinValue = 0, Step = 1)]
        public double IDTF4 { get; set; }

        [Parameter("ID of TF5", DefaultValue = 10.0, MinValue = 0, Step = 1)]
        public double IDTF5 { get; set; }

        [Parameter("ID of RE1", DefaultValue = 10.0, MinValue = 0, Step = 1)]
        public double IDRE1 { get; set; }

        [Parameter("ID of RE2", DefaultValue = 10.0, MinValue = 0, Step = 1)]
        public double IDRE2 { get; set; }

        [Parameter("ID of RE3", DefaultValue = 10.0, MinValue = 0, Step = 1)]
        public double IDRE3 { get; set; }

        [Parameter("ID of RE4", DefaultValue = 10.0, MinValue = 0, Step = 1)]
        public double IDRE4 { get; set; }

        [Parameter("ID of RE5", DefaultValue = 10.0, MinValue = 0, Step = 1)]
        public double IDRE5 { get; set; }

        [Parameter("DM of TF", DefaultValue = 2.0, MinValue = 0, Step = 1)]
        public double DMTF { get; set; }

        [Parameter("DM of RE", DefaultValue = 2.0, MinValue = 0, Step = 1)]
        public double DMRE { get; set; }

        [Parameter("Position Id", DefaultValue = "1010")]
        public string PositionId { get; set; }

        private OgimaReversalandTrendFollow ORTF;
        private FractalChaosBands fractal;

        double buy_re_y1 = 0.0;
        double buy_re_y2 = 0.0;
        double buy_re_y3 = 0.0;
        double buy_re_y4 = 0.0;
        double buy_re_y5 = 0.0;

        double buy_fo_y1 = 0.0;
        double buy_fo_y2 = 0.0;
        double buy_fo_y3 = 0.0;
        double buy_fo_y4 = 0.0;
        double buy_fo_y5 = 0.0;

        double sell_re_y1 = 0.0;
        double sell_re_y2 = 0.0;
        double sell_re_y3 = 0.0;
        double sell_re_y4 = 0.0;

        double sell_fo_y1 = 0.0;
        double sell_fo_y2 = 0.0;
        double sell_fo_y3 = 0.0;
        double sell_fo_y4 = 0.0;
        double sell_fo_y5 = 0.0;

        protected override void OnStart()
        {
            // Put your initialization logic here   

            if (lockaccount != 0)
            {
                if ((lockaccount != Account.Number))
                {
                    Print("Invalid account! Please contact admin!");
                    Stop();
                }
                else
                {
                }
            }
            else
            {
            }

            ORTF = Indicators.GetIndicator<OgimaReversalandTrendFollow>(SolvesPeriods, true, true, true, 0.0, 0.0, 0.0, 0.0);
            fractal = Indicators.FractalChaosBands(14);

            int buy_re = TotalOrder("buy re1") + TotalOrder("buy re2") + TotalOrder("buy re3") + TotalOrder("buy re4") + TotalOrder("buy re5");
            int buy_fo = TotalOrder("buy fo1") + TotalOrder("buy fo2") + TotalOrder("buy fo3") + TotalOrder("buy fo4") + TotalOrder("buy fo5");

            int sell_re = TotalOrder("sell re1") + TotalOrder("sell re2") + TotalOrder("sell re3") + TotalOrder("sell re4");
            int sell_fo = TotalOrder("sell fo1") + TotalOrder("sell fo2") + TotalOrder("sell fo3") + TotalOrder("sell fo4") + TotalOrder("sell fo5");

            int buy_re1 = TotalOrder("buy re1");
            int buy_re2 = TotalOrder("buy re2");
            int buy_re3 = TotalOrder("buy re3");
            int buy_re4 = TotalOrder("buy re4");
            int buy_re5 = TotalOrder("buy re5");

            int buy_fo1 = TotalOrder("buy fo1");
            int buy_fo2 = TotalOrder("buy fo2");
            int buy_fo3 = TotalOrder("buy fo3");
            int buy_fo4 = TotalOrder("buy fo4");
            int buy_fo5 = TotalOrder("buy fo5");

            int sell_re1 = TotalOrder("sell re1");
            int sell_re2 = TotalOrder("sell re2");
            int sell_re3 = TotalOrder("sell re3");
            int sell_re4 = TotalOrder("sell re4");

            int sell_fo1 = TotalOrder("sell fo1");
            int sell_fo2 = TotalOrder("sell fo2");
            int sell_fo3 = TotalOrder("sell fo3");
            int sell_fo4 = TotalOrder("sell fo4");
            int sell_fo5 = TotalOrder("sell fo5");

            int totalPositions0 = TotalOrder("BS");
            int totalPositions00 = TotalOrder("BL");
            int totalPositions1 = TotalOrder("SS");
            int totalPositions11 = TotalOrder("SL");

            if (buy_re1 > 0)
            {
                buy_re_y1 = getLastLot_buy_re_y1();
            }

            if (buy_re2 > 0)
            {
                buy_re_y2 = getLastLot_buy_re_y2();
            }

            if (buy_re3 > 0)
            {
                buy_re_y3 = getLastLot_buy_re_y3();
            }

            if (buy_re4 > 0)
            {
                buy_re_y4 = getLastLot_buy_re_y4();
            }

            if (buy_re5 > 0)
            {
                buy_re_y5 = getLastLot_buy_re_y5();
            }

            if (buy_fo1 > 0)
            {
                buy_fo_y1 = getLastLot_buy_fo_y1();
            }

            if (buy_fo2 > 0)
            {
                buy_fo_y2 = getLastLot_buy_fo_y2();
            }

            if (buy_fo3 > 0)
            {
                buy_fo_y3 = getLastLot_buy_fo_y3();
            }

            if (buy_fo4 > 0)
            {
                buy_fo_y4 = getLastLot_buy_fo_y4();
            }
            if (buy_fo5 > 0)
            {
                buy_fo_y5 = getLastLot_buy_fo_y5();
            }

            if (sell_re1 > 0)
            {
                sell_re_y1 = getLastLot_sell_re_y1();
            }

            if (sell_re2 > 0)
            {
                sell_re_y2 = getLastLot_sell_re_y2();
            }

            if (sell_re3 > 0)
            {
                sell_re_y3 = getLastLot_sell_re_y3();
            }

            if (sell_re4 > 0)
            {
                sell_re_y4 = getLastLot_sell_re_y4();
            }

            if (sell_fo1 > 0)
            {
                sell_fo_y1 = getLastLot_sell_fo_y1();
            }

            if (sell_fo2 > 0)
            {
                sell_fo_y2 = getLastLot_sell_fo_y2();
            }

            if (sell_fo3 > 0)
            {
                sell_fo_y3 = getLastLot_sell_fo_y3();
            }

            if (sell_fo4 > 0)
            {
                sell_fo_y4 = getLastLot_sell_fo_y4();
            }

            if (sell_fo5 > 0)
            {
                sell_fo_y5 = getLastLot_sell_fo_y5();
            }
        }

        protected override void OnBar()
        {

            int buy_re = TotalOrder("buy re1") + TotalOrder("buy re2") + TotalOrder("buy re3") + TotalOrder("buy re4") + TotalOrder("buy re5");
            int buy_fo = TotalOrder("buy fo1") + TotalOrder("buy fo2") + TotalOrder("buy fo3") + TotalOrder("buy fo4") + TotalOrder("buy fo5");

            int sell_re = TotalOrder("sell re1") + TotalOrder("sell re2") + TotalOrder("sell re3") + TotalOrder("sell re4");
            int sell_fo = TotalOrder("sell fo1") + TotalOrder("sell fo2") + TotalOrder("sell fo3") + TotalOrder("sell fo4") + TotalOrder("sell fo5");

            int buy_re1 = TotalOrder("buy re1");
            int buy_re2 = TotalOrder("buy re2");
            int buy_re3 = TotalOrder("buy re3");
            int buy_re4 = TotalOrder("buy re4");
            int buy_re5 = TotalOrder("buy re5");

            int buy_fo1 = TotalOrder("buy fo1");
            int buy_fo2 = TotalOrder("buy fo2");
            int buy_fo3 = TotalOrder("buy fo3");
            int buy_fo4 = TotalOrder("buy fo4");
            int buy_fo5 = TotalOrder("buy fo5");

            int sell_re1 = TotalOrder("sell re1");
            int sell_re2 = TotalOrder("sell re2");
            int sell_re3 = TotalOrder("sell re3");
            int sell_re4 = TotalOrder("sell re4");

            int sell_fo1 = TotalOrder("sell fo1");
            int sell_fo2 = TotalOrder("sell fo2");
            int sell_fo3 = TotalOrder("sell fo3");
            int sell_fo4 = TotalOrder("sell fo4");
            int sell_fo5 = TotalOrder("sell fo5");

            int totalPositions0 = TotalOrder("BS");
            int totalPositions00 = TotalOrder("BL");
            int totalPositions1 = TotalOrder("SS");
            int totalPositions11 = TotalOrder("SL");

            totalPositions0 = 1;
            totalPositions00 = 1;
            totalPositions1 = 1;
            totalPositions11 = 1;


            if (buy_re1 == 0)
            {
                buy_re_y1 = Quantity;
            }

            if (buy_re2 == 0)
            {
                buy_re_y2 = Quantity;
            }

            if (buy_re3 == 0)
            {
                buy_re_y3 = Quantity;
            }

            if (buy_re4 == 0)
            {
                buy_re_y4 = Quantity;
            }

            if (buy_re5 == 0)
            {
                buy_re_y5 = Quantity;
            }

            if (buy_fo1 == 0)
            {
                buy_fo_y1 = Quantity;
            }

            if (buy_fo2 == 0)
            {
                buy_fo_y2 = Quantity;
            }

            if (buy_fo3 == 0)
            {
                buy_fo_y3 = Quantity;
            }

            if (buy_fo4 == 0)
            {
                buy_fo_y4 = Quantity;
            }

            if (buy_fo5 == 0)
            {
                buy_fo_y5 = Quantity;
            }

            if (sell_re1 == 0)
            {
                sell_re_y1 = Quantity;
            }

            if (sell_re2 == 0)
            {
                sell_re_y2 = Quantity;
            }

            if (sell_re3 == 0)
            {
                sell_re_y3 = Quantity;
            }

            if (sell_re4 == 0)
            {
                sell_re_y4 = Quantity;
            }

            if (sell_fo1 == 0)
            {
                sell_fo_y1 = Quantity;
            }

            if (sell_fo2 == 0)
            {
                sell_fo_y2 = Quantity;
            }

            if (sell_fo3 == 0)
            {
                sell_fo_y3 = Quantity;
            }

            if (sell_fo4 == 0)
            {
                sell_fo_y4 = Quantity;
            }

            if (sell_fo5 == 0)
            {
                sell_fo_y5 = Quantity;
            }

            if (buy_re1 > 0)
            {
                buy_re_y1 = getLastLot_buy_re_y1();
            }

            if (buy_re2 > 0)
            {
                buy_re_y2 = getLastLot_buy_re_y2();
            }

            if (buy_re3 > 0)
            {
                buy_re_y3 = getLastLot_buy_re_y3();
            }

            if (buy_re4 > 0)
            {
                buy_re_y4 = getLastLot_buy_re_y4();
            }

            if (buy_re5 > 0)
            {
                buy_re_y5 = getLastLot_buy_re_y5();
            }

            if (buy_fo1 > 0)
            {
                buy_fo_y1 = getLastLot_buy_fo_y1();
            }

            if (buy_fo2 > 0)
            {
                buy_fo_y2 = getLastLot_buy_fo_y2();
            }

            if (buy_fo3 > 0)
            {
                buy_fo_y3 = getLastLot_buy_fo_y3();
            }

            if (buy_fo4 > 0)
            {
                buy_fo_y4 = getLastLot_buy_fo_y4();
            }
            if (buy_fo5 > 0)
            {
                buy_fo_y5 = getLastLot_buy_fo_y5();
            }

            if (sell_re1 > 0)
            {
                sell_re_y1 = getLastLot_sell_re_y1();
            }

            if (sell_re2 > 0)
            {
                sell_re_y2 = getLastLot_sell_re_y2();
            }

            if (sell_re3 > 0)
            {
                sell_re_y3 = getLastLot_sell_re_y3();
            }

            if (sell_re4 > 0)
            {
                sell_re_y4 = getLastLot_sell_re_y4();
            }

            if (sell_fo1 > 0)
            {
                sell_fo_y1 = getLastLot_sell_fo_y1();
            }

            if (sell_fo2 > 0)
            {
                sell_fo_y2 = getLastLot_sell_fo_y2();
            }

            if (sell_fo3 > 0)
            {
                sell_fo_y3 = getLastLot_sell_fo_y3();
            }

            if (sell_fo4 > 0)
            {
                sell_fo_y4 = getLastLot_sell_fo_y4();
            }

            if (sell_fo5 > 0)
            {
                sell_fo_y5 = getLastLot_sell_fo_y5();
            }

            if (Open1 && (totalPositions0 > 0 || totalPositions00 > 0 || totalPositions1 > 0 || totalPositions11 > 0))
            {
                if ((buy_re1 < MaxUpReversal1) && ReversalEnabled && double.IsNaN(ORTF.UpReversal1[ORTF.UpReversal1.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy re1", Math.Round(buy_re_y1 * Math.Pow(2.0, Lot_up_r1), 2));
                    buy_re_y1 = buy_re_y1 * Math.Pow(2.0, Lot_up_r1);
                }
                else if ((buy_re2 < MaxUpReversal2) && ReversalEnabled && double.IsNaN(ORTF.UpReversal2[ORTF.UpReversal2.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy re2", Math.Round(buy_re_y2 * Math.Pow(2.0, Lot_up_r2), 2));
                    buy_re_y2 = buy_re_y2 * Math.Pow(2.0, Lot_up_r2);
                }
                else if ((buy_re3 < MaxUpReversal3) && ReversalEnabled && double.IsNaN(ORTF.UpReversal3[ORTF.UpReversal3.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy re3", Math.Round(buy_re_y3 * Math.Pow(2.0, Lot_up_r3), 2));
                    buy_re_y3 = buy_re_y3 * Math.Pow(2.0, Lot_up_r3);
                }
                else if ((buy_re4 < MaxUpReversal4) && ReversalEnabled && double.IsNaN(ORTF.UpReversal4[ORTF.UpReversal4.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy re4", Math.Round(buy_re_y4 * Math.Pow(2.0, Lot_up_r4), 2));
                    buy_re_y4 = buy_re_y4 * Math.Pow(2.0, Lot_up_r4);
                }
                else if ((buy_re5 < MaxUpReversal5) && ReversalEnabled && double.IsNaN(ORTF.UpReversal5[ORTF.UpReversal5.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy re5", Math.Round(buy_re_y5 * Math.Pow(2.0, Lot_up_r5), 2));
                    buy_re_y5 = buy_re_y5 * Math.Pow(2.0, Lot_up_r5);
                }

                if ((buy_fo1 < MaxUpTrendFollow1) && TrendFollowEnabled && double.IsNaN(ORTF.UpTrendFollow1[ORTF.UpTrendFollow1.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy fo1", Math.Round(buy_fo_y1 * Math.Pow(2.0, Lot_up_f1), 2));
                    buy_fo_y1 = buy_fo_y1 * Math.Pow(2.0, Lot_up_f1);
                }
                else if ((buy_fo2 < MaxUpTrendFollow2) && TrendFollowEnabled && double.IsNaN(ORTF.UpTrendFollow2[ORTF.UpTrendFollow2.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy fo2", Math.Round(buy_fo_y2 * Math.Pow(2.0, Lot_up_f2), 2));
                    buy_fo_y2 = buy_fo_y2 * Math.Pow(2.0, Lot_up_f2);
                }
                else if ((buy_fo3 < MaxUpTrendFollow3) && TrendFollowEnabled && double.IsNaN(ORTF.UpTrendFollow3[ORTF.UpTrendFollow3.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy fo3", Math.Round(buy_fo_y3 * Math.Pow(2.0, Lot_up_f3), 2));
                    buy_fo_y3 = buy_fo_y3 * Math.Pow(2.0, Lot_up_f3);
                }
                else if ((buy_fo4 < MaxUpTrendFollow4) && TrendFollowEnabled && double.IsNaN(ORTF.UpTrendFollow4[ORTF.UpTrendFollow4.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy fo4", Math.Round(buy_fo_y4 * Math.Pow(2.0, Lot_up_f4), 2));
                    buy_fo_y4 = buy_fo_y4 * Math.Pow(2.0, Lot_up_f4);
                }
                else if ((buy_fo5 < MaxUpTrendFollow5) && TrendFollowEnabled && double.IsNaN(ORTF.UpTrendFollow5[ORTF.UpTrendFollow5.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy fo5", Math.Round(buy_fo_y5 * Math.Pow(2.0, Lot_up_f5), 2));
                    buy_fo_y5 = buy_fo_y5 * Math.Pow(2.0, Lot_up_f5);
                }
            }
            else if (Open2 && (totalPositions0 > 0 || totalPositions00 > 0))
            {
                if ((buy_re1 < MaxUpReversal1) && ReversalEnabled && double.IsNaN(ORTF.UpReversal1[ORTF.UpReversal1.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy re1", Math.Round(buy_re_y1 * Math.Pow(2.0, Lot_up_r1), 2));
                    buy_re_y1 = buy_re_y1 * Math.Pow(2.0, Lot_up_r1);
                }
                else if ((buy_re1 >= MaxUpReversal1) && (buy_re2 < MaxUpReversal2) && ReversalEnabled && double.IsNaN(ORTF.UpReversal2[ORTF.UpReversal2.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy re2", Math.Round(buy_re_y2 * Math.Pow(2.0, Lot_up_r2), 2));
                    buy_re_y2 = buy_re_y2 * Math.Pow(2.0, Lot_up_r2);
                }
                else if ((buy_re3 < MaxUpReversal3) && ReversalEnabled && double.IsNaN(ORTF.UpReversal3[ORTF.UpReversal3.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy re3", Math.Round(buy_re_y3 * Math.Pow(2.0, Lot_up_r3), 2));
                    buy_re_y3 = buy_re_y3 * Math.Pow(2.0, Lot_up_r3);
                }
                else if ((buy_re4 < MaxUpReversal4) && ReversalEnabled && double.IsNaN(ORTF.UpReversal4[ORTF.UpReversal4.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy re4", Math.Round(buy_re_y4 * Math.Pow(2.0, Lot_up_r4), 2));
                    buy_re_y4 = buy_re_y4 * Math.Pow(2.0, Lot_up_r4);
                }
                else if ((buy_re5 < MaxUpReversal5) && ReversalEnabled && double.IsNaN(ORTF.UpReversal5[ORTF.UpReversal5.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy re5", Math.Round(buy_re_y5 * Math.Pow(2.0, Lot_up_r5), 2));
                    buy_re_y5 = buy_re_y5 * Math.Pow(2.0, Lot_up_r5);
                }

                if ((buy_fo1 < MaxUpTrendFollow1) && TrendFollowEnabled && double.IsNaN(ORTF.UpTrendFollow1[ORTF.UpTrendFollow1.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy fo1", Math.Round(buy_fo_y1 * Math.Pow(2.0, Lot_up_f1), 2));
                    buy_fo_y1 = buy_fo_y1 * Math.Pow(2.0, Lot_up_f1);
                }
                else if ((buy_fo2 < MaxUpTrendFollow2) && TrendFollowEnabled && double.IsNaN(ORTF.UpTrendFollow2[ORTF.UpTrendFollow2.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy fo2", Math.Round(buy_fo_y2 * Math.Pow(2.0, Lot_up_f2), 2));
                    buy_fo_y2 = buy_fo_y2 * Math.Pow(2.0, Lot_up_f2);
                }
                else if ((buy_fo3 < MaxUpTrendFollow3) && TrendFollowEnabled && double.IsNaN(ORTF.UpTrendFollow3[ORTF.UpTrendFollow3.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy fo3", Math.Round(buy_fo_y3 * Math.Pow(2.0, Lot_up_f3), 2));
                    buy_fo_y3 = buy_fo_y3 * Math.Pow(2.0, Lot_up_f3);
                }
                else if ((buy_fo4 < MaxUpTrendFollow4) && TrendFollowEnabled && double.IsNaN(ORTF.UpTrendFollow4[ORTF.UpTrendFollow4.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy fo4", Math.Round(buy_fo_y4 * Math.Pow(2.0, Lot_up_f4), 2));
                    buy_fo_y4 = buy_fo_y4 * Math.Pow(2.0, Lot_up_f4);
                }
                else if ((buy_fo5 < MaxUpTrendFollow5) && TrendFollowEnabled && double.IsNaN(ORTF.UpTrendFollow5[ORTF.UpTrendFollow5.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy fo5", Math.Round(buy_fo_y5 * Math.Pow(2.0, Lot_up_f5), 2));
                    buy_fo_y5 = buy_fo_y5 * Math.Pow(2.0, Lot_up_f5);
                }
            }
            else if (Open3 && (totalPositions0 > 0 || totalPositions00 > 0))
            {
                if ((buy_re1 < MaxUpReversal1) && ReversalEnabled && double.IsNaN(ORTF.UpReversal1[ORTF.UpReversal1.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy re1", Math.Round(buy_re_y1 * Math.Pow(2.0, Lot_up_r1), 2));
                    buy_re_y1 = buy_re_y1 * Math.Pow(2.0, Lot_up_r1);
                }
                else if ((buy_re2 < MaxUpReversal2) && ReversalEnabled && double.IsNaN(ORTF.UpReversal2[ORTF.UpReversal2.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy re2", Math.Round(buy_re_y2 * Math.Pow(2.0, Lot_up_r2), 2));
                    buy_re_y2 = buy_re_y2 * Math.Pow(2.0, Lot_up_r2);
                }
                else if ((buy_re3 < MaxUpReversal3) && ReversalEnabled && double.IsNaN(ORTF.UpReversal3[ORTF.UpReversal3.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy re3", Math.Round(buy_re_y3 * Math.Pow(2.0, Lot_up_r3), 2));
                    buy_re_y3 = buy_re_y3 * Math.Pow(2.0, Lot_up_r3);
                }
                else if ((buy_re4 < MaxUpReversal4) && ReversalEnabled && double.IsNaN(ORTF.UpReversal4[ORTF.UpReversal4.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy re4", Math.Round(buy_re_y4 * Math.Pow(2.0, Lot_up_r4), 2));
                    buy_re_y4 = buy_re_y4 * Math.Pow(2.0, Lot_up_r4);
                }

                if ((sell_fo1 < MaxDownTrendFollow1) && TrendFollowEnabled && double.IsNaN(ORTF.DownTrendFollow1[ORTF.DownTrendFollow1.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell fo1", Math.Round(sell_fo_y1 * Math.Pow(2.0, Lot_down_f1), 2));
                    sell_fo_y1 = sell_fo_y1 * Math.Pow(2.0, Lot_down_f1);
                }
                else if ((sell_fo2 < MaxDownTrendFollow2) && TrendFollowEnabled && double.IsNaN(ORTF.DownTrendFollow2[ORTF.DownTrendFollow2.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell fo2", Math.Round(sell_fo_y2 * Math.Pow(2.0, Lot_down_f2), 2));
                    sell_fo_y2 = sell_fo_y2 * Math.Pow(2.0, Lot_down_f2);
                }
                else if ((sell_fo3 < MaxDownTrendFollow3) && TrendFollowEnabled && double.IsNaN(ORTF.DownTrendFollow3[ORTF.DownTrendFollow3.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell fo3", Math.Round(sell_fo_y3 * Math.Pow(2.0, Lot_down_f3), 2));
                    sell_fo_y3 = sell_fo_y3 * Math.Pow(2.0, Lot_down_f3);
                }
                else if ((sell_fo4 < MaxDownTrendFollow4) && TrendFollowEnabled && double.IsNaN(ORTF.DownTrendFollow4[ORTF.DownTrendFollow4.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell fo4", Math.Round(sell_fo_y4 * Math.Pow(2.0, Lot_down_f4), 2));
                    sell_fo_y4 = sell_fo_y4 * Math.Pow(2.0, Lot_down_f4);
                }


            }

            if (Open1 && (totalPositions0 > 0 || totalPositions00 > 0 || totalPositions1 > 0 || totalPositions11 > 0))
            {
                if ((sell_re1 < MaxDownReversal1) && ReversalEnabled && double.IsNaN(ORTF.DownReversal1[ORTF.DownReversal1.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell re1", Math.Round(sell_re_y1 * Math.Pow(2.0, Lot_down_r1), 2));
                    sell_re_y1 = sell_re_y1 * Math.Pow(2.0, Lot_down_r1);
                }
                else if ((sell_re2 < MaxDownReversal2) && ReversalEnabled && double.IsNaN(ORTF.DownReversal2[ORTF.DownReversal2.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell re2", Math.Round(sell_re_y2 * Math.Pow(2.0, Lot_down_r2), 2));
                    sell_re_y2 = sell_re_y2 * Math.Pow(2.0, Lot_down_r2);
                }
                else if ((sell_re3 < MaxDownReversal3) && ReversalEnabled && double.IsNaN(ORTF.DownReversal3[ORTF.DownReversal3.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell re3", Math.Round(sell_re_y3 * Math.Pow(2.0, Lot_down_r3), 2));
                    sell_re_y3 = sell_re_y3 * Math.Pow(2.0, Lot_down_r3);
                }
                else if ((sell_re4 < MaxDownReversal4) && ReversalEnabled && double.IsNaN(ORTF.DownReversal4[ORTF.DownReversal4.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell re4", Math.Round(sell_re_y4 * Math.Pow(2.0, Lot_down_r4), 2));
                    sell_re_y4 = sell_re_y4 * Math.Pow(2.0, Lot_down_r4);
                }

                if ((sell_fo1 < MaxDownTrendFollow1) && TrendFollowEnabled && double.IsNaN(ORTF.DownTrendFollow1[ORTF.DownTrendFollow1.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell fo1", Math.Round(sell_fo_y1 * Math.Pow(2.0, Lot_down_f1), 2));
                    sell_fo_y1 = sell_fo_y1 * Math.Pow(2.0, Lot_down_f1);
                }
                else if ((sell_fo2 < MaxDownTrendFollow2) && TrendFollowEnabled && double.IsNaN(ORTF.DownTrendFollow2[ORTF.DownTrendFollow2.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell fo2", Math.Round(sell_fo_y2 * Math.Pow(2.0, Lot_down_f2), 2));
                    sell_fo_y2 = sell_fo_y2 * Math.Pow(2.0, Lot_down_f2);
                }
                else if ((sell_fo3 < MaxDownTrendFollow3) && TrendFollowEnabled && double.IsNaN(ORTF.DownTrendFollow3[ORTF.DownTrendFollow3.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell fo3", Math.Round(sell_fo_y3 * Math.Pow(2.0, Lot_down_f3), 2));
                    sell_fo_y3 = sell_fo_y3 * Math.Pow(2.0, Lot_down_f3);
                }
                else if ((sell_fo4 < MaxDownTrendFollow4) && TrendFollowEnabled && double.IsNaN(ORTF.DownTrendFollow4[ORTF.DownTrendFollow4.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell fo4", Math.Round(sell_fo_y4 * Math.Pow(2.0, Lot_down_f4), 2));
                    sell_fo_y4 = sell_fo_y4 * Math.Pow(2.0, Lot_down_f4);
                }
                else if ((sell_fo5 < MaxDownTrendFollow5) && TrendFollowEnabled && double.IsNaN(ORTF.DownTrendFollow5[ORTF.DownTrendFollow5.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell fo5", Math.Round(sell_fo_y5 * Math.Pow(2.0, Lot_down_f5), 2));
                    sell_fo_y5 = sell_fo_y5 * Math.Pow(2.0, Lot_down_f5);
                }
            }
            else if (Open2 && (totalPositions1 > 0 || totalPositions11 > 0))
            {
                if ((sell_re1 < MaxDownReversal1) && ReversalEnabled && double.IsNaN(ORTF.DownReversal1[ORTF.DownReversal1.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell re1", Math.Round(sell_re_y1 * Math.Pow(2.0, Lot_down_r1), 2));
                    sell_re_y1 = sell_re_y1 * Math.Pow(2.0, Lot_down_r1);
                }
                else if ((sell_re1 >= MaxDownReversal1) && (sell_re2 < MaxDownReversal2) && ReversalEnabled && double.IsNaN(ORTF.DownReversal2[ORTF.DownReversal2.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell re2", Math.Round(sell_re_y2 * Math.Pow(2.0, Lot_down_r2), 2));
                    sell_re_y2 = sell_re_y2 * Math.Pow(2.0, Lot_down_r2);
                }
                else if ((sell_re3 < MaxDownReversal3) && ReversalEnabled && double.IsNaN(ORTF.DownReversal3[ORTF.DownReversal3.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell re3", Math.Round(sell_re_y3 * Math.Pow(2.0, Lot_down_r3), 2));
                    sell_re_y3 = sell_re_y3 * Math.Pow(2.0, Lot_down_r3);
                }
                else if ((sell_re4 < MaxDownReversal4) && ReversalEnabled && double.IsNaN(ORTF.DownReversal4[ORTF.DownReversal4.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell re4", Math.Round(sell_re_y4 * Math.Pow(2.0, Lot_down_r4), 2));
                    sell_re_y4 = sell_re_y4 * Math.Pow(2.0, Lot_down_r4);
                }

                if ((sell_fo1 < MaxDownTrendFollow1) && TrendFollowEnabled && double.IsNaN(ORTF.DownTrendFollow1[ORTF.DownTrendFollow1.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell fo1", Math.Round(sell_fo_y1 * Math.Pow(2.0, Lot_down_f1), 2));
                    sell_fo_y1 = sell_fo_y1 * Math.Pow(2.0, Lot_down_f1);
                }
                else if ((sell_fo2 < MaxDownTrendFollow2) && TrendFollowEnabled && double.IsNaN(ORTF.DownTrendFollow2[ORTF.DownTrendFollow2.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell fo2", Math.Round(sell_fo_y2 * Math.Pow(2.0, Lot_down_f2), 2));
                    sell_fo_y2 = sell_fo_y2 * Math.Pow(2.0, Lot_down_f2);
                }
                else if ((sell_fo3 < MaxDownTrendFollow3) && TrendFollowEnabled && double.IsNaN(ORTF.DownTrendFollow3[ORTF.DownTrendFollow3.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell fo3", Math.Round(sell_fo_y3 * Math.Pow(2.0, Lot_down_f3), 2));
                    sell_fo_y3 = sell_fo_y3 * Math.Pow(2.0, Lot_down_f3);
                }
                else if ((sell_fo4 < MaxDownTrendFollow4) && TrendFollowEnabled && double.IsNaN(ORTF.DownTrendFollow4[ORTF.DownTrendFollow4.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell fo4", Math.Round(sell_fo_y4 * Math.Pow(2.0, Lot_down_f4), 2));
                    sell_fo_y4 = sell_fo_y4 * Math.Pow(2.0, Lot_down_f4);
                }
                else if ((sell_fo5 < MaxDownTrendFollow5) && TrendFollowEnabled && double.IsNaN(ORTF.DownTrendFollow5[ORTF.DownTrendFollow5.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell fo5", Math.Round(sell_fo_y5 * Math.Pow(2.0, Lot_down_f5), 2));
                    sell_fo_y5 = sell_fo_y5 * Math.Pow(2.0, Lot_down_f5);
                }
            }
            else if (Open3 && (totalPositions1 > 0 || totalPositions11 > 0))
            {
                if ((sell_re1 < MaxDownReversal1) && ReversalEnabled && double.IsNaN(ORTF.DownReversal1[ORTF.DownReversal1.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell re1", Math.Round(sell_re_y1 * Math.Pow(2.0, Lot_down_r1), 2));
                    sell_re_y1 = sell_re_y1 * Math.Pow(2.0, Lot_down_r1);
                }
                else if ((sell_re2 < MaxDownReversal2) && ReversalEnabled && double.IsNaN(ORTF.DownReversal2[ORTF.DownReversal2.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell re2", Math.Round(sell_re_y2 * Math.Pow(2.0, Lot_down_r2), 2));
                    sell_re_y2 = sell_re_y2 * Math.Pow(2.0, Lot_down_r2);
                }
                else if ((sell_re3 < MaxDownReversal3) && ReversalEnabled && double.IsNaN(ORTF.DownReversal3[ORTF.DownReversal3.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell re3", Math.Round(sell_re_y3 * Math.Pow(2.0, Lot_down_r3), 2));
                    sell_re_y3 = sell_re_y3 * Math.Pow(2.0, Lot_down_r3);
                }
                else if ((sell_re4 < MaxDownReversal4) && ReversalEnabled && double.IsNaN(ORTF.DownReversal4[ORTF.DownReversal4.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Sell, "sell re4", Math.Round(sell_re_y4 * Math.Pow(2.0, Lot_down_r4), 2));
                    sell_re_y4 = sell_re_y4 * Math.Pow(2.0, Lot_down_r4);
                }

                if ((buy_fo1 < MaxUpTrendFollow1) && TrendFollowEnabled && double.IsNaN(ORTF.UpTrendFollow1[ORTF.UpTrendFollow1.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy fo1", Math.Round(buy_fo_y1 * Math.Pow(2.0, Lot_up_f1), 2));
                    buy_fo_y1 = buy_fo_y1 * Math.Pow(2.0, Lot_up_f1);
                }
                else if ((buy_fo2 < MaxUpTrendFollow2) && TrendFollowEnabled && double.IsNaN(ORTF.UpTrendFollow2[ORTF.UpTrendFollow2.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy fo2", Math.Round(buy_fo_y2 * Math.Pow(2.0, Lot_up_f2), 2));
                    buy_fo_y2 = buy_fo_y2 * Math.Pow(2.0, Lot_up_f2);
                }
                else if ((buy_fo3 < MaxUpTrendFollow3) && TrendFollowEnabled && double.IsNaN(ORTF.UpTrendFollow3[ORTF.UpTrendFollow3.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy fo3", Math.Round(buy_fo_y3 * Math.Pow(2.0, Lot_up_f3), 2));
                    buy_fo_y3 = buy_fo_y3 * Math.Pow(2.0, Lot_up_f3);
                }
                else if ((buy_fo4 < MaxUpTrendFollow4) && TrendFollowEnabled && double.IsNaN(ORTF.UpTrendFollow4[ORTF.UpTrendFollow4.Count - 1]) == false)
                {
                    OpenOrder(TradeType.Buy, "buy fo4", Math.Round(buy_fo_y4 * Math.Pow(2.0, Lot_up_f4), 2));
                    buy_fo_y4 = buy_fo_y4 * Math.Pow(2.0, Lot_up_f4);
                }
            }
        }



        protected override void OnTick()
        {

            int buy_re1 = TotalOrder("buy re1");
            int buy_re2 = TotalOrder("buy re2");
            int buy_re3 = TotalOrder("buy re3");
            int buy_re4 = TotalOrder("buy re4");
            int buy_re5 = TotalOrder("buy re5");

            int buy_fo1 = TotalOrder("buy fo1");
            int buy_fo2 = TotalOrder("buy fo2");
            int buy_fo3 = TotalOrder("buy fo3");
            int buy_fo4 = TotalOrder("buy fo4");
            int buy_fo5 = TotalOrder("buy fo5");

            int sell_re1 = TotalOrder("sell re1");
            int sell_re2 = TotalOrder("sell re2");
            int sell_re3 = TotalOrder("sell re3");
            int sell_re4 = TotalOrder("sell re4");

            int sell_fo1 = TotalOrder("sell fo1");
            int sell_fo2 = TotalOrder("sell fo2");
            int sell_fo3 = TotalOrder("sell fo3");
            int sell_fo4 = TotalOrder("sell fo4");
            int sell_fo5 = TotalOrder("sell fo5");

            int totalPositions0 = TotalOrder("BS");
            int totalPositions00 = TotalOrder("BL");
            int totalPositions1 = TotalOrder("SS");
            int totalPositions11 = TotalOrder("SL");
//SAMPLE SPACE OF CLOSED BUY REVERSAL
//EVENTS
            if (buy_re1 > 0)
            {
                if (Close_BuyRe && TotalLot_buyre1() == 0.02 && TotalProfitBuyRe1() >= Math.Pow(pf * 2, 2.0) * TotalLot_buyre1())
                {
                    Closebuyre1();
                }
                if (Close_BuyRe && TotalLot_buyre1() == 0.03 && TotalProfitBuyRe1() >= Math.Pow(pf * 0.9, 2.0) * TotalLot_buyre1())
                {
                    Closebuyre1();
                }
                if (Close_BuyRe && TotalLot_buyre1() == 0.04 && TotalProfitBuyRe1() >= Math.Pow(pf * 0.8, 2.0) * TotalLot_buyre1())
                {
                    Closebuyre1();
                }
                if (Close_BuyRe && TotalLot_buyre1() == 0.05 && TotalProfitBuyRe1() >= Math.Pow(pf * 0.7, 2.0) * TotalLot_buyre1())
                {
                    Closebuyre1();
                }
                if (Close_BuyRe && TotalLot_buyre1() == 0.06 && TotalProfitBuyRe1() >= Math.Pow(pf * 0.6, 2.0) * TotalLot_buyre1())
                {
                    Closebuyre1();
                }
                if (Close_BuyRe && TotalLot_buyre1() >= 0.07 && TotalProfitBuyRe1() >= Math.Pow(pf * 0.5, 2.0) * TotalLot_buyre1())
                {
                    Closebuyre1();
                }
                if (Close_BuyRe && TotalLot_buyre1() >= 0.32 && TotalProfitBuyRe1() >= Math.Pow(pf * 0.1, 2.0) * TotalLot_buyre1())
                {
                    Closebuyre1();
                }
            }
            if (buy_re2 > 0)
            {
                if (Close_BuyRe && TotalLot_buyre2() == 0.02 && TotalProfitBuyRe2() >= Math.Pow(pf * 2, 2.0) * TotalLot_buyre2())
                {
                    Closebuyre2();
                }
                if (Close_BuyRe && TotalLot_buyre2() == 0.03 && TotalProfitBuyRe2() >= Math.Pow(pf * 0.9, 2.0) * TotalLot_buyre2())
                {
                    Closebuyre2();
                }
                if (Close_BuyRe && TotalLot_buyre2() == 0.04 && TotalProfitBuyRe2() >= Math.Pow(pf * 0.8, 2.0) * TotalLot_buyre2())
                {
                    Closebuyre2();
                }
                if (Close_BuyRe && TotalLot_buyre2() == 0.05 && TotalProfitBuyRe2() >= Math.Pow(pf * 0.7, 2.0) * TotalLot_buyre2())
                {
                    Closebuyre2();
                }
                if (Close_BuyRe && TotalLot_buyre2() == 0.06 && TotalProfitBuyRe2() >= Math.Pow(pf * 0.6, 2.0) * TotalLot_buyre2())
                {
                    Closebuyre2();
                }
                if (Close_BuyRe && TotalLot_buyre2() >= 0.07 && TotalProfitBuyRe2() >= Math.Pow(pf * 0.5, 2.0) * TotalLot_buyre2())
                {
                    Closebuyre2();
                }
                if (Close_BuyRe && TotalLot_buyre2() >= 0.32 && TotalProfitBuyRe2() >= Math.Pow(pf * 0.1, 2.0) * TotalLot_buyre2())
                {
                    Closebuyre2();
                }
            }
            if (buy_re3 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe3() >= Math.Pow(pf, 2.0) * TotalLot_buyre3())
                {
                    Closebuyre3();
                }
                if (Close_BuyRe && TotalLot_buyre3() > 0.02 && TotalProfitBuyRe2() >= Math.Pow(pf / 3, 2.0) * TotalLot_buyre3())
                {
                    Closebuyre3();
                }
                if (Close_BuyRe && TotalLot_buyre3() > 0.04 && TotalProfitBuyRe2() >= Math.Pow(pf / 4, 2.0) * TotalLot_buyre3())
                {
                    Closebuyre3();
                }
                if (Close_BuyRe && TotalLot_buyre3() > 0.08 && TotalProfitBuyRe2() >= Math.Pow(pf / 5, 2.0) * TotalLot_buyre3())
                {
                    Closebuyre3();
                }
            }
            if (buy_re4 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre4();
                }
            }
            if (buy_re5 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre5();
                }
            }

            //if (buy_re1 > 0 && buy_re2 > 0)
            //{
            // if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
            //{
            // Closebuyre12();
            //}
            //}
            if (buy_re1 > 0 && buy_re3 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre13();
                }
            }
            if (buy_re1 > 0 && buy_re4 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre14();
                }
            }
            if (buy_re1 > 0 && buy_re5 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre15();
                }
            }
            if (buy_re2 > 0 && buy_re3 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre23();
                }
            }
            if (buy_re2 > 0 && buy_re4 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre24();
                }
            }
            if (buy_re2 > 0 && buy_re5 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre25();
                }
            }
            if (buy_re3 > 0 && buy_re4 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre34();
                }
            }
            if (buy_re3 > 0 && buy_re5 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre35();
                }
            }
            if (buy_re4 > 0 && buy_re5 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre45();
                }
            }
            if (buy_re1 > 0 && buy_re2 > 0 && buy_re3 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre123();
                }
            }
            if (buy_re1 > 0 && buy_re2 > 0 && buy_re4 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre124();
                }
            }
            if (buy_re1 > 0 && buy_re2 > 0 && buy_re5 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre125();
                }
            }
            if (buy_re1 > 0 && buy_re3 > 0 && buy_re4 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre134();
                }
            }
            if (buy_re1 > 0 && buy_re3 > 0 && buy_re5 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre135();
                }
            }
            if (buy_re1 > 0 && buy_re4 > 0 && buy_re5 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre145();
                }
            }

            if (buy_re2 > 0 && buy_re3 > 0 && buy_re4 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre234();
                }
            }
            if (buy_re2 > 0 && buy_re3 > 0 && buy_re5 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre235();
                }
            }
            if (buy_re2 > 0 && buy_re4 > 0 && buy_re5 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre245();
                }
            }
            if (buy_re3 > 0 && buy_re4 > 0 && buy_re5 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre345();
                }
            }
            if (buy_re1 > 0 && buy_re2 > 0 && buy_re3 > 0 && buy_re4 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre1234();
                }
            }
            if (buy_re1 > 0 && buy_re2 > 0 && buy_re3 > 0 && buy_re5 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre1235();
                }
            }
            if (buy_re1 > 0 && buy_re3 > 0 && buy_re4 > 0 && buy_re5 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre1345();
                }
            }
            if (buy_re2 > 0 && buy_re3 > 0 && buy_re4 > 0 && buy_re5 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre2345();
                }
            }
            if (buy_re1 > 0 && buy_re2 > 0 && buy_re3 > 0 && buy_re4 > 0 && buy_re5 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre12345();
                }
            }
            if (buy_re1 > 0 && buy_re2 > 0 && buy_re3 > 0 && buy_re4 > 0 && buy_re5 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre12345();
                }
            }
            if (buy_re1 > 0 || buy_re2 > 0 || buy_re3 > 0 || buy_re4 > 0 || buy_re5 > 0)
            {
                if (Close_BuyRe && TotalProfitBuyRe() >= Math.Pow(pf, 2.0) * TotalLot_buyre())
                {
                    Closebuyre12345();
                }
            }
//SAMPLE SPACE OF CLOSED BUY TREND FOLLOW
//EVENTS
            if (buy_fo1 > 0)
            {
                if (Close_BuyFo && TotalLot_buyfo1() >= Math.Pow(pf, 2.0) * TotalLot_buyfo1())
                {
                    Closebuyfo1();
                }
                if (Close_BuyFo && TotalLot_buyfo1() > 0.01 && TotalProfitBuyFo1() >= Math.Pow(pf / 1.5, 2.0) * TotalLot_buyfo1())
                {
                    Closebuyfo1();
                }
                if (Close_BuyFo && TotalLot_buyfo1() > 0.32 && TotalProfitBuyFo1() >= Math.Pow(pf / 2.0, 2.0) * TotalLot_buyfo1())
                {
                    Closebuyfo1();
                }
                if (Close_BuyFo && TotalLot_buyfo1() > 1.28 && TotalProfitBuyFo1() >= Math.Pow(pf / 2.5, 2.0) * TotalLot_buyfo1())
                {
                    Closebuyfo1();
                }
            }
            if (buy_fo2 > 0)
            {
                if (Close_BuyFo && TotalLot_buyfo2() >= Math.Pow(pf, 2.0) * TotalLot_buyfo2())
                {
                    Closebuyfo2();
                }
                if (Close_BuyFo && TotalLot_buyfo2() > 0.01 && TotalProfitBuyFo2() >= Math.Pow(pf / 1.5, 2.0) * TotalLot_buyfo2())
                {
                    Closebuyfo2();
                }
                if (Close_BuyFo && TotalLot_buyfo2() > 0.032 && TotalProfitBuyFo2() >= Math.Pow(pf / 2.0, 2.0) * TotalLot_buyfo2())
                {
                    Closebuyfo2();
                }
                if (Close_BuyFo && TotalLot_buyfo2() > 1.28 && TotalProfitBuyFo2() >= Math.Pow(pf / 2.5, 2.0) * TotalLot_buyfo2())
                {
                    Closebuyfo2();
                }
            }
            if (buy_fo3 > 0)
            {
                if (Close_BuyFo && TotalLot_buyfo3() >= Math.Pow(pf, 2.0) * TotalLot_buyfo3())
                {
                    Closebuyfo3();
                }
                if (Close_BuyFo && TotalLot_buyfo3() > 0.01 && TotalProfitBuyFo3() >= Math.Pow(pf / 1.5, 2.0) * TotalLot_buyfo3())
                {
                    Closebuyfo3();
                }
                if (Close_BuyFo && TotalLot_buyfo3() > 0.16 && TotalProfitBuyFo3() >= Math.Pow(pf / 2.0, 2.0) * TotalLot_buyfo3())
                {
                    Closebuyfo3();
                }
                if (Close_BuyFo && TotalLot_buyfo3() > 0.32 && TotalProfitBuyFo3() >= Math.Pow(pf / 2.5, 2.0) * TotalLot_buyfo3())
                {
                    Closebuyfo3();
                }

            }
            if (buy_fo4 > 0)
            {
                if (Close_BuyFo && TotalProfitBuyFo() >= Math.Pow(pf, 2.0) * TotalLot_buyfo())
                {
                    Closebuyfo4();
                }
                if (Close_BuyFo && TotalLot_buyfo4() <= 0.02 && TotalProfitBuyFo4() >= Math.Pow(pf * 2, 2.0) * TotalLot_buyfo4())
                {
                    Closebuyfo4();
                }
                if (Close_BuyFo && TotalLot_buyfo4() > 0.04 && TotalProfitBuyFo4() >= Math.Pow(pf / 1.5, 2.0) * TotalLot_buyfo4())
                {
                    Closebuyfo4();
                }
                if (Close_BuyFo && TotalLot_buyfo4() > 0.08 && TotalProfitBuyFo4() >= Math.Pow(pf / 2.0, 2.0) * TotalLot_buyfo4())
                {
                    Closebuyfo4();
                }
                if (Close_BuyFo && TotalLot_buyfo4() > 0.16 && TotalProfitBuyFo4() >= Math.Pow(pf / 2.5, 2.0) * TotalLot_buyfo4())
                {
                    Closebuyfo4();
                }
                if (Close_BuyFo && TotalLot_buyfo4() > 0.32 && TotalProfitBuyFo4() >= Math.Pow(pf / 10.0, 2.0) * TotalLot_buyfo4())
                {
                    Closebuyfo4();
                }
                //if (Close_BuyFo && MarketSeries.Close.Last(1) < fractal.Low.Last(1))
                // {
                // Closebuyfo4();
                //}
            }
            if (buy_fo5 > 0)
            {
                if (Close_BuyFo && TotalProfitBuyFo() >= Math.Pow(pf, 2.0) * TotalLot_buyfo())
                {
                    Closebuyfo5();
                }
                if (Close_BuyFo && TotalLot_buyfo5() > 0.01 && TotalProfitBuyFo5() >= Math.Pow(pf / 1.5, 2.0) * TotalLot_buyfo5())
                {
                    Closebuyfo5();
                }
                if (Close_BuyFo && TotalLot_buyfo5() > 0.08 && TotalProfitBuyFo5() >= Math.Pow(pf / 2.0, 2.0) * TotalLot_buyfo5())
                {
                    Closebuyfo5();
                }
                if (Close_BuyFo && TotalLot_buyfo5() > 0.16 && TotalProfitBuyFo5() >= Math.Pow(pf / 2.5, 2.0) * TotalLot_buyfo5())
                {
                    Closebuyfo5();
                }
            }
            if (buy_fo1 > 0 && buy_fo2 > 0)
            {
                if (Close_BuyFo && TotalProfitBuyFo() >= Math.Pow(pf, 2.0) * TotalLot_buyfo())
                {
                    Closebuyfo1();
                    Closebuyfo2();
                }
            }
            if (buy_fo1 > 0 && buy_fo3 > 0)
            {
                if (Close_BuyFo && TotalProfitBuyFo() >= Math.Pow(pf, 2.0) * TotalLot_buyfo())
                {
                    Closebuyfo13();
                }
            }
            if (buy_fo1 > 0 && buy_fo4 > 0)
            {
                if (Close_BuyFo && TotalProfitBuyFo() >= Math.Pow(pf, 2.0) * TotalLot_buyfo())
                {
                    Closebuyfo14();
                }
            }
            if (buy_fo1 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyFo && TotalProfitBuyFo() >= Math.Pow(pf, 2.0) * TotalLot_buyfo())
                {
                    Closebuyfo15();
                }
            }
            if (buy_fo2 > 0 && buy_fo3 > 0)
            {
                if (Close_BuyFo && TotalProfitBuyFo() >= Math.Pow(pf, 2.0) * TotalLot_buyfo())
                {
                    Closebuyfo23();
                }
            }
            if (buy_fo2 > 0 && buy_fo4 > 0)
            {
                if (Close_BuyFo && TotalProfitBuyFo() >= Math.Pow(pf, 2.0) * TotalLot_buyfo())
                {
                    Closebuyfo24();
                }
            }
            if (buy_fo2 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyFo && TotalProfitBuyFo() >= Math.Pow(pf, 2.0) * TotalLot_buyfo())
                {
                    Closebuyfo25();
                }
            }
            if (buy_fo3 > 0 && buy_fo4 > 0)
            {
                if (Close_BuyFo && TotalProfitBuyFo() >= Math.Pow(pf, 2.0) * TotalLot_buyfo())
                {
                    Closebuyfo34();
                }
            }
            if (buy_fo3 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyFo && TotalProfitBuyFo() >= Math.Pow(pf, 2.0) * TotalLot_buyfo())
                {
                    Closebuyfo35();
                }
            }
            if (buy_fo4 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyFo && TotalProfitBuyFo() >= Math.Pow(pf, 2.0) * TotalLot_buyfo())
                {
                    Closebuyfo45();
                }
            }
//SAMPLE SPACE OF CLOSED SELL TREND FOLLOW
//EVENTS
            if (sell_fo1 > 0)
            {
                if (Close_SellFo && TotalProfitSellFo() >= Math.Pow(pf, 2.0) * TotalLot_sellfo())
                {
                    Closesellfo1();
                }
                if (Close_SellFo && TotalLot_sellfo1() > 0.02 && TotalProfitSellFo1() >= Math.Pow(pf / 1.5, 2.0) * TotalLot_sellfo1())
                {
                    Closesellfo1();
                }
                if (Close_SellFo && TotalLot_sellfo1() > 0.08 && TotalProfitSellFo1() >= Math.Pow(pf / 2.0, 2.0) * TotalLot_sellfo1())
                {
                    Closesellfo1();
                }
                if (Close_SellFo && TotalLot_sellfo1() > 0.16 && TotalProfitSellFo1() >= Math.Pow(pf / 2.5, 2.0) * TotalLot_sellfo1())
                {
                    Closesellfo1();
                }
            }
            if (sell_fo2 > 0)
            {
                if (Close_SellFo && TotalProfitSellFo() >= Math.Pow(pf, 2.0) * TotalLot_sellfo())
                {
                    Closesellfo2();
                }
                if (Close_SellFo && TotalLot_sellfo2() > 0.02 && TotalProfitSellFo2() >= Math.Pow(pf / 1.5, 2.0) * TotalLot_sellfo2())
                {
                    Closesellfo2();
                }
                if (Close_SellFo && TotalLot_sellfo2() > 0.08 && TotalProfitSellFo2() >= Math.Pow(pf / 2.0, 2.0) * TotalLot_sellfo2())
                {
                    Closesellfo2();
                }
                if (Close_SellFo && TotalLot_sellfo2() > 0.16 && TotalProfitSellFo2() >= Math.Pow(pf / 2.5, 2.0) * TotalLot_sellfo2())
                {
                    Closesellfo2();
                }
            }
            if (sell_fo3 > 0)
            {
                if (Close_SellFo && TotalProfitSellFo() >= Math.Pow(pf, 2.0) * TotalLot_sellfo())
                {
                    Closesellfo3();
                }
                if (Close_SellFo && TotalLot_sellfo3() > 0.02 && TotalProfitSellFo3() >= Math.Pow(pf / 1.5, 2.0) * TotalLot_sellfo3())
                {
                    Closesellfo3();
                }
                if (Close_SellFo && TotalLot_sellfo3() > 0.08 && TotalProfitSellFo3() >= Math.Pow(pf / 2.0, 2.0) * TotalLot_sellfo3())
                {
                    Closesellfo3();
                }
                if (Close_SellFo && TotalLot_sellfo3() > 0.16 && TotalProfitSellFo3() >= Math.Pow(pf / 2.5, 2.0) * TotalLot_sellfo3())
                {
                    Closesellfo3();
                }
            }
            if (sell_fo4 > 0)
            {
                if (Close_SellFo && TotalProfitSellFo() >= Math.Pow(pf, 2.0) * TotalLot_sellfo())
                {
                    Closesellfo4();
                }
                if (Close_SellFo && TotalLot_sellfo4() > 0.02 && TotalProfitSellFo4() >= Math.Pow(pf / 1.5, 2.0) * TotalLot_sellfo4())
                {
                    Closesellfo4();
                }
                if (Close_SellFo && TotalLot_sellfo4() > 0.08 && TotalProfitSellFo4() >= Math.Pow(pf / 2.0, 2.0) * TotalLot_sellfo4())
                {
                    Closesellfo4();
                }
                if (Close_SellFo && TotalLot_sellfo4() > 0.16 && TotalProfitSellFo4() >= Math.Pow(pf / 2.5, 2.0) * TotalLot_sellfo4())
                {
                    Closesellfo4();
                }
                if (Close_SellFo && TotalLot_sellfo4() >= 0.3 && TotalProfitSellFo4() >= Math.Pow(pf / 10.0, 2.0) * TotalLot_sellfo4())
                {
                    Closesellfo4();
                }
                // if (Close_SellFo && MarketSeries.Close.Last(1) > fractal.High.Last(1))
                //{
                // Closesellfo4();
                //}
            }
            if (sell_fo5 > 0)
            {
                if (Close_SellFo && TotalProfitSellFo() >= Math.Pow(pf, 2.0) * TotalLot_sellfo())
                {
                    Closesellfo5();
                }
                if (Close_SellFo && TotalLot_sellfo5() > 0.02 && TotalProfitSellFo5() >= Math.Pow(pf / 1.5, 2.0) * TotalLot_sellfo5())
                {
                    Closesellfo5();
                }
                if (Close_SellFo && TotalLot_sellfo5() > 0.08 && TotalProfitSellFo5() >= Math.Pow(pf / 2.0, 2.0) * TotalLot_sellfo5())
                {
                    Closesellfo5();
                }
                if (Close_SellFo && TotalLot_sellfo5() > 0.16 && TotalProfitSellFo5() >= Math.Pow(pf / 2.5, 2.0) * TotalLot_sellfo5())
                {
                    Closesellfo5();
                }
            }
//SAMPLE SPACE OF CLOSED BUY&SELL TREND FOLLOW
//EVENTS
            if ((buy_fo1 > 0 || buy_fo2 > 0 || buy_fo3 > 0) && (sell_fo1 > 0 || sell_fo2 > 0 || sell_fo3 > 0 || sell_fo4 > 0 || sell_fo5 > 0))
            {
                if (Close_BuySellFo && TotalProfitBuySellFo() >= Math.Pow(pf, 2.0) * TotalLot())
                {
                    Closebuyfo1();
                    CloseAllSell();
                }
            }

//SAMPLE SPACE OF CLOSED BUY REVERSAL AND TREND FOLLOW
//EVENTS
            if (buy_re1 > 0 && buy_fo1 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo1();
                }
            }
            if (buy_re1 > 0 && buy_fo2 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo2();
                }
            }
            if (buy_re1 > 0 && buy_fo3 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo3();
                }
            }
            if (buy_re1 > 0 && buy_fo4 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo4();
                }
            }
            if (buy_re1 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo5();
                }
            }
            if (buy_re1 > 0 && buy_fo1 > 0 && buy_fo2 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo12();
                }
            }
            if (buy_re1 > 0 && buy_fo1 > 0 && buy_fo3 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo13();
                }
            }
            if (buy_re1 > 0 && buy_fo1 > 0 && buy_fo4 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo14();
                }
            }
            if (buy_re1 > 0 && buy_fo1 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo15();
                }
            }
            if (buy_re1 > 0 && buy_fo2 > 0 && buy_fo3 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo23();
                }
            }
            if (buy_re1 > 0 && buy_fo2 > 0 && buy_fo4 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo24();
                }
            }
            if (buy_re1 > 0 && buy_fo2 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo25();
                }
            }
            if (buy_re1 > 0 && buy_fo3 > 0 && buy_fo4 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo34();
                }
            }
            if (buy_re1 > 0 && buy_fo3 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo35();
                }
            }
            if (buy_re1 > 0 && buy_fo4 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo45();
                }
            }
            if (buy_re1 > 0 && buy_fo1 > 0 && buy_fo2 > 0 && buy_fo3 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo123();
                }
            }
            if (buy_re1 > 0 && buy_fo1 > 0 && buy_fo2 > 0 && buy_fo4 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo124();
                }
            }
            if (buy_re1 > 0 && buy_fo1 > 0 && buy_fo2 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo125();
                }
            }
            if (buy_re1 > 0 && buy_fo1 > 0 && buy_fo3 > 0 && buy_fo4 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo134();
                }
            }
            if (buy_re1 > 0 && buy_fo1 > 0 && buy_fo3 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo135();
                }
            }
            if (buy_re1 > 0 && buy_fo1 > 0 && buy_fo4 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo145();
                }
            }
            if (buy_re1 > 0 && buy_fo2 > 0 && buy_fo3 > 0 && buy_fo4 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo234();
                }
            }
            if (buy_re1 > 0 && buy_fo2 > 0 && buy_fo3 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo235();
                }
            }
            if (buy_re1 > 0 && buy_fo2 > 0 && buy_fo4 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo245();
                }
            }
            if (buy_re1 > 0 && buy_fo3 > 0 && buy_fo4 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo345();
                }
            }

            if (buy_re1 > 0 && buy_fo1 > 0 && buy_fo2 > 0 && buy_fo3 > 0 && buy_fo4 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo1234();
                }
            }
            if (buy_re1 > 0 && buy_fo1 > 0 && buy_fo2 > 0 && buy_fo3 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo1235();
                }
            }
            if (buy_re1 > 0 && buy_fo1 > 0 && buy_fo3 > 0 && buy_fo4 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo1345();
                }
            }
            if (buy_re1 > 0 && buy_fo2 > 0 && buy_fo3 > 0 && buy_fo4 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo2345();
                }
            }
            if (buy_re1 > 0 && buy_fo1 > 0 && buy_fo2 > 0 && buy_fo3 > 0 && buy_fo4 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re1fo12345();
                }
            }

            if (buy_re2 > 0 && buy_fo1 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re2fo1();
                }
            }
            if (buy_re2 > 0 && buy_fo2 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re2fo2();
                }
            }
            if (buy_re2 > 0 && buy_fo3 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re2fo3();
                }
            }
            if (buy_re2 > 0 && buy_fo4 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re2fo4();
                }
            }
            if (buy_re2 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re2fo5();
                }
            }
            if (buy_re3 > 0 && buy_fo1 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re3fo1();
                }
            }
            if (buy_re3 > 0 && buy_fo2 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re3fo2();
                }
            }
            if (buy_re3 > 0 && buy_fo3 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re3fo3();
                }
            }
            if (buy_re3 > 0 && buy_fo4 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re3fo4();
                }
            }
            if (buy_re3 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re3fo5();
                }
            }
            if (buy_re4 > 0 && buy_fo1 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re4fo1();
                }
            }
            if (buy_re4 > 0 && buy_fo2 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re4fo2();
                }
            }
            if (buy_re4 > 0 && buy_fo3 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re4fo3();
                }
            }
            if (buy_re4 > 0 && buy_fo4 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re4fo4();
                }
            }
            if (buy_re4 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re4fo5();
                }
            }
            if (buy_re5 > 0 && buy_fo1 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re5fo1();
                }
            }
            if (buy_re5 > 0 && buy_fo2 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re5fo2();
                }
            }
            if (buy_re5 > 0 && buy_fo3 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re5fo3();
                }
            }
            if (buy_re5 > 0 && buy_fo4 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re5fo4();
                }
            }
            if (buy_re5 > 0 && buy_fo5 > 0)
            {
                if (Close_BuyReFo && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                {
                    Closebuy_re5fo5();
                }
            }


            if (buy_re1 > 0 || buy_re2 > 0 || buy_re3 > 0 || buy_re4 > 0 || buy_fo1 > 0 || buy_fo2 > 0 || buy_fo3 > 0 || buy_fo4 > 0 || buy_fo5 > 0)
            {
                if (Close1 && TotalProfit() >= Math.Pow(pf, 2.0) * TotalLot())
                {
                    ClosePendingBS();
                    ClosePendingBL();
                    ClosePendingSS();
                    ClosePendingSL();
                    CloseAll();
                }
            }

            if (sell_re1 > 0 || sell_re2 > 0 || sell_re3 > 0 || sell_re4 > 0 || sell_fo1 > 0 || sell_fo2 > 0 || sell_fo3 > 0 || sell_fo4 > 0 || sell_fo5 > 0)
            {
                if (Close1 && TotalProfit() >= Math.Pow(pf, 2.0) * TotalLot())
                {
                    ClosePendingBS();
                    ClosePendingBL();
                    ClosePendingSS();
                    ClosePendingSL();
                    CloseAll();
                }
            }

            if (buy_re1 > 0 || buy_re2 > 0 || buy_re3 > 0 || buy_re4 > 0 || buy_re5 > 0 || buy_fo1 > 0 || buy_fo2 > 0 || buy_fo3 > 0 || buy_fo4 > 0 || buy_fo5 > 0)
            {
                //if (Close2 && TotalProfitBuy() >= Math.Pow(pf, 2.0) * TotalLotBuy())
                //{
                // ClosePendingBS();
                // ClosePendingBL();
                // CloseAllBuy();
                //}
                if (Close2 && TotalLotBuy() == 0.01 && TotalProfitBuy() >= Math.Pow(pf * 1.5, 2.0) * TotalLotBuy())
                {
                    CloseAllBuy();
                }
                if (Close2 && TotalLotBuy() == 0.02 && TotalProfitBuy() >= Math.Pow(pf * 1.25, 2.0) * TotalLotBuy())
                {
                    CloseAllBuy();
                }
                if (Close2 && TotalLotBuy() == 0.03 && TotalProfitBuy() >= Math.Pow(pf * 0.9, 2.0) * TotalLotBuy())
                {
                    CloseAllBuy();
                }
                if (Close2 && buy_re1 == 3 && TotalLotBuy() == 0.03 && TotalProfitBuy() >= Math.Pow(pf * 0.5, 2.0) * TotalLotBuy())
                {
                    CloseAllBuy();
                }
                if (Close2 && TotalLotBuy() == 0.04 && TotalProfitBuy() >= Math.Pow(pf * 0.8, 2.0) * TotalLotBuy())
                {
                    CloseAllBuy();
                }
                if (Close2 && TotalLotBuy() == 0.05 && TotalProfitBuy() >= Math.Pow(pf * 0.7, 2.0) * TotalLotBuy())
                {
                    CloseAllBuy();
                }
                if (Close2 && totalPositions0 > 0 && TotalLotBuy() == 0.05 && TotalProfitBuy() >= Math.Pow(pf * 0.1, 2.0) * TotalLotBuy())
                {
                    CloseAllBuy();
                }
                if (Close2 && TotalLotBuy() == 0.06 && TotalProfitBuy() >= Math.Pow(pf * 0.6, 2.0) * TotalLotBuy())
                {
                    CloseAllBuy();
                }
                if (Close2 && TotalLotBuy() >= 0.07 && TotalProfitBuy() >= Math.Pow(pf * 0.5, 2.0) * TotalLotBuy())
                {
                    CloseAllBuy();
                }
                if (Close2 && TotalLotBuy() >= 0.12 && TotalProfitBuy() >= Math.Pow(pf * 0.25, 2.0) * TotalLotBuy())
                {
                    CloseAllBuy();
                }
                if (Close2 && TotalLotBuy() >= 0.32 && TotalProfitBuy() >= Math.Pow(pf * 0.1, 2.0) * TotalLotBuy())
                {
                    CloseAllBuy();
                }

            }


            if (sell_re1 > 0 || sell_re2 > 0 || sell_re3 > 0 || sell_re4 > 0 || sell_fo1 > 0 || sell_fo2 > 0 || sell_fo3 > 0 || sell_fo4 > 0 || sell_fo5 > 0)
            {
                //if (Close2 && TotalProfitSell() >= Math.Pow(pf, 2.0) * TotalLotSell())
                //{
                //ClosePendingSS();
                //ClosePendingSL();
                //CloseAllSell();
                //}
                if (Close2 && TotalLotSell() == 0.01 && TotalProfitSell() >= Math.Pow(pf * 1.5, 2.0) * TotalLotSell())
                {
                    CloseAllSell();
                }
                if (Close2 && TotalLotSell() == 0.02 && TotalProfitSell() >= Math.Pow(pf * 1.25, 2.0) * TotalLotSell())
                {
                    CloseAllSell();
                }
                if (Close2 && TotalLotSell() == 0.03 && TotalProfitSell() >= Math.Pow(pf * 0.9, 2.0) * TotalLotSell())
                {
                    CloseAllSell();
                }
                if (Close2 && TotalLotSell() == 0.04 && TotalProfitSell() >= Math.Pow(pf * 0.8, 2.0) * TotalLotSell())
                {
                    CloseAllSell();
                }
                if (Close2 && TotalLotSell() == 0.05 && TotalProfitSell() >= Math.Pow(pf * 0.7, 2.0) * TotalLotSell())
                {
                    CloseAllSell();
                }
                if (Close2 && TotalLotSell() == 0.06 && TotalProfitSell() >= Math.Pow(pf * 0.6, 2.0) * TotalLotSell())
                {
                    CloseAllSell();
                }
                if (Close2 && TotalLotSell() >= 0.07 && TotalProfitSell() >= Math.Pow(pf * 0.5, 2.0) * TotalLotSell())
                {
                    CloseAllSell();
                }
                if (Close2 && TotalLotSell() >= 0.12 && TotalProfitSell() >= Math.Pow(pf * 0.25, 2.0) * TotalLotSell())
                {
                    CloseAllSell();
                }
                if (Close2 && TotalLotSell() >= 0.32 && TotalProfitSell() >= Math.Pow(pf * 1.5, 2.0) * TotalLotSell())
                {
                    CloseAllSell();
                }
            }

            if (buy_re1 > 0 || buy_re2 > 0 || buy_re3 > 0 || buy_re4 > 0 || buy_fo1 > 0 || buy_fo2 > 0 || buy_fo3 > 0 || buy_fo4 > 0)
            {
                if (Close3 && TotalProfitSellBuy() >= Math.Pow(pf, 2.0) * TotalLotSellBuy())
                {
                    CloseAllSellBuy();
                }
            }

            if (sell_re1 > 0 || sell_re2 > 0 || sell_re3 > 0 || sell_re4 > 0 || sell_fo1 > 0 || sell_fo2 > 0 || sell_fo3 > 0 || sell_fo4 > 0)
            {
                if (Close3 && TotalProfitBuySell() >= Math.Pow(pf, 2.0) * TotalLotBuySell())
                {
                    CloseAllBuySell();
                }
            }

            if (buy_re1 > 0 || buy_re2 > 0 || buy_re3 > 0 || buy_re4 > 0)
            {
                if (Close4 && TotalProfitBuyBuySell() >= Math.Pow(pf, 2.0) * TotalLotBuyBuySell())
                {
                    CloseAllBuyBuySell();
                }
            }

            if (sell_re1 > 0 || sell_re2 > 0 || sell_re3 > 0 || sell_re4 > 0)
            {
                if (Close4 && TotalProfitSellSellBuy() >= Math.Pow(pf, 2.0) * TotalLotSellSellBuy())
                {
                    CloseAllSellSellBuy();
                }
            }

            if (BeEnabled)
            {
                BreakEven();
            }

            if (BeEnabled2)
            {
                BreakEven2();
            }

            totalPositions0 = 0;
            totalPositions1 = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "BS" || order.Label == PositionId + "BL")
                {
                    totalPositions0++;
                }
            }

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "SS" || order.Label == PositionId + "SL")
                {
                    totalPositions1++;
                }
            }

            if (totalPositions0 >= MaxOrder)
            {
                ClosePendingBS();
                ClosePendingBL();
            }

            if (totalPositions1 >= MaxOrder)
            {
                ClosePendingSS();
                ClosePendingSL();
            }

            int bs_count = 0;
            double low_order = 0.0;
            foreach (var order in PendingOrders)
            {
                if (order.Label == PositionId + "BS")
                {
                    bs_count++;
                    if (low_order == 0 || low_order > order.TargetPrice)
                    {
                        low_order = order.TargetPrice;
                    }
                }
            }

            int low_orderInPips = (int)(double)((low_order - Symbol.Bid) / Symbol.PipSize);

            if (CheckDay() && CheckTime() && bs_count == 0 && (totalPositions0 < MaxOrder))
            {
                if ((TrendEnabled == false || ((double.IsNaN(ORTF.UT_EMAClose.Last(1)) == false && ORTF.UT_EMAClose.Last(1) <= MarketSeries.Low.Last(1)) && (double.IsNaN(ORTF.DT_EMAClose.Last(1)) || ORTF.DT_EMAClose.Last(1) <= MarketSeries.Low.Last(1)))))
                {
                    OpenPendingBS(TradeType.Buy);
                }

                if ((TrendEnabled && ((double.IsNaN(ORTF.UT_EMAClose.Last(1)) == false && ORTF.UT_EMAClose.Last(1) <= MarketSeries.Low.Last(1)) && (double.IsNaN(ORTF.DT_EMAClose.Last(1)) || ORTF.DT_EMAClose.Last(1) <= MarketSeries.Low.Last(1)))))
                {
                    ClosePendingSS();
                    ClosePendingSL();
                }
            }
            else if (bs_count > 0 && bs_count < BS_order && (totalPositions0 < MaxOrder))
            {
                OpenPendingBS(TradeType.Buy);
            }
            else if (bs_count == BS_order && low_orderInPips >= DM + FG && (totalPositions0 < MaxOrder))
            {
                ClosePendingBS();
                OpenPendingBS(TradeType.Buy);
            }

            //////////////////////////////////////////////////////////////////////////////

            int ss_count = 0;
            double high_order = 0.0;
            foreach (var order in PendingOrders)
            {
                if (order.Label == PositionId + "SS")
                {
                    ss_count++;
                    if (high_order == 0 || high_order < order.TargetPrice)
                    {
                        high_order = order.TargetPrice;
                    }
                }
            }

            int high_orderInPips = (int)(double)((Symbol.Bid - high_order) / Symbol.PipSize);

            if (CheckDay() && CheckTime() && ss_count == 0 && (totalPositions1 < MaxOrder))
            {
                if ((TrendEnabled == false || ((double.IsNaN(ORTF.DT_EMAClose.Last(1)) == false && ORTF.DT_EMAClose.Last(1) >= MarketSeries.High.Last(1)) && (double.IsNaN(ORTF.UT_EMAClose.Last(1)) || ORTF.UT_EMAClose.Last(1) >= MarketSeries.High.Last(1)))))
                {
                    OpenPendingSS(TradeType.Sell);
                }

                if ((TrendEnabled && ((double.IsNaN(ORTF.DT_EMAClose.Last(1)) == false && ORTF.DT_EMAClose.Last(1) >= MarketSeries.High.Last(1)) && (double.IsNaN(ORTF.UT_EMAClose.Last(1)) || ORTF.UT_EMAClose.Last(1) >= MarketSeries.High.Last(1)))))
                {
                    ClosePendingBS();
                    ClosePendingBL();
                }
            }
            else if (ss_count > 0 && ss_count < SS_order && (totalPositions1 < MaxOrder))
            {
                OpenPendingSS(TradeType.Sell);
            }
            else if (ss_count == SS_order && high_orderInPips >= DM + FG && (totalPositions1 < MaxOrder))
            {
                ClosePendingSS();
                OpenPendingSS(TradeType.Sell);
            }

            //////////////////////////////////////////////////////////////////////////////

            int bl_count = 0;
            double high_order_bl = 0.0;
            foreach (var order in PendingOrders)
            {
                if (order.Label == PositionId + "BL")
                {
                    bl_count++;
                    if (high_order_bl == 0 || high_order_bl < order.TargetPrice)
                    {
                        high_order_bl = order.TargetPrice;
                    }
                }
            }

            int high_orderInPips_bl = (int)(double)((Symbol.Bid - high_order_bl) / Symbol.PipSize);

            if (CheckDay() && CheckTime() && bl_count == 0 && (totalPositions0 < MaxOrder))
            {
                if ((TrendEnabled == false || ((double.IsNaN(ORTF.UT_EMAClose.Last(1)) == false && ORTF.UT_EMAClose.Last(1) <= MarketSeries.Low.Last(1)) && (double.IsNaN(ORTF.DT_EMAClose.Last(1)) || ORTF.DT_EMAClose.Last(1) <= MarketSeries.Low.Last(1)))))
                {
                    OpenPendingBL(TradeType.Buy);
                }

                if ((TrendEnabled && ((double.IsNaN(ORTF.UT_EMAClose.Last(1)) == false && ORTF.UT_EMAClose.Last(1) <= MarketSeries.Low.Last(1)) && (double.IsNaN(ORTF.DT_EMAClose.Last(1)) || ORTF.DT_EMAClose.Last(1) <= MarketSeries.Low.Last(1)))))
                {
                    ClosePendingSS();
                    ClosePendingSL();
                }
            }
            else if (bl_count > 0 && bl_count < BL_order && (totalPositions0 < MaxOrder))
            {
                OpenPendingBL(TradeType.Buy);
            }
            else if (bl_count == BL_order && high_orderInPips_bl >= DM + FG && (totalPositions0 < MaxOrder))
            {
                ClosePendingBL();
                OpenPendingBL(TradeType.Buy);
            }

            //////////////////////////////////////////////////////////////////////////////

            int sl_count = 0;
            double low_order_sl = 0.0;
            foreach (var order in PendingOrders)
            {
                if (order.Label == PositionId + "SL")
                {
                    sl_count++;
                    if (low_order_sl == 0 || low_order_sl > order.TargetPrice)
                    {
                        low_order_sl = order.TargetPrice;
                    }
                }
            }

            int low_orderInPips_sl = (int)(double)((low_order_sl - Symbol.Bid) / Symbol.PipSize);

            if (CheckDay() && CheckTime() && sl_count == 0 && (totalPositions1 < MaxOrder))
            {
                if ((TrendEnabled == false || ((double.IsNaN(ORTF.DT_EMAClose.Last(1)) == false && ORTF.DT_EMAClose.Last(1) >= MarketSeries.High.Last(1)) && (double.IsNaN(ORTF.UT_EMAClose.Last(1)) || ORTF.UT_EMAClose.Last(1) >= MarketSeries.High.Last(1)))))
                {
                    OpenPendingSL(TradeType.Sell);
                }

                if ((TrendEnabled && ((double.IsNaN(ORTF.DT_EMAClose.Last(1)) == false && ORTF.DT_EMAClose.Last(1) >= MarketSeries.High.Last(1)) && (double.IsNaN(ORTF.UT_EMAClose.Last(1)) || ORTF.UT_EMAClose.Last(1) >= MarketSeries.High.Last(1)))))
                {
                    ClosePendingBS();
                    ClosePendingBL();
                }
            }
            else if (sl_count > 0 && sl_count < SL_order && (totalPositions1 < MaxOrder))
            {
                OpenPendingSL(TradeType.Sell);
            }
            else if (sl_count == SL_order && low_orderInPips_sl >= DM + FG && (totalPositions1 < MaxOrder))
            {
                ClosePendingSL();
                OpenPendingSL(TradeType.Sell);
            }
        }


        protected override void OnStop()
        {
            // Put your deinitialization logic here
            ClosePendingBS();
            ClosePendingSS();
            ClosePendingBL();
            ClosePendingSL();
        }

        private void OpenPendingBS(TradeType tradeType)
        {
            var volumeInUnits = Symbol.QuantityToVolume(Quantity);

            int bs_count = 0;
            double last_order = 0.0;
            foreach (var order in PendingOrders)
            {
                if (order.Label == PositionId + "BS")
                {
                    bs_count++;
                    if (last_order == 0 || last_order < order.TargetPrice)
                    {
                        last_order = order.TargetPrice;
                    }
                }
            }

            if (bs_count == 0 && (B_orderEnabled))
            {
                for (int i = 1; i <= BS_order; i++)
                {
                    double newPrice = Symbol.Bid + (FG) * Symbol.PipSize;

                    if (i > 1)
                    {
                        newPrice = newPrice + ((GBP + TP) * (i - 1)) * Symbol.PipSize;
                    }

                    PlaceStopOrder(tradeType, Symbol, volumeInUnits, newPrice, PositionId + "BS");
                }
            }
            else if (bs_count > 0 && bs_count < BS_order && B_orderEnabled)
            {
                double newPrice = last_order;

                newPrice = newPrice + ((GBP + TP)) * Symbol.PipSize;

                PlaceStopOrder(tradeType, Symbol, volumeInUnits, newPrice, PositionId + "BS");
            }

            foreach (var order in PendingOrders)
            {
                if (order.Label == PositionId + "BS" && (order.TakeProfitPips != TP || order.StopLossPips != SL))
                {
                    ModifyPendingOrder(order, order.TargetPrice, SL, TP, order.ExpirationTime);
                }
            }
        }

        private void OpenPendingSS(TradeType tradeType)
        {
            var volumeInUnits = Symbol.QuantityToVolume(Quantity);

            int ss_count = 0;
            double last_order = 0.0;
            foreach (var order in PendingOrders)
            {
                if (order.Label == PositionId + "SS")
                {
                    ss_count++;
                    if (last_order == 0 || last_order > order.TargetPrice)
                    {
                        last_order = order.TargetPrice;
                    }
                }
            }

            if (ss_count == 0 && S_orderEnabled)
            {
                for (int i = 1; i <= SS_order; i++)
                {
                    double newPrice = Symbol.Bid - (FG) * Symbol.PipSize;

                    if (i > 1)
                    {
                        newPrice = newPrice - ((GBP + TP) * (i - 1)) * Symbol.PipSize;
                    }

                    PlaceStopOrder(tradeType, Symbol, volumeInUnits, newPrice, PositionId + "SS");
                }
            }
            else if (ss_count > 0 && ss_count < SS_order && S_orderEnabled)
            {
                double newPrice = last_order;

                newPrice = newPrice - ((GBP + TP)) * Symbol.PipSize;

                PlaceStopOrder(tradeType, Symbol, volumeInUnits, newPrice, PositionId + "SS");
            }

            foreach (var order in PendingOrders)
            {
                if (order.Label == PositionId + "SS" && (order.TakeProfitPips != TP || order.StopLossPips != SL))
                {
                    ModifyPendingOrder(order, order.TargetPrice, SL, TP, order.ExpirationTime);
                }
            }
        }

        private void OpenPendingBL(TradeType tradeType)
        {
            var volumeInUnits = Symbol.QuantityToVolume(Quantity);

            int bl_count = 0;
            double last_order = 0.0;
            foreach (var order in PendingOrders)
            {
                if (order.Label == PositionId + "BL")
                {
                    bl_count++;
                    if (last_order == 0 || last_order > order.TargetPrice)
                    {
                        last_order = order.TargetPrice;
                    }
                }
            }

            if (bl_count == 0 && B_orderEnabled)
            {
                for (int i = 1; i <= BL_order; i++)
                {
                    double newPrice = Symbol.Bid - (FG) * Symbol.PipSize;

                    if (i > 1)
                    {
                        newPrice = newPrice - ((GBP + TP) * (i - 1)) * Symbol.PipSize;
                    }

                    PlaceLimitOrder(tradeType, Symbol, volumeInUnits, newPrice, PositionId + "BL");
                }
            }
            else if (bl_count > 0 && bl_count < BL_order && B_orderEnabled)
            {
                double newPrice = last_order;

                newPrice = newPrice - ((GBP + TP)) * Symbol.PipSize;

                PlaceLimitOrder(tradeType, Symbol, volumeInUnits, newPrice, PositionId + "BL");
            }

            foreach (var order in PendingOrders)
            {
                if (order.Label == PositionId + "BL" && (order.TakeProfitPips != TP || order.StopLossPips != SL))
                {
                    ModifyPendingOrder(order, order.TargetPrice, SL, TP, order.ExpirationTime);
                }
            }
        }

        private void OpenPendingSL(TradeType tradeType)
        {
            var volumeInUnits = Symbol.QuantityToVolume(Quantity);

            int sl_count = 0;
            double last_order = 0.0;
            foreach (var order in PendingOrders)
            {
                if (order.Label == PositionId + "SL")
                {
                    sl_count++;
                    if (last_order == 0 || last_order < order.TargetPrice)
                    {
                        last_order = order.TargetPrice;
                    }
                }
            }

            if (sl_count == 0 && S_orderEnabled)
            {
                for (int i = 1; i <= SL_order; i++)
                {
                    double newPrice = Symbol.Bid + (FG) * Symbol.PipSize;

                    if (i > 1)
                    {
                        newPrice = newPrice + ((GBP + TP) * (i - 1)) * Symbol.PipSize;
                    }

                    PlaceLimitOrder(tradeType, Symbol, volumeInUnits, newPrice, PositionId + "SL");
                }
            }
            else if (sl_count > 0 && sl_count < SL_order && S_orderEnabled)
            {
                double newPrice = last_order;

                newPrice = newPrice + ((GBP + TP)) * Symbol.PipSize;

                PlaceLimitOrder(tradeType, Symbol, volumeInUnits, newPrice, PositionId + "SL");
            }

            foreach (var order in PendingOrders)
            {
                if (order.Label == PositionId + "SL" && (order.TakeProfitPips != TP || order.StopLossPips != SL))
                {
                    ModifyPendingOrder(order, order.TargetPrice, SL, TP, order.ExpirationTime);
                }
            }
        }

        private void ClosePendingBS()
        {
            foreach (var order in PendingOrders)
            {
                if (order.Label == PositionId + "BS")
                {
                    CancelPendingOrder(order);
                }
            }
        }

        private void ClosePendingSS()
        {
            foreach (var order in PendingOrders)
            {
                if (order.Label == PositionId + "SS")
                {
                    CancelPendingOrder(order);
                }
            }
        }

        private void ClosePendingBL()
        {
            foreach (var order in PendingOrders)
            {
                if (order.Label == PositionId + "BL")
                {
                    CancelPendingOrder(order);
                }
            }
        }

        private void ClosePendingSL()
        {
            foreach (var order in PendingOrders)
            {
                if (order.Label == PositionId + "SL")
                {
                    CancelPendingOrder(order);
                }
            }
        }

        private bool CheckDay()
        {
            if (Server.Time.DayOfWeek == DayOfWeek.Monday && MondayEnabled == false)
            {
                return (false);
            }
            else if (Server.Time.DayOfWeek == DayOfWeek.Tuesday && TuesdayEnabled == false)
            {
                return (false);
            }
            else if (Server.Time.DayOfWeek == DayOfWeek.Wednesday && WednesdayEnabled == false)
            {
                return (false);
            }
            else if (Server.Time.DayOfWeek == DayOfWeek.Thursday && ThursdayEnabled == false)
            {
                return (false);
            }
            else if (Server.Time.DayOfWeek == DayOfWeek.Friday && FridayEnabled == false)
            {
                return (false);
            }
            else
            {
                return (true);
            }
        }

        private bool CheckTime()
        {
            // Start Time is the same day at 22:00:00 Server Time
            DateTime _startTime = Server.Time.Date.AddHours(StartTime).AddMinutes(StartTimeMinute);

            // Stop Time is the next day at 06:00:00
            DateTime _stopTime = Server.Time.Date.AddHours(StopTime).AddMinutes(StopTimeMinute);

            DateTime currentHours = Server.Time;

            if (TimerEnabled && (currentHours < _startTime || currentHours > _stopTime))
            {
                return (false);
            }
            else
            {
                return (true);
            }
        }


        private double TotalProfit()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "BL" || order.Label == PositionId + "BS" || order.Label == PositionId + "SL" || order.Label == PositionId + "SS")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "buy re1" || order.Label == PositionId + "buy re2" || order.Label == PositionId + "buy re3" || order.Label == PositionId + "buy re4" || order.Label == PositionId + "buy re5")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "buy fo1" || order.Label == PositionId + "buy fo2" || order.Label == PositionId + "buy fo3" || order.Label == PositionId + "buy fo4" || order.Label == PositionId + "buy fo5")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "sell re1" || order.Label == PositionId + "sell re2" || order.Label == PositionId + "sell re3" || order.Label == PositionId + "sell re4")
                {
                    pf += order.NetProfit;
                }
            }

            return (pf);
        }

        private double TotalProfitBuy()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "BL" || order.Label == PositionId + "BS")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "buy re1" || order.Label == PositionId + "buy re2" || order.Label == PositionId + "buy re3" || order.Label == PositionId + "buy re4" || order.Label == PositionId + "buy re5")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "buy fo1" || order.Label == PositionId + "buy fo2" || order.Label == PositionId + "buy fo3" || order.Label == PositionId + "buy fo4" || order.Label == PositionId + "buy fo5")
                {
                    pf += order.NetProfit;
                }
            }

            return (pf);
        }
        private double TotalProfitBuyRe()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "BL" || order.Label == PositionId + "BS")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "buy re1" || order.Label == PositionId + "buy re2" || order.Label == PositionId + "buy re3" || order.Label == PositionId + "buy re4" || order.Label == PositionId + "buy re5")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitBuyRe1()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "BL" || order.Label == PositionId + "BS")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "buy re1")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitBuyRe2()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "BL" || order.Label == PositionId + "BS")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "buy re2")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitBuyRe3()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "BL" || order.Label == PositionId + "BS")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "buy re3")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitBuyRe4()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "BL" || order.Label == PositionId + "BS")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "buy re4")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitBuyRe5()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "BL" || order.Label == PositionId + "BS")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "buy re5")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitBuyFo()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo1" || order.Label == PositionId + "buy fo2" || order.Label == PositionId + "buy fo3" || order.Label == PositionId + "buy fo4" || order.Label == PositionId + "buy fo5")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitBuyFo1()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo1")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitBuyFo2()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo2")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitBuyFo3()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo3")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitBuyFo4()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo4")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitBuyFo5()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo5")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitSellFo()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell fo1" || order.Label == PositionId + "sell fo2" || order.Label == PositionId + "sell fo3" || order.Label == PositionId + "sell fo4" || order.Label == PositionId + "sell fo5")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitSellFo1()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell fo1")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitSellFo2()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell fo2")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitSellFo3()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell fo3")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitSellFo4()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell fo4")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitSellFo5()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell fo5")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitBuySellFo()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo1" || order.Label == PositionId + "buy fo2" || order.Label == PositionId + "buy fo3" || order.Label == PositionId + "buy fo4" || order.Label == PositionId + "buy fo5")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "sell fo1" || order.Label == PositionId + "sell fo2" || order.Label == PositionId + "sell fo3" || order.Label == PositionId + "sell fo4" || order.Label == PositionId + "sell fo5")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitBuy_re1()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re1")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitBuy_re2()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re2")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitBuy_re3()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re3")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitBuy_re4()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re4")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitBuy_re5()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re5")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }
        private double TotalProfitBuy_re5fo1()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re5")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "buy fo1")
                {
                    pf += order.NetProfit;
                }
            }
            return (pf);
        }


        private double TotalProfitSell()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "SL" || order.Label == PositionId + "SS")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "sell re1" || order.Label == PositionId + "sell re2" || order.Label == PositionId + "sell re3" || order.Label == PositionId + "sell re4")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "sell fo1" || order.Label == PositionId + "sell fo2" || order.Label == PositionId + "sell fo3" || order.Label == PositionId + "sell fo4" || order.Label == PositionId + "sell fo5")
                {
                    pf += order.NetProfit;
                }
            }

            return (pf);
        }

        private int TotalOrder(string n)
        {
            int t = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + n)
                {
                    t++;
                }
            }

            return (t);
        }
        private double TotalLot_buyre1()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re1")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }
        private double TotalLot_buyre2()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re2")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }
        private double TotalLot_buyre3()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re3")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }
        private double TotalLot_buyre4()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re4")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }
        private double TotalLot_buyre5()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re5")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }
        private double TotalLot_buyre()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re1" || order.Label == PositionId + "buy re2" || order.Label == PositionId + "buy re3" || order.Label == PositionId + "buy re4" || order.Label == PositionId + "buy re5")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }
        private double TotalLot_buyfo()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo1" || order.Label == PositionId + "buy fo2" || order.Label == PositionId + "buy fo3" || order.Label == PositionId + "buy fo4" || order.Label == PositionId + "buy fo5")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }
        private double TotalLot_buyfo1()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo1")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }
        private double TotalLot_buyfo2()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo2")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }
        private double TotalLot_buyfo3()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo3")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }
        private double TotalLot_buyfo4()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo4")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }
        private double TotalLot_buyfo5()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo5")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }
        private double TotalLot_sellfo()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell fo1" || order.Label == PositionId + "sell fo2" || order.Label == PositionId + "sell fo3" || order.Label == PositionId + "sell fo4" || order.Label == PositionId + "sell fo5")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }
        private double TotalLot_sellfo1()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell fo1")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }
        private double TotalLot_sellfo2()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell fo2")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }
        private double TotalLot_sellfo3()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell fo3")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }
        private double TotalLot_sellfo4()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell fo4")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }
        private double TotalLot_sellfo5()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell fo5")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }


        private double TotalLot()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "BL" || order.Label == PositionId + "BS" || order.Label == PositionId + "SL" || order.Label == PositionId + "SS")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
                else if (order.Label == PositionId + "buy re1" || order.Label == PositionId + "buy re2" || order.Label == PositionId + "buy re3" || order.Label == PositionId + "buy re4")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
                else if (order.Label == PositionId + "sell re1" || order.Label == PositionId + "sell re2" || order.Label == PositionId + "sell re3" || order.Label == PositionId + "sell re4")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
                else if (order.Label == PositionId + "buy fo1" || order.Label == PositionId + "buy fo2" || order.Label == PositionId + "buy fo3" || order.Label == PositionId + "buy fo4" || order.Label == PositionId + "buy fo5")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
                else if (order.Label == PositionId + "sell fo1" || order.Label == PositionId + "sell fo2" || order.Label == PositionId + "sell fo3" || order.Label == PositionId + "sell fo4" || order.Label == PositionId + "sell fo5")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }

            return (lot);
        }

        private double TotalLotBuy()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "BL" || order.Label == PositionId + "BS")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
                else if (order.Label == PositionId + "buy re1" || order.Label == PositionId + "buy re2" || order.Label == PositionId + "buy re3" || order.Label == PositionId + "buy re4" || order.Label == PositionId + "buy re5")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
                else if (order.Label == PositionId + "buy fo1" || order.Label == PositionId + "buy fo2" || order.Label == PositionId + "buy fo3" || order.Label == PositionId + "buy fo4" || order.Label == PositionId + "buy fo5")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }

            return (lot);
        }
        private double TotalLotBuy_re5fo1()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re5")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
                else if (order.Label == PositionId + "buy fo1")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }
            return (lot);
        }

        private double TotalLotSell()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "SL" || order.Label == PositionId + "SS")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
                else if (order.Label == PositionId + "sell re1" || order.Label == PositionId + "sell re2" || order.Label == PositionId + "sell re3" || order.Label == PositionId + "sell re4")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
                else if (order.Label == PositionId + "sell fo1" || order.Label == PositionId + "sell fo2" || order.Label == PositionId + "sell fo3" || order.Label == PositionId + "sell fo4" || order.Label == PositionId + "sell fo5")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }

            return (lot);
        }
        private void BreakEven()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                if (position != null && position.TradeType == TradeType.Buy && position.Pips >= BePips && position.StopLoss == null)
                {
                    ModifyPosition(position, (position.EntryPrice + AddPips * Symbol.PipSize), position.TakeProfit);

                }
            }

            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                if (position != null && position.TradeType == TradeType.Buy && position.Pips >= BePips && position.StopLoss == null)
                {
                    ModifyPosition(position, (position.EntryPrice + AddPips * Symbol.PipSize), position.TakeProfit);

                }
            }

            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                if (position != null && position.TradeType == TradeType.Buy && position.Pips >= BePips && position.StopLoss == null)
                {
                    ModifyPosition(position, (position.EntryPrice + AddPips * Symbol.PipSize), position.TakeProfit);

                }
            }

            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                if (position != null && position.TradeType == TradeType.Buy && position.Pips >= BePips && position.StopLoss == null)
                {
                    ModifyPosition(position, (position.EntryPrice + AddPips * Symbol.PipSize), position.TakeProfit);

                }
            }

            foreach (var position in Positions.FindAll(PositionId + "sell fo1", Symbol))
            {
                if (position != null && position.TradeType == TradeType.Sell && position.Pips >= BePips && position.StopLoss == null)
                {
                    ModifyPosition(position, (position.EntryPrice - AddPips * Symbol.PipSize), position.TakeProfit);

                }
            }

            foreach (var position in Positions.FindAll(PositionId + "sell fo2", Symbol))
            {
                if (position != null && position.TradeType == TradeType.Sell && position.Pips >= BePips && position.StopLoss == null)
                {
                    ModifyPosition(position, (position.EntryPrice - AddPips * Symbol.PipSize), position.TakeProfit);

                }
            }

            foreach (var position in Positions.FindAll(PositionId + "sell fo3", Symbol))
            {
                if (position != null && position.TradeType == TradeType.Sell && position.Pips >= BePips && position.StopLoss == null)
                {
                    ModifyPosition(position, (position.EntryPrice - AddPips * Symbol.PipSize), position.TakeProfit);

                }
            }

            foreach (var position in Positions.FindAll(PositionId + "sell fo4", Symbol))
            {
                if (position != null && position.TradeType == TradeType.Sell && position.Pips >= BePips && position.StopLoss == null)
                {
                    ModifyPosition(position, (position.EntryPrice - AddPips * Symbol.PipSize), position.TakeProfit);

                }
            }
        }

        private void BreakEven2()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                if (position != null && position.TradeType == TradeType.Buy && position.Pips >= BePips && position.StopLoss == null)
                {
                    ModifyPosition(position, (position.EntryPrice + AddPips * Symbol.PipSize), position.TakeProfit);

                }
            }

            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                if (position != null && position.TradeType == TradeType.Buy && position.Pips >= BePips && position.StopLoss == null)
                {
                    ModifyPosition(position, (position.EntryPrice + AddPips * Symbol.PipSize), position.TakeProfit);

                }
            }

            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                if (position != null && position.TradeType == TradeType.Buy && position.Pips >= BePips && position.StopLoss == null)
                {
                    ModifyPosition(position, (position.EntryPrice + AddPips * Symbol.PipSize), position.TakeProfit);

                }
            }

            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                if (position != null && position.TradeType == TradeType.Buy && position.Pips >= BePips && position.StopLoss == null)
                {
                    ModifyPosition(position, (position.EntryPrice + AddPips * Symbol.PipSize), position.TakeProfit);

                }
            }

            foreach (var position in Positions.FindAll(PositionId + "sell re1", Symbol))
            {
                if (position != null && position.TradeType == TradeType.Sell && position.Pips >= BePips && position.StopLoss == null)
                {
                    ModifyPosition(position, (position.EntryPrice - AddPips * Symbol.PipSize), position.TakeProfit);

                }
            }

            foreach (var position in Positions.FindAll(PositionId + "sell re2", Symbol))
            {
                if (position != null && position.TradeType == TradeType.Sell && position.Pips >= BePips && position.StopLoss == null)
                {
                    ModifyPosition(position, (position.EntryPrice - AddPips * Symbol.PipSize), position.TakeProfit);

                }
            }

            foreach (var position in Positions.FindAll(PositionId + "sell re3", Symbol))
            {
                if (position != null && position.TradeType == TradeType.Sell && position.Pips >= BePips && position.StopLoss == null)
                {
                    ModifyPosition(position, (position.EntryPrice - AddPips * Symbol.PipSize), position.TakeProfit);

                }
            }

            foreach (var position in Positions.FindAll(PositionId + "sell re4", Symbol))
            {
                if (position != null && position.TradeType == TradeType.Sell && position.Pips >= BePips && position.StopLoss == null)
                {
                    ModifyPosition(position, (position.EntryPrice - AddPips * Symbol.PipSize), position.TakeProfit);

                }
            }
        }
        private void Closebuyre1()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre2()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre3()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre4()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre5()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre12()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre13()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre14()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre15()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre23()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre24()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre25()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre34()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre35()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre45()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre123()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre124()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre125()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre134()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre135()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre145()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre234()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre235()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre245()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre345()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre1234()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre1235()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre1345()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre2345()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyre12345()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyfo1()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyfo2()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyfo3()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyfo4()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyfo5()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyfo12()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyfo13()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyfo14()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyfo15()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyfo23()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyfo24()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyfo25()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyfo34()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyfo35()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuyfo45()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closesellfo1()
        {
            foreach (var position in Positions.FindAll(PositionId + "sell fo1", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closesellfo2()
        {
            foreach (var position in Positions.FindAll(PositionId + "sell fo2", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closesellfo3()
        {
            foreach (var position in Positions.FindAll(PositionId + "sell fo3", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closesellfo4()
        {
            foreach (var position in Positions.FindAll(PositionId + "sell fo4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closesellfo5()
        {
            foreach (var position in Positions.FindAll(PositionId + "sell fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo1()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo2()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo3()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo4()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo5()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo12()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo13()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo14()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo15()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo23()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo24()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo25()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo34()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo35()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo45()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo123()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo124()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo125()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo134()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo135()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo145()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo234()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo235()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo245()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo345()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo1234()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo1235()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo1345()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo2345()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re1fo12345()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re2fo1()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re2fo2()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re2fo3()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re2fo4()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re2fo5()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re3fo1()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re3fo2()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re3fo3()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re3fo4()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re3fo5()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re4fo1()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re4fo2()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re4fo3()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re4fo4()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re4fo5()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re5fo1()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re5fo2()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re5fo3()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re5fo4()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void Closebuy_re5fo5()
        {
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }
        }
        private void CloseAll()
        {
            foreach (var position in Positions.FindAll(PositionId + "BS", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "BL", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "SS", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "SL", Symbol))
            {
                ClosePosition(position);
            }

            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }

            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }

            foreach (var position in Positions.FindAll(PositionId + "sell re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell re4", Symbol))
            {
                ClosePosition(position);
            }

            foreach (var position in Positions.FindAll(PositionId + "sell fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell fo4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell fo5", Symbol))
            {
                ClosePosition(position);
            }
        }

        private void CloseAllBuy()
        {
            foreach (var position in Positions.FindAll(PositionId + "BS", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "BL", Symbol))
            {
                ClosePosition(position);
            }


            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re5", Symbol))
            {
                ClosePosition(position);
            }

            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo5", Symbol))
            {
                ClosePosition(position);
            }

        }

        private void CloseAllSell()
        {

            foreach (var position in Positions.FindAll(PositionId + "SS", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "SL", Symbol))
            {
                ClosePosition(position);
            }


            foreach (var position in Positions.FindAll(PositionId + "sell re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell re4", Symbol))
            {
                ClosePosition(position);
            }

            foreach (var position in Positions.FindAll(PositionId + "sell fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell fo4", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell fo5", Symbol))
            {
                ClosePosition(position);
            }
        }

        private void OpenOrder(TradeType tradeType, string n, double m)
        {
            var position = Positions.Find(PositionId + n, Symbol, tradeType);
            var volumeInUnits = Symbol.QuantityToVolume(m);

            int buy_re = TotalOrder("buy re1") + TotalOrder("buy re2") + TotalOrder("buy re3") + TotalOrder("buy re4") + TotalOrder("buy re5");
            int buy_fo = TotalOrder("buy fo1") + TotalOrder("buy fo2") + TotalOrder("buy fo3") + TotalOrder("buy fo4") + TotalOrder("buy fo5");

            int sell_re = TotalOrder("sell re1") + TotalOrder("sell re2") + TotalOrder("sell re3") + TotalOrder("sell re4");
            int sell_fo = TotalOrder("sell fo1") + TotalOrder("sell fo2") + TotalOrder("sell fo3") + TotalOrder("sell fo4") + TotalOrder("sell fo5");

            int buy_ = 0, sell_ = 0;

            double d_orderInPips = 0.0, id = 0.0, dmm = 0.0;

            if (n == "buy fo1" || n == "buy fo2" || n == "buy fo3" || n == "buy fo4" || n == "buy fo5")
            {
                d_orderInPips = (int)(double)((getLastBuy_fo() - Symbol.Ask) / Symbol.PipSize);
                buy_ = buy_fo;
                if (n == "buy fo1")
                {
                    id = IDTF1;
                    dmm = DMTF;
                }
                else if (n == "buy fo2")
                {
                    id = IDTF2;
                    dmm = DMTF;
                }
                else if (n == "buy fo3")
                {
                    id = IDTF3;
                    dmm = DMTF;
                }
                else if (n == "buy fo4")
                {
                    id = IDTF4;
                    dmm = DMTF;
                }
                else if (n == "buy fo5")
                {
                    id = IDTF5;
                    dmm = DMTF;
                }
            }
            else if (n == "buy re1" || n == "buy re2" || n == "buy re3" || n == "buy re4" || n == "buy re5")
            {
                d_orderInPips = (int)(double)((getLastBuy_re() - Symbol.Ask) / Symbol.PipSize);
                buy_ = buy_re;
                if (n == "buy re1")
                {
                    id = IDRE1;
                    dmm = DMRE;
                }
                else if (n == "buy re2")
                {
                    id = IDRE2;
                    dmm = DMRE;
                }
                else if (n == "buy re3")
                {
                    id = IDRE3;
                    dmm = DMRE;
                }
                else if (n == "buy re4")
                {
                    id = IDRE4;
                    dmm = DMRE;
                }
                else if (n == "buy re5")
                {
                    id = IDRE5;
                    dmm = DMRE;
                }

            }


            else if (n == "sell fo1" || n == "sell fo2" || n == "sell fo3" || n == "sell fo4" || n == "sell fo5")
            {
                d_orderInPips = (int)(double)((Symbol.Bid - getLastSell_fo()) / Symbol.PipSize);
                sell_ = sell_fo;
                if (n == "sell fo1")
                {
                    id = IDTF1;
                    dmm = DMTF;
                }
                else if (n == "sell fo2")
                {
                    id = IDTF2;
                    dmm = DMTF;
                }
                else if (n == "sell fo3")
                {
                    id = IDTF3;
                    dmm = DMTF;
                }
                else if (n == "sell fo4")
                {
                    id = IDTF4;
                    dmm = DMTF;
                }
                else if (n == "sell fo5")
                {
                    id = IDTF5;
                    dmm = DMTF;
                }
            }
            else if (n == "sell re1" || n == "sell re2" || n == "sell re3" || n == "sell re4" || n == "sell re5")
            {
                d_orderInPips = (int)(double)((Symbol.Bid - getLastSell_re()) / Symbol.PipSize);
                sell_ = sell_re;
                if (n == "sell re1")
                {
                    id = IDRE1;
                    dmm = DMRE;
                }
                else if (n == "sell re2")
                {
                    id = IDRE2;
                    dmm = DMRE;
                }
                else if (n == "sell re3")
                {
                    id = IDRE3;
                    dmm = DMRE;
                }
                else if (n == "sell re4")
                {
                    id = IDRE4;
                    dmm = DMRE;
                }
                else if (n == "sell re5")
                {
                    id = IDRE5;
                    dmm = DMRE;
                }
            }

            if (Open_DM && buy_ == 0)
            {
                if (tradeType == TradeType.Buy && (UpperSupplyZone == 0 || LowerSupplyZone == 0))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
                else if (tradeType == TradeType.Buy && (UpperSupplyZone != 0 && LowerSupplyZone != 0) && (Symbol.Ask > UpperSupplyZone && Symbol.Ask < LowerSupplyZone))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
            }
            else if (Open_DM && buy_ == 1 && d_orderInPips >= id)
            {
                if (tradeType == TradeType.Buy && (UpperSupplyZone == 0 || LowerSupplyZone == 0))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
                else if (tradeType == TradeType.Buy && (UpperSupplyZone != 0 && LowerSupplyZone != 0) && (Symbol.Ask > UpperSupplyZone && Symbol.Ask < LowerSupplyZone))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
            }
            // 
            else if (Open_DM && buy_ > 1 && d_orderInPips >= id * Math.Pow(Math.Pow(2.0, dmm), buy_ - 1))
            {
                if (tradeType == TradeType.Buy && (UpperSupplyZone == 0 || LowerSupplyZone == 0))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
                else if (tradeType == TradeType.Buy && (UpperSupplyZone != 0 && LowerSupplyZone != 0) && (Symbol.Ask > UpperSupplyZone && Symbol.Ask < LowerSupplyZone))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
            }
            else if (Open_DM && buy_ > 1 && getLastBuy_re() < Symbol.Ask && Math.Abs(d_orderInPips) > 50)
            {
                if (tradeType == TradeType.Buy && (UpperSupplyZone == 0 || LowerSupplyZone == 0))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
                else if (tradeType == TradeType.Buy && (UpperSupplyZone != 0 && LowerSupplyZone != 0) && (Symbol.Ask > UpperSupplyZone && Symbol.Ask < LowerSupplyZone))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
            }
            else if (Open_DM && buy_ > 4 && d_orderInPips >= id * Math.Pow(Math.Pow(2.0, dmm * 0.5), buy_ - 1))
            {
                if (tradeType == TradeType.Buy && (UpperSupplyZone == 0 || LowerSupplyZone == 0))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
                else if (tradeType == TradeType.Buy && (UpperSupplyZone != 0 && LowerSupplyZone != 0) && (Symbol.Ask > UpperSupplyZone && Symbol.Ask < LowerSupplyZone))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
            }



            if (sell_ == 0)
            {
                if (tradeType == TradeType.Sell && (UpperDemandZone == 0 || LowerDemandZone == 0))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
                else if (tradeType == TradeType.Sell && (UpperDemandZone != 0 && LowerDemandZone != 0) && (Symbol.Bid > UpperDemandZone && Symbol.Bid < LowerDemandZone))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
            }
            else if (sell_ == 1 && d_orderInPips >= id)
            {
                if (tradeType == TradeType.Sell && (UpperDemandZone == 0 || LowerDemandZone == 0))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
                else if (tradeType == TradeType.Sell && (UpperDemandZone != 0 && LowerDemandZone != 0) && (Symbol.Bid > UpperDemandZone && Symbol.Bid < LowerDemandZone))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
            }
            else if (sell_ > 1 && d_orderInPips >= id * Math.Pow(Math.Pow(2.0, dmm), sell_ - 1))
            {
                if (tradeType == TradeType.Sell && (UpperDemandZone == 0 || LowerDemandZone == 0))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
                else if (tradeType == TradeType.Sell && (UpperDemandZone != 0 && LowerDemandZone != 0) && (Symbol.Bid > UpperDemandZone && Symbol.Bid < LowerDemandZone))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
            }
            else if (sell_ > 1 && getLastBuy_re() > Symbol.Bid && Math.Abs(d_orderInPips) > 50)
            {
                if (tradeType == TradeType.Sell && (UpperDemandZone == 0 || LowerDemandZone == 0))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
                else if (tradeType == TradeType.Sell && (UpperDemandZone != 0 && LowerDemandZone != 0) && (Symbol.Bid > UpperDemandZone && Symbol.Bid < LowerDemandZone))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
            }
            else if (sell_ > 4 && d_orderInPips >= id * Math.Pow(Math.Pow(2.0, dmm * 0.5), sell_ - 1))
            {
                if (tradeType == TradeType.Sell && (UpperDemandZone == 0 || LowerDemandZone == 0))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
                else if (tradeType == TradeType.Sell && (UpperDemandZone != 0 && LowerDemandZone != 0) && (Symbol.Bid > UpperDemandZone && Symbol.Bid < LowerDemandZone))
                {
                    ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, PositionId + n, 0, 0);
                }
            }
        }

        private double getLastLotBuy()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "BL" || order.Label == PositionId + "BS")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
                else if (order.Label == PositionId + "buy re1" || order.Label == PositionId + "buy re2" || order.Label == PositionId + "buy re3" || order.Label == PositionId + "buy re4")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
                else if (order.Label == PositionId + "buy fo1" || order.Label == PositionId + "buy fo2" || order.Label == PositionId + "buy fo3" || order.Label == PositionId + "buy fo4" || order.Label == PositionId + "buy fo5")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLotSell()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "SL" || order.Label == PositionId + "SS")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
                else if (order.Label == PositionId + "sell re1" || order.Label == PositionId + "sell re2" || order.Label == PositionId + "sell re3" || order.Label == PositionId + "sell re4")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
                else if (order.Label == PositionId + "sell fo1" || order.Label == PositionId + "sell fo2" || order.Label == PositionId + "sell fo3" || order.Label == PositionId + "sell fo4" || order.Label == PositionId + "sell fo5")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLot()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "BL" || order.Label == PositionId + "BS")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
                else if (order.Label == PositionId + "buy re1" || order.Label == PositionId + "buy re2" || order.Label == PositionId + "buy re3" || order.Label == PositionId + "buy re4" || order.Label == PositionId + "buy re5")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
                else if (order.Label == PositionId + "buy fo1" || order.Label == PositionId + "buy fo2" || order.Label == PositionId + "buy fo3" || order.Label == PositionId + "buy fo4" || order.Label == PositionId + "buy fo5")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
                else if (order.Label == PositionId + "SL" || order.Label == PositionId + "SS")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
                else if (order.Label == PositionId + "sell re1" || order.Label == PositionId + "sell re2" || order.Label == PositionId + "sell re3" || order.Label == PositionId + "sell re4")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
                else if (order.Label == PositionId + "sell fo1" || order.Label == PositionId + "sell fo2" || order.Label == PositionId + "sell fo3" || order.Label == PositionId + "sell fo4" || order.Label == PositionId + "sell fo5")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double TotalProfitSellBuy()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "SL" || order.Label == PositionId + "SS")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "buy re1" || order.Label == PositionId + "buy re2" || order.Label == PositionId + "buy re3" || order.Label == PositionId + "buy re4")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "buy fo1" || order.Label == PositionId + "buy fo2" || order.Label == PositionId + "buy fo3" || order.Label == PositionId + "buy fo4" || order.Label == PositionId + "buy fo5")
                {
                    pf += order.NetProfit;
                }
            }

            return (pf);
        }

        private double TotalProfitBuySell()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "BL" || order.Label == PositionId + "BS")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "sell re1" || order.Label == PositionId + "sell re2" || order.Label == PositionId + "sell re3" || order.Label == PositionId + "sell re4")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "sell fo1" || order.Label == PositionId + "sell fo2" || order.Label == PositionId + "sell fo3" || order.Label == PositionId + "sell fo4" || order.Label == PositionId + "sell fo5")
                {
                    pf += order.NetProfit;
                }
            }

            return (pf);
        }

        private double TotalLotSellBuy()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "SL" || order.Label == PositionId + "SS")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
                else if (order.Label == PositionId + "buy re1" || order.Label == PositionId + "buy re2" || order.Label == PositionId + "buy re3" || order.Label == PositionId + "buy re4")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
                else if (order.Label == PositionId + "buy fo1" || order.Label == PositionId + "buy fo2" || order.Label == PositionId + "buy fo3" || order.Label == PositionId + "buy fo4" || order.Label == PositionId + "buy fo5")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }

            return (lot);
        }

        private double TotalLotBuySell()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "BL" || order.Label == PositionId + "BS")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
                else if (order.Label == PositionId + "sell re1" || order.Label == PositionId + "sell re2" || order.Label == PositionId + "sell re3" || order.Label == PositionId + "sell re4")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
                else if (order.Label == PositionId + "sell fo1" || order.Label == PositionId + "sell fo2" || order.Label == PositionId + "sell fo3" || order.Label == PositionId + "sell fo4" || order.Label == PositionId + "sell fo5")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }

            return (lot);
        }

        private void CloseAllSellBuy()
        {
            foreach (var position in Positions.FindAll(PositionId + "SS", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "SL", Symbol))
            {
                ClosePosition(position);
            }


            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }

            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }

        }

        private void CloseAllBuySell()
        {

            foreach (var position in Positions.FindAll(PositionId + "BS", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "BL", Symbol))
            {
                ClosePosition(position);
            }


            foreach (var position in Positions.FindAll(PositionId + "sell re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell re4", Symbol))
            {
                ClosePosition(position);
            }

            foreach (var position in Positions.FindAll(PositionId + "sell fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell fo4", Symbol))
            {
                ClosePosition(position);
            }
        }

        private double TotalProfitSellSellBuy()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "SL" || order.Label == PositionId + "SS")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "sell re1" || order.Label == PositionId + "sell re2" || order.Label == PositionId + "sell re3" || order.Label == PositionId + "sell re4")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "buy fo1" || order.Label == PositionId + "buy fo2" || order.Label == PositionId + "buy fo3" || order.Label == PositionId + "buy fo4")
                {
                    pf += order.NetProfit;
                }
            }

            return (pf);
        }

        private double TotalProfitBuyBuySell()
        {
            double pf = 0.0;
            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "BL" || order.Label == PositionId + "BS")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "buy re1" || order.Label == PositionId + "buy re2" || order.Label == PositionId + "buy re3" || order.Label == PositionId + "buy re4")
                {
                    pf += order.NetProfit;
                }
                else if (order.Label == PositionId + "sell fo1" || order.Label == PositionId + "sell fo2" || order.Label == PositionId + "sell fo3" || order.Label == PositionId + "sell fo4")
                {
                    pf += order.NetProfit;
                }
            }

            return (pf);
        }

        private double TotalLotSellSellBuy()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "SL" || order.Label == PositionId + "SS")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
                else if (order.Label == PositionId + "sell re1" || order.Label == PositionId + "sell re2" || order.Label == PositionId + "sell re3" || order.Label == PositionId + "sell re4")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
                else if (order.Label == PositionId + "buy fo1" || order.Label == PositionId + "buy fo2" || order.Label == PositionId + "buy fo3" || order.Label == PositionId + "buy fo4")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }

            return (lot);
        }

        private double TotalLotBuyBuySell()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "BL" || order.Label == PositionId + "BS")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
                else if (order.Label == PositionId + "buy re1" || order.Label == PositionId + "buy re2" || order.Label == PositionId + "buy re3" || order.Label == PositionId + "buy re4")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
                else if (order.Label == PositionId + "sell fo1" || order.Label == PositionId + "sell fo2" || order.Label == PositionId + "sell fo3" || order.Label == PositionId + "sell fo4")
                {
                    lot += Symbol.VolumeToQuantity(order.Volume);
                }
            }

            return (lot);
        }

        private void CloseAllSellSellBuy()
        {
            foreach (var position in Positions.FindAll(PositionId + "SS", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "SL", Symbol))
            {
                ClosePosition(position);
            }


            foreach (var position in Positions.FindAll(PositionId + "sell re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell re4", Symbol))
            {
                ClosePosition(position);
            }

            foreach (var position in Positions.FindAll(PositionId + "buy fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy fo4", Symbol))
            {
                ClosePosition(position);
            }

        }

        private void CloseAllBuyBuySell()
        {

            foreach (var position in Positions.FindAll(PositionId + "BS", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "BL", Symbol))
            {
                ClosePosition(position);
            }


            foreach (var position in Positions.FindAll(PositionId + "buy re1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "buy re4", Symbol))
            {
                ClosePosition(position);
            }

            foreach (var position in Positions.FindAll(PositionId + "sell fo1", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell fo2", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell fo3", Symbol))
            {
                ClosePosition(position);
            }
            foreach (var position in Positions.FindAll(PositionId + "sell fo4", Symbol))
            {
                ClosePosition(position);
            }
        }

        private double getLastLot_buy_re_y1()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re1")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLot_buy_re_y2()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re2")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLot_buy_re_y3()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re3")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLot_buy_re_y4()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re4")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }
        private double getLastLot_buy_re_y5()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re5")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLot_buy_fo_y1()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo1")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLot_buy_fo_y2()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo2")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLot_buy_fo_y3()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo3")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLot_buy_fo_y4()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo4")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLot_buy_fo_y5()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo5")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLot_sell_re_y1()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell re1")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLot_sell_re_y2()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell re2")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLot_sell_re_y3()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell re3")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLot_sell_re_y4()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell re4")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLot_sell_fo_y1()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell fo1")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLot_sell_fo_y2()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell fo2")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLot_sell_fo_y3()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell fo3")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLot_sell_fo_y4()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell fo4")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastLot_sell_fo_y5()
        {
            double lot = 0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell fo5")
                {
                    lot = Symbol.VolumeToQuantity(order.Volume);
                    //return (lot);
                }
            }

            return (lot);
        }

        private double getLastBuy_fo()
        {
            double op = 0.0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy fo1")
                {
                    op = order.EntryPrice;
                }
                else if (order.Label == PositionId + "buy fo2")
                {
                    op = order.EntryPrice;
                }
                else if (order.Label == PositionId + "buy fo3")
                {
                    op = order.EntryPrice;
                }
                else if (order.Label == PositionId + "buy fo4")
                {
                    op = order.EntryPrice;
                }
                else if (order.Label == PositionId + "buy fo5")
                {
                    op = order.EntryPrice;
                }
            }

            return (op);
        }

        private double getLastBuy_re()
        {
            double op = 0.0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re1")
                {
                    op = order.EntryPrice;
                }
                else if (order.Label == PositionId + "buy re2")
                {
                    op = order.EntryPrice;
                }
                else if (order.Label == PositionId + "buy re3")
                {
                    op = order.EntryPrice;
                }
                else if (order.Label == PositionId + "buy re4")
                {
                    op = order.EntryPrice;
                }
                else if (order.Label == PositionId + "buy re5")
                {
                    op = order.EntryPrice;
                }
            }

            return (op);
        }
        private double getLastBuy_re1()
        {
            double op = 0.0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re1")
                {
                    op = order.EntryPrice;
                }
            }

            return (op);
        }
        private double getLastBuy_re2()
        {
            double op = 0.0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "buy re2")
                {
                    op = order.EntryPrice;
                }
            }

            return (op);
        }

        private double getLastSell_fo()
        {
            double op = 0.0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell fo1")
                {
                    op = order.EntryPrice;
                }
                else if (order.Label == PositionId + "sell fo2")
                {
                    op = order.EntryPrice;
                }
                else if (order.Label == PositionId + "sell fo3")
                {
                    op = order.EntryPrice;
                }
                else if (order.Label == PositionId + "sell fo4")
                {
                    op = order.EntryPrice;
                }
                else if (order.Label == PositionId + "sell fo5")
                {
                    op = order.EntryPrice;
                }
            }

            return (op);
        }

        private double getLastSell_re()
        {
            double op = 0.0;

            foreach (var order in Positions)
            {
                if (order.Label == PositionId + "sell re1")
                {
                    op = order.EntryPrice;
                }
                else if (order.Label == PositionId + "sell re2")
                {
                    op = order.EntryPrice;
                }
                else if (order.Label == PositionId + "sell re3")
                {
                    op = order.EntryPrice;
                }
                else if (order.Label == PositionId + "sell re4")
                {
                    op = order.EntryPrice;
                }
                else if (order.Label == PositionId + "sell re5")
                {
                    op = order.EntryPrice;
                }
            }

            return (op);
        }
    }

}

 


@ogima.515@gmail.com

PanagiotisCharalampous
18 Feb 2021, 11:36 ( Updated at: 21 Dec 2023, 09:22 )

Hi,

Did you add a reference to System.Windows.Forms?

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous