Plotting objects (buy / sell) arrows on a lower timeframe using higher time frame data.

Created at 09 May 2024, 11:48
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!
J_

j_matu

Joined 11.12.2022

Plotting objects (buy / sell) arrows on a lower timeframe using higher time frame data.
09 May 2024, 11:48


Hello, 

Need help plotting higher time frame buy / sell arrows on a lower timeframe using data from a higher timeframe. When two moving averages cross over on the 1hr timeframe, can I plot (display) buy / sell arrows on a lower time frame (M15) using data from the H1 time frame. 

Any help will be highly appreciated. 

Below is a sample ma cross.

Thanks

 

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Lib;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class FastCrossSlow : Indicator
    {
        [Parameter("MA Type", DefaultValue=6)]
        public MovingAverageType MaType { get; set; }

        [Parameter("Slow Period", DefaultValue = 11, MinValue = 1)]
        public int SlowPeriod { get; set; }

        [Parameter("Fast Period", DefaultValue = 5, MinValue = 1)]
        public int fastPeriod { get; set; }

        [Output("slowMa",Thickness=2,Color=Colors.DeepSkyBlue)]
        public IndicatorDataSeries SlowMAResult { get; set; }

        [Output("fastMA",Thickness=2,Color=Colors.Green)]
        public IndicatorDataSeries FastMAResult { get; set; }

        MovingAverage slowMA;
        MovingAverage fastMA;
        protected override void Initialize()
        {
            fastMA = Indicators.MovingAverage(MarketSeries.Close, fastPeriod, MaType);
            slowMA = Indicators.MovingAverage(MarketSeries.Close, SlowPeriod, MaType);

        }
        public override void Calculate(int index)
        {
            FastMAResult[index] = fastMA.Result[index];
            SlowMAResult[index] = slowMA.Result[index];

            
            
            if (isCrossAbove())
                ChartObjects.drawUpArrow(index-1, null, MarketSeries, Symbol);

            if (isCrossBelow())
                ChartObjects.drawDnArrow(index-1, null, MarketSeries, Symbol);
        }

        #region Predicate
        public bool isCrossAbove()
        {
            return FastMAResult.HasCrossedAbove(SlowMAResult, 0);
        }
        public bool isCrossBelow()
        { 
            return FastMAResult.HasCrossedBelow(SlowMAResult, 0);
        }
        #endregion

    }
}


@j_matu
Replies

firemyst
28 Jul 2024, 05:24 ( Updated at: 28 Jul 2024, 06:43 )

You can do it, but it might not be 100% accurate on when it happens when calculating previous candles.

This is because on the higher timeframe, it'll be seen as crossing at the opening time of that bar. So like 1pm, 2pm, 3pm,. etc.

 

So on your 15M chart, you can:

  1. have it shown on the 4 15-minute bars that make up the hour
  2. or it'll probably just be shown on the first 15-minute bar of the corresponding hour. That is, if it crossed at 1:20pm, yesterday, when the indicator opens and calculates previous bars, it only goes by closing prices, not actual ticks, so it'll show as closing at 1pm and not the 15-minute bar that represents 1:20pm.

OTherwise, for example code, check out Spotware's online documentation:

https://help.ctrader.com/ctrader-algo/indicator-code-samples/#multiple-timeframes

 


@firemyst