The MQL4 based ADX is buggy and trades incorrectly in the tester

 

Hi 

I have written a very simple logic based on ADX that is shipped with MT4.

Code:


double adx_previous = iADX(NULL,PERIOD_M15,6,PRICE_CLOSE,MODE_MAIN,1); //Previous Candle ADX Double Value

double adx_current = iADX(NULL,PERIOD_M15,6,PRICE_CLOSE,MODE_MAIN,0); //Current Candle ADX Double Value 

   if(adx_current > 25 && adx_previous < 25 

      && iADX(NULL,PERIOD_M15,6,PRICE_CLOSE,MODE_PLUSDI,0)> iADX(NULL,PERIOD_M15,6,PRICE_CLOSE,MODE_MINUSDI,0)

      )

      {

         adxupflag = true;

         adxdownflag = false;

         return 5;

This code expect mt4 to take a buy position only in case if current candle has ADX more than 25 and previous candle less than 25 or more simply trade only when adx crossed 25 level however, in strategy tester you see trades with incorrect ADX values. A snapshot is being attached. Why it is so? A bug in ADX indicator?? Any enlightening thoughts are more than welcomed!

Files:
ADX_Error.png  35 kb
 
poorasianguy: in strategy tester you see trades with incorrect ADX values. A snapshot is being attached. Why it is so? A bug in ADX indicator?? Any enlightening thoughts are more than welcomed!
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it

  2. Your arrow points to where ADX went below 25. No orders were opened there. The values are correct.
 
poorasianguy:

Hi 

I have written a very simple logic based on ADX that is shipped with MT4.

Code:


double adx_previous = iADX(NULL,PERIOD_M15,6,PRICE_CLOSE,MODE_MAIN,1); //Previous Candle ADX Double Value

double adx_current = iADX(NULL,PERIOD_M15,6,PRICE_CLOSE,MODE_MAIN,0); //Current Candle ADX Double Value 

   if(adx_current > 25 && adx_previous < 25 

      && iADX(NULL,PERIOD_M15,6,PRICE_CLOSE,MODE_PLUSDI,0)> iADX(NULL,PERIOD_M15,6,PRICE_CLOSE,MODE_MINUSDI,0)

      )

      {

         adxupflag = true;

         adxdownflag = false;

         return 5;

This code expect mt4 to take a buy position only in case if current candle has ADX more than 25 and previous candle less than 25 or more simply trade only when adx crossed 25 level however, in strategy tester you see trades with incorrect ADX values. A snapshot is being attached. Why it is so? A bug in ADX indicator?? Any enlightening thoughts are more than welcomed!

Did you forget   && iADX(NULL,PERIOD_M15,6,PRICE_CLOSE,MODE_PLUSDI,0)> iADX(NULL,PERIOD_M15,6,PRICE_CLOSE,MODE_MINUSDI,0) ?
 
Irwan Adnan:
Did you forget   && iADX(NULL,PERIOD_M15,6,PRICE_CLOSE,MODE_PLUSDI,0)> iADX(NULL,PERIOD_M15,6,PRICE_CLOSE,MODE_MINUSDI,0) ?

Thanks for the reply. I did not think this was important, however, now I have checked the code you suggested - still the same issue.
 
whroeder1:
  1. Please edit your post.
    For large amounts of code, attach it

  2. Your arrow points to where ADX went below 25. No orders were opened there. The values are correct.

Sorry to confuse you with graphics. I meant to show that 2 candles right to arrow you see a breach  of level 25(upwards). The condition of ADX value less than 25 and more than 25 in subsequent candles holds true. Still no trade. Also look at the white vertical line - the MT4 crossbar cursor- . Data window show the ADX value > 50 but there is a trade and it should not have taken place. I am not adding any additional logic still this happens.This suggests that ADX implementation in MT4 is behaving incorrectly. Let me know what you think.
 
poorasianguy:

I meant to show that 2 candles right to arrow you see a breach  of level 25(upwards). The condition of ADX value less than 25 and more than 25 in subsequent candles holds true. Still no trade. 


Yes, it did breach level 25 upwards

But at the time of the breach, the red dashed line (-DI) was above the yellow dashed line (+DI) so this prevented any trade: 

 && iADX(NULL,PERIOD_M15,6,PRICE_CLOSE,MODE_PLUSDI,0)> iADX(NULL,PERIOD_M15,6,PRICE_CLOSE,MODE_MINUSDI,0)
I see you are using flags. Some of your problems could be how the flag gets reset.
 
honest_knave: I see you are using flags. Some of your problems could be how the flag gets reset.
I agree, that is likely the problem, not ADX.
bool isUp    = iADX(NULL,PERIOD_M15,6,PRICE_CLOSE,MODE_PLUSDI,0) > iADX(NULL,PERIOD_M15,6,PRICE_CLOSE,MODE_MINUSDI,0);
bool isValid = adx_current > 25 && adx_previous < 25;
adxupflag   = isValid && isUp;
adxdownflag = isValid && !isUp;