find local maximum in history

Created at 02 Feb 2021, 02:50
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!
itmfar's avatar

itmfar

Joined 08.11.2017

find local maximum in history
02 Feb 2021, 02:50


What the Robot needs to do is, finding the local maximum in history.
In OnStart, I use a loop to have access to previous bars of days but I need to find the index of local maximums hours as well as days (into extremumsdaily and extremumshourly).
Any Idea how I can loop in both daily and hourly bars?

 

 

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.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class multitemp : Robot
    {

        public List<int> extremumsdaily = new List<int>();
        public List<int> extremumshourly = new List<int>();
        protected override void OnStart()
        {
            // Put your initialization logic here
            Bars barsD1 = MarketData.GetBars(TimeFrame.Daily);
            Bars barsH1 = MarketData.GetBars(TimeFrame.Hour);
            int Index = barsH1.Count - 1;
            int Indexdaily = barsD1.Count - 1;

            var MaxLine = barsD1.HighPrices.Last(Indexdaily);

            for (int i = Index; i > 0; i--)
            {
                // FIND MAX
                if (MaxLine < barsD1.ClosePrices.Last(i))
                {
                    // find hourly and daily indexes here
                MaxLine = barsD1.HighPrices.LastValue;
                
                extremumsdaily.Add( showingBars.Count - 1);
                }

            }
        }

        protected override void OnTick()
        {
            // Put your core logic here

        }

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

 


@itmfar