Cbot gives wrong calculation result

ctid3179522 since: 21 Jan 2021;

  15 Nov 2021, 14:37
Cbot gives wrong calculation result

 I made a bot that make trades based on the Inside bar pattern- it opens a trade when the previous candles+ wicks is smaller/bigger than the one before it. 

It gives me wrong weird math calculation result that contains candles prices like this : Bars.ClosePrices.Last(1) - Bars.OpenPrices.Last(1)

The value c is shown in log which  gives this subtractions result.

What could cause this?

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class InsideBarPatternbot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        [Parameter("volume", Group = "Volume", DefaultValue = 100000)]
        public double volume { get; set; }

        



        static double IB;
        static double c;

        protected override void OnStart()
        {


           
        }

        
        protected override void OnTick()
        {
            


            // check if inside bar
            if ((Bars.HighPrices.Last(2) > Bars.HighPrices.Last(1) & Bars.LowPrices.Last(2) < Bars.LowPrices.Last(1)))
            {
                // Print("open price{0}", (Bars.LowPrices.Last(2) - 0.1 * (Bars.HighPrices.Last(2) - Bars.LowPrices.Last(2))));

                c = (Bars.ClosePrices.Last(1) - Bars.OpenPrices.Last(1));
                Print("calculation {0}", c);

                 Print("open {0}", Bars.OpenPrices.Last(1));

                //   IB = (Bars.HighPrices.Last(2) - Bars.LowPrices.Last(2));



                if ((Bars.HighPrices.Last(2) - Bars.LowPrices.Last(2)) != IB)
                {
                    // check IB  1s candle range so it closes opens /trades only when new IB
                    IB = Bars.HighPrices.Last(2) - Bars.LowPrices.Last(2);

                    foreach (var order in PendingOrders)
                    {

                        CancelPendingOrder(order);
                    }

                    foreach (var position in Positions)
                    {

                        ClosePosition(position);

                    }



                    // check if long candle
                    if (Bars.ClosePrices.Last(2) - Bars.OpenPrices.Last(2) > 0)
                    {
                        var openprice = (Bars.HighPrices.Last(2) + 0.1 * (Bars.HighPrices.Last(2) - Bars.LowPrices.Last(2)));

                        PlaceStopOrder(TradeType.Buy, SymbolName, 100000, openprice, "myStopOrder");





                        foreach (var order in PendingOrders)
                        {
                            var sl1 = 100 * (0.4 * (Bars.HighPrices.Last(2) - Bars.LowPrices.Last(2)));
                            var tp1 = 100 * (0.8 * (Bars.HighPrices.Last(2) - Bars.LowPrices.Last(2)));

                            ModifyPendingOrder(order, order.TargetPrice, sl1, tp1, order.ExpirationTime);
                        }


                    }


                    else
                    {

                        var openprice1 = (Bars.LowPrices.Last(2) - 0.1 * (Bars.HighPrices.Last(2) - Bars.LowPrices.Last(2)));

                        PlaceStopOrder(TradeType.Sell, SymbolName, 100000, openprice1, "myStopOrder");

                        foreach (var order in PendingOrders)
                        {
                            Print(" sl  {0}", (100 * (0.4 * (Bars.HighPrices.Last(2) - Bars.LowPrices.Last(2)))));

                            var sl2 = 100 * (0.4 * (Bars.HighPrices.Last(2) - Bars.LowPrices.Last(2)));

                            var tp2 = 100 * (0.8 * (Bars.HighPrices.Last(2) - Bars.LowPrices.Last(2)));

                            ModifyPendingOrder(order, order.TargetPrice, sl2, tp2, order.ExpirationTime);
                        }


                    }
                }
            }




        }
    }
}





PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  15 Nov 2021, 14:41

Hi there,

Can you please provide us with examples of these "wrong weird math calculation results"?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Head of Community Management at cTrader

ctid3179522 since: 21 Jan 2021;

  18 Nov 2021, 11:34
RE:

PanagiotisCharalampous said:

Hi there,

Can you please provide us with examples of these "wrong weird math calculation results"?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 I took 2 screenshots to show them :

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  18 Nov 2021, 11:39

Hi there,

Please explain what do you thing s wrong here. The results seem correct to me.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Head of Community Management at cTrader

ctid3179522 since: 21 Jan 2021;

  18 Nov 2021, 21:14
RE:

PanagiotisCharalampous said:

Hi there,

Please explain what do you thing s wrong here. The results seem correct to me.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

The result of 1.15922 - 1.15949 is - 0,00027 not - 0.000269999999999992

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  18 Nov 2021, 21:26

Hi there,

That's normal. Read here. You need to apply rounding.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Head of Community Management at cTrader

ctid3179522 since: 21 Jan 2021;

  21 Nov 2021, 10:12
RE:

PanagiotisCharalampous said:

Hi there,

That's normal. Read here. You need to apply rounding.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

ok thank you