-
Play videoPlease edit your post.
For large amounts of code, attach it - Your arrow points to where ADX went below 25. No orders were opened there. The values are correct.
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!
-
Please edit your post.
For large amounts of code, attach it - 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.
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.
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; |
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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!