Plotting objects (buy / sell) arrows on a lower timeframe using higher time frame data.
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
}
}
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:
OTherwise, for example code, check out Spotware's online documentation:
https://help.ctrader.com/ctrader-algo/indicator-code-samples/#multiple-timeframes
@firemyst