Technical Error

Created at 16 May 2019, 04:33
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!
lec0456's avatar

lec0456

Joined 14.11.2012

Technical Error
16 May 2019, 04:33


I have a strange issue.  While Backtesting using FxPro on 12/10/2018, it is returning a Technical Error when I modify the positions. When the BOt opens a second buy or sell position the OnOpen event modifies the TP of all buy or sell position. If i use the ModifyPosition method directly, it gives me a technical error.  If i use my modified Modify trade procedure it does not. But I don't understand what is causeing the technical error or why their would be a difference.

OnOpen code:

            if (opened.Position.TradeType == TradeType.Buy && BuyCount > 1)
            {    
                 foreach (var position in Positions)
                 {   
                    if (position.TradeType == TradeType.Buy) 
                    ModifyPosition(position, null, RelPrice(10, opened.Position.TradeType));
                    //ModifyTrade("Martingale Buy TP Set: "+position.Label, position, null, RelPrice(10, opened.Position.TradeType));
                 }   
            }
            
            if (opened.Position.TradeType == TradeType.Sell && SellCount > 1)
            {
                foreach (var position in Positions)
                {
                    if (position.TradeType == TradeType.Sell) ModifyTrade("Martingale Sell TP Set: "+position.Label, position, null, RelPrice(9.5, opened.Position.TradeType));
                }
            }
        double RelPrice(double _takeprofitpips, TradeType _tradetype)
        {
            return Math.Round(_tradetype == TradeType.Buy ? AvgPrice(TradeType.Buy) + _takeprofitpips * Symbol.PipSize : AvgPrice(TradeType.Sell) - _takeprofitpips * Symbol.PipSize, 5);
        }
protected override void OnError(Error error)
        {
            switch (error.Code)  
            {
                case ErrorCode.BadVolume:                   
                    _thread = new Thread(() => {MessageBox.Show("ErrorCode: " +error.Code.ToString(), Account.BrokerName+" - "+this.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Stop);});
                    _thread.SetApartmentState(ApartmentState.STA);
                    _thread.Start();
                    Log(paramIntLogEnable, paramExtLogEnable,"ErrorCode: Bad volume for order open, robot is stopped.");
                    RobotStopped = true;
                    break;
                case ErrorCode.EntityNotFound:
                    //_thread = new Thread(() => {MessageBox.Show("ErrorCode: " +error.Code.ToString(), Account.BrokerName+" - "+this.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Stop );});
                    //_thread.SetApartmentState(ApartmentState.STA);
                    //_thread.Start();
                    Log(paramIntLogEnable, paramExtLogEnable,"ErrorCode: Entity Not Found.");
                    //RobotStopped = true;
                    break;
                case ErrorCode.TechnicalError:
                    _thread = new Thread(() => {MessageBox.Show("ErrorCode: " +error.Code.ToString(), Account.BrokerName+" - "+this.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Stop );});
                    _thread.SetApartmentState(ApartmentState.STA);
                    _thread.Start();
                    Log(paramIntLogEnable, paramExtLogEnable,"ErrorCode: Technical Error.");
                    //RobotStopped = true;
                    break;
                case ErrorCode.NoMoney:
                    MessageBox.Show("ErrorCode: " +error.Code.ToString(), Account.BrokerName+" - "+this.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Stop );
                    Log(paramIntLogEnable, paramExtLogEnable,"ErrorCode: No money for order open, robot is stopped.");
                    RobotStopped = true;
                    break;
                case ErrorCode.Disconnected:
                    MessageBox.Show("ErrorCode: " +error.Code.ToString(), Account.BrokerName+" - "+this.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Stop );
                    Log(paramIntLogEnable, paramExtLogEnable,"ErrorCode: Disconnected.");
                    break;
                case ErrorCode.MarketClosed:
                    MessageBox.Show("ErrorCode: " +error.Code.ToString(), Account.BrokerName+" - "+this.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Stop );
                    Log(paramIntLogEnable, paramExtLogEnable,"ErrorCode: The market is closed.");
                    break;
            }
        }

Is there anyway to get more error information to understand what is causing the technical error??


@lec0456
Replies

lec0456
16 May 2019, 04:39

I forgot to include my procedure that modifies the position.  For some reason, if I use it, it does not raise the technical error.  But it should because its using the same method.

        bool ModifyTrade(string descrip, Position position, double? sl = null, double? tp = null, bool _hasTrail=false)
        {
            if (position.StopLoss != sl || position.TakeProfit != tp)
            {
                Log(paramIntLogEnable, paramExtLogEnable,descrip);
                
                if (ModifyPosition(position, sl, tp, _hasTrail).IsSuccessful) return true;
                else Log(paramIntLogEnable, paramExtLogEnable,"Modify Failed: {0}", LastResult.Error);
            }
            return false;
        }

 


@lec0456

lec0456
16 May 2019, 08:54

Well, I figured out the issue.  If you try to modify a position and give it the same values it already has for Tp and SL, it will return a technical error.

I guess it would be nice to know if there are any more robust error messages that can be returned from the OnError event or TradeResult objects.


@lec0456