Replies

itmfar
25 Mar 2021, 19:10

RE:

Wow, interesting, you made my day.

amusleh said:

Try this:

using cAlgo.API;
using cAlgo.API.Internals;
using System.Collections.Generic;
using System.Linq;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Callindicator : Indicator
    {
        private Symbol[] _symbols;
        private Bars[] _bars;

        [Parameter("Symbols", DefaultValue = "EURUSD,GBPUSD,USDJPY,USDCHF,AUDCAD,AUDCHF,AUDJPY,AUDNZD,AUDUSD,CADCHF,CADJPY")]
        public string SymbolNames { get; set; }

        [Parameter("Bigger Timeframe", DefaultValue = "Daily")]
        public TimeFrame TimeframeBigger { get; set; }

        public int IndexMinDaily = 0;
        public int MinIndexB = 0;
        public double MinLineB = 0;

        public int IndexMaxDaily = 0;
        public int MaxIndexB = 0;
        public double MaxLineB = 0;

        public bool is_minB = false;
        public bool is_maxB = false;

        public List<Extremum> extremums = new List<Extremum>();

        public int lastHighindexB;
        public int LastLowindexB;

        public bool isBuy_allowedB = true;
        public bool isSell_allowedB = true;

        public bool signal_BuyB = false;
        public bool signal_SellB = false;

        public double high_insideB;
        public double low_insideB;

        public int lastbuy_exIndexB;
        public int lastsell_exIndexB;

        private MarketSeries Biggermarketseries;

        private int lastIndex = 0;

        protected override void Initialize()
        {
            _symbols = Symbols.GetSymbols(SymbolNames.Replace(" ", string.Empty).Split(',').ToArray());
            _bars = _symbols.Select(iSymbol => MarketData.GetBars(TimeframeBigger, iSymbol.Name)).ToArray();

            foreach (var bars in _bars)
            {
                while (bars.Count < 1000)
                {
                    var loadedCount = bars.LoadMoreHistory();
                    Print("Loaded {0} bars of {1}", loadedCount, bars.SymbolName);
                    if (loadedCount == 0)
                        break;
                }

                bars.Tick += Bars_Tick;
                bars.BarOpened += Bars_BarOpened;
            }

            Biggermarketseries = MarketData.GetSeries(TimeframeBigger);

            int index = Bars.Count - 2;

            int idx1 = Biggermarketseries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);
            int indaxstart = idx1 - 10;
            MinIndexB = indaxstart;
            MinLineB = double.MaxValue;
            MaxIndexB = indaxstart;
            MaxLineB = double.MinValue;
        }

        private void Bars_BarOpened(BarOpenedEventArgs obj)
        {
            // each symbol will call this method on new bar open
        }

        private void Bars_Tick(BarsTickEventArgs obj)
        {
            // each symbol will call this method on tick change
        }

        public override void Calculate(int index)
        {
            foreach (var symbol in _symbols)
            {
                // run indicator for each symbol
            }

            int idx1 = Biggermarketseries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);
            // index daily
            int idx2 = MarketSeries.OpenTime.GetIndexByTime(Biggermarketseries.OpenTime[idx1]);

            Bars barsD1 = MarketData.GetBars(TimeFrame.Daily);
            Bars barsH1 = MarketData.GetBars(TimeFrame.Hour);
            if (is_maxB && Biggermarketseries.High[idx1 - 1] > MaxLineB)
            {
                MaxLineB = Biggermarketseries.High[idx1 - 1];
                MaxIndexB = findindexmax(idx2, MaxLineB);
            }

            Chart.DrawStaticText("text", index + SymbolName, VerticalAlignment.Bottom, HorizontalAlignment.Left, Color.Red);
            returnfun(MaxIndexB);
        }

        public string returnfun(int index)
        {
            return index + SymbolName;
        }

        public int findindexmax(int index, double high)
        {
            for (int i = index - 24; i <= index + 24; i++)
            {
                if (high == Bars.HighPrices[i])
                    return i;
            }
            return index;
        }
    }
}

You can put any code you want to inside "Bars_BarOpened" and "Bars_Tick" methods, you can use the Calculate method to calculate the indicator for historical data, its called only for current chart symbol ticks not your other symbols, so instead use "Bars_Tick" method.

Now you have all you need, the symbols and their bars, and you can pass the symbols via a parameter instead of hard coding the symbol names inside your indicator.

 

 
 
 
 

@itmfar

itmfar
27 Feb 2018, 12:33

Hi panagiotis

thanks for your answer
what about gained pips and total winning trades?


@itmfar

itmfar
16 Feb 2018, 14:33

RE:

Panagiotis Charalampous said:

Hi itmfar,

I was with the impression that you wanted to place orders only on the D sign, Here it is for S sign as well

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System.Collections.Generic;
namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }
        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType maType { get; set; }
        private StochasticOscillator _stochastic;
        private readonly List<bool> _ssdRising = new List<bool>();
        [Parameter("Source")]
        public DataSeries Source { get; set; }
        protected override void OnStart()
        {
            _stochastic = Indicators.StochasticOscillator(9, 3, 9, maType);
        }

        protected override void OnBar()
        {

            _ssdRising.Add(_stochastic.PercentD.IsRising());
            if (_ssdRising.Count > 1)
            {
                FindSSCrossovers(Source.Count - 1);
                DrawLinesSSD(Source.Count - 1);
            }
        }
        private void FindSSCrossovers(int index)
        {
            if (_stochastic.PercentD.HasCrossedAbove(_stochastic.PercentK, 0))
            {
                ChartObjects.DrawText("MAXss1" + index, "S⮟", index, Source[index], VerticalAlignment.Top, HorizontalAlignment.Center, Colors.Yellow);
                ExecuteMarketOrder(TradeType.Sell, Symbol, 1000, "lalbelmax", 120, 200);
            }
            else
            {
                ChartObjects.RemoveObject("MAXss1" + index);
            }

            if (_stochastic.PercentK.HasCrossedAbove(_stochastic.PercentD, 0))
            {
                ChartObjects.DrawText("Minss1" + index, "S⮝", index, Source[index], VerticalAlignment.Bottom, HorizontalAlignment.Center, Colors.Yellow);
                ExecuteMarketOrder(TradeType.Buy, Symbol, 1000, "lalbelmax", 120, 200);
            }
            else
            {
                ChartObjects.RemoveObject("Minss1" + index);
            }
        }

        private void DrawLinesSSD(int index)
        {
            if (_ssdRising[_ssdRising.Count - 2] != _ssdRising[_ssdRising.Count - 1] && _stochastic.PercentD[index] > 60 && _ssdRising[_ssdRising.Count - 1] == false)
            {
                ChartObjects.DrawText("maxrssd" + index, "D⮟", index, Source[index], VerticalAlignment.Top, HorizontalAlignment.Center, Colors.White);
                ExecuteMarketOrder(TradeType.Sell, Symbol, 1000, "lalbelmax", 120, 200);
            }
            else
            {
                ChartObjects.RemoveObject("maxrssd" + index);
            }

            if (_ssdRising[_ssdRising.Count - 2] != _ssdRising[_ssdRising.Count - 1] && _stochastic.PercentD[index] < 40 && _ssdRising[_ssdRising.Count - 1] == true)
            {
                ChartObjects.DrawText("minrssd" + index, "D⮝", index, Source[index], VerticalAlignment.Bottom, HorizontalAlignment.Center, Colors.White);
                ExecuteMarketOrder(TradeType.Buy, Symbol, 1000, "lalbelmax", 120, 200);
            }
            else
            {
                ChartObjects.RemoveObject("minrssd" + index);
            }
        }
        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Let me know if this works.

Best Regards,

Panagiotis
 

thanks panagiotis

 


@itmfar

itmfar
11 Feb 2018, 12:05

RE:

Panagiotis Charalampous said:

Hi itmfar,

See below

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System.Collections.Generic;
namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }
        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType maType { get; set; }
        private StochasticOscillator _stochastic;
        private readonly List<bool> _ssdRising = new List<bool>();
        [Parameter("Source")]
        public DataSeries Source { get; set; }
        protected override void OnStart()
        {
            _stochastic = Indicators.StochasticOscillator(9, 3, 9, maType);
        }

        protected override void OnBar()
        {

            _ssdRising.Add(_stochastic.PercentD.IsRising());
            if (_ssdRising.Count > 1)
            {
                FindSSCrossovers(Source.Count - 1);
                DrawLinesSSD(Source.Count - 1);
            }
        }
        private void FindSSCrossovers(int index)
        {
            if (_stochastic.PercentD.HasCrossedAbove(_stochastic.PercentK, 0))
            {
                ChartObjects.DrawText("MAXss1" + index, "S⮟", index, Source[index], VerticalAlignment.Top, HorizontalAlignment.Center, Colors.Yellow);
            }
            else
            {
                ChartObjects.RemoveObject("MAXss1" + index);
            }

            if (_stochastic.PercentK.HasCrossedAbove(_stochastic.PercentD, 0))
            {
                ChartObjects.DrawText("Minss1" + index, "S⮝", index, Source[index], VerticalAlignment.Bottom, HorizontalAlignment.Center, Colors.Yellow);
            }
            else
            {
                ChartObjects.RemoveObject("Minss1" + index);
            }
        }

        private void DrawLinesSSD(int index)
        {
            if (_ssdRising[_ssdRising.Count - 2] != _ssdRising[_ssdRising.Count - 1] && _stochastic.PercentD[index] > 60 && _ssdRising[_ssdRising.Count - 1] == false)
            {
                ChartObjects.DrawText("maxrssd" + index, "D⮟", index, Source[index], VerticalAlignment.Top, HorizontalAlignment.Center, Colors.White);
                ExecuteMarketOrder(TradeType.Sell, Symbol, 1000, "lalbelmax", 120, 200);
            }
            else
            {
                ChartObjects.RemoveObject("maxrssd" + index);
            }

            if (_ssdRising[_ssdRising.Count - 2] != _ssdRising[_ssdRising.Count - 1] && _stochastic.PercentD[index] < 40 && _ssdRising[_ssdRising.Count - 1] == true)
            {
                ChartObjects.DrawText("minrssd" + index, "D⮝", index, Source[index], VerticalAlignment.Bottom, HorizontalAlignment.Center, Colors.White);
                ExecuteMarketOrder(TradeType.Buy, Symbol, 1000, "lalbelmax", 120, 200);
            }
            else
            {
                ChartObjects.RemoveObject("minrssd" + index);
            }
        }
        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Let me know if this is working for you,

Best Regards,

Panagiotis

Thank you Panagiotis, it is really helpful and it works for D-sign . but when buys or sells are excecuted in S conditions it repeats numerous times.


@itmfar

itmfar
09 Feb 2018, 14:01

RE:

tmc. said:

Works on my end.

using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class testRefresh : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

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

        private StochasticOscillator _stochastic;
        private readonly List<bool> _ssdRising = new List<bool>();

        protected override void Initialize()
        {
            _stochastic = Indicators.StochasticOscillator(9, 3, 9, maType);
        }

        public override void Calculate(int index)
        {
            var lastIndex = _ssdRising.Count - 1;
            if (lastIndex < index)
            {
                _ssdRising.Add(_stochastic.PercentD.IsRising());
            }
            else
            {
                _ssdRising[lastIndex] = _stochastic.PercentD.IsRising();
            }

            FindSSCrossovers(index);
            DrawLinesSSD(index);
        }

        private void FindSSCrossovers(int index)
        {
            if (_stochastic.PercentD.HasCrossedAbove(_stochastic.PercentK, 0))
            {
                ChartObjects.DrawText("MAXss1" + index, "S⮟", index, Source[index], VerticalAlignment.Top, HorizontalAlignment.Center, Colors.Yellow);
            }
            else
            {
                ChartObjects.RemoveObject("MAXss1" + index);
            }

            if (_stochastic.PercentK.HasCrossedAbove(_stochastic.PercentD, 0))
            {
                ChartObjects.DrawText("Minss1" + index, "S⮝", index, Source[index], VerticalAlignment.Bottom, HorizontalAlignment.Center, Colors.Yellow);
            }
            else
            {
                ChartObjects.RemoveObject("Minss1" + index);
            }
        }

        private void DrawLinesSSD(int index)
        {
            if (_ssdRising[index - 1] != _ssdRising[index] && _stochastic.PercentD[index] > 60 && _ssdRising[index] == false)
            {
                ChartObjects.DrawText("maxrssd" + index, "D⮟", index, Source[index], VerticalAlignment.Top, HorizontalAlignment.Center, Colors.White);
            }
            else
            {
                ChartObjects.RemoveObject("maxrssd" + index);
            }

            if (_ssdRising[index - 1] != _ssdRising[index] && _stochastic.PercentD[index] < 40 && _ssdRising[index] == true)
            {
                ChartObjects.DrawText("minrssd" + index, "D⮝", index, Source[index], VerticalAlignment.Bottom, HorizontalAlignment.Center, Colors.White);
            }
            else
            {
                ChartObjects.RemoveObject("minrssd" + index);
            }
        }
    }
}

is there any way to convert or use indicator as a bot? for example when D-sign pops up a boolean whould be set true, and a result of that bool, we exacute ExecteMarketOrder(TradeType.Sell, Symbol, 20, "lalbelmax", 120, 200);

 


@itmfar

itmfar
09 Feb 2018, 10:37

RE:

tmc. said:

Works on my end.

using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class testRefresh : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

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

        private StochasticOscillator _stochastic;
        private readonly List<bool> _ssdRising = new List<bool>();

        protected override void Initialize()
        {
            _stochastic = Indicators.StochasticOscillator(9, 3, 9, maType);
        }

        public override void Calculate(int index)
        {
            var lastIndex = _ssdRising.Count - 1;
            if (lastIndex < index)
            {
                _ssdRising.Add(_stochastic.PercentD.IsRising());
            }
            else
            {
                _ssdRising[lastIndex] = _stochastic.PercentD.IsRising();
            }

            FindSSCrossovers(index);
            DrawLinesSSD(index);
        }

        private void FindSSCrossovers(int index)
        {
            if (_stochastic.PercentD.HasCrossedAbove(_stochastic.PercentK, 0))
            {
                ChartObjects.DrawText("MAXss1" + index, "S⮟", index, Source[index], VerticalAlignment.Top, HorizontalAlignment.Center, Colors.Yellow);
            }
            else
            {
                ChartObjects.RemoveObject("MAXss1" + index);
            }

            if (_stochastic.PercentK.HasCrossedAbove(_stochastic.PercentD, 0))
            {
                ChartObjects.DrawText("Minss1" + index, "S⮝", index, Source[index], VerticalAlignment.Bottom, HorizontalAlignment.Center, Colors.Yellow);
            }
            else
            {
                ChartObjects.RemoveObject("Minss1" + index);
            }
        }

        private void DrawLinesSSD(int index)
        {
            if (_ssdRising[index - 1] != _ssdRising[index] && _stochastic.PercentD[index] > 60 && _ssdRising[index] == false)
            {
                ChartObjects.DrawText("maxrssd" + index, "D⮟", index, Source[index], VerticalAlignment.Top, HorizontalAlignment.Center, Colors.White);
            }
            else
            {
                ChartObjects.RemoveObject("maxrssd" + index);
            }

            if (_ssdRising[index - 1] != _ssdRising[index] && _stochastic.PercentD[index] < 40 && _ssdRising[index] == true)
            {
                ChartObjects.DrawText("minrssd" + index, "D⮝", index, Source[index], VerticalAlignment.Bottom, HorizontalAlignment.Center, Colors.White);
            }
            else
            {
                ChartObjects.RemoveObject("minrssd" + index);
            }
        }
    }
}

you are genius . thank you so much. it really saves my time :)

 


@itmfar

itmfar
08 Feb 2018, 17:31

RE:

Panagiotis Charalampous said:

Hi itmfar,

I don't know what to suggest since I cannot reproduce the problem and understand what is going wrong. Could you share a short video demonstrating the problem? Also, I don't understand how you will solve the problem by calling Calculate on a more frequent basis. Calculate is called on every tick therefore frequently enough. Do you mean redrawing the entire indicator instead? Even if this is what you are looking for, it is not a proper solution. It would be easier to understand how the issue is caused and apply a proper solution instead of forcing a brute force redrawing of the indicator.

Best Regards

Panagiotis

with every refresh some D will be added and S will be gone


@itmfar

itmfar
08 Feb 2018, 17:29 ( Updated at: 21 Dec 2023, 09:20 )

RE:

Panagiotis Charalampous said:

Hi itmfar,

I don't know what to suggest since I cannot reproduce the problem and understand what is going wrong. Could you share a short video demonstrating the problem? Also, I don't understand how you will solve the problem by calling Calculate on a more frequent basis. Calculate is called on every tick therefore frequently enough. Do you mean redrawing the entire indicator instead? Even if this is what you are looking for, it is not a proper solution. It would be easier to understand how the issue is caused and apply a proper solution instead of forcing a brute force redrawing of the indicator.

Best Regards

Panagiotis

I captured two print-screens one before refresh the other after 

it is obvious that after refresh only D-sing will be shown


@itmfar

itmfar
08 Feb 2018, 16:33

RE:

tmc. said:

Hi itmfar,

The Calculate() method is called on each bar when processing historical data and on each incoming tick when processing real-time data. You should be adding a new element to the list only on a new bar. Try this:

var lastIndex = ssdRising.Count - 1;

if (index > lastIndex)
{
    ssdRising.Add(_stochastic.PercentD.IsRising());
}
else
{
    ssdRising[lastIndex] = _stochastic.PercentD.IsRising();
}

Also, you should remove chart objects if the conditions are not met. Otherwise, it might remain there from previous tick before a bar is closed and show false results.

Hi tmc
​Thanks for solution but it still does not work. if I remove all object how i can reproduce them for pervious calculations?


@itmfar

itmfar
08 Feb 2018, 16:29

RE:

Panagiotis Charalampous said:

Hi itmfar,

Thanks for posting the indicator. I used your indicator on a minute chart for some time but did not experience any problem. It would be helpful to be able to reproduce the problem so that I can see it and see how I can help you.

Best Regards,

Panagiotis

Hi Panagotis

I still have my problem. how we can refresh or restart the indicator on regular basis? 

 


@itmfar

itmfar
06 Feb 2018, 20:28

RE:

Panagiotis Charalampous said:

Hi itmfar,

Calculate() is called on each tick. Therefore pretty often on major pairs. You could have timer but I don't think this would be a good idea. It would be better to tell us what the problem is so that we could propose a more proper solution.

Best Regards,

Panagiotis

My code for example in 1 minute timeframe, after 1 hour generates some signals but when you refresh the chart some of them will be lost and some of them will be added due to some interruptions. So I need to refresh the chart on each candle to address this problem. Or we can cancalculate once exactly when a candle is closing

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class testRefresh : Indicator
    {

        [Parameter("Source")]
        public DataSeries Source { get; set; }
        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType maType { get; set; }
        private StochasticOscillator _stochastic;
        private List<bool> ssdRising = new List<bool>();

        protected override void Initialize()
        {
            _stochastic = Indicators.StochasticOscillator(9, 3, 9, maType);
        }

        public override void Calculate(int index)
        {
            ssdRising.Add(_stochastic.PercentD.IsRising());
            FindSSCrossovers(index);
            DrawLinesSSD(index);
        }

        private void FindSSCrossovers(int index)
        {

            if (_stochastic.PercentD.HasCrossedAbove(_stochastic.PercentK, 0))
            {

                ChartObjects.DrawText("MAXss1" + index, "S⮟", index, Source[index], VerticalAlignment.Top, HorizontalAlignment.Center, Colors.Yellow);
            }

            if (_stochastic.PercentK.HasCrossedAbove(_stochastic.PercentD, 0))
            {

                ChartObjects.DrawText("Minss1" + index, "S⮝", index, Source[index], VerticalAlignment.Bottom, HorizontalAlignment.Center, Colors.Yellow);
            }
        }

        private void DrawLinesSSD(int index)
        {
            if (ssdRising[index - 1] != ssdRising[index] && _stochastic.PercentD[index] > 60 && ssdRising[index] == false)
            {
                ChartObjects.DrawText("maxrssd" + index, "D⮟", index, Source[index], VerticalAlignment.Top, HorizontalAlignment.Center, Colors.White);

            }
            else if (ssdRising[index - 1] != ssdRising[index] && _stochastic.PercentD[index] < 40 && ssdRising[index] == true)
            {
                ChartObjects.DrawText("minrssd" + index, "D⮝", index, Source[index], VerticalAlignment.Bottom, HorizontalAlignment.Center, Colors.White);

            }
        }
    }
}
 

 


@itmfar

itmfar
06 Feb 2018, 10:06

RE:

hungtonydang said:

Hi itmfar,

I have an idea on how I am going to go about this, how much programming and knowledge of neural netoworks do you have? If you can understand this we might be able to collaborate on this. I plan to have 4 input neurons high low open and close with 3 output bull bear neutral and at this stage plan to back propogate the learning.

Regards,

Tony

I used to program java and c# as a junior and I worked with weka api as a learning machine.


@itmfar

itmfar
06 Feb 2018, 10:03

RE:

Panagiotis Charalampous said:

Hi itmfar,

Did you mean EURUSD instead of EURUSG? In any case, please try the code sample below

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MultiCurrency : Indicator
    {
        [Parameter(DefaultValue = "EURUSG")]
        public string Symboleu { get; set; }

        [Parameter(DefaultValue = "USDJPY")]
        public string Symboluj { get; set; }

        [Parameter(DefaultValue = "XAUUSD")]
        public string Symbolxu { get; set; }


        [Output("Correlation1", Color = Colors.Goldenrod)]
        public IndicatorDataSeries Result1 { get; set; }
        [Output("Correlation2", Color = Colors.Blue)]
        public IndicatorDataSeries Result2 { get; set; }
        [Output("Correlation3", Color = Colors.GhostWhite)]
        public IndicatorDataSeries Result3 { get; set; }


        MarketSeries series1;
        MarketSeries series2;
        MarketSeries series3;


        protected override void Initialize()
        {
            series1 = MarketData.GetSeries(Symboleu, this.TimeFrame);
            series2 = MarketData.GetSeries(Symboluj, this.TimeFrame);
            series3 = MarketData.GetSeries(Symbolxu, this.TimeFrame);
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            //Result1[index] = MarketData.GetSeries(Symboleu, TimeFrame.Hour).Close[index];
            if (series1 != null)
            {
                int index1 = series1.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index]);
                Result1[index] = series1.Close[index1];
            }
            if (series2 != null)
            {
                int index2 = series2.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index]);
                Result2[index] = series2.Close[index2];
            }
            if (series3 != null)
            {
                int index3 = series3.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index]);
                Result3[index] = series3.Close[index3];
            }
        }
    }
}

You need to check first if the series have any values before invoking them to avoid any unexpected issues.

Let me know if this solves your problem.

Best Regards,

Panagiotis

Thanks alot


@itmfar

itmfar
02 Jan 2018, 19:43

I would glad if we can cooperate in this field


@itmfar

itmfar
30 Dec 2017, 18:32

cTrader for Mac is vital


@itmfar

itmfar
23 Nov 2017, 15:51

RE:

Panagiotis Charalampous said:

Hi itmfar,

This is not possible either. You can add it as a suggestion in the Suggestions section so that the cAlgo team can consider it for future releases.

Best Regards,

Panagiotis

Thanks you Panagiotis


@itmfar

itmfar
23 Nov 2017, 14:00

RE:

Panagiotis Charalampous said:

Hi itmfar,

No this is currently not possible in cTrader.

Best Regards,

Panagiotis

 

I need to access " X % of client accounts with open positions in this market expect the price to rise" is there any way?


@itmfar

itmfar
23 Nov 2017, 13:57

RE:

tmc. said:

By the way, if you need historical data to be calculated as well, add this into OnStart method.

for (var index = 0; index < MarketSeries.Open.Count; index++)
{
   newIndicator.Calculate(index);
}

 

After that how i can use historical data in OnTick() method?


@itmfar

itmfar
23 Nov 2017, 13:55

RE:

tmc. said:

The calculation method in the refenreced indicator won't be invoked unless you read its output value or force it to calculate.

Add one of these lines into OnTick method inside your cBot.

newIndicator.Calculate(MarketSeries.Open.Count - 1);
var unused = newIndicator.Result.LastValue;

Both samples will make the indicator to calculate at current index.

Great, It saved my day.

 


@itmfar

itmfar
22 Nov 2017, 09:23

RE:

tmc. said:

Don't forget to force the calculation of the referenced indicator if you are not reading any output attribute. Otherwise, the state of the boolean will remain false all the time.

Thanks tmc. would you please explain more with sample?


@itmfar