CHART_BRING_TO_TOP

Author: Copyright © 2014, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
CHART_BRING_TO_TOP
ÿþ//+------------------------------------------------------------------+

//|                                           CHART_BRING_TO_TOP.mq5 |

//|                              Copyright © 2014, Vladimir Karputov |

//|                                           http://wmua.ru/slesar/ |

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

#property copyright "Copyright © 2014, Vladimir Karputov"

#property link      "http://wmua.ru/slesar/"

#property version   "1.02"

#property description "The script switches all open charts after a certain interval."

//--- ?>:065< >:=> 2E>4=KE ?0@0<5B@>2 ?@8 70?CA:5 A:@8?B0

//--- show window of input parameters when you run the script

#property script_show_inputs

//--- 2E>4=K5 ?0@0<5B@K A:@8?B0

//--- the script input parameters

input int      milliseconds=3000;      // 8=B5@20; // interval

input string   name_symbol="RTS-9.16"; // 0:B828@>20BL B>;L:> // activate only

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

//| Script program start function                                    |

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

void OnStart()

  {

//---

// variables for chart ID

   long currChart,prevChart=ChartFirst();

//--- >1@010BK205< ?5@2K9 3@0D8: // process the first graph

   if(name_symbol!="")

     {

      if(ChartSymbol(prevChart)==name_symbol)

        {

         // Print(i," ",ChartSymbol(currChart)," ID =",currChart);

         ChartBringToTop(prevChart);

         Sleep((int)MathAbs(milliseconds));

        }

     }

   else

     {

      // Print(i," ",ChartSymbol(currChart)," ID =",currChart);

      ChartBringToTop(prevChart);

      Sleep((int)MathAbs(milliseconds));

     }

//---

   int i=0,limit=100;

//   Print("ChartFirst = ",ChartSymbol(prevChart)," ID = ",prevChart);

// # =0A =025@=O:0 =5 1>;LH5 100 >B:@KBKE 3@0D8:>2

// We have certainly not more than 100 open charts

   while(i<limit)// 

     {

      // 0 >A=>20=88 ?@54K4CI53> ?>;CG8< =>2K9 3@0D8:

      // Get the new chart ID by using the previous chart ID

      currChart=ChartNext(prevChart);

      if(currChart<0) break;  // 4>AB83;8 :>=F0 A?8A:0 3@0D8:>2 // Have reached the end of the chart list

      if(name_symbol!="")

        {

         if(ChartSymbol(currChart)==name_symbol)

           {

            // Print(i," ",ChartSymbol(currChart)," ID =",currChart);

            ChartBringToTop(currChart);

            Sleep((int)MathAbs(milliseconds));

           }

        }

      else

        {

         // Print(i," ",ChartSymbol(currChart)," ID =",currChart);

         ChartBringToTop(prevChart);

         Sleep((int)MathAbs(milliseconds));

        }

      // 0?><=8< 845=B8D8:0B>@ B5:CI53> 3@0D8:0 4;O ChartNext()

      // Let's save the current chart ID for the ChartNext()

      prevChart=currChart;

      // 5 701C45< C25;8G8BL AG5BG8:

      // Do not forget to increase the counter

      i++;

     }

  }

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

//| B?@02:0 B5@<8=0;C :><0=4K =0 ?>:07 3@0D8:0 ?>25@E 2A5E 4@C38E.  |

//| Sends command to the terminal to display the chart above all others  |

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

bool ChartBringToTop(const long chart_ID=0)

  {

//--- A1@>A8< 7=0G5=85 >H81:8

   ResetLastError();

//--- ?>:065< 3@0D8: ?>25@E 2A5E 4@C38E

   if(!ChartSetInteger(chart_ID,CHART_BRING_TO_TOP,0,true))

     {

      //--- 2K2545< A>>1I5=85 >1 >H81:5 2 6C@=0; "-:A?5@BK"

      Print(__FUNCTION__+", Error Code = ",GetLastError());

      return(false);

     }

   ChartRedraw(chart_ID);

//--- CA?5H=>5 2K?>;=5=85

   return(true);

  }

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

Comments