Embedded Indicators
Embedded Indicators
07 Nov 2012, 00:34
Hello Admin,
I would like to ask you, why calculation time is significantly increases when I use embedded indicators? Maybe I'm doing somethimg wrong?
1. case : I press "Build Indicator" button and indicator appears in 1 sec.
using System; using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Indicators { [Indicator(IsOverlay = true)] public class _RI_Test : Indicator { [Parameter(DefaultValue = 14)] public int periodDMS { get; set; } [Output("Trigger", PlotType = PlotType.Points, Color = Colors.Red, Thickness = 3)] public IndicatorDataSeries Trigger { get; set; } private DirectionalMovementSystem _dms; protected override void Initialize() { _dms = Indicators.DirectionalMovementSystem(periodDMS); } public override void Calculate(int index) { if(MarketSeries.Open[index] < MarketSeries.Close[index]) // & _dms.DIPlus[index] > _dms.DIMinus[index]) { Trigger[index] = MarketSeries.High[index] + (2*Symbol.PipSize); } } } }
2. case : I press "Build Indicator" button and indicator appears in 28 sec.
using System; using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Indicators { [Indicator(IsOverlay = true)] public class _RI_Test : Indicator { [Parameter(DefaultValue = 14)] public int periodDMS { get; set; } [Output("Trigger", PlotType = PlotType.Points, Color = Colors.Red, Thickness = 3)] public IndicatorDataSeries Trigger { get; set; } private DirectionalMovementSystem _dms; protected override void Initialize() { _dms = Indicators.DirectionalMovementSystem(periodDMS); } public override void Calculate(int index) { if(MarketSeries.Open[index] < MarketSeries.Close[index] & _dms.DIPlus[index] > _dms.DIMinus[index]) { Trigger[index] = MarketSeries.High[index] + (2*Symbol.PipSize); } } } }
Replies
rkokerti
07 Nov 2012, 13:13
( Updated at: 21 Dec 2023, 09:20 )
Hello,
I try to visualize the issue on screeshot below:
You find the differece in row 26, if you copy the code back into cAlgo.
1. case : I dosen't use DMS as condition (1 sec)
if(MarketSeries.Open[index] < MarketSeries.Close[index]) // & _dms.DIPlus[index] > _dms.DIMinus[index])
2. case: I use DMS as condition (28 sec)
if(MarketSeries.Open[index] < MarketSeries.Close[index] & _dms.DIPlus[index] > _dms.DIMinus[index])
Thanks for your help!
@rkokerti
rkokerti
14 Nov 2012, 13:22
RE:
Unfortunately, still the same slow! 28 seconds, nothing has changed...Your code is actually loading fast. Nowhere close to 28 seconds. Could you test it for instance on EURUSD and see if the loading time is still slow? It could be that the symbol you are using has more historical trendbars and it takes longer to calculate.
@rkokerti
rkokerti
14 Nov 2012, 18:07
RE:
I understand and trust me, I do not build it every time. But what you wrote down dosen't eliminate the cause, only a temporary solution to.You only need to build it once when you have completed coding. After that all you need to do to load it, is to add an instance. Then the indicator should be loaded in a very short time. You do not need to build it every time you want to load it to the chart.
{
int index = MarketSeries.Close.Count-2;
if(_dms.DIPlus[index] > _dms.DIMinus[index])
{
Trade.CreateBuyMarketOrder(Symbol, Volume);
}
{
Trade.CreateSellMarketOrder(Symbol, Volume);
}
}
@rkokerti
admin
15 Nov 2012, 12:23
We tested a robot that references DirectionalMovementSystem Indicator, more specifically your code above and it does not crash. Please explain a bit more what exactly are the circumstances under which your robot crashes and what is exactly the code that you receive a technical error for.
using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Robots { [Robot] public class DMIRobot :Robot { private DirectionalMovementSystem _dms; [Parameter("Volume", DefaultValue = 10000)] public int Volume { get; set; } protected override void OnStart() { _dms = Indicators.DirectionalMovementSystem(14); } protected override void OnBar() { if(Trade.IsExecuting) return; int index = MarketSeries.Close.Count - 2; if (_dms.DIPlus[index] > _dms.DIMinus[index]) { Trade.CreateBuyMarketOrder(Symbol, Volume); } else if (_dms.DIPlus[index] < _dms.DIMinus[index]) { Trade.CreateSellMarketOrder(Symbol, Volume); } } } }
@admin
admin
07 Nov 2012, 10:26
Hello,
Can you please clarify what you mean by "indicator appears" Is the problem when you build or when you add an instance to the chart?
We will investigate DirectionalMovementSystem as a referenced indicator in the meantime and the time it takes to build.
In the cases you describe above the code is identical, so what is it that differentiates one case from the other exactly?
Regards,
@admin