Getting Swing highs and lows

Created at 19 Dec 2019, 21: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!
CO

CollinsKipchumba

Joined 14.09.2018

Getting Swing highs and lows
19 Dec 2019, 21:28


Hello, i would like to be able to access the previous prices of major swing highs and lows using for my cbot how do we do it please.


@CollinsKipchumba
Replies

PanagiotisCharalampous
20 Dec 2019, 08:12

Hi Collins,

You can try using and modifying a Zig Zag indicator that detects highs and lows. You can find some below

https://ctrader.com/algos/indicators/show/157

https://ctrader.com/algos/indicators/show/1218

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

erik.lindblad
19 Oct 2020, 23:41

Hi Panagiotis!

I stumbled upon this post and the The ZigZag indicator that you are referring to is exactly what I am looking for. However, there is one problem that I am having with all custom indicators I have experimented with so far. Maybe I am misunderstanding the purpose of the indicators but I do not care about lines or objects being drawn on the charts, I want the indicator calculate something for me and to pass that data to my cBot so it can be used in the trading.

How am I supposed to do this? It looks that an indicator can only output properties of type IndicatorDataSeries, which seems to be just a list of doubles. I would like the indicator to expose just a simple list of custom objects representing the swing points. I tried to put the swing point objects in a public property inside the indicator and access them like shown in simplified pseudo below, but it does not work.

public class ZigZagIndicator : Indicator
{
    public List<SwingPoint> SwingPoints;

    public override void Calculate(int index)
    {
        //Calculate swing points and add them to my swing points list
        // Do not care about drawing anything on the chart
    }
}

public class SwingPoint
{
    public string Type { get; set; }
    public double Price { get; set; }
    // Maybe something more here, like date or index or something
}

public class Bot : Robot
{
    private ZigZagIndicator zigZagIndicator;

    protected override void OnStart()
    {
        zigZagIndicator = Indicators.GetIndicator<ZigZagIndicator>();
    }

    protected void OnBar()
    {
        var swingPoints = zigZagIndicator.SwingPoints; // Does not work, always empty
    }
}

Maybe I do not even need an indicator if I don't care about drawing anything on the chart? Maybe the bot can find the swing points itself? However, I do not fully understand the ZigZag algorithm so I have not been able to move that logic into the cbot.

Could you please point me in the right direction, feels like I am missing something obvious.

Best regards

Erik


@erik.lindblad

PanagiotisCharalampous
20 Oct 2020, 09:03

Hi Collins,

This happens because the indicator's Calculate method implements a lazy loading logic and is only called when an IndicatorDataSeries is called. So you should add an IndicatorDataSeries to your indicator, even a dummy one, and call it from your cBot to trigger the Calculate method.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous