ctid3179522
ctid3179522's avatar

Info

Username:ctid3179522
Name:ctid3179522
Member since: 21 Jan 2021

About

None

Signature

None

Last Forum Posts

@Cbot gives wrong calculation result:  21 Nov 2021, 10:12


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

@Cbot gives wrong calculation result:  18 Nov 2021, 21:14


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

@Cbot gives wrong calculation result:  18 Nov 2021, 11:34


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 :

@Cbot gives wrong calculation result:  15 Nov 2021, 14:34


 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);
                        }


                    }
                }
            }




        }
    }
}





@Inside bar bot doesnt work:  02 Jun 2021, 08:59


PanagiotisCharalampous said:

Hi ctid3179522,

You need to be a bit more specific. What is the exact functionality you are trying to code? Where would you expect trades to open and they don't? 

Looking at the following conditions

Symbol.Bid == Bars.HighPrices.Last(2)

Symbol.Bid == Bars.LowPrices.Last(2)

 These will rarely be true.

Best Regards,

Panagiotis 

Join us on Telegram

 The 1st candle must contain the 2nd candle(1st high-low range contains de 2nd) , opens trade in current candle if price hits 1st candle high/low. If 1st candle is bullish than its buy order if its bearish than its sell order. I checked in backtesting and it doesnt open trades when these conditions are met like this year GBP/JPY  4 hour it opens no trades

@Inside bar bot doesnt work:  01 Jun 2021, 19:15


     Hello, I tried to write a simple inside bar robot but for some reason it doesnt open as many trades as it should or none. What could be the problem?

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 = 1, MinValue = 0.01, Step = 0.01)]
        public double volume { get; set; }

           

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


        protected override void OnTick()
        {
            

            if (Positions.Count == 0 && (Bars.ClosePrices.Last(2) - Bars.OpenPrices.Last(2)) > 0 & Bars.HighPrices.Last(2) > Bars.HighPrices.Last(1) & Bars.LowPrices.Last(2) < Bars.LowPrices.Last(1) & Symbol.Bid == Bars.HighPrices.Last(2))
            {

                


                var result = ExecuteMarketOrder(TradeType.Buy, SymbolName, 100000, "1", 10, 10);
                if (result.IsSuccessful)
                {
                    var position = result.Position;

                  


                    var sl = Bars.HighPrices.Last(2) - (0.4 * (Bars.HighPrices.Last(2) - Bars.LowPrices.Last(2)));
                    var tp = Bars.HighPrices.Last(2) + (0.8 * (Bars.HighPrices.Last(2) - Bars.LowPrices.Last(2)));

                    ModifyPosition(position, sl, tp);

               

                }
            }

            


            if (Positions.Count == 0 & (Bars.ClosePrices.Last(2) - Bars.OpenPrices.Last(2)) < 0 & Bars.HighPrices.Last(2) > Bars.HighPrices.Last(1) & Bars.LowPrices.Last(2) < Bars.LowPrices.Last(1) & Symbol.Bid == Bars.LowPrices.Last(2))
            {

var result = ExecuteMarketOrder(TradeType.Sell, SymbolName, 100000, "1", 10, 10);
                if (result.IsSuccessful)
                {
                    var position = result.Position;


                    var sl = Bars.LowPrices.Last(2) + (0.4 * (Bars.HighPrices.Last(2) - Bars.LowPrices.Last(2)));
                    var tp = Bars.LowPrices.Last(2) - (0.8 * (Bars.HighPrices.Last(2) - Bars.LowPrices.Last(2)));


                    ModifyPosition(position, sl, tp);
                }
            }
        }


        
        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}
 

@Martingale sample bot backtest issue:  25 Feb 2021, 12:40


ctid3179522 said:

PanagiotisCharalampous said:

Hi ctid3179522,

Can you share the cBot code?

Best Regards,

Panagiotis 

Join us on Telegram

  It is the Sample Martingale bot that comes with Ctrader installation. nothing changed but if you think i mistakenly changed something here it is:

// -------------------------------------------------------------------------------------------------
//
//    This code is a cTrader Automate API example.
//
//    This cBot is intended to be used as a sample and does not guarantee any particular outcome or
//    profit of any kind. Use it at your own risk.
//    
//    All changes to this file might be lost on the next application update.
//    If you are going to modify this file please make a copy using the "Duplicate" command.
//
//    The "Sample Martingale cBot" creates a random Sell or Buy order. If the Stop loss is hit, a new 
//    order of the same type (Buy / Sell) is created with double the Initial Volume amount. The cBot will 
//    continue to double the volume amount for  all orders created until one of them hits the take Profit. 
//    After a Take Profit is hit, a new random Buy or Sell order is created with the Initial Volume amount.
//
// -------------------------------------------------------------------------------------------------

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SampleMartingalecBot : Robot
    {
        [Parameter("Initial Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double InitialQuantity { get; set; }

        [Parameter("Stop Loss", Group = "Protection", DefaultValue = 40)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", Group = "Protection", DefaultValue = 40)]
        public int TakeProfit { get; set; }


        private Random random = new Random();

        protected override void OnStart()
        {
            Positions.Closed += OnPositionsClosed;

            ExecuteOrder(InitialQuantity, GetRandomTradeType());
        }

        private void ExecuteOrder(double quantity, TradeType tradeType)
        {
            var volumeInUnits = Symbol.QuantityToVolumeInUnits(quantity);
            var result = ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "Martingale", StopLoss, TakeProfit);

            if (result.Error == ErrorCode.NoMoney)
                Stop();
        }

        private void OnPositionsClosed(PositionClosedEventArgs args)
        {
            Print("Closed");
            var position = args.Position;

            if (position.Label != "Martingale" || position.SymbolName != SymbolName)
                return;

            if (position.GrossProfit > 0)
            {
                ExecuteOrder(InitialQuantity, GetRandomTradeType());
            }
            else
            {
                ExecuteOrder(position.Quantity * 2, position.TradeType);
            }
        }

        private TradeType GetRandomTradeType()
        {
            return random.Next(2) == 0 ? TradeType.Buy : TradeType.Sell;
        }
    }
}

@Martingale sample bot backtest issue:  25 Feb 2021, 12:37


PanagiotisCharalampous said:

Hi ctid3179522,

Can you share the cBot code?

Best Regards,

Panagiotis 

Join us on Telegram

  It is the Sample Martingale bot that comes with Ctrader installation. nothing changed

@Martingale sample bot backtest issue:  24 Feb 2021, 22:34


   I have the latest Ctrader version, and while backtesting this bot the optimization backtest didnt match the simple bactktest at all- it gave completely different results, also it gave different result each time I ran it . I deleted Ctrader cache. The optimization gives slightly different result each time I ran it. I dont have this problem with other bots.  Maybe it happens to others or its something wrong with my system? I am building a bot based on it so I can't fully test the bot

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.

No uploaded.

Warning! Executing cBots downloaded from this section may result in loss of funds. Use them at your own risk.

No uploaded.