Period Switch

Author: Yuriy Tokman (YTG)
Miscellaneous
It plays sound alerts
0 Views
0 Downloads
0 Favorites
Period Switch
ÿþ//+------------------------------------------------------------------+

//|                                                           TF.mq4 |

//|                                               Yuriy Tokman (YTG) |

//|                                               https://ytg.com.ua |

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

#property copyright "Yuriy Tokman (YTG)"

#property link      "https://ytg.com.ua"

#property version   "1.00"

#property strict

#property indicator_chart_window



input ENUM_TIMEFRAMES TimeFrame_1 = 60;

input ENUM_TIMEFRAMES TimeFrame_2 = 240;

input double _TimeMinute = 0.05;



datetime _time;

int _tf1, _tf2;



#include <WinUser32.mqh>

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping 

 if(TimeFrame_1==1)_tf1=33137;

 if(TimeFrame_1==5)_tf1=33138;

 if(TimeFrame_1==15)_tf1=33139; 

 if(TimeFrame_1==30)_tf1=33140; 

 if(TimeFrame_1==60)_tf1=35400; 

 if(TimeFrame_1==240)_tf1=33136;

 if(TimeFrame_1==1440)_tf1=33134; 

 if(TimeFrame_1==10080)_tf1=33141;

 if(TimeFrame_1==43200)_tf1=33334;

 

 if(TimeFrame_2==1)_tf2=33137;

 if(TimeFrame_2==5)_tf2=33138;

 if(TimeFrame_2==15)_tf2=33139; 

 if(TimeFrame_2==30)_tf2=33140; 

 if(TimeFrame_2==60)_tf2=35400; 

 if(TimeFrame_2==240)_tf2=33136;

 if(TimeFrame_2==1440)_tf2=33134; 

 if(TimeFrame_2==10080)_tf2=33141;

 if(TimeFrame_2==43200)_tf2=33334;      

//---

 EventSetTimer(1);

//---

   return(INIT_SUCCEEDED);

  }

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

int deinit()

  {

//----

   Comment("");

//----

   return(0);

  }

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

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

 Comment(

     "TimeFrame_1 - "+GetNameTF(TimeFrame_1) 

  +"\nTimeFrame_2 - "+GetNameTF(TimeFrame_2) 

  +"\nPause - "+DoubleToStr(_TimeMinute,2)+" minutes"  

 );



   return(rates_total);

  }

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

//| Timer function                                                   |

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

void OnTimer()

  {

//---

//---

   if(_time==0)_time=TimeCurrent();

   int hwnd;

//---?5@5E>4 =0 30



 if(Period()!=TimeFrame_1 && TimeCurrent()>=_time+(int)(_TimeMinute*60)){

   hwnd=WindowHandle(Symbol(),Period());

   PostMessageA(hwnd,WM_COMMAND,_tf1,0);

   _time = TimeCurrent();

   PlaySound("ok.wav");

   return;}

   

 if(Period()!=TimeFrame_2){

 if(_time!=0){

 if(TimeCurrent()>=_time+(int)(_TimeMinute*60)){

   hwnd=WindowHandle(Symbol(),Period());

   PostMessageA(hwnd,WM_COMMAND,_tf2,0);

   _time = TimeCurrent();

   PlaySound("tick.wav");

   return;}}} 

//---   

  }

//----

string GetNameTF(int TimeFrame=0) {

  if (TimeFrame==0) TimeFrame=Period();

  switch (TimeFrame) {

    case PERIOD_M1:  return("M1");

    case PERIOD_M5:  return("M5");

    case PERIOD_M15: return("M15");

    case PERIOD_M30: return("M30");

    case PERIOD_H1:  return("H1");

    case PERIOD_H4:  return("H4");

    case PERIOD_D1:  return("Daily");

    case PERIOD_W1:  return("Weekly");

    case PERIOD_MN1: return("Monthly");

    default:         return("UnknownPeriod");

  }

}

//----

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