How to read Heikin Ashi indicator data in a Cbot ?

Created at 03 Nov 2020, 18:28
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
CT

ctid2775993

Joined 03.11.2020

How to read Heikin Ashi indicator data in a Cbot ?
03 Nov 2020, 18:28


Hi there!

I'm using this Hekin Ashi indicator from the repository: https://ctrader.com/algos/indicators/show/60

I want to use the open and close values from the indicator in a cbot instance to make trades based on the color ha candles.

I'm using the next cbot script (at the end) it's found on the forum from an old heikin ashi help topic

And I get this error while I want to read open or close values from the indicator thought this line Print(HA.Result._haOpen);

Error CS1061: 'cAlgo.Indicators.HeikenAshi' does not contain a definition for 'Result' and no extension method 'Result' accepting a first argument of type 'cAlgo.Indicators.HeikenAshi' could be found (are you missing a using directive or an assembly reference?)

I've tried to look on the forum for similar topics but they are pretty outdated and the advices from those topics not works in my case, what I'm doing wrong?

The reference it's checked from cbot.see the below screenshot.

Have a nice day!
 

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 HAK : Robot
    {
        [Parameter("Initial Volume", DefaultValue = 10000, MinValue = 0)]
        public int InitialVolume { get; set; }

        [Parameter("Initial Stop Loss", DefaultValue = 40)]
        public int SL { get; set; }

        [Parameter("Initial Take Profit", DefaultValue = 40)]
        public int TP { get; set; }

        private HeikenAshi HA;

        string label = "HAK";


        protected override void OnStart()
        {
            HA = Indicators.GetIndicator<HeikenAshi>(6, "Blue", "Red");
        }

        protected override void OnBar()
        {

            Print(HA);

            Print(HA.Result._haOpen);

            //int index = MarketSeries.Close.Count - 2;

            //Print("Open : " + HA._haOpen[index] + " | Close : " + HA._haClose[index] + " | Last : " + HAJ._haClose.LastValue);

            //if (HAJ.Close[index] < HA._haOpen[index])
            //{
            //ExecuteMarketOrder(TradeType.Sell, Symbol, InitialVolume, label, SL, TP);
            //}

            //if (HAJ.xClose[index] > HA._haOpen[index])
            //{
            //ExecuteMarketOrder(TradeType.Buy, Symbol, InitialVolume, label, SL, TP);
            //}
        }
    }
}

 


@ctid2775993
Replies

ctid2775993
03 Nov 2020, 19:06

Instead of using the indicator then pulling the data from it, can I make the calculations directly in the cbot ? since I don't have any important parameters to change on the Heikin Ashi indicator.


@ctid2775993

PanagiotisCharalampous
04 Nov 2020, 08:32

Hi there,

The indicator does not have any public variables that can be read. You need to rewrite the indicator in a way that it exposed the relevant information through public properties.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

ctid2775993
04 Nov 2020, 10:22 ( Updated at: 21 Dec 2023, 09:22 )

Thank you for the prompt response PanagiotisCharalampous

Following your advice, I was able to get rid of that error by changing the private to public for those next statements in the indicator:

public IndicatorDataSeries _haOpen;
public IndicatorDataSeries _haClose;

Now the compiler says successfully but on a cbot backtest all values are NaN

I'm accessing the values in this way HA._haOpen or HA._haClose or HA._haClose.LastValue

 

What I miss there? Can you please guide me in the right direction ?

Regards


@ctid2775993

PanagiotisCharalampous
04 Nov 2020, 11:13

Hi there,

I cannot provide you with a solution since I am not the author of the indicator but I would advise you to use parameters that have the Output attribute to pass results to a cBot. This will guarantee that Calculate method is executed. If you still do not get values, you should run some debugging to figure out why are the values not set.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

... Deleted by UFO ...