Functions.HasCrossed

Created at 20 Jul 2022, 12:21
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!
GE

gennimatas

Joined 19.09.2018

Functions.HasCrossed
20 Jul 2022, 12:21


Both Functions.HasCrossed, Above and Below always return true.

 

Btw, please notice that attached code creates a large quantity of 3*Bars.Count ChartIcons.

When you run the indicator on a m1 chart and refresh the chart or change TimeFrame the operation is taking too long as m1 charts have a large number of bars.

This reminds me of emptying large collections using their first index instead of the last.

Regards

Takis

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

namespace cAlgo
{
    [Indicator(AccessRights = AccessRights.None)]
    public class TestHasCrossed : Indicator
    {
        [Output("Main", Color = Colors.White)]
        public IndicatorDataSeries Result { get; set; }

        Random r = new Random();

        protected override void Initialize()
        {
        }

        public override void Calculate(int index)
        {
            if (IsLastBar)
                IndicatorArea.DrawIcon(index.ToString() + "lb", ChartIconType.Diamond, index, 0.0, Color.Yellow);

            int max = 100;
            Result[index] = r.Next(max) - max / 2;

            if (Result.HasCrossedAbove(0, index))
                IndicatorArea.DrawIcon(index.ToString() + "u", ChartIconType.UpArrow, index, max / 4, Color.Green);
            if (Result.HasCrossedBelow(0, index))
                IndicatorArea.DrawIcon(index.ToString() + "d", ChartIconType.DownArrow, index, -max / 4, Color.Red);
        }
    }
}

 


@gennimatas
Replies

PanagiotisCharalampous
21 Jul 2022, 10:39

Hi Takis, 

I could not reproduce any problem. Please let me know the following

  1. Explain to us what do you think the indicator is doing. The logic as is does not make any sense to me.
  2. Provide broker, symbol and timeframe, as well as screenshots demonstrating the problem.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

gennimatas
21 Jul 2022, 12:09

RE:

PanagiotisCharalampous said:

Hi Takis, 

I could not reproduce any problem. Please let me know the following

  1. Explain to us what do you think the indicator is doing. The logic as is does not make any sense to me.
  2. Provide broker, symbol and timeframe, as well as screenshots demonstrating the problem.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 

Hi Pano,

Hahahahaa What logic. This is paralogic.

HasCrossedAbove(0, index) should be HasCrossedAbove(0, 0)

I'm getting old, sorry Pano!

Regards

 


@gennimatas

PanagiotisCharalampous
21 Jul 2022, 12:30

Hi Takis, 

Cool! So problem sorted or is there something you still wish me to look at?

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous