Trigger lines indicator

Created at 29 Apr 2013, 22:11
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!
TE

Tebogo121

Joined 29.04.2013

Trigger lines indicator
29 Apr 2013, 22:11


Hi, I compiled the code below from the MT4 trigger lines code. The problem I have is that I cannot make the lines colored Lime to disappear when the market goes down or the ones clored Magenta to disappear when the market goes up. Can any one please help (Screen shot attached). Thanks a million.

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true)]
    public class Triggerlines : Indicator
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }
        

       #region indicator line
       
        
        [Output("Up", Color = Colors.Lime)]
        public IndicatorDataSeries UpBuffer { get; set; }
        [Output("UpMa", Color = Colors.Lime)]
        public IndicatorDataSeries UpBuffer_ma { get; set; }

        [Output("Dn", Color = Colors.Magenta)]
        public IndicatorDataSeries DnBuffer { get; set; }
        [Output("Dnma", Color = Colors.Magenta)]
        public IndicatorDataSeries DnBuffer_ma { get; set; }


        #endregion
        private IndicatorDataSeries wt;
        private IndicatorDataSeries lsma_ma;
        private ExponentialMovingAverage _EMA;
        private const int length = 25;
        private const int lsma_length = 13;

        private int shift;
        private int loopbegin;
        private int cnt;
        private int i;
        private double su;
        private double lengthvar;
        private double tmp ;
        
        protected override void Initialize()
        {
            wt = CreateDataSeries();
            lsma_ma = CreateDataSeries();
            _EMA = Indicators.ExponentialMovingAverage(wt, lsma_length);

        }

        public override void Calculate(int index)
        {
            
         /*    DnBuffer[index] = double.NaN;
             DnBuffer_ma[index] = double.NaN;
             UpBuffer[index] = double.NaN;
             UpBuffer_ma[index] = double.NaN;*/

       
            for(cnt = index - 1; cnt <= index; cnt++)
                 { 
                   su = 0;
                   for(i = length; i >= 1 ; i--)
                        {
                           lengthvar = (length + 1);
                           lengthvar /= 3;
                           tmp = 0;
                           tmp = ( i - lengthvar)*MarketSeries.Close[index-length+i];
                           su+=tmp;
                         }
                     wt[cnt] = su*6/(length*(length+1));
                }

     
         lsma_ma[index] =_EMA.Result[index];
                          
//========== COLOR CODING ===========================================                       
        
        
            
            if (wt[index]  < lsma_ma[index] && wt[index-1]  < lsma_ma[index-1])
            {
              DnBuffer[index] = wt[index]; 
              DnBuffer_ma[index] = lsma_ma[index]; 
               UpBuffer[index] = double.NaN;
               UpBuffer_ma[index] = double.NaN;
            }          
            
           if (wt[index]  > lsma_ma[index]&& wt[index-1]  > lsma_ma[index-1])
            {
                UpBuffer[index] = wt[index]; 
                UpBuffer_ma[index] = lsma_ma[index]; 
                DnBuffer[index] = double.NaN;
                DnBuffer_ma[index] = double.NaN;
               
            }  
                  
      }  
    } 
}

 


@Tebogo121
Replies

cAlgo_Development
30 Apr 2013, 16:53

Right now such painting is not supported in cAlgo. The only way you can color series like this is to use PlotType.Points or PlotType.Histogram. Try this in your example:

 

[Output("Dn", Color = Colors.Magenta, PlotType = PlotType.Points)]


You will get points colored correctly. You can also draw line and that draw points on top of it to indicate up or down trend.


@cAlgo_Development

Tebogo121
30 Apr 2013, 19:32

RE:
cAlgo_Development said:

Right now such painting is not supported in cAlgo. The only way you can color series like this is to use PlotType.Points or PlotType.Histogram. Try this in your example:

 

[Output("Dn", Color = Colors.Magenta, PlotType = PlotType.Points)]


You will get points colored correctly. You can also draw line and that draw points on top of it to indicate up or down trend.

Thanks a lot. It really helps to know some of this limitation when compiling a program.


@Tebogo121