Indicator values in a Custom class - Issue
Hi, I am trying to get the value for Moving Average in a custom class by passing in the Historic Data but iMA is always null, not sure why?
public double GetMa(HistoricalData data, int period, MAMode mode)
{
iMA = _platformEngine.Indicators.iMA(data, period, mode, 0, PriceType.Close);
if (iMA == null) // This is always null ????
{
MessageBox.Show("iMA is null");
}
else
{
MessageBox.Show("iMA is no more null");
}
return iMA.GetValue(0,0);
}
----- Here is the full class -----
using System.Windows.Forms;
using PTLRuntime.NETScript;
using PTLRuntime.NETScript.Indicators;
namespace MarketTools.Services
{
public class GenericIndicator
{
private readonly NETSDK _platformEngine;
private Indicator iMA;
public GenericIndicator(NETSDK platformEngine)
{
_platformEngine = platformEngine;
}
public double GetMa(HistoricalData data, int period, MAMode mode)
{
iMA = _platformEngine.Indicators.iMA(data, period, mode, 0, PriceType.Close);
if (iMA == null)
{
MessageBox.Show("iMA is null");
}
else
{
MessageBox.Show("iMA is no more null");
}
return iMA.GetValue(0,0);
}
}
}
The GenericIndicator class mentioned above is part of that. In an ideal world as long as I am using a valid instance of NETSDK (_platformEngine in the above example). I should be able to use the code below.
iMA = _platformEngine.Indicators.iMA(data, period, mode, 0, PriceType.Close);
It seems to me that the IndicatorsCollection is tightly coupled with the chart object, hence it's causing this issue.
It will be a good idea to have it decoupled and available through an instance of the NETSDK object.
I think this will be a pretty powerful improvement.