accessing a value in custom indicator1 from custom indicator2
accessing a value in custom indicator1 from custom indicator2
07 Sep 2020, 23:25
Hi all, maybe someone can give a little help here:
I'm trying to access a value in indicator#1 from indicator#2 via reference:
indicator #1:
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class Indi1 : Indicator
{
[Output("Main")]
public int _intResult { get; set; }
protected override void Initialize()
{
_intResult = 777;
}
public override void Calculate(int index)
{
_intResult += 1;
Print(_intResult);
string Text = "Trade allowed : " + _intResult;
IndicatorArea.DrawStaticText("Symbols", Text, VerticalAlignment.Top, HorizontalAlignment.Left, Color.Silver);
}
}
}
and here the code from the "receiving" indicator #2
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class Indi2 : Indicator
{
[Output("Main")]
public int Result { get; set; }
private Indi1 _newIndicator;
protected override void Initialize()
{
_newIndicator = Indicators.GetIndicator<Indi1>();
}
public override void Calculate(int index)
{
Print(_newIndicator);
string Text = "Trade allowed : " + _newIndicator._intResult;
IndicatorArea.DrawStaticText("Symbols", Text, VerticalAlignment.Top, HorizontalAlignment.Left, Color.Silver);
}
}
}
but it doesn't work, the received value is always 777 but not the actual value of this variable in indicator #1...
I'm greatful for any kind of help,
Kindest regards,
Replies
PanagiotisCharalampous
08 Sep 2020, 09:28
Hi xabbu,
1) You have to change indicator #1
2) Just call _newIndicator.Calculate(index);
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
08 Sep 2020, 09:55
Hi xabbu,
Just use an IndicatorDataSeries to store your values.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
08 Sep 2020, 10:14
Hi xabbu,
On indicator 1.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
08 Sep 2020, 10:17
Hi xabbu,
Yes I would recommend this approach.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
08 Sep 2020, 08:02
Hi xabbu,
The indicator's Calculate() method is only called when an IndicatorDataSeries accessed by external code. In your case this does not happen, hence the Calculate() method is never actually executed. You have two options a) use IndicatorDataSeries instead of a normal variable b) call Calculate() method manually.
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous