It takes trade even with wrong condition

11 May 2019, 11:28It takes trade even with wrong condition#1
pierrecrotposts: 4since: 08 May 2019

Hi, Why in this case the bot takes trades even when the condition is wrong?

Thanks in advance for your help.

 

 if (_smaTrend1.Result.LastValue < _smaTrend2.Result.LastValue)
               
            {

                if (!IsPositionOpenByType(TradeType.Sell))
                {
                    OpenPosition(TradeType.Sell);
                }

            }

            ClosePosition(TradeType.Buy);
        }


 private void OpenPosition(TradeType type)
        {
            // calculate volume from lot size.
            long volume = Symbol.QuantityToVolume(LotSize);

            // open a new position
            ExecuteMarketOrder(type, this.Symbol, volume, InstanceName, StopLoss, TakeProfit);
        }

        private void ClosePosition(TradeType type)
        {
            var p = Positions.Find(InstanceName, this.Symbol, type);

            if (p != null)
            {
                ClosePosition(p);
            }
        }


private bool IsPositionOpenByType(TradeType type)
        {
            var p = Positions.FindAll(InstanceName, Symbol, type);

            if (p.Count() >= 1)
            {
                return true;
            }

            return false;
        }

        #endregion
    }
}

 

 

13 May 2019, 01:43#2
erisoftdevelopposts: 12since: 09 Feb 2019

What do you expect to do the robot...

What is the error clearly a good description?

 

 

13 May 2019, 09:16#3
pierrecrotposts: 4since: 08 May 2019

Hi, 

I'd like the robot to take position when the SMA Trend1 is lower than the SMA Trend2. Now it takes also position when Trend1 is higher than Trend2.

Thanks.

13 May 2019, 10:10#4
Panagiotis Charalampousposts: 2715since: 13 Jan 2017

Hi pierrecrot,

Can you provide the full cBot code, cBot parameters and backtesting dates so that we can reproduce this and provide an explanation?

Best Regards,

Panagiotis


Head of Community Management at cTrader