Author: Safe-Forex.ru
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
ADX_Alert
ÿþ//+-------------------------------------------------------------------------------------------------------------------------------------------------+

//|  07@01>BG8:: 8=052 =4@59                                                                                                                      |

//| =48:0B>@:   ADX_Alert.mq4                                                                                                                      |

//| !09B:        safe-forex.ru                                                                                                                      |

//| >GB0:       minaev.work@mail.ru                                                                                                                |

//| !:09?:       live:minaev.work                                                                                                                   |

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

#property copyright "Safe-Forex.ru"

#property link      "https://safe-forex.ru"

#property strict

#property indicator_chart_window



#include <Classes\Indicators.mqh>

#include <Classes\Convert.mqh>



input int                inpPeriod    = 14;             // 5@8>4

input ENUM_APPLIED_PRICE inpPrice     = PRICE_CLOSE;    // "8? F5=K

input ENUM_TIMEFRAMES    inpTimeFrame = PERIOD_CURRENT; // "09<D@59<



ADX adx;

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

//| $C=:F8O 8=8F80;870F88 8=48:0B>@0                                                                                                                |

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

int OnInit(void)

{

   adx.Create(_Symbol,inpPeriod,inpPrice,inpTimeFrame);

   return INIT_SUCCEEDED;

}

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

//| $C=:F8O 2K7K205BAO :064K9 B8:                                                                                                                   |

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

int OnCalculate(const int      ratesTotal,

                const int      prevCalculated,

                const datetime &time[],

                const double   &open[],

                const double   &high[],

                const double   &low[],

                const double   &close[],

                const long     &tickVolume[],

                const long     &volume[],

                const int      &spread[])

{

   if(IsNewCandle()) CheckIndicator();

   

   return ratesTotal;

}

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

//| $C=:F8O ?@>25@O5B 7=0G5=8O 8=48:0B>@0                                                                                                           |

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

void CheckIndicator(void)

{

   double posDI_1 = adx.GetPosDI(1),

          posDI_2 = adx.GetPosDI(2),

          negDI_1 = adx.GetNegDI(1),

          negDI_2 = adx.GetNegDI(2);

   

   Convert ps;

   

   string period = ps.GetPeriodString(adx.GetTimeFrame()),

          alert  = adx.GetSymbol()+", "+period+":";

          

   if(posDI_1>negDI_1 && posDI_2<negDI_2)

   {

      alert+=" 5@5A5:;8AL ;8=88 8=48:0B>@0 "+adx.GetName()+" (+DI: "+DoubleToString(posDI_1,_Digits)+" > -DI: "+DoubleToString(negDI_1,_Digits)+")";

      Alert(alert);

   }

   if(posDI_1<negDI_1 && posDI_2>negDI_2)

   {

      alert+=" 5@5A5:;8AL ;8=88 8=48:0B>@0 "+adx.GetName()+" (+DI: "+DoubleToString(posDI_1,_Digits)+" < -DI: "+DoubleToString(negDI_1,_Digits)+")";

      Alert(alert);

   }

}

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

//| $C=:F8O 2>72@0I05B true, 5A;8 ?>O28;0AL =>20O A25G0, 8=0G5 false                                                                                |

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

bool IsNewCandle(void)

{

   static datetime prevTime;                               // 2@5<O >B:@KB8O ?@54K4CI59 A25G8

          datetime currTime=iTime(_Symbol,inpTimeFrame,0); // 2@5<O >B:@KB8O B5:CI59 A25G8

   //--- 5A;8 7=0G5=8O =5 @02=K, 7=0G8B ?>O28;0AL =>20O A25G0

   if(prevTime!=currTime)

   {

      prevTime=currTime;

      return true;

   }

   return false;

}

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

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 ---