Embedded Indicators

Created at 07 Nov 2012, 00:34
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!
RK

rkokerti

Joined 28.06.2012

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);
	}
   	}
   }   
}

 


@rkokerti
Replies

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

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
13 Nov 2012, 18:32

Hello Admin,

Have you got any new information about this issue?

Thanks!


@rkokerti

admin
13 Nov 2012, 19:12

We did find that on some symbols it does take a few more seconds to load but we are still testing to identify the issue. We will let you know.

 


@admin

admin
14 Nov 2012, 11:42

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.

 

 


@admin

rkokerti
14 Nov 2012, 13:22

RE:
admin said:

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.

 

 

Unfortunately, still the same slow! 28 seconds, nothing has changed...
If I remove this part "& _dms.DIPlus[index] > _dms.DIMinus[index]) " from code, then again 1 second :-)
If I add this part "& _dms.DIPlus[index] > _dms.DIMinus[index]) " to code, then 28 seconds... I dont understand why!

@rkokerti

admin
14 Nov 2012, 16:25

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.

 


@admin

rkokerti
14 Nov 2012, 18:07

RE:
admin said:

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.

 

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.
I just wanted to know what is the reason for this. Because if you use the above-mentioned code in a robot like this:
 
     protected override void OnBar() 
    {    

    int index = MarketSeries.Close.Count-2;

    if(_dms.DIPlus[index] > _dms.DIMinus[index])
    {
    Trade.CreateBuyMarketOrder(Symbol, Volume);
    }
    
    if(_dms.DIPlus[index] < _dms.DIMinus[index])
    {
    Trade.CreateSellMarketOrder(Symbol, Volume);
    }
    } 
 
In this case the execution of robot is totally crashed!!! I need to restart the program, or all orders has error message : "technical error"
So, please investigate this Directional Movement System indicator, because this is useless.
 
Thanks

@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