Labelling an Exit for Better Optimization

Created at 18 Dec 2024, 11:57
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!
TH

thecaffeinatedtrader

Joined 22.07.2020

Labelling an Exit for Better Optimization
18 Dec 2024, 11:57


Hi, 

I have a bot that will be using various moving averages as the exit criteria. 
Below are the exit lines that will be running during the back testing, but I want to be able to determine which moving average provides the best result.

Is there a way to use a label so in the events tab, after running optimization, I can see which MA's performed the best by seeing the actual MA type as the label instead of just seeing ‘position closed’ and not knowing which ExitMA was actually triggered?

Any help would be GREATLY appreciated! 
Thank you.

        private void Exit1(int index1)
        {              
                    {
                    var positions = Positions.FindAll(InstanceName, SymbolName);
              
                    foreach (var position in positions)

                    if ((position.TradeType == TradeType.Buy && Bars.ClosePrices[index1] < _ExitMA1.Result.LastValue) || (position.TradeType == TradeType.Sell && Bars.ClosePrices[index1] > _ExitMA1.Result.LastValue))
                    ClosePosition(position);
                    }
                    
        }
        private void Exit2(int index2)
        {              
                    {
                    var positions = Positions.FindAll(InstanceName, SymbolName);
              
                    foreach (var position in positions)

                    if ((position.TradeType == TradeType.Buy && Bars.ClosePrices[index2] < _ExitMA2.Result.LastValue) || (position.TradeType == TradeType.Sell && Bars.ClosePrices[index2] > _ExitMA2.Result.LastValue))
                    ClosePosition(position);
                    }
                    
        }
        private void Exit3(int index3)
        {              
                    {
                    var positions = Positions.FindAll(InstanceName, SymbolName);
              
                    foreach (var position in positions)

                    if ((position.TradeType == TradeType.Buy && Bars.ClosePrices[index3] < _ExitMA3.Result.LastValue) || (position.TradeType == TradeType.Sell && Bars.ClosePrices[index3] > _ExitMA3.Result.LastValue))
                    ClosePosition(position);
                    }
                    
        }
        private void Exit4(int index4)
        {              
                    {
                    var positions = Positions.FindAll(InstanceName, SymbolName);
              
                    foreach (var position in positions)

                    if ((position.TradeType == TradeType.Buy && Bars.ClosePrices[index4] < _ExitMA4.Result.LastValue) || (position.TradeType == TradeType.Sell && Bars.ClosePrices[index4] > _ExitMA4.Result.LastValue))
                    ClosePosition(position);
                    }
                    
        }
        private void Exit5(int index5)
        {              
                    {
                    var positions = Positions.FindAll(InstanceName, SymbolName);
              
                    foreach (var position in positions)

                    if ((position.TradeType == TradeType.Buy && Bars.ClosePrices[index5] < _ExitMA5.Result.LastValue) || (position.TradeType == TradeType.Sell && Bars.ClosePrices[index5] > _ExitMA5.Result.LastValue))
                    ClosePosition(position);
                    }
                    
        }
        private void Exit6(int index6)
        {              
                    {
                    var positions = Positions.FindAll(InstanceName, SymbolName);
              
                    foreach (var position in positions)

                    if ((position.TradeType == TradeType.Buy && Bars.ClosePrices[index6] < _ExitMA6.Result.LastValue) || (position.TradeType == TradeType.Sell && Bars.ClosePrices[index6] > _ExitMA6.Result.LastValue))
                    ClosePosition(position);
                    }
                    
        }
        private void Exit7(int index7)
        {              
                    {
                    var positions = Positions.FindAll(InstanceName, SymbolName);
              
                    foreach (var position in positions)

                    if ((position.TradeType == TradeType.Buy && Bars.ClosePrices[index7] < _ExitMA7.Result.LastValue) || (position.TradeType == TradeType.Sell && Bars.ClosePrices[index7] > _ExitMA7.Result.LastValue))
                    ClosePosition(position);
                    }
                    
        }
        private void Exit8(int index8)
        {              
                    {
                    var positions = Positions.FindAll(InstanceName, SymbolName);
              
                    foreach (var position in positions)

                    if ((position.TradeType == TradeType.Buy && Bars.ClosePrices[index8] < _ExitMA8.Result.LastValue) || (position.TradeType == TradeType.Sell && Bars.ClosePrices[index8] > _ExitMA8.Result.LastValue))
                    ClosePosition(position);
                    }
                    
        }

@thecaffeinatedtrader