TF Switcher

Author: Copyright 2017, Tor
0 Views
0 Downloads
0 Favorites
TF Switcher
ÿþ//+------------------------------------------------------------------+

//|                                                  TF Switcher.mq4 |

//|                                              Copyright 2017, Tor |

//|                                             http://einvestor.ru/ |

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

#property copyright "Copyright 2017, Tor"

#property link      "http://einvestor.ru/"

#property version   "1.00"

#property strict

#property indicator_chart_window



input string upTF = "O";//Increase TF

input string dnTF = "P";//Reduce TF



#include <WinUser32.mqh>

int curPeriod=-1;

int Per[9]={1,5,15,30,60,240,1440,10080,43200};

string Keys[200];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   for(int t=0; t<ArraySize(Per); t++)

     {

      if(_Period==Per[t]){ curPeriod=t; break; }

     }

   Keys[9]="Tab";

   Keys[13] = "Enter";

   Keys[16] = "Shift";

   Keys[17] = "Ctrl";

   Keys[18] = "Alt";

   Keys[19] = "Pause";

   Keys[20] = "CapsLock";

   Keys[27] = "Esc";

   Keys[32] = "Space";

   Keys[33] = "PageUp";

   Keys[34] = "PageDown";

   Keys[35] = "End";

   Keys[36] = "Home";

   Keys[37] = "Left";

   Keys[38] = "Up";

   Keys[39] = "Right";

   Keys[40] = "Down";

   Keys[45] = "Insert";

   Keys[46] = "Delete";

   Keys[48] = "0";

   Keys[49] = "1";

   Keys[50] = "2";

   Keys[51] = "3";

   Keys[52] = "4";

   Keys[53] = "5";

   Keys[54] = "6";

   Keys[55] = "7";

   Keys[56] = "8";

   Keys[57] = "9";

   Keys[65] = "A";

   Keys[66] = "B";

   Keys[67] = "C";

   Keys[68] = "D";

   Keys[69] = "E";

   Keys[70] = "F";

   Keys[71] = "G";

   Keys[72] = "H";

   Keys[73] = "I";

   Keys[74] = "J";

   Keys[75] = "K";

   Keys[76] = "L";

   Keys[77] = "M";

   Keys[78] = "N";

   Keys[79] = "O";

   Keys[80] = "P";

   Keys[81] = "Q";

   Keys[82] = "R";

   Keys[83] = "S";

   Keys[84] = "T";

   Keys[85] = "U";

   Keys[86] = "V";

   Keys[87] = "W";

   Keys[88] = "X";

   Keys[89] = "Y";

   Keys[90] = "Z";

   Keys[192]= "`";

//---

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

  {

//---



//--- 

   return(rates_total);

  }

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

void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)

  {



   if(id==CHARTEVENT_KEYDOWN)

     {

      if(Keys[(int)lparam]==upTF && curPeriod<(ArraySize(Per)-1))

        {

         KeyScript(GetTFid(Per[curPeriod+1]));// Up

        }

      if(Keys[(int)lparam]==dnTF && curPeriod>0)

        {

         KeyScript(GetTFid(Per[curPeriod-1]));// Dn

        }

     }



   return;

  }

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

//|                                                                  |

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

void KeyScript(int tfcode)

  {

   int hwnd;

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

   PostMessageA(hwnd,WM_COMMAND,tfcode,0);

   return;

  }

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

//|                                                                  |

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

int GetTFid(int tf0=PERIOD_CURRENT)

  {



   switch(tf0)

     {

      case PERIOD_M1:

         return 33137;

         break;

      case PERIOD_M5:

         return 33138;

         break;

      case PERIOD_M15:

         return 33139;

         break;

      case PERIOD_M30:

         return 33140;

         break;

      case PERIOD_H1:

         return 35400;

         break;

      case PERIOD_H4:

         return 33136;

         break;

      case PERIOD_D1:

         return 33134;

         break;

      case PERIOD_W1:

         return 33141;

         break;

      case PERIOD_MN1:

         return 33334;

         break;

     }



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