Author: soft4traders.com
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
S4T_Alerts
ÿþ//+------------------------------------------------------------------+

//|                                                   S4T_Alerts.mq4 |

//|                                                 soft4traders.com |

//|                                             www.soft4traders.com |

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

#property copyright "soft4traders.com"

#property link      "www.soft4traders.com"

#property version   "1.00"

#property strict

#property indicator_chart_window



#property description "This indicator informs the user that the closing time of the current bar is approaching."

#property description " "

#property description "0==K9 8=48:0B>@ A>>1I05B ?>;L7>20B5;N > ?@81;865=88 2@5<5=8 70:@KB8O B5:CI53> 10@0."

// VARIABLES

input int AlertNSecondsBeforeNewBar=120; //Alert in N Seconds Before New Bar

input int NAlertsPerSignal=5; //N Alerts On Each Signal

input bool   DisplayComment=true; //Display Comment

int nTimesAlerted;



MqlDateTime sTimeCur,sTimeLocal;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   EventSetTimer(1);

//---

   return(INIT_SUCCEEDED);

  }

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

//|                                                                  |

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

void OnDeinit(const int reason)

  {

   if(DisplayComment)

     {

      Comment("");

     }

   EventKillTimer();  

  }

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

//| 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[])

  {

//---



//--- return value of prev_calculated for next call

   return(rates_total);

  }

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

//| Timer function                                                   |

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

void OnTimer()

  {

//---

   if(AlertNSecondsBeforeNewBar>0)

     {

      TimeCurrent(sTimeCur);

      TimeLocal(sTimeLocal);

      sTimeCur.min=sTimeLocal.min;

      sTimeCur.sec=sTimeLocal.sec;

      datetime curTime=StructToTime(sTimeCur);



      datetime curTimeStartAlert=Time[0]+PeriodSeconds()-AlertNSecondsBeforeNewBar;



      if(curTime>=curTimeStartAlert && 

         NAlertsPerSignal>nTimesAlerted)

        {

         Alert(_Symbol," Period: ",_Period," m. THE NEW BAR IS APPROACHING!!!");

         nTimesAlerted++;

        }

      if(curTime<curTimeStartAlert){nTimesAlerted=0;}



      if(DisplayComment)

        {

         Comment("Current Time ",curTime

                 ,"\nCurrent Time Start Alert: ",curTimeStartAlert);

        }

     }

  }

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

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