Cant get ADX indicator to return values matching the CTrader charts

Created at 19 Nov 2024, 11:21
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!
MO

Mohammadq

Joined 05.10.2024

Cant get ADX indicator to return values matching the CTrader charts
19 Nov 2024, 11:21


Dear Experts 

 

I'm writing a cbot where i want to use ADX to read trend direction and strength. The issue is that the values ADX is returning are not matching those on the chart. 

I read in the indicators library that ADX and chart are both using Welles Wilder method. But they dont seem to match.

I use the 15 minutes timeframe. 

 

Any advices please

 

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

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None, AddIndicators = true)]
    public class TextADX : Robot
    {
       public string Message { get; set; }
        private DirectionalMovementSystem _directionalMovementSystem;
        
        // ADX period
        private const int AdxPeriod = 14;

        protected override void OnStart()
        {
            
            // Initialize Directional Movement System
            _directionalMovementSystem = Indicators.DirectionalMovementSystem(AdxPeriod);
   
            Print($"ADX Period: {AdxPeriod}");
            Print($"Timeframe: {TimeFrame}");
        }
          protected override void OnBar()
    {
        // Ensure we have enough bars to calculate ADX values
        if (Bars.Count < AdxPeriod + 1)
        {
            Print("Not enough bars to calculate ADX values.");
            return;
        }

        // Calculate values for the last completed bar
        double adx = _directionalMovementSystem.ADX.Last(1);
        double positiveDI = _directionalMovementSystem.DIPlus.Last(1);
        double negativeDI = _directionalMovementSystem.DIMinus.Last(1);

        Print("=====================================================");
        Print($"Bar Time: {Bars.OpenTimes.Last(1):yyyy-MM-dd HH:mm:ss}");
        Print($"Directional Movement System Values:");
        Print($"  ADX: {adx:F2}");
        Print($"  +DI: {positiveDI:F2}");
        Print($"  -DI: {negativeDI:F2}");
       // Print($"Average Directional Movement Index Rating (ADXR):");
        //Print($"  ADXR: {adxr:F2}");
        Print("=====================================================");
    }
        

        protected override void OnTick()
        {
            // Handle price updates here
        }

        protected override void OnStop()
        {
            // Handle cBot stop here
        }
    }
}


@Mohammadq
Replies

PanagiotisCharalampous
19 Nov 2024, 11:28

Hi there,

Can you share screenshots showing what you are comparing?

Best regards,

Panagiotis


@PanagiotisCharalampous

Mohammadq
19 Nov 2024, 12:43 ( Updated at: 20 Nov 2024, 08:39 )

RE: Cant get ADX indicator to retuen values matching the CTrader charts

PanagiotisCharalampous said: 

Hi there,

Can you share screenshots showing what you are comparing?

Best regards,

Panagiotis

Hello PanagiotisCharalampous , 

Sure, 

 

 


@Mohammadq

Mohammadq
19 Nov 2024, 15:10 ( Updated at: 20 Nov 2024, 06:50 )

RE: Cant get ADX indicator to retuen values matching the CTrader charts

PanagiotisCharalampous said: 

Hi there,

Can you share screenshots showing what you are comparing?

Best regards,

Panagiotis

Here you go..

 


@Mohammadq

PanagiotisCharalampous
20 Nov 2024, 07:05

RE: RE: Cant get ADX indicator to retuen values matching the CTrader charts

Mohammadq said: 

PanagiotisCharalampous said: 

Hi there,

Can you share screenshots showing what you are comparing?

Best regards,

Panagiotis

Here you go..

 

Hi there,

Your chart is set to UTC+3 while your cBot prints in UTC+0.

Best regards,

Panagiotis


@PanagiotisCharalampous

Mohammadq
20 Nov 2024, 08:41

RE: RE: RE: Cant get ADX indicator to retuen values matching the CTrader charts

PanagiotisCharalampous said: 

Mohammadq said: 

PanagiotisCharalampous said: 

Hi there,

Can you share screenshots showing what you are comparing?

Best regards,

Panagiotis

Here you go..

 

Hi there,

Your chart is set to UTC+3 while your cBot prints in UTC+0.

Best regards,

Panagiotis

Many thanks for the catch, you're absolutely right.

I changed that and i get much closer results. is it ok to still have minor differences or it must be exact match?

 

Thanks

Mohammad


@Mohammadq

PanagiotisCharalampous
20 Nov 2024, 09:37

RE: RE: RE: RE: Cant get ADX indicator to retuen values matching the CTrader charts

Mohammadq said: 

PanagiotisCharalampous said: 

Mohammadq said: 

PanagiotisCharalampous said: 

Hi there,

Can you share screenshots showing what you are comparing?

Best regards,

Panagiotis

Here you go..

 

Hi there,

Your chart is set to UTC+3 while your cBot prints in UTC+0.

Best regards,

Panagiotis

Many thanks for the catch, you're absolutely right.

I changed that and i get much closer results. is it ok to still have minor differences or it must be exact match?

 

Thanks

Mohammad

Hi Mohammad,

The values displayed on the chart are rounded. So you should expect minor differences.

Best regards,

Panagiotis


@PanagiotisCharalampous