Error message (New to coding)

Created at 03 Nov 2021, 03:35
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!
NI

nicolelimx3

Joined 03.11.2021

Error message (New to coding)
03 Nov 2021, 03:35


Hey guys, this is the code. 

see if and else if please.

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NNFXBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        //Create indicator variables
        private AverageTrueRange atr;
        private MacdCrossOver macd;

        protected override void OnStart()
        {
            //load indicators on start up
            atr = Indicators.AverageTrueRange(14, MovingAverageType.Exponential);
            macd = Indicators.MacdCrossOver(26, 12, 9);

        }

        protected override void OnBar()
        {
            //Calculate Trade Amount Based on ATR        
            var PrevATR = Math.Round(atr.Result.Last(1) / Symbol.PipSize);
            var TradeAmount = (Account.Equity * 0.05) / (1.5 * PrevATR * Symbol.PipValue);
            TradeAmount = Symbol.NormalizeVolumeInUnits(TradeAmount, RoundingMode.Down);

            //Zero line Cross Example
            var Histogram = macd.Histogram.Last(1);
            var prevHistogram = macd.Histogram.Last(2);

            //Check for trade signal
            if (Histogram boo 0 % prevHistogram < 0)
            {
                ExecuteMarketOrder(TradeType.Buy, SymbolName, TradeAmount, "MACD", 1.5 * PrevATR, PrevATR);
            }
            else if (Histogram < 0 % prevHistogram > 0)
            {
                ExecuteMarketOrder(TradeType.Sell, SymbolName, TradeAmount, "MACD", 1.5 * PrevATR, PrevATR);
            }

        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

 

Error Code:

Error NNFX Bot.cs: Operator '<' cannot be applied of type 'bool' and 'int'

Error NNFX Bot.cs: Operator '>' cannot be applied of type 'bool' and 'int'

How would I be able to fix these errors? 

cheers.


@nicolelimx3
Replies

firemyst
17 Nov 2021, 13:15

You have error in the bolded code:

 

   if (Histogram boo 0 % prevHistogram < 0)
            {
                ExecuteMarketOrder(TradeType.Buy, SymbolName, TradeAmount, "MACD", 1.5 * PrevATR, PrevATR);
            }
            else if (Histogram < 0 % prevHistogram > 0)
            {
                ExecuteMarketOrder(TradeType.Sell, SymbolName, TradeAmount, "MACD", 1.5 * PrevATR, PrevATR);
            }
 

I *think* you want the following:

 

 

  if (Histogram > 0 && prevHistogram < 0)
            {
                ExecuteMarketOrder(TradeType.Buy, SymbolName, TradeAmount, "MACD", 1.5 * PrevATR, PrevATR);
            }
            else if (Histogram < 0 && prevHistogram > 0)
            {
                ExecuteMarketOrder(TradeType.Sell, SymbolName, TradeAmount, "MACD", 1.5 * PrevATR, PrevATR);
            }

 


@firemyst