Custom Indicator not moving as time passes

Created at 19 Apr 2022, 14:07
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!
Capt.Z-Fort.Builder's avatar

Capt.Z-Fort.Builder

Joined 03.06.2020

Custom Indicator not moving as time passes
19 Apr 2022, 14:07


Hello, 

I have the below code for an indicator, to show USD strength based on 7 major pairs. But it is delayed to show the result and seems not moving along as time passes. 

Please help and advise. Thank you. :)

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class StrengthAndWeakness : Indicator
    {

        [Output("USD", LineColor = "FFFF0005", Thickness = 2, PlotType = PlotType.DiscontinuousLine)] 
        public IndicatorDataSeries USD { get; set; }  

        private Bars EURUSD;
        private Bars GBPUSD;
        private Bars AUDUSD;
        private Bars NZDUSD;
        private Bars USDCAD;
        private Bars USDCHF;
        private Bars USDJPY;

        protected override void Initialize()
        {
            EURUSD = MarketData.GetBars(Bars.TimeFrame, "EURUSD");
            GBPUSD = MarketData.GetBars(Bars.TimeFrame, "GBPUSD"); 
            AUDUSD = MarketData.GetBars(Bars.TimeFrame, "AUDUSD"); 
            NZDUSD = MarketData.GetBars(Bars.TimeFrame, "NZDUSD"); 
            USDCAD = MarketData.GetBars(Bars.TimeFrame, "USDCAD"); 
            USDCHF = MarketData.GetBars(Bars.TimeFrame, "USDCHF"); 
            USDJPY = MarketData.GetBars(Bars.TimeFrame, "USDJPY");
        }

        public override void Calculate(int index)
        {
            USD[index] = 200*(  (1/EURUSD[index].Close)
                               *(1/GBPUSD[index].Close)
                               *(1/AUDUSD[index].Close)
                               *(1/USDCAD[index].Close)
                               *(1/NZDUSD[index].Close)
                               *  (USDCHF[index].Close)
                               *  (USDJPY[index].Close)
                               -137);
        }

    }
}


@Capt.Z-Fort.Builder
Replies

Capt.Z-Fort.Builder
20 Apr 2022, 03:24

RE:

Thank me, the problem has been resolved. 

There are some bars gaps between the data series to the bars' index number. Get the gap value e.g gap_EURUDS and put them in the right place as below would fix the problem.

...
        {
            USD[index] = 200*(  (1/EURUSD[index + gap_EURUDS].Close)
                               *(1/GBPUSD[index + gap_GBPUSD].Close)
                               *(1/AUDUSD[index + gap_AUDUSD].Close)
                               *(1/USDCAD[index + gap_USDCAD].Close)
                               *(1/NZDUSD[index + gap_NZDUSD].Close)
                               *  (USDCHF[index + gap_USDCHF].Close)
                               *  (USDJPY[index + gap_USDJPY].Close)
                               -137);
        }
...

 

 


@Capt.Z-Fort.Builder