Discussion of article "Learn how to design a trading system by ADX" - page 2

 
Hi. i just started learning about adx and dmi for couple months. and i wish there is an ea for this. since this is lagging indicator. maybe timeframe M15 is better suited. can you make one? where can i contact you for term and conditon? thank you
 

Hello Mohamed,

Instead of: 

   double ADXArray0[];
   double ADXArray1[];
...
   double ADXValue=NormalizeDouble(ADXArray0[0],2);
   double ADXValueLast=NormalizeDouble(ADXArray1[1],2);

Wouldn't it be enough ?:

      double ADXArray[];
...
      double ADXValue=NormalizeDouble(ADXArray[0],2);
      double ADXValueLast=NormalizeDouble(ADXArray[1],2);

Regards,

Juan Luis

Learn how to design a trading system by ADX
Learn how to design a trading system by ADX
  • www.mql5.com
In this article, we will continue our series about designing a trading system using the most popular indicators and we will talk about the average directional index (ADX) indicator. We will learn this indicator in detail to understand it well and we will learn how we to use it through a simple strategy. By learning something deeply we can get more insights and we can use it better.
 
Juan Luis De Frutos Blanco #:

Hello Mohamed,

Instead of: 

Wouldn't it be enough ?:

Regards,

Juan Luis

Hello Juan,

You are correct, it can be like what you mentioned also.


Regards,

 
Good article: one of the legs of the EA I am building at the moment.
Thanks Mohamed. 🏅🏅🏅

 
You have great article.I love to use ADX for my scalping.I have idea that when ADX line above 25 and dmi plus crossing up dmi minus,the colour of the candle became green colour indicate that trend is bullish and vice versa.I'm trying to code but not lucky so far.
 
1
 

Excellent article!  However I did spot an error in one of the, and I also spotted an opportunity for a tip.  The error is with the CopyBuffers,and using the same buffer index for the same handle.   An indicator handle in MQL5 can only access a specific buffer using its corresponding unique buffer index in a call to the  CopyBuffer()  function. 


So when you put:

CopyBuffer(ADXDef,0,0,3,ADXArray0);
CopyBuffer(ADXDef,0,0,2,ADXArray1);
CopyBuffer(ADXDef,1,0,3,PDIArray);
CopyBuffer(ADXDef,2,0,3,NDIArray);


It should be:

CopyBuffer(ADXDef,0,0,3,ADXArray0);
CopyBuffer(ADXDef,1,0,2,ADXArray1);
CopyBuffer(ADXDef,2,0,3,PDIArray);
CopyBuffer(ADXDef,3,0,3,NDIArray);


The key points regarding indicator handles and buffers are:
  • Unique Indexing: Each indicator handle manages a set of internal buffers, each identified by a unique index (starting from 0).
  • One Handle, One Index: When you use  CopyBuffer(handle, buffer_index, ...)  you are specifying which single buffer associated with that  handle  you want to copy data from.
  • Multiple Calls: If an indicator has multiple data buffers (e.g., a high and low band of a channel), you must call  CopyBuffer()  multiple times, using the same handle but with different buffer indexes (e.g., index 0 for the upper band, index 1 for the lower band). 
You cannot have two separate  CopyBuffer  calls for the same buffer index within the same handle that somehow point to different data, as the index is the unique identifier for the data series within that handle


I guessing this was a typo but thought I should point it out just in case anyone else gets confused.  It was correct in the full code, just not in the example.


Now for the litte tip...

Not a big deal but would definitely save you some unnecessary key strokes, when you wrote:


 Comment("Simple ADX System - Signal is ",signal,"\n""ADX Value is ", ADXValue,
   "\n""ADX Value Last is ", ADXValueLast, "\n""+DI Value is ", PDIValue,
   "\n""-DI Value is ", NDIValue);


There's some extra quotation marks you don't need.  To simplify, you could do this:


 Comment("Simple ADX System - Signal is ",signal,"\nADX Value is ", ADXValue,
   "\nADX Value Last is ", ADXValueLast, "\n+DI Value is ", PDIValue,
   "\n-DI Value is ", NDIValue);


Other than that, I found the article very informative and detailed. 


 

The only other thing I would add here is error handling in OnInit() and DeOnit(), and change the variable name from ADXDef to h_ADXDef (or handle_ADXDef), so it's more clear when reading the code and just makes it a better identifier which shows its specific purpose.

In OnInit():


  if(h_ADXDef == INVALID_HANDLE)
   {
      Print("Error creating indicator handles: ", GetLastError());
      return(INIT_FAILED);
   }


And, in DeOninit():


if(h_ADXDef != INVALID_HANDLE) IndicatorRelease(h_ADXDef);