Replies

calgodemo
14 Jun 2019, 06:13

Further development on this:

 

I'm getting nullreference crashes on the indicator where it draws to the indicatorArea.... says the IndicatorArea is null.... 


@calgodemo

calgodemo
13 Jun 2019, 19:38

RE:

Panagiotis Charalampous said:

Hi calgodemo,

Can you share the cBot and Indicator code? 

Best Regards,

Panagiotis

Thanks for replying Panagiotis, 

here is the cbot, all I'm doing at this point is drawing text on the chart.

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 MDE : Robot
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }
        [Parameter(DefaultValue = 60, MinValue = 5)]
        public int Timeframe { get; set; }

        // Declare indicator.
        public MDEv2I MDE;

        // here are some variables I am creating along the way.


        protected override void OnStart()
        {
            // instantiate custom indicator
            MDE = Indicators.GetIndicator<MDEv2I>(Source);



        }

        protected override void OnBar()
        {
            // count indicies and display to chart to test indicator values are being read correctly
       Chart.DrawStaticText("D_Orange", "Last orange dot index is " + MDE.D_Orange.ToString(), VerticalAlignment.Center, HorizontalAlignment.Right, "orange");
        }

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

Let me post the part of the indicator that generates the D_orange variable I'm trying to count the index of. 

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 MDEv2I : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Output("MACD", LineColor = "blue", Thickness = 3)]
        public IndicatorDataSeries Blueline { get; set; }
        [Output("Signal", LineColor = "red", Thickness = 3)]
        public IndicatorDataSeries Redline { get; set; }
        [Output("Histogram", IsHistogram = true, LineColor = "lightblue", Thickness = 4)]
        public IndicatorDataSeries Histogram { get; set; }

        [Output("D_Orange")]
        public int D_O { get; set; }

        #region declaring variables
        public MacdCrossOver Macd;
        public int Dr_last;
        public int Dr;
        public int Vg_last;
        public int Vg;
        public int D_Orange;
        public int D_Orange_Last;
        #endregion

        protected override void Initialize()
        {
            Macd = Indicators.MacdCrossOver(Source, 26, 12, 9);
            Dr = 0;
            Vg = 0;
            Dr_last = 0;
            Vg_last = 0;
            D_Orange = 0;
            D_Orange_Last = 0;
        }

        public override void Calculate(int index)
        {
            Blueline[index] = Macd.MACD[index];
            Redline[index] = Macd.Signal[index];
            Histogram[index] = Macd.Histogram[index];

            if (CalcHistZero() != 0)
            {
                D_Orange_Last = D_Orange;
                D_Orange = index;
                D_O = D_Orange;
            }
            if (CalcMacdZeroCross() != 0)
            {
                Vg_last = Vg;
                Vg = index;
            }
        }

        public int CalcHistZero()
        {
            int tempindex = 5;
            int period = 0;
            if (Vg != 0 && D_Orange != 0)
            {
                tempindex = Math.Max(Vg, D_Orange);
            }
            period = Histogram.Count - tempindex;
            for (int calc = (Histogram.Count - 1); calc > (Histogram.Count - period); calc--)
            {
                if (Blueline[calc] > 0)
                {
                    if (Histogram[calc - 1] > 0 && Histogram[calc] < 0)
                        return calc;
                }
                if (Blueline[calc] < 0)
                {
                    if (Histogram[calc - 1] < 0 && Histogram[calc] > 0 || Histogram[calc - 1] > 0 && Histogram[calc] < 0)
                        return calc;
                }
            }
            return 0;
        }
        public int CalcMacdZeroCross()
        {
            int tempindex = 5;
            int period = 0;
            if (Vg != 0 && D_Orange != 0)
            {
                tempindex = Math.Max(Vg, D_Orange);
            }
            period = Histogram.Count - tempindex;
            for (int calc = Blueline.Count; calc > (Blueline.Count - period); calc--)
            {
                // crossing below zero line
                if (Blueline[calc] > 0)
                {
                    if (Blueline[calc - 1] > 0 && (Blueline[calc] > 0 && Blueline[calc + 1] < 0))
                    {
                        return calc;
                    }
                }
                // crossing above zero line
                if (Blueline[calc] < 0)
                {
                    if (Blueline[calc - 1] < 0 && (Blueline[calc] < 0 && Blueline[calc + 1] > 0))
                    {
                        return calc;
                    }
                }
            }
            return 0;
        }        
      }
}

 

So the quick question I'm facing, is that when I choose the indicator from the custom indicators list and run the cbot in backtesting.... I see the following.

https://gyazo.com/417a8b01c94c37dd19910b734876cdd4

The indicator is drawing the dots, at the different indicies, but the readout from the cbot is identical to when the variable was initialized...0. 

Hope that clarifies some things, appreciate your time looking into it. Thank you!

cAD


@calgodemo

calgodemo
28 May 2019, 03:47

RE:

calgodemo said:

Hello all,

I'm experiencing a rather bizzare bug?

I started by adding and displaying a RSI 14 period indicator to my custom indicator. Nothing special about that, worked fine.

Then I added some logic, went back to the indicator to see result - nothing there, probably made a mistake so I went to debug the indicator. Now, for that time frame (1hr) and all higher timeframes I get no RSI displayed, but for 30min/15min etc... it does still display. Huh???

On the debug the values of the currency pair seemed to be off from the real thing.

Next I get to the second part of my question:

Can someone kindly write an example of how to draw a line on the chart? 

I'm using the Chart.DrawTrendLine("label", startindex,  maxvalue, 0, currentvalue, "red", 3);

Playing around drawing a trendline on the RSI values... but can't get the thing to display.

Many Thanks,

cAD

Figured it out - to draw the thing in the indicator area one has to use the IndicatorArea.DrawTrendLine function... lots of research later now ya know!

 

Still don't know why the darn thing won't display on the 1hr though.


@calgodemo