and
ATR1=iATR(NULL, 14, PERIOD_CURRENT, 1);
ATR2=iATR(NULL, 14, PERIOD_CURRENT, 1);
are not correct.
should be:
ATR1=iATR(NULL, PERIOD_CURRENT, 14, 1);
ATR2=iATR(NULL, PERIOD_CURRENT, 14, 1);
//+------------------------------------------------------------------+ //| ATR.mq4 | //| Copyright 2014,J| //| | //+------------------------------------------------------------------+ #property copyright "Copyright 2014,J" #property link "" #property version "1.00" #property strict #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 White extern int Period_ATR1 = 9; extern int Period_ATR2 = 14; //--- buffers double Buffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer (0, Buffer); SetIndexStyle (0, DRAW_LINE, STYLE_SOLID, 2, White); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { double ATR1, ATR2; //--- int i, Counted_bars; Counted_bars = IndicatorCounted(); i= Bars - Counted_bars - 1; while (i>0) { ATR1=iATR(NULL, PERIOD_CURRENT, Period_ATR1, i); ATR2=iATR(NULL, PERIOD_CURRENT, Period_ATR2, i); Buffer[i]=ATR1-ATR2; i--; } //--- return value of prev_calculated for next call return(rates_total); }
![]() Play video | Please edit your post. For large amounts of code, attach it. |
All true. Because ATR1-ATR2=0.
and
ATR1=iATR(NULL, 14, PERIOD_CURRENT, 1);
ATR2=iATR(NULL, 14, PERIOD_CURRENT, 1);
are not correct.
should be:
ATR1=iATR(NULL, PERIOD_CURRENT, 14, 1);
ATR2=iATR(NULL, PERIOD_CURRENT, 14, 1);
Ready. Thank you!
Why this part?:
and what it means?
extern int Period_ATR1 = 9;
extern int Period_ATR2 = 14;
rephrase my question:
rephrase my question:
Because Period_ATR1 and Period_ATR2 are the input parameters of the indicator ATR. So it is accepted. But if you do not want to change these settings, you can do so:
//+------------------------------------------------------------------+ //| ATR.mq4 | //| Copyright 2014,J| //| | //+------------------------------------------------------------------+ #property copyright "Copyright 2014,J" #property link "" #property version "1.00" #property strict #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 White //--- buffers double Buffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer (0, Buffer); SetIndexStyle (0, DRAW_LINE, STYLE_SOLID, 2, White); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { double ATR1, ATR2; //--- int i, Counted_bars; Counted_bars = IndicatorCounted(); i= Bars - Counted_bars - 1; while (i>0) { ATR1=iATR(NULL, PERIOD_CURRENT, 14, i); ATR2=iATR(NULL, PERIOD_CURRENT, 14, i); Buffer[i]=ATR1-ATR2; i--; } //--- return value of prev_calculated for next call return(rates_total); }
Thank for everything Boeing747. You has definitely helped me with all this. I'm already doing EAs again.
When I used the first way (period declared in the header), it worked. When I used the second, is not the line of the indicator. Even, I copy and pasted the 2 codes you placed, and the same thing happened.
?
trader201: When I used the first way (period declared in the header), it worked. When I used the second, is not the line of the indicator. Even, I copy and pasted the 2 codes you placed, and the same thing happened.
| Because you are now back to Boeing747: All true. Because ATR1-ATR2=0
ATR1=iATR(NULL, PERIOD_CURRENT, 14, i); ATR2=iATR(NULL, PERIOD_CURRENT, 14, i); Buffer[i]=ATR1-ATR2; < ZERO |
![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
Does anyone knows why is happening that?
This is the code:
//+------------------------------------------------------------------+
//| ATR.mq4 |
//| Copyright 2014,J|
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014,J"
#property link ""
#property version "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 White
//--- buffers
double Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer (0, Buffer);
SetIndexStyle (0, DRAW_LINE, STYLE_SOLID, 2, White);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
double ATR1, ATR2;
ATR1=iATR(NULL, 14, PERIOD_CURRENT, 1);
ATR2=iATR(NULL, 14, PERIOD_CURRENT, 1);
//---
int i,
Counted_bars;
Counted_bars = IndicatorCounted();
i= Bars - Counted_bars - 1;
while (i>0)
{
Buffer[i]=ATR1-ATR2;
i--;
}
//--- return value of prev_calculated for next call
return(rates_total);
}