Sum iADX of 2 days mql 4

 
Good evening,

I'm coding an EA on mql4. I need to sum 2 iADX. Could you tell me if is this code correct?

(iADX(NULL,PERIOD_D1,14,PRICE_CLOSE,MODE_MAIN,1)+
iADX(NULL,PERIOD_D1,14,PRICE_CLOSE,MODE_MAIN,2))
Thanks a lot
 
  1. Claudio Lasso: I'm coding an EA on mql4.
    Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. iADX(NULL,PERIOD_D1
    On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4

  3. Don't use NULL.
    • You can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not. OrderSend does not.
    • Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
    • Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
    • MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
 
William Roeder:
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4

hI William sorry I don't pay attention how I posted...sorry to much

You say don't use NULL....but if I go in the webpage of iADX ( https://docs.mql4.com/indicators/iadx)..they use it

iADX - Technical Indicators - MQL4 Reference
iADX - Technical Indicators - MQL4 Reference
  • docs.mql4.com
iADX - Technical Indicators - MQL4 Reference
 
Claudio Lasso:
I'm coding an EA on mql4. I need to sum 2 iADX...
what are you trying to do?
 

Hi @lippmaje,

I'd like to define an iADX value as a medium value of the ADX value of the past 2 days.

I use this EA on a graph of a 1M TF..My strategy is based on movement on 1M TF. It opens trade only if there are some condition on D1 TF.

Now  William Roeder tells that I must download the history of that TF but i really don't know how to do..any help will be appreciate. Thanks a lot

 

The medium of two values is formed by (val1+val2)/2 this holds also for ADX.

Your EA will run on M1 timeframe, that means D1 timeframe data may yet not be available when the EA runs.

MQL is event oriented that means when you request history data such as D1 - which is seen as 'foreign' by your M1 EA - it may not be served instantly, but the data request will cause all sort of spooky things going on in the background so that a few milliseconds later it may be ready to be retrieved.

Write a new bar function so that on every new minute you're going to retrieve that D1 data, and use it in OnTick, not OnInit. This assures you'll eventually succeed in retrieving that data. Combine it with an initialization flag to prevent redundant calls.

https://www.mql5.com/en/forum/5762
Documentation on MQL5: Timeseries and Indicators Access / Bars
Documentation on MQL5: Timeseries and Indicators Access / Bars
  • www.mql5.com
If the start_time and stop_time parameters are defined, the function returns the number of bars in the specified time interval, otherwise it returns the total number of bars. If data for the timeseries with specified parameters are not formed in the terminal by the time of the Bars() function call, or data of the timeseries are not synchronized...
 
Claudio Lasso: Now  William Roeder tells that I must download the history of that TF but i really don't know how to do.

Do you see words with underlines? Those are links. They take you to more information. You would know how, had you bothered to click on the provided link.

Reason: