Double indi

Created at 31 Aug 2012, 16:32
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!
MI

misado

Joined 31.08.2012

Double indi
31 Aug 2012, 16:32


Hi,

first I have to say that I have serious problems with calgo because its working very very slow. Every step take a horrible time. Do you have any idea?

Second I tried to add a second cmo to the code a. m. but there might be some mistakes. Thanks guys for your support. The code is

using System;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false)]
    public class CMO : Indicator
    {
        [Parameter]
        public DataSeries Source { get; set; }
        
        [Parameter(DefaultValue = 9)]
        public int period { get; set; }
        
        [Output("CMOfast",Color = Colors.Yellow)]
        public IndicatorDataSeries cmo1 { get; set; }
        
        [Parameter(DefaultValue = 20)]
        public int period { get; set; }
        
        [Output("CMOslow",Color = Colors.Red)]
        public IndicatorDataSeries cmo2 { get; set; }
        
        double downs;
        double ups;
        
        private IndicatorDataSeries ddown;
        private IndicatorDataSeries dup;
        
        protected override void Initialize()
        {
            ddown = CreateDataSeries();
            dup = CreateDataSeries();
        }

        public override void Calculate(int index)
        {
        if(index==0)
        {
            ddown[index]=0;
            dup[index]=0;
            return;
        }
        
            ddown[index] = Math.Max(Source[index-1] - Source[index],0);
            dup[index] = Math.Max(Source[index] - Source[index-1],0);
            
            downs=0;
            ups=0;
            for(int i=index; i > index - period; i--)
            {
                downs += ddown[i];
                ups += dup[i];
            }
            if (Math.Abs(ups + downs) < double.Epsilon)
            {
                cmo1[index] =0;

 

  cmo2[index] =0;

            }
            else
            {
                cmo1[index] = (100 * ((ups - downs) / (ups + downs)));

 

  cmo2[index] = (100 * ((ups - downs) / (ups + downs)));
            }
        }
    }
}

 


@misado
Replies

admin
31 Aug 2012, 16:49

Hi

Can you please explain to us what exactly are you experiencing?Is this happening when you use and indicator or a robot? Do you use any complicated robot/indicator that does a lot of calculations? How many instances of indicator/robots have you got opened at the same time?

 

As i understand you want this indicator to produce one more line with different period. Most probably the code below will do the trick for you:

 

using System;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false)]
    public class cmo : Indicator
    {
        [Parameter]
        public DataSeries Source { get; set; }
        
        [Parameter("CMOSlow",DefaultValue = 20)]
        public int CMOSlow { get; set; }
        
        [Parameter("CMOfast",DefaultValue = 9)]
        public int CMOfast { get; set; }
        
        [Output("CMOfast",Color = Colors.Yellow)]
        public IndicatorDataSeries cmo1 { get; set; }
        
        [Output("CMOslow",Color = Colors.Red)]
        public IndicatorDataSeries cmo2 { get; set; }
        
        double downs,downs2;
        double ups,ups2;
        
        private IndicatorDataSeries ddown;
        private IndicatorDataSeries dup;
        
        protected override void Initialize()
        {
            ddown = CreateDataSeries();
            dup = CreateDataSeries();
        }

        public override void Calculate(int index)
        {
        if(index==0)
        {
            ddown[index]=0;
            dup[index]=0;
            return;
        }
            ddown[index] = Math.Max(Source[index-1] - Source[index],0);
            dup[index] = Math.Max(Source[index] - Source[index-1],0);
            
            downs=0;
            ups=0;
            downs2=0;
            ups2=0;
            
            for(int i=index; i > index - CMOfast; i--)
            {
                downs += ddown[i];
                ups += dup[i];
            }
            
            for(int i=index; i > index - CMOSlow; i--)
            {
                downs2 += ddown[i];
                ups2 += dup[i];
            }
            
            if (Math.Abs(ups + downs) < double.Epsilon)
            {
                cmo1[index] =0;
 
  				cmo2[index] =0;

            }
            else
            {
                cmo1[index] = (100 * ((ups - downs) / (ups + downs)));
 
  				cmo2[index] = (100 * ((ups2 - downs2) / (ups2 + downs2)));
            }
        }
    }
}




@admin

misado
05 Sep 2012, 12:14

Hi

thanks a lot for your fast and good support.

First item why calgo works so slowly: "How many instances of indicator/robots have you got opened at the same time?" - Exactly that was the problem, now its solved and calgo works absolutely perfect.

Second item: The double indi works fine and the logic behind seems to me much more easiert than mt4.

 

Another question:

I've downloaded the indi "AdaptiveCG" but I can't compile it, so it doesn't work!?


@misado

admin
05 Sep 2012, 12:29

Hello again,

Can you please try to download this indicator too: /algos/show/124, build it and then try to build the adaptive center of gravity(AdaptiveCG)?

 

 


@admin

misado
05 Sep 2012, 14:11

Hi,

it works. Thanks again.


@misado