Change Time Frame All

Author: Matthew Kastor
0 Views
0 Downloads
0 Favorites
Change Time Frame All
ÿþ//+------------------------------------------------------------------+

//|                                  All Charts Switch Timeframe.mq4 |

//|                                                   Matthew Kastor |

//|                                 https://github.com/matthewkastor |

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

#property copyright "Matthew Kastor"

#property link      "https://github.com/matthewkastor"

#property version   "1.00"

#property strict

#property show_inputs



extern ENUM_TIMEFRAMES Timeframe=PERIOD_W1;

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

//|                                                                  |

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

void OnStart()

  {

   long chartIds[];

   long chartId;

   if(GetChartIds(chartIds))

     {

      for(int i=ArraySize(chartIds)-1;i>=0;i--)

        {

         chartId=chartIds[i];

         ChartSetSymbolPeriod(chartId,ChartSymbol(chartId),Timeframe);

        }

     }

   return;

  }

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

//|                                                                  |

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

bool GetChartIds(long &chartIds[])

  {

   int i=0;

   long chartId=ChartFirst();

   while(chartId>=0)

     {

      if(ArrayResize(chartIds,i+1)<0) return(false);

      chartIds[i]=chartId;

      chartId=ChartNext(chartId);

      i++;

     }

   if(ArraySize(chartIds)>0)

     {

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