Author: Copyright © Tony Black 2023
Price Data Components
Series array that contains open time of each bar
Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
ATR_Max
ÿþ//+------------------------------------------------------------------+

//|                                                      ATR Max.mq4 |

//|                                      Copyright © Tony Black 2023 |

//|                                       http://www.metaquotes.net/ |

//+------------------------------------------------------------------+

#property copyright "Copyright © Tony Black 2023"

#property link      "http://www.metaquotes.net/"



#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 clrRed

#property indicator_color2 clrLime

#property indicator_width1 2

#property indicator_width2 2

#property indicator_style1 STYLE_SOLID

#property indicator_style2 STYLE_SOLID

#property strict



//---- input parameters

input int InpPeriod=7; //Period (7)

input int NumDays=3; //NumDays (50)



//---- buffers

double ExtMaxBuffer[];

double ExtMainBuffer[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int init()

  {

   string short_name;

   SetIndexStyle(0,DRAW_LINE);

   SetIndexBuffer(0,ExtMaxBuffer);

   SetIndexStyle(1,DRAW_LINE);

   SetIndexBuffer(1,ExtMainBuffer);

   SetIndexLabel(1,"ATR Atual");

   short_name="ATR Max";

   IndicatorShortName(short_name);

   SetIndexLabel(0,short_name);



   return(0);

  }

//+------------------------------------------------------------------+

//| ATR Max                                                          |

//+------------------------------------------------------------------+

int start()

  {

   double PipFactor = 1/MathPow(10,Digits);

   double atr = 0;

   double auxHigh,auxLow;

   int tf = Period();

   int dayIn=0, dayOut=0;

   int shift=-1;

   int x=-1;

   int barDay=iBarShift(NULL,tf,iTime(NULL,PERIOD_D1,NumDays));

   

   static datetime PrevBar1;

   

   if(PrevBar1 < TimeLocal())

     {

      PrevBar1 = TimeLocal() + 60;



      for(int i=0; i<=NumDays; i++)

        {

         x=-1;

         for(int j=i; j<=barDay; j++)

           {

            if(TimeToStr(iTime(NULL,PERIOD_D1,i), TIME_DATE) == TimeToStr(Time[j], TIME_DATE))

              {

               x++;

               shift++;

              }

           }

         dayIn=shift;

         dayOut=shift-x;



         auxHigh=0;

         auxLow=999999999999;



         for(int k=dayIn; k>=dayOut; k--)

           {

            auxHigh=fmax(High[k],auxHigh);

            auxLow=fmin(Low[k],auxLow);

            ExtMainBuffer[k]=(auxHigh-auxLow)/_Point;

           }



         for(int k=dayIn; k>=dayOut; k--)

           {

            atr = (int)((iATR(NULL, PERIOD_D1, InpPeriod, i) / PipFactor)/1.5);

            ExtMaxBuffer[k]=atr; //Linha Vermelha

           }

        }



      /*int ATR_Trend = 0;

      GlobalVariableSet(Symbol()+ "_ATR", 0);



      //Print(ExtMaxBuffer[1]);

      //Print(ExtMainBuffer[1]);



      if(ExtMainBuffer[1] <= ExtMaxBuffer[1])

        {

         ATR_Trend = 1;

         GlobalVariableSet(Symbol()+ "_ATR", 1);

        }*/

     }

//----

   return(0);

  }

//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---