Help with Function IsRising and IsFallling Incorrect Result

Created at 29 Jan 2016, 11:09
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

mikepecson72

Joined 15.01.2016

Help with Function IsRising and IsFallling Incorrect Result
29 Jan 2016, 11:09


Dear Spotware,

 

Im not sure where did I go wrong but I dont think I am getting the correct result for the IsRising and IsFalling method.

If you notice on the chart, the ADX is falling from previous value of 19 down to 18 so the IsFalling report is correct.

But the IsRising method should report "false" if the IsFalling result is "true".

I am testing this and both functions report "true" even though one of them is false.

please find the code for your perusal.

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class test : Indicator
    {
        [Parameter("ADX Period", DefaultValue = 14)]
        public int Period { get; set; }

        private DirectionalMovementSystem dms;
        protected override void Initialize()
        {
            dms = Indicators.DirectionalMovementSystem(Period);
        }

        public override void Calculate(int index)
        {
            ChartObjects.DrawText("ADX1", xySpace(0, 1) + "ADX previous: " + Math.Round(dms.ADX.Last(1)), StaticPosition.TopLeft, Colors.Black);
            ChartObjects.DrawText("ADX2", xySpace(0, 2) + "ADX last value: " + Math.Round(dms.ADX.LastValue), StaticPosition.TopLeft, Colors.Black);
            ChartObjects.DrawText("+Di", xySpace(0, 3) + "+DI: " + Math.Round(dms.DIPlus.LastValue), StaticPosition.TopLeft, Colors.Black);
            ChartObjects.DrawText("-Di", xySpace(0, 4) + "-DI: " + Math.Round(dms.DIMinus.LastValue), StaticPosition.TopLeft, Colors.Black);

            if (dms.ADX.IsRising())
            {
                ChartObjects.DrawText("IsRising", xySpace(0, 5) + "Is the ADX Rising? " + dms.ADX.IsRising(), StaticPosition.TopLeft, Colors.Black);

            }

            if (dms.ADX.IsFalling())
            {
                ChartObjects.DrawText("IsFalling", xySpace(0, 6) + "Is the ADX Falling? " + dms.ADX.IsFalling(), StaticPosition.TopLeft, Colors.Black);

            }
        }

        private string xySpace(int x, int y)
        {
            if (x < 0 || y < 0)
                return ("");
            string str = "";
            for (int i = 0; i < y; i++)
                str += "\n";
            for (int i = 0; i < x; i++)
                str += "\t";
            return (str);
        }
    }
}

so where do you think the problem lies? 

thanks and waiting for your reply the soonest.


@mikepecson72
Replies

cyfer
30 Jan 2016, 02:16

if (dms.ADX.IsRising())
            {
                ChartObjects.DrawText("IsRising", xySpace(0, 5) + "Is the ADX Rising? " + dms.ADX.IsRising(), StaticPosition.TopLeft, Colors.Black);
                Print("it is Rising !");
            }
            else
            {
                ChartObjects.RemoveObject("IsRising");
            }

            if (dms.ADX.IsFalling())
            {
                ChartObjects.DrawText("IsFalling", xySpace(0, 6) + "Is the ADX Falling? " + dms.ADX.IsFalling(), StaticPosition.TopLeft, Colors.Black);
                Print("it is Falling !");
            }
            else
            {
                ChartObjects.RemoveObject("IsFalling");
            }

I can't look into this in depth because the market is closed , but i did have problems before from this "Drawn text " multiple times with the same name 

or not removing the drawn object  on the chart 

if this is not the solution , I suggest you keep the Print() command .. it's actually proving IsFalling & IsRising are working 

 


@cyfer