travkinsm1
travkinsm1's avatar

Info

Username:travkinsm1
Name:travkinsm1
Member since: 05 Apr 2018

About

None

Signature

None

Last Forum Posts

@variables from the indicator for use in the bot:  15 Sep 2021, 16:57


Thanks for the quick response. Do I understand correctly that the Calculate function will be called again?

@variables from the indicator for use in the bot:  14 Sep 2021, 16:12


Hello! I am facing the following problem. I needed a boolean variable from an indicator in a bot, which changes when Calculate is called. The only way I've found to call it is to create an IndicatorDataSeries that takes the value 1 if it's false, and 2 if it's true. It turned out that this is very inconvenient for testing, because all the time the graph is reset to the position where this variable is displayed, capturing the values ​​1 and 2. How can you solve my problem? Thanks in advance. I am attaching an example to illustrate my problem.

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TestTI : Indicator
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        public bool b;
        protected override void Initialize()
        {
            b = false;
        }

        public override void Calculate(int index)
        {
            b = !b;
            // Calculate value at specified index
            // Result[index] = ...
        }
    }
}
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 BoolBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }
        private TestTI ind;
        protected override void OnStart()
        {
            ind = Indicators.GetIndicator<TestTI>(1.0);
        }

        protected override void OnTick()
        {
            Print(ind.b);
        }

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

@Errors in all 60th lines.:  25 Mar 2021, 14:13


Stupid mistake. Indeed, in the indicator, to which all these files are linked in one way or another, the error is in line 60.

@Errors in all 60th lines.:  22 Mar 2021, 14:13


Error in my CAlgo

I have a problem with the latest version of calgo too. But of a different kind. Robots and indicators that I have been working on during this period (only they) gave an "} expected" error with the cursor on the 60th line. (I don't know if this is an accurate translation, in Russian it sounds like "ожидалась }") I attach screenshots.

I rebooted my computer and reinstalled CAlgo. I rebooted my computer and reinstalled CAlgo. Also I was retyping lines around 60th. It did not help. The code for one of these files is below.

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ATRMTF_time_History : Indicator
    {
        [Parameter("Period", DefaultValue = 30)]
        public int Period { get; set; }

        [Parameter("Timeframe", DefaultValue = "Ticks10")]
        public TimeFrame TF { get; set; }

        [Parameter(DefaultValue = 200)]
        public int LoadHistory_for_ind { get; set; }
        [Parameter("Загрузка ист. в индикаторе", DefaultValue = false)]
        public bool LoadIndHist { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        private AverageTrueRange atr;
        private MarketSeries series;
        private Bars Bars3;
        public int loaded = 0;
        protected override void Initialize()
        {
            if (LoadIndHist)
            {
                if (loaded == 0)
                {
                    Print("Start");
                    Bars3 = MarketData.GetBars(TF, Symbol.Name);
                    // Print("2");
                    Print("{0} bar on the chart. Loading 2.000.000 bars", Bars3.Count);
                    //Print("3");

                    while (Bars3.Count < LoadHistory_for_ind)
                    {
                        //  Print("3");
                        var loadedCount = Bars3.LoadMoreHistory();
                        //Print("3");
                        //Print("Loaded {0} bars", loadedCount);
                        //Print("Total bars {0}", Bars2.Count);
                        if (loadedCount == 0)
                            break;
                    }
                    Print("Finished, total bars {0}", Bars3.Count);

                    Print("2");
                    loaded = 1;
                }
            }
            series = MarketData.GetSeries(TF);
            atr = Indicators.AverageTrueRange(series, Period, MovingAverageType.Exponential);
        }
        public override void Calculate(int index)
        {
            var index1 = series.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);
            // Print(index1, " ", Result[index - 1], " ", atr.Result[index1]);
            if (Result[index - 1] != atr.Result[index1])
                Result[index] = atr.Result[index1];
            else
                Result[index] = Result[index - 1];
            // (int)Math.Round(minJamp * Symbol.PipSize / Math.Pow(0.1, Symbol.Digits));
        }
    }
}

Computer is protected with dr.Web

@Issue with new cTrader Desktop:  16 Mar 2021, 16:22


I have a problem with the latest version of calgo too. But of a different kind. All robots and indicators that I compiled gave an "} expected" error with the cursor on the 60th line. (I don't know if this is an accurate translation, in Russian it sounds like "ожидалась }")

@Variable is displayed differently in the indicator and in the robot:  12 Mar 2021, 12:22


Fixed indicator and bot. All the same, the values partially coincide, partially not. (As in the screenshot)

@Variable is displayed differently in the indicator and in the robot:  10 Mar 2021, 13:54


 Thanks for the answer. I think that in order to localize the error, you don't need to parse the entire code. Look, there is a _isLong variable in the indicator. It returns true if the indicator is at the bottom, and false if the indicator is at the top. And, according to my observations, there is no error here. To make sure of this, it is enough to insert into line 163

Print("Indicator" + Bars.OpenPrices.LastValue + "" + Bars.OpenTimes.LastValue + "" + Period + "" + Weight + "" + _isLong);

Lines 159 through 162 bind _isLong to _myIsLong. In the bot, _myIsLong is bound to dirInd in OnTick, and often is sent to Print() a different value.

As for the time error, it seems to me that this is unlikely to be, because _myIsLong receives LastValue. And I send the ATRMTF_time_History indicator.

Sorry for not thinking about it right away

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ATRMTF_time_History : Indicator
    {
        [Parameter("Period", DefaultValue = 30)]
        public int Period { get; set; }

        [Parameter("Timeframe", DefaultValue = 0.0)]
        public TimeFrame TF { get; set; }

        [Parameter(DefaultValue = 200)]
        public int LoadHistory_for_ind { get; set; }
        [Parameter("Загрузка ист. в индикаторе", DefaultValue = false)]
        public bool LoadIndHist { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        private AverageTrueRange atr;
        private MarketSeries series;
        private Bars Bars3;
        public int loaded = 0;
        protected override void Initialize()
        {
            if (LoadIndHist)
            {
                if (loaded == 0)
                {
                    Print("Start");
                    Bars3 = MarketData.GetBars(TF, Symbol.Name);
                    // Print("2");
                    Print("{0} bar on the chart. Loading 2.000.000 bars", Bars3.Count);
                    //Print("3");

                    while (Bars3.Count < LoadHistory_for_ind)
                    {
                        //  Print("3");
                        var loadedCount = Bars3.LoadMoreHistory();
                        //Print("3");
                        //Print("Loaded {0} bars", loadedCount);
                        //Print("Total bars {0}", Bars2.Count);
                        if (loadedCount == 0)
                            break;
                    }
                    Print("Finished, total bars {0}", Bars3.Count);

                    Print("2");
                    loaded = 1;
                }
            }

            series = MarketData.GetSeries(TF);
            atr = Indicators.AverageTrueRange(series, Period, MovingAverageType.Exponential);
        }

        public override void Calculate(int index)
        {
            var index1 = series.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);
            // Print(index1, " ", Result[index - 1], " ", atr.Result[index1]);
            if (Result[index - 1] != atr.Result[index1])
                Result[index] = atr.Result[index1];
            else
                Result[index] = Result[index - 1];
            // (int)Math.Round(minJamp * Symbol.PipSize / Math.Pow(0.1, Symbol.Digits));
        }
    }
}
//ATRMTF_time_History

@Variable is displayed differently in the indicator and in the robot:  08 Mar 2021, 18:06


members of the forum, and first of all amusleh, have any thoughts about my problem?

@Variable is displayed differently in the indicator and in the robot:  04 Mar 2021, 16:22


Perhaps this is because I am using an array of indicators, but when I corrected the code as follows, nothing changed.

using System;
using System.Linq;
using System.Windows;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;


namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class MycBot : Robot
    {
        [Parameter("MA Method", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MaType { get; set; }


        [Parameter("True:High_Low False:Close", DefaultValue = false)]
        public bool UseHighAndLow { get; set; }

        [Parameter("Timeframe1", DefaultValue = "Ticks10")]
        public TimeFrame TF { get; set; }

        [Parameter("Загрузить Баров", DefaultValue = 30000)]
        public int BarCount_set { get; set; }

        [Parameter("Загрузка ист. в индикаторе", DefaultValue = false)]
        public bool LoadIndHist { get; set; }

        private Int32 weightCount = 3;
        private double weightMin = 2, weightStep = 1;
        private Int32 perCount = 3;
        private Int32 perMin = 10, perStep = 5;
        private Int32 arPeriod, arWeight;

        private ATR_Stops_time_MarketData_History[,] stop_ind;

        private Bars Bars2;
        private StreamWriter file;
        private int LoadHistory_for_ind = 3000;
        private int period;
        private double weight;
        private bool dirInd;

        protected override void OnStart()
        {
            while (Bars.Count < BarCount_set)
            {
                var loadedCount = Bars.LoadMoreHistory();
                Print("Loaded {0} bars", loadedCount);
                Print("Total bars {0}", Bars.Count);
                if (loadedCount == 0)
                    break;
            }
            Print("Finished, total bars {0}", Bars.Count);
            Bars2 = MarketData.GetBars(TF, Symbol.Name);
            while (Bars2.Count < (BarCount_set / 10))
            {
                var loadedCount = Bars2.LoadMoreHistory();
                if (loadedCount == 0)
                    break;
            }
            stop_ind = new ATR_Stops_time_MarketData_History[perCount, weightCount];
            for (int z2 = 0; z2 < perCount; z2++)
                for (int z3 = 0; z3 < weightCount; z3++)
                {
                    int Per = perMin + perStep * z3;
                    double Weight = weightMin + weightStep * z2;
                    stop_ind[z2, z3] = Indicators.GetIndicator<ATR_Stops_time_MarketData_History>(TF, MaType, Per, Weight, UseHighAndLow, LoadHistory_for_ind, LoadIndHist);
                }
            Print("Finished, total bars {0}", Bars2.Count);
            file = new StreamWriter("C:\\Users\\travk_000\\Documents\\bot1.3_is_long2.txt", false);
            file.WriteLine("Begin");
            file.Flush();
            file.Close();
            Calc();
            Timer.Start(120);
        }
        protected override void OnTimer()
        {
            Calc();
        }
        protected void Calc()
        {
            var rand = new Random();
            arPeriod = rand.Next(0, perCount - 1);
            period = perMin + arPeriod * perStep;
            arWeight = rand.Next(0, weightCount - 1);
            weight = weightMin + arWeight * weightStep;
            Print("weight=" + weight + " period=" + period);
        }
        protected override void OnTick()
        {
            if (stop_ind[arWeight, arPeriod]._myIsLong.LastValue == 1)
                dirInd = true;
            else
                dirInd = false;
            file = new StreamWriter("C:\\Users\\travk_000\\Documents\\bot1.3_is_long2.txt", true);
            file.WriteLine("Bot " + Bars.OpenPrices.LastValue + " " + Bars.OpenTimes.LastValue + " " + weight + " " + period + " " + dirInd);
            file.Flush();
            file.Close();
            Print("Bot " + Bars.OpenPrices.LastValue + " " + Bars.OpenTimes.LastValue + " " + weight + " " + period + " " + dirInd);
        }
    }
}
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Indicators
{
    [Indicator("ATR Trailing Stop", AutoRescale = false, IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FileSystem)]
    public class ATR_Stops_time_MarketData_History : Indicator
    {

        [Parameter("Timeframe", DefaultValue = 0.0)]
        public TimeFrame TF { get; set; }

        [Parameter("MA Method", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MaType { get; set; }

        [Parameter("Period", DefaultValue = 10, MinValue = 2, MaxValue = 50000)]
        public int Period { get; set; }

        [Parameter("Weight", DefaultValue = 4.0, MinValue = 0.1, MaxValue = 400.0)]
        public double Weight { get; set; }

        [Parameter("True:High_Low False:Close", DefaultValue = false)]
        public bool UseHighAndLow { get; set; }

        [Parameter(DefaultValue = 16000)]
        public int LoadHistory_for_ind { get; set; }

        [Parameter("Загрузка ист. в индикаторе", DefaultValue = false)]
        public bool LoadIndHist { get; set; }


        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }
        [Output("My")]
        public IndicatorDataSeries _myIsLong { get; set; }
        private ATRMTF_time_History _atr;
        public bool _isLong;


        private MarketSeries _marketSeries;

        //private AverageTrueRange_Cust_lag[,] stop_ind = new ATRStops[perCount, weightCount];
        private Bars Bars2;
        public StreamWriter file3;

        protected override void Initialize()
        {
            Print("Start");

            Bars2 = MarketData.GetBars(TF, Symbol.Name);
            // Print("2");
            Print("{0} bar on the chart. Loading 2.000.000 bars", Bars2.Count);
            //Print("3");
            if (LoadIndHist == true)
            {
                while (Bars2.Count < LoadHistory_for_ind)
                {
                    //  Print("3");
                    var loadedCount = Bars2.LoadMoreHistory();
                    //Print("3");
                    //Print("Loaded {0} bars", loadedCount);
                    //Print("Total bars {0}", Bars2.Count);
                    if (loadedCount == 0)
                        break;
                }
                Print("Finished, total bars {0}", Bars2.Count);
            }
            /*file3 = new StreamWriter("C:\\Users\\travk_000\\Documents\\bot1.3_is_long.txt", false);
            file3.WriteLine("Indicator Begin");
            file3.Flush();
            file3.Close();
            */
            Print("1");
            // Result = CreateDataSeries();
            //ATR = CreateDataSeries();
            // _marketSeries = MarketData.GetSeries(TF);
            _atr = Indicators.GetIndicator<ATRMTF_time_History>(Period, TF, LoadHistory_for_ind, LoadIndHist);
            // _atr = Indicators.AverageTrueRange(Period, MaType);
            ////Print("_marketSeries : {0}", _marketSeries);
            ////Print("_atr : {0}", _atr);
            this._marketSeries = MarketData.GetSeries(MarketData.GetSymbol(Symbol.Name), TF);

            //else
            //Print("Не загружено {0} баров", BarCount_set);
        }


        public override void Calculate(int index)
        {

            ////Print(index, " ", _atr.Result[index]);

            var currentAtr = Weight * _atr.Result[index];

            if (double.IsNaN(currentAtr))
                return;
            /* Print("_marketSeries.Close {0}", this._marketSeries.Close[_marketSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index])]);
            Print("_marketSeries.High {0}", this._marketSeries.High[_marketSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index])]);
            Print("_marketSeries.Low {0}", this._marketSeries.Low[_marketSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index])]);
            */
            //Print("MarketData..close..IsRising: {0}", MarketData.GetBars(TF, Symbol.Name).ClosePrices.IsRising());
                        /*
            Print("MarketData..close[index] {0}", MarketData.GetBars(TF, Symbol.Name).ClosePrices[index]);
            Print("MarketData..LastValue: {0}", MarketData.GetBars(TF, Symbol.Name).ClosePrices.LastValue);
            Print("MarketData..Last: {0}", MarketData.GetBars(TF, Symbol.Name).ClosePrices.Count);
*/

if (double.IsNaN(Result[index - 1]) && !double.IsNaN(_atr.Result[index - 1]))
            {
                var previousATR = Weight * _atr.Result[index - 1];

                _isLong = MarketSeries.Close.IsRising();

                var previous = UseHighAndLow ? (_isLong ? this._marketSeries.High[_marketSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index - 1])] : this._marketSeries.Low[_marketSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index - 1])]) : this._marketSeries.Close[_marketSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index - 1])];

                Result[index] = _isLong ? previous - previousATR : previous + previousATR;
            }
            else
            {
                var current = this._marketSeries.Close[_marketSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index])];

                if (_isLong)
                {
                    if (current >= Result[index - 1])
                    {
                        if (UseHighAndLow)
                            current = this._marketSeries.High[_marketSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index])];
                        Result[index] = Math.Max(Result[index - 1], current - currentAtr);
                    }
                    else
                    {
                        _isLong = false;
                        if (UseHighAndLow)
                            current = this._marketSeries.Low[_marketSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index])];
                        Result[index] = current + currentAtr;
                    }
                }
                else
                {
                    if (current <= Result[index - 1])
                    {
                        if (UseHighAndLow)
                            current = this._marketSeries.Low[_marketSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index])];
                        Result[index] = Math.Min(Result[index - 1], current + currentAtr);
                    }
                    else
                    {
                        _isLong = true;
                        if (UseHighAndLow)
                            current = this._marketSeries.High[_marketSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index])];
                        Result[index] = current - currentAtr;
                    }
                }
            }
            if (_isLong)
                _myIsLong[index] = 1;
            else
                _myIsLong[index] = -1;
        }
    }
    /*file3 = new StreamWriter("C:\\Users\\travk_000\\Documents\\bot1.3_is_long.txt", true);
            file3.WriteLine("Indicator " + Bars.OpenPrices.LastValue + " " + Bars.OpenTimes.LastValue + " " + Period + " " + Weight + " " + _isLong);
            file3.Flush();
            file3.Close();*/

}

naturally in my original code weight and period are not random

@Variable is displayed differently in the indicator and in the robot:  03 Mar 2021, 15:36


I forgot to say that I launch the robot on the 1 tick timeframe, and the indicator on 10 ticks. The timeframe parameter in the indicator is also 10 ticks

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.