Replies

Nobody
11 Dec 2020, 10:15 ( Updated at: 11 Dec 2020, 10:22 )

RE:

PanagiotisCharalampous said:

Hi Nobody,

Please provide the complete cBot code and steps to reproduce the problem, like cBot parameters, backtesting dates etc.

Best Regards,

Panagiotis 

Join us on Telegram

Hi Pangiotis,

i just found error using logger, it occurs when SL (pips) too much near prices, crash disappears when i add this condition before sending order :

         //Control SL value from actual price
          if(tradetype ==TradeType.Buy && sl_pips > 0 && ((_ms.ClosePrices.Last(0)-sl_pips) > _robot.Symbol.Bid))
          {
            _log.Write("Buy Order rejected : SL over Bid price !");
            return;
          }
          else if (tradetype ==TradeType.Sell && sl_pips > 0 && ((_ms.ClosePrices.Last(0)+sl_pips) > _robot.Symbol.Ask))
          {
            _log.Write("Sell Order rejected : SL under Ask price !");
            return;
          }
          //Send order
          TradeResult result;
          result = _robot.ExecuteMarketOrder(tradetype, _robot.SymbolName, vol, _cBotLabel, sl_pips, tp_pips, my_comment);
       

Core should reject order in this context or recording SL with some value (0 ?) that won't make program crashed ...

Regards,

Alex


@Nobody

Nobody
18 Nov 2020, 15:43 ( Updated at: 21 Dec 2023, 09:22 )

RE:

PanagiotisCharalampous said:

Hi Nobody,

I guess that the problem is here

If you notice the series have only 96 bars but your are looking for a 420 moving average. You should make sure that you have at least as much bars as the moving average period else load more using LoadMoreHistory() method. Let me know if this resolves the problem.

Best Regards,

Panagiotis 

Join us on Telegram

...i am so...Stupid ! ;( thank you very much Panagiotis....i didn't think to check this ! solved !


@Nobody

Nobody
18 Nov 2020, 12:57 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE:

Panagiotis,

 

here a simpler code that reproduce this issue... as you can see on printscreens : 2h HMA typical price 420 peiod in cbot = 13152 and for same parameters on chart 12.509

2h SMA 100 close is equal on chart and cbot as HMA  typical price 17 periods 5mn...unbelievable !

 

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System.Collections.Generic;
using System.Web.Script.Serialization;
// Add System.Web.Extension reference
using Microsoft.CSharp.RuntimeBinder;
// Add Microsoft.CSharp reference
using System.Dynamic;
using System.Globalization;

namespace cAlgo
{
    [Robot(AccessRights = AccessRights.FullAccess, TimeZone = TimeZones.WEuropeStandardTime)]
//TimeZone = TimeZones.WEuropeStandardTime, 

    public class BOT_MOD : Robot
    {
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //                                                      PARAMETERS INITIALIZATION
        //
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public enum TradeTypeFilter
        {
            No,
            Buy,
            Sell
        }

        //SIGNAL SETTINGS
        [Parameter("Main Signal Timeframe", Group = "SIGNAL SETTINGS")]
        public TimeFrame _ms2_timeframe { get; set; }

        //TIME FRAME 3
        [Parameter("Second Timeframe (optional)", Group = "SIGNAL SETTINGS")]
        public TimeFrame _ms3_timeframe { get; set; }

        //TIME FRAME 4
        [Parameter("Third Timeframe (optional)", Group = "SIGNAL SETTINGS")]
        public TimeFrame _ms4_timeframe { get; set; }

        //TIME FRAME 5
        [Parameter("Third Timeframe (optional)", Group = "SIGNAL SETTINGS")]
        public TimeFrame _ms5_timeframe { get; set; }

        //TIME FRAME 6
        [Parameter("Third Timeframe (optional)", Group = "SIGNAL SETTINGS")]
        public TimeFrame _ms6_timeframe { get; set; }



        //MACD PARAMETERS
        public int _macd_long_cycle = 26;
        public int _macd_short_cycle = 12;
        public int _macd_period = 9;


        //STOCHASTIC PARAMETERS
        public int _sto_K_Periods = 8;
        public int _sto_D_Periods = 3;
        public int _sto_K_Slowing = 3;

        //MA PARAMETERS
        public MovingAverageType _MA_Type = MovingAverageType.Simple;


        //BOT TIME FRAME INDICATORS (1mn)
        private int _ms_index = 0;
        private Bars _ms;
        private BollingerBands _boll;
        private MacdCrossOver _macd;
        private RelativeStrengthIndex _rsi;

        //UT2 TIMEFRAME INDICATORS (5mn)
        private int _ms2_index = 0;
        private Bars _ms2;
        private BollingerBands _boll_ms2;
        private MacdCrossOver _macd_ms2;
        private RelativeStrengthIndex _rsi_ms2;
        private MovingAverage _ma7_ms2, _ma20_ms2, _ma50_ms2, _ma100_ms2;
        private HullMovingAverage _hma17_ms2;
        private StochasticforIndicators _stoRsi_ms2;

        //UT3 TIMEFRAME INDICATORS (15mn)
        private int _ms3_index = 0;
        private Bars _ms3;
        private BollingerBands _boll_ms3;
        private MacdCrossOver _macd_ms3;
        private RelativeStrengthIndex _rsi_ms3;
        private MovingAverage _ma6_ms3, _ma8_ms3;
        private HullMovingAverage _hma20_ms3;

        //UT4 TIMEFRAME INDICATORS (30mn)
        private int _ms4_index = 0;
        private Bars _ms4;
        private MovingAverage _ma3_ms4;
        private MovingAverage _ma6_ms4;

        //UT5 TIMEFRAME INDICATORS (2h)
        private int _ms5_index = 0;
        private Bars _ms5;
        private RelativeStrengthIndex _rsi_ms5;
        private StochasticforIndicators _stoRsi_ms5;
        private HullMovingAverage _hma420_ms5;
        private TriangularMovingAverage _tma40_ms5;
        private Supertrend _st_ms5;
        private MovingAverage _ma5_ms100;

        //UT6 TIMEFRAME INDICATORS (Daily)
        private int _ms6_index = 0;
        private Bars _ms6;



        //BOT NAME
        public string _cBotLabel = "BOT_MOD";



        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //                                                      OnStart METHOD
        //
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        protected override void OnStart()
        {

            //Set the offset of the current bar
            _ms_index = Bars.ClosePrices.Count - 1;

            //ROBOT DEFAULT TIMEFRAME INDICATORS
            Print("Load Main TF Indicators...\r\n");
            _ms = MarketData.GetBars(TimeFrame);
            _boll = Indicators.BollingerBands(_ms.ClosePrices, 20, 2, _MA_Type);
            _macd = Indicators.MacdCrossOver(_macd_long_cycle, _macd_short_cycle, _macd_period);
            _rsi = Indicators.RelativeStrengthIndex(_ms.ClosePrices, 14);

            //SIGNAL TIMEFRAME INDICATORS
            Print("Load MS2 TF Indicators...\r\n");
            _ms2 = MarketData.GetBars(_ms2_timeframe);
            _boll_ms2 = Indicators.BollingerBands(_ms2.ClosePrices, 20, 2, _MA_Type);
            _macd_ms2 = Indicators.MacdCrossOver(_ms2.ClosePrices, _macd_long_cycle, _macd_short_cycle, _macd_period);
            _rsi_ms2 = Indicators.RelativeStrengthIndex(_ms2.ClosePrices, 10);
            _ma7_ms2 = Indicators.MovingAverage(_ms2.ClosePrices, 7, MovingAverageType.Simple);
            _ma20_ms2 = Indicators.MovingAverage(_ms2.ClosePrices, 23, MovingAverageType.Simple);
            _ma50_ms2 = Indicators.MovingAverage(_ms2.ClosePrices, 50, MovingAverageType.Simple);
            _ma100_ms2 = Indicators.MovingAverage(_ms2.ClosePrices, 100, MovingAverageType.Simple);
            _hma17_ms2 = Indicators.HullMovingAverage(_ms2.TypicalPrices, 17);
            _stoRsi_ms2 = Indicators.GetIndicator<StochasticforIndicators>(12, 3, MovingAverageType.Simple, 7, _rsi_ms2.Result);

            // TIMEFRAME 3 INDICATORS
            Print("Load MS3 TF Indicators...\r\n");
            _ms3 = MarketData.GetBars(_ms3_timeframe);
            _boll_ms3 = Indicators.BollingerBands(_ms3.ClosePrices, 20, 2, _MA_Type);
            _macd_ms3 = Indicators.MacdCrossOver(_ms3.ClosePrices, _macd_long_cycle, _macd_short_cycle, _macd_period);
            _rsi_ms3 = Indicators.RelativeStrengthIndex(_ms3.ClosePrices, 14);
            _ma6_ms3 = Indicators.MovingAverage(_ms3.TypicalPrices, 6, MovingAverageType.Simple);
            _ma8_ms3 = Indicators.MovingAverage(_ms3.TypicalPrices, 8, MovingAverageType.Simple);
            _hma20_ms3 = Indicators.HullMovingAverage(_ms3.TypicalPrices, 20);

            // TIMEFRAME 4 INDICATORS
            Print("Load MS4 TF Indicators...\r\n");
            _ms4 = MarketData.GetBars(_ms4_timeframe);
            _ma3_ms4 = Indicators.MovingAverage(_ms4.TypicalPrices, 3, MovingAverageType.Simple);
            _ma6_ms4 = Indicators.MovingAverage(_ms4.TypicalPrices, 6, MovingAverageType.Simple);

            //TIMEFRAME 5 INDICATORS
            Print("Load MS5 TF Indicators...\r\n");
            _ms5 = MarketData.GetBars(_ms5_timeframe);
            _rsi_ms5 = Indicators.RelativeStrengthIndex(_ms5.ClosePrices, 6);
            _stoRsi_ms5 = Indicators.GetIndicator<StochasticforIndicators>(19, 5, MovingAverageType.Simple, 3, _rsi_ms5.Result);
            _hma420_ms5 = Indicators.HullMovingAverage(_ms5.ClosePrices, 420);
            _tma40_ms5 = Indicators.TriangularMovingAverage(_ms5.ClosePrices, 40);
            _st_ms5 = Indicators.Supertrend(3, 3);
            _ma5_ms100 = Indicators.MovingAverage(_ms5.ClosePrices, 100, MovingAverageType.Simple);

            //TIMEFRAME 6 INDICATORS
            Print("Load MS6 TF Indicators...\r\n");
            _ms6 = MarketData.GetBars(_ms6_timeframe);


        }



        protected override void OnTick()
        {
        }


        protected override void OnBar()
        {
            //Refresh the offsets of the current bar
            _ms_index = Bars.ClosePrices.Count - 1;
            _ms2_index = _ms2.ClosePrices.Count - 1;
            _ms3_index = _ms3.ClosePrices.Count - 1;
            _ms4_index = _ms4.ClosePrices.Count - 1;
            _ms5_index = _ms5.ClosePrices.Count - 1;
            _ms6_index = _ms6.ClosePrices.Count - 1;


            //Check the famous signal
            CheckSignal();

        }


        protected override void OnStop()
        {

        }


        public void OnPositionOpened(PositionOpenedEventArgs obj)
        {
            if (Object.ReferenceEquals(null, obj.Position))
                Print("WOW ! FATAL ERROR !");

        }

        private void CheckSignal()
        {
            //Check if opened conditions needs to be closed (and close them)
            CheckConditionsToClosePositions();


            //Check Buy signal
            if (IsSignalBuy())
            {
                double sl_dist_pips = (Symbol.Ask * 0.015) / Symbol.PipSize;
                double tp_dist_pips = (Symbol.Ask * 0.016) / Symbol.PipSize;
                ExecuteMarketOrder(TradeType.Buy, SymbolName, 1, _cBotLabel, Math.Round(sl_dist_pips, 1), Math.Round(tp_dist_pips, 1), "my_comment");

            }

        }

        private bool IsSignalBuy()
        {
            int opened_pos_buy = 0;
            foreach (Position position in Positions.FindAll(_cBotLabel, SymbolName))
            {
                if (position.TradeType == TradeType.Buy)
                    opened_pos_buy += 1;
            }

            if (opened_pos_buy > 0)
                return false;

            //UT2H : C1 = MMHull 2h doit être ascendante
            //if (_hma420_ms5.Result.Last(1) < _hma420_ms5.Result.Last(2))
            if (_ma5_ms100.Result.Last(1) < _ma5_ms100.Result.Last(2))
                return false;

            //UT2H : C11 = MM40 triangulaire UT2h doit être ascendnate
            if (_tma40_ms5.Result.Last(1) < _tma40_ms5.Result.Last(2))
                return false;

            //UT2H : C13 =  K Sto RSI UT2h doit être > D
            if (_stoRsi_ms5.KLine.Last(1) < _stoRsi_ms5.DLine.Last(1))
                return false;

            //UT2H :C3 = la clôture de la bougie précédente doit être supérieur à la valeur du SuperTrend[3,3] UT2h en cours 
            if (_ms5.ClosePrices.Last(1) < Math.Max(_st_ms5.DownTrend.Last(1), _st_ms5.UpTrend.Last(1)))
                return false;

            //UT30 : C15 = la MM 3 périodes (typicalprice) UT30  doit être >  MA  6 périodes(typicalprice) 
            if (_ma3_ms4.Result.Last(1) < _ma6_ms4.Result.Last(1))
                return false;

            //UT15 : C7 = la MM 6 périodes UT15 (sur typical price) doit être au dessus de la MM 8 périodes UT15 (sur typical price)
            if (_ma6_ms3.Result.Last(1) < _ma8_ms3.Result.Last(1))
                return false;


            //UT15 : C9 = la MM 20 périodes de Hull UT15 est ascendante
            if (_hma20_ms3.Result.Last(1) < _hma20_ms3.Result.Last(2))
                return false;

            //UT5 : La distance entre le plus haut du jour et le plus haut de la bougie Ut5mn actuelle soit inférieur à 140 points
            if (_ms6.HighPrices.Last(0) - _ms2.HighPrices.Last(0) > 140)
                return false;

            //UT5 : C5 =  en 5mn la MM de Hull 17 périodes est entrain de se retourner à la hausse (avec la bougie en cours)
            if (!(_hma17_ms2.Result.Last(0) > _hma17_ms2.Result.Last(1) && _hma17_ms2.Result.Last(1) < _hma17_ms2.Result.Last(2)))
                return false;

            //UT5 : C23 = Stochastic RSI 10 périodes lissé UT5mn à l’achat (K>D)
            if (!(_stoRsi_ms2.KLine.Last(0) < _stoRsi_ms2.DLine.Last(0)))
                return false;

            return true;
        }


        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //                                                      CheckConditionsToClosePositions METHOD
        //
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private void CheckConditionsToClosePositions()
        {
            int opened_pos_buy = 0;
            Position last_pos_buy = null;
            foreach (Position position in Positions.FindAll(_cBotLabel, SymbolName))
            {
                if (position.TradeType == TradeType.Buy)
                {
                    opened_pos_buy += 1;
                    last_pos_buy = position;
                }
            }
            if (opened_pos_buy < 1)
                return;


            //Exit in profit (C6 & C8)
            if (_hma17_ms2.Result.Last(0) < _hma17_ms2.Result.Last(1) && _hma17_ms2.Result.Last(1) > _hma17_ms2.Result.Last(2) && _ma6_ms3.Result.Last(1) < _ma8_ms3.Result.Last(1) && Symbol.Bid > last_pos_buy.EntryPrice)
            {
                foreach (Position position in Positions.FindAll(_cBotLabel, SymbolName, TradeType.Buy))
                    ClosePosition(position);
            }

            //Exit at loss (C6 & C2)

            Print("_hma420_ms5.Result.Last(1) < _hma420_ms5.Result.Last(2)  => " + _hma420_ms5.Result.Last(1) + " < " + _hma420_ms5.Result.Last(2) + "................ (_hma17_ms2.Result.Last(0) = " + _hma17_ms2.Result.Last(0));
            Print("_ma5_ms100.Result.Last(1) < _ma5_ms100.Result.Last(2)  => " + _ma5_ms100.Result.Last(1) + " < " + _ma5_ms100.Result.Last(2));
            //if (_hma17_ms2.Result.Last(0) < _hma17_ms2.Result.Last(1) && _hma17_ms2.Result.Last(1) > _hma17_ms2.Result.Last(2) && _hma420_ms5.Result.Last(1) < _hma420_ms5.Result.Last(2) && Symbol.Bid < _pm._last_pos_buy.EntryPrice)
            if (_hma17_ms2.Result.Last(0) < _hma17_ms2.Result.Last(1) && _hma17_ms2.Result.Last(1) > _hma17_ms2.Result.Last(2) && _ma5_ms100.Result.Last(1) < _ma5_ms100.Result.Last(2) && Symbol.Bid < last_pos_buy.EntryPrice)
            {
                foreach (Position position in Positions.FindAll(_cBotLabel, SymbolName, TradeType.Buy))
                    ClosePosition(position);
            }
        }
    }
}

 


@Nobody

Nobody
18 Nov 2020, 12:25

RE:

PanagiotisCharalampous said:

Hi Nobody,

Can you provide a simpler cBot code without dependencies that we can use to reproduce this behavior?

Best Regards,

Panagiotis 

Join us on Telegram

Hi Pangiotis, thanks, ok let me time to do that...

I just replaced HMA typical by a SMA100 for a test and no problem with it...and the same HMA (on typical price) seems to be OK too on the M5 timeframe....very very strange...

 

I come back with simpler code soon


@Nobody

Nobody
16 Nov 2020, 15:38

RE: RE:

Nobody said:

PanagiotisCharalampous said:

Hi Nobody,

If you expect it to appear in cTrader Code Editor, it won't. Try using Visual Studio.

Best Regards,

Panagiotis 

Join us on Telegram

last thing :

i try to use my custom indicator like this :

declaration in the class  :

[Parameter("Third Timeframe (optional)", Group = "SIGNAL SETTINGS")]
public TimeFrame _ms5_timeframe { get; set; }

private RelativeStrengthIndex _rsi_ms5;

private StochasticforIndicators _stoRsi_ms5;

 

and next in functions :

_rsi_ms5 = Indicators.RelativeStrengthIndex(_ms5.ClosePrices, 6);
_stoRsi_ms5 = Indicators.StochasticforIndicators(9, 3, MovingAverageType.Simple, 9, _rsi_ms5.Result);

 

but i get a build error : Erro : "cAlgo.API.internals.IIndicatorsAccessor' dos not contains definition for "StochasticforIndicators" and no extension method 'StocasticforIndicators' accepts for first argumet type 'cAlgo.API.Internals.IIndicatorsAccessor' found (a using directive or assembly reference missing ?)

replaced last line by this one  :             _stoRsi_ms5 = Indicators.GetIndicator<StochasticforIndicators>(9, 3, MovingAverageType.Simple, 9, _rsi_ms5.Result);

 

and now it builds successfully, could you just confirm it is the good way to work please ?

 

thank you !


@Nobody

Nobody
16 Nov 2020, 15:28

RE:

PanagiotisCharalampous said:

Hi Nobody,

If you expect it to appear in cTrader Code Editor, it won't. Try using Visual Studio.

Best Regards,

Panagiotis 

Join us on Telegram

last thing :

i try to use my custom indicator like this :

declaration in the class  :

[Parameter("Third Timeframe (optional)", Group = "SIGNAL SETTINGS")]
public TimeFrame _ms5_timeframe { get; set; }

private RelativeStrengthIndex _rsi_ms5;

private StochasticforIndicators _stoRsi_ms5;

 

and next in functions :

_rsi_ms5 = Indicators.RelativeStrengthIndex(_ms5.ClosePrices, 6);
_stoRsi_ms5 = Indicators.StochasticforIndicators(9, 3, MovingAverageType.Simple, 9, _rsi_ms5.Result);

 

but i get a build error : Erro : "cAlgo.API.internals.IIndicatorsAccessor' dos not contains definition for "StochasticforIndicators" and no extension method 'StocasticforIndicators' accepts for first argumet type 'cAlgo.API.Internals.IIndicatorsAccessor' found (a using directive or assembly reference missing ?)


@Nobody

Nobody
16 Nov 2020, 15:02

RE:

PanagiotisCharalampous said:

Hi Nobody,

If you expect it to appear in cTrader Code Editor, it won't. Try using Visual Studio.

Best Regards,

Panagiotis 

Join us on Telegram

OK, i used it writing it manually and it works fine, thank you !


@Nobody

Nobody
16 Nov 2020, 14:45 ( Updated at: 21 Dec 2023, 09:22 )

RE:

PanagiotisCharalampous said:

Hi Nobody,

I just tried this and seems to work fine for me

Can you confirm that the indicator builds successfully?

Best Regards,

Panagiotis 

Join us on Telegram

Hi Pangiotis,

yes it builds successfully, but in the bot it does not appears even if i add a reference to it via "Manage references" of the cbot options ...


@Nobody

Nobody
20 Oct 2020, 10:57

RE: RE:

genappsforex said:

maybe use the ms2 index? youre using the Bars index.
find the index corresponding with the Bars.OpenTimes[index] and you're OK

 

Thannk you Genappsforex, but it is exactly what i have done, it is the "GetIndexByExactTime" that was not the proper way, it is ok with GetIndexByTime() !


@Nobody

Nobody
20 Oct 2020, 10:54

RE:

PanagiotisCharalampous said:

Hi Nobody,

Try using GetIndexByTime() instead.

Best Regards,

Panagiotis 

Join us on Telegram

Thanks Panagiotis, it works fine !


@Nobody

Nobody
08 Oct 2020, 19:51

RE:

PanagiotisCharalampous said:

Hi Alex,

The best thing would be use Visual Studio for your development. cTrader Automate editor is very primitive compared to Visual Studio.

Best Regards,

Panagiotis 

Join us on Telegram

OK thank you Panagiotis !


@Nobody

Nobody
23 Mar 2020, 18:33

RE:

firemyst said:

Chart.DrawEquidistantChannel()

 

thanks ;)


@Nobody

Nobody
12 Feb 2020, 14:51

RE:

PanagiotisCharalampous said:

Hi Nobody,

We will release a hotfix for this issue soon.

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis,

thank you !


@Nobody

Nobody
11 Feb 2020, 16:54

RE: RE:

TzvetomirTerziysky said:

Nobody said:

Hello,

when i run my cbot on backtest or live there is no problem, all run fine.

 

But when i run it on optimization, tests passes but there is no result found as shown on picture below...how is it possible ?

 

 

I have raised that yesterday: 

The issue will appear at least when one uses multi timeframe. I am waiting for an update

 

OK thanks, but somebody of Spotware can confirm that issue will be solved soon please ? is this due to last update (cause multiple timeframe in optimization run well before) ?


@Nobody

Nobody
06 Feb 2020, 18:37

RE:

kdm1956 said:

Simple MA crossover bot 

Auto money management would also be required.

Not sure what this is worth so let's talk

Thanks in advance

Ken

Hi Ken, 

 

i can develop your bot for free if you want, contact me on twitter : @1millionprofit

Regards,

HB


@Nobody

Nobody
02 Sep 2016, 15:28 ( Updated at: 21 Dec 2023, 09:20 )

RE:

Hello,

i tried to add the Tweetinvi package to calgo using nuget (by command line) but once package installed i do not see it in .net reference or library...

How do you use it ? 

thanks in advance,

Alex

 

Paul_Hayes said:

Also you will what these references or get them from NuGet.

 


@Nobody

Nobody
14 Jan 2016, 18:53

RE: RE: Formatting proper CSV File for Backtesting and optimisation

This post was removed by moderator because it duplicates another post. /forum/calgo-support/7782


@Nobody