Call ATR in EA

 
Hello guys! I am trying to add a buy/sell condition to my EA. As if buy/Sell only if ATR(1)<ATR(14). So I have called atr indicator into my EA, add the condition but my EA will not care about this condition. What am I doing wrong?



input int InpAtrPer=14;
input int InpAtr=1;

/ 
/
/

double ATR1=iATR(_Symbol,0,InpAtrPer,0);
double ATR2=iATR(_Symbol,0,InpAtr,0);

//Open Buy

if (ATR2<ATR1 && // " other conditions")
 
Daniel Cioca: What am I doing wrong?

Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
          Code debugging - Developing programs - MetaEditor Help
          Error Handling and Logging in MQL5 - MQL5 Articles (2015)
          Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
          Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

 
William Roeder #:

Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
          Code debugging - Developing programs - MetaEditor Help
          Error Handling and Logging in MQL5 - MQL5 Articles (2015)
          Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
          Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

William...mate....who is "us" that you are referring too.

Everybody else is giving an answer...or not...you are the only one very nasty and frustrated...don't know why...you don't want to help...please move on... We can live without you telling "us" useless tips... if you don't know what to answer...you don't have to say anything

A I was saying...EA is working fine with the other buy/sell conditions...but I have added the above condition, and EA is opening trades without taking into account the above condition. I have printed above ATR1 and ATR2 and is showing the values of this parameters, but still something is wrong
 
  1. The "us" is the thousand people that read your post.
  2. No one else has answered you.
  3. Post all relevant code. Your non-input lines are without context; no idea whether those lines are inside a function or not.
  4. "Something is wrong" is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
         How To Ask Questions The Smart Way. (2004)
              When asking about code
              Be precise and informative about your problem

 
William Roeder #:
  1. The "us" is the thousand people that read your post.
  2. No one else has answered you.
  3. Post all relevant code. Your non-input lines are without context; no idea whether those lines are inside a function or not.
  4. "Something is wrong" is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
         How To Ask Questions The Smart Way. (2004)
              When asking about code
              Be precise and informative about your problem

1. You should live that thousand to answer...or not...there is no need for you to speak in their name

2. Yet...maybe someone will...

3. There is no need for the hole code...whatever you need is there...I called ATR twice...ATR1 and ATR2...with different periods...I have print this values and even if ATR1=0.0018 and ATR2=0.0025, and condition is <<Open trade if ATR1<ATR2>>, trade it is getting open also if ATR1>ATR2....and I don't understand why. Because I did the same thing with MA and it is working. I called MA twice with different periods, and buy trade will open only if MA(5)>MA(20)...for example...but with ATR it doesn't work


"

 How To Ask Questions The Smart Way. (2004)"


 


 I am Not that smart like you... I am asking questions the way I can. As long as I am not offending anyone this should be fine.

If the question is too stupid for you...as I said...move on to the next ... simple as that

 
Daniel Cioca #:
     and condition is <<Open trade if ATR1<ATR2>>, trade it is getting open also if ATR1>ATR2....and I don't understand why. Because I did the same thing with MA and it is working. I called MA twice with different periods, and buy trade will open only if MA(5)>MA(20)...for example...but with ATR it doesn't work

nobody can know what you tried with MA & nobody see your entire code with ATR... BTW, if you do not hesitate not only to demand for the answer on your very uncertain question but first to explore your problem yourself - you'll find many examples already discussed ... ? why don't you want to check ==INVALID_HANDLE & to work with GetLastError()); ...

p.s.

BTW, MA is a chart_indicator (all vars are measured in the same coordinates), ATR is a separate_window indicator  (did you compare values of your ATRs yourself ? ) - N.B. you should compare values of indicators, not their handles, but getArrays... (learn examples at the link I've left)

Spent time to look through enormous number of examples TO TEST them & to provide more concrete question of your misunderstanding (with nonworking but Minimal Compilable code that reflects the problem)

Daniel Cioca #:

  I am Not that smart like you...

- and you will be...

How to start with MQL5
How to start with MQL5
  • 2020.09.17
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
 
right for you appeared the indicator ATR MAOnATR - perhaps you meant something like this... in 1 system of co-ordinates they can be compared, I think... just look through the code to get some tips for yourself
Индикаторы: ATR MAOnATR
Индикаторы: ATR MAOnATR
  • 2021.09.29
  • www.mql5.com
ATR MAOnATR : Автор: Vladimir Karputov...
Reason: