Indicator not moving along with time passes
Indicator not moving along with time passes
20 Apr 2022, 04:42
Hello,
If anyone could help me to sort out a strange problem. Details as below, thanks.
I want to make 2 indicators, which will show GBPUSD and NZDUSD movement in the chart of EURUSD in a low timeframe (e.g 3min). Both indicators will be aligned with EURUSD at a time point, which I call 'Reset Time Point' as below screen chop:
The problem is that the GBP indicator works very well, but NZD doesn't. See the below explanation:
The sample code is attached below:
using System;
using cAlgo.API;
using cAlgo.API.Internals;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class USDCorelation : Indicator
{
[Parameter("Reset Time", DefaultValue = "2022-4-19 22:15:00", Group = "Ver. 1.01")]
public string ResetPoint { get; set; }
[Output("GBP", LineColor = "FFB600FF", Thickness = 2, PlotType = PlotType.DiscontinuousLine)]
public IndicatorDataSeries GBP { get; set; }
[Output("NZD", LineColor = "FF00BF00", Thickness = 2, PlotType = PlotType.DiscontinuousLine)]
public IndicatorDataSeries NZD { get; set; }
private DateTime dt_RstPnt; //Reset Time Point;
//Bars to load for Calculate
private Bars EURUSD, GBPUSD, NZDUSD;
//Index at ResetTimePoint of EachSymbol;
private int in_EURUSD, in_GBPUSD, in_NZDUSD;
//BaseValue at ResetTimePoint of EachSymbol;
private double db_EURUSD, db_GBPUSD, db_NZDUSD;
//BarNumber from ResetTimePoint to LastBar
private int gap;
protected override void Initialize()
{
//1.Get MarketData in Series Ready
EURUSD = MarketData.GetBars(Bars.TimeFrame, "EURUSD");
GBPUSD = MarketData.GetBars(Bars.TimeFrame, "GBPUSD");
NZDUSD = MarketData.GetBars(Bars.TimeFrame, "NZDUSD");
//2.Get ResetTimePoint Index
dt_RstPnt = DateTime.Parse(ResetPoint).Add(-Application.UserTimeOffset);
in_EURUSD = EURUSD.OpenTimes.GetIndexByTime(dt_RstPnt);
in_GBPUSD = GBPUSD.OpenTimes.GetIndexByTime(dt_RstPnt);
in_NZDUSD = NZDUSD.OpenTimes.GetIndexByTime(dt_RstPnt);
//3.Get OpenPrice of each symbol at ResetTimePoint
db_EURUSD = EURUSD[in_EURUSD].Open;
db_GBPUSD = GBPUSD[in_GBPUSD].Open;
db_NZDUSD = NZDUSD[in_NZDUSD].Open;
}
public override void Calculate(int index)
{
gap = index - in_EURUSD;
GBP[index] = ((GBPUSD[in_GBPUSD + gap].Close) + db_EURUSD - db_GBPUSD);
NZD[index] = ((NZDUSD[in_NZDUSD + gap].Close) + db_EURUSD - db_NZDUSD);
}
}
}
Replies
Capt.Z-Fort.Builder
20 Apr 2022, 13:34
RE:
Thank you like always, it works perfectly. :)
amusleh said:
Hi,
Try this:
using System; using cAlgo.API; using cAlgo.API.Internals; namespace cAlgo { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class USDCorelation : Indicator { [Parameter("Reset Time", DefaultValue = "2022-4-19 22:15:00", Group = "Ver. 1.01")] public string ResetPoint { get; set; } [Output("GBP", LineColor = "FFB600FF", Thickness = 2, PlotType = PlotType.DiscontinuousLine)] public IndicatorDataSeries GBP { get; set; } [Output("NZD", LineColor = "FF00BF00", Thickness = 2, PlotType = PlotType.DiscontinuousLine)] public IndicatorDataSeries NZD { get; set; } private DateTime dt_RstPnt; //Reset Time Point; //Bars to load for Calculate private Bars EURUSD, GBPUSD, NZDUSD; //Index at ResetTimePoint of EachSymbol; private int in_EURUSD, in_GBPUSD, in_NZDUSD; //BaseValue at ResetTimePoint of EachSymbol; private double db_EURUSD, db_GBPUSD, db_NZDUSD; protected override void Initialize() { //1.Get MarketData in Series Ready EURUSD = MarketData.GetBars(Bars.TimeFrame, "EURUSD"); GBPUSD = MarketData.GetBars(Bars.TimeFrame, "GBPUSD"); NZDUSD = MarketData.GetBars(Bars.TimeFrame, "NZDUSD"); //2.Get ResetTimePoint Index dt_RstPnt = DateTime.Parse(ResetPoint).Add(-Application.UserTimeOffset); in_EURUSD = EURUSD.OpenTimes.GetIndexByTime(dt_RstPnt); in_GBPUSD = GBPUSD.OpenTimes.GetIndexByTime(dt_RstPnt); in_NZDUSD = NZDUSD.OpenTimes.GetIndexByTime(dt_RstPnt); //3.Get OpenPrice of each symbol at ResetTimePoint db_EURUSD = EURUSD[in_EURUSD].Open; db_GBPUSD = GBPUSD[in_GBPUSD].Open; db_NZDUSD = NZDUSD[in_NZDUSD].Open; } public override void Calculate(int index) { if (Bars.OpenTimes[index] < dt_RstPnt) return; var gbpIndex = GBPUSD.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]); var gbpGap = gbpIndex - in_GBPUSD; GBP[index] = ((GBPUSD[in_GBPUSD + gbpGap].Close) + db_EURUSD - db_GBPUSD); var nzdIndex = NZDUSD.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]); var nzdGap = nzdIndex - in_NZDUSD; NZD[index] = ((NZDUSD[in_NZDUSD + nzdGap].Close) + db_EURUSD - db_NZDUSD); } } }
@Capt.Z-Fort.Builder
amusleh
20 Apr 2022, 09:23
Hi,
Try this:
@amusleh