Macd Histogram LastValue

Created at 26 Dec 2016, 23:51
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!
irmscher9's avatar

irmscher9

Joined 22.12.2016

Macd Histogram LastValue
26 Dec 2016, 23:51


Hello traders

I'm creating cbot based on Macd indicators. I have a question.

 

I'm executing market order:

 

 if (_macd.Histogram.LastValue > 0.0 && _macd.Histogram.LastValue < 1.0)
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "order 1", 8, 8);
                Print("Hello, ", _macd.Histogram.LastValue);
            }

 

I want to execute this order only if macd.Histogram.LastValue is higher than 0 but also lower than 1. However my LOG shows that this command executes any order where macd.Histogram.LastValue is higher than 0, even if it's 9, etc. Am I doing something wrong?

Also, I have noticed that some values have weird signs in the end, like this: 6.52828430662833E-05 ... E-05 is what I'm concerned about, can it be the reason? If yes, how can I get rid of E-05 in the end? I have tried both input.Replace("E-05", "");​ and  input.Remove(input.Length - 3);​ but it doesn't work. I also have tried to round it up but it doesn't work either since it probably ain't even considered to be a number.

 

The error log says: Error CS1061: 'double' does not contain a definition for 'Remove' and no extension method 'Remove' accepting a first argument of type 'double' could be found (are you missing a using directive or an assembly reference?)

 

The whole code is below:

 

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Macdbot : Robot
    {
        private MacdHistogram _macd;
        private Position _position;

        [Parameter(DefaultValue = 10000, MinValue = 0)]
        public int Volume { get; set; }

        [Parameter("Period", DefaultValue = 9)]
        public int Period { get; set; }

        [Parameter("Long Cycle", DefaultValue = 26)]
        public int LongCycle { get; set; }

        [Parameter("Short Cycle", DefaultValue = 12)]
        public int ShortCycle { get; set; }

        protected override void OnStart()
        {
            _macd = Indicators.MacdHistogram(LongCycle, ShortCycle, Period);

        }
        protected override void OnTick()
        {
            

            var macd_last_value = _macd.Histogram.LastValue;

            macd_last_value = macd_last_value.Remove(macd_last_value.Length - 1);

            if (macd_last_value > 0.0 && macd_last_value < 1.0)
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "order 1", 8, 8);
                Print("Hello, ", macd_last_value);
            }
        }

    }
}



Thanks a lot in advance!


@irmscher9