sort Market Watch window by Symbol name? - page 3

 
Also, the script above sorts what's already in the market watch.
If you need sorting all symbols, selected or not, by type with forex appearing first, run it on AUDCAD:
#property strict
#include <Arrays\ArrayString.mqh>
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   string calc;
   CArrayString list;
   for(int i=SymbolsTotal(false)-1; i>=0; i--)
     {
      SymbolSelect(SymbolName(i,false),false);
      calc=SymbolInfoInteger(SymbolName(i,false),SYMBOL_TRADE_CALC_MODE);
      //if(calc!=SYMBOL_CALC_MODE_FOREX) //--- skip if not forex
      //   continue;
      list.Add(calc+"~"+SymbolName(i,false));;
     }
   list.Sort();
   Sleep(10);
   for(int i=0; i<list.Total(); i++)
      SymbolSelect(StringSubstr(list[i],StringFind(list[i],"~")+1),true);
  }
 

or run as expert advisor on whatever chart..

#property strict
#include <Arrays\ArrayString.mqh>
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   if(Symbol()!="AUDCAD")
     {
      if(ChartSetSymbolPeriod(0,"AUDCAD",Period()))
         return(INIT_SUCCEEDED);
      else
         return(INIT_FAILED);
     }
   string calc;
   CArrayString list;
//--- close all charts
   long curr_chart=ChartFirst(),prev_chart;
   while(curr_chart!=WRONG_VALUE)
     {
      prev_chart=curr_chart;
      curr_chart=ChartNext(prev_chart);
      //--- not closing our chart
      if(prev_chart!=ChartID())
         ChartClose(prev_chart);
     }
   Sleep(10);
//--- hide market & build list
   for(int i=SymbolsTotal(false)-1; i>=0; i--)
     {
      SymbolSelect(SymbolName(i,false),false);
      calc=SymbolInfoInteger(SymbolName(i,false),SYMBOL_TRADE_CALC_MODE);
      //if(calc!=SYMBOL_CALC_MODE_FOREX)
      //   continue;
      list.Add(calc+"~"+SymbolName(i,false));;
     }
   list.Sort();
   Sleep(10);
   for(int i=0; i<list.Total(); i++)
      SymbolSelect(StringSubstr(list[i],StringFind(list[i],"~")+1),true);

//---
   ExpertRemove();
   return(INIT_SUCCEEDED);
  }
 
Amir Yacoby:

Or run as expert advisor on whatever chart..

What is it supposed to do ? I tried your code and :

  • Now my market watch contains a lot of undesired symbols.
  • It's not sorted.

Picture of the first part :


 
Alain Verleyen:

What is it supposed to do ? I tried your code and :

  • Now my market watch contains a lot of undesired symbols.
  • It's not sorted.

Picture of the first part :


As for undesired symbols, it selects all of the available. As opposed to previous script (Nicholi's) which sorts only symbols you already have on market. 
As for sorting, maybe you have open positions/pending orders on EURUSD, GBPUSD, USDCHF, USDJPY?

And for EURDKK - what is the calculation mode of that symbol? is it not same as the first sorted ones (like AUDCHF for instance)?

 
Amir Yacoby:

As for undesired symbols, it selects all of the available. As opposed to previous script (Nicholi's) which sorts only symbols you already have on market. 
As for sorting, maybe you have open positions/pending orders on EURUSD, GBPUSD, USDCHF, USDJPY?

And for EURDKK - what is the calculation mode of that symbol? is it not same as the first sorted ones (like AUDCHF for instance)?

It would be better to sort what is already select instead of selecting new ones.

I don't have open position.

EURDKK calculation is Forex.


 
Alain Verleyen:

It would be better to sort what is already select instead of selecting new ones.

I don't have open position.

EURDKK calculation is Forex.


Strange, the only thing I can think of with regards to the sorting, is maybe increase the Sleep from 10 to something more.


This is with input parm - leave market is default:

#property strict
#include <Arrays\ArrayString.mqh>
input bool inpCurrentMarketSymbols=true;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   if(Symbol()!="AUDCAD")
     {
      if(ChartSetSymbolPeriod(0,"AUDCAD",Period()))
         return(INIT_SUCCEEDED);
      else
         return(INIT_FAILED);
     }
   string calc;
   CArrayString list;
//--- close all charts
   long curr_chart=ChartFirst(),prev_chart;
   while(curr_chart!=WRONG_VALUE)
     {
      prev_chart=curr_chart;
      curr_chart=ChartNext(prev_chart);
      //--- not closing our chart
      if(prev_chart!=ChartID())
         ChartClose(prev_chart);
     }
   Sleep(10);
//--- hide market & build list
   for(int i=SymbolsTotal(inpCurrentMarketSymbols)-1; i>=0; i--)
     {
      SymbolSelect(SymbolName(i,inpCurrentMarketSymbols),inpCurrentMarketSymbols);
      calc=SymbolInfoInteger(SymbolName(i,false),SYMBOL_TRADE_CALC_MODE);
      //if(calc!=SYMBOL_CALC_MODE_FOREX)
      //   continue;
      list.Add(calc+"~"+SymbolName(i,inpCurrentMarketSymbols));;
     }
   list.Sort();
   Sleep(10);
   for(int i=0; i<list.Total(); i++)
      SymbolSelect(StringSubstr(list[i],StringFind(list[i],"~")+1),true);

//---
   ExpertRemove();
   return(INIT_SUCCEEDED);
  }
 
Alain Verleyen:

It would be better to sort what is already select instead of selecting new ones.

I don't have open position.

EURDKK calculation is Forex.


Maybe the string value is forex for EURDKK but the actual code value is different from say "EURUSD"?
because it seems you have 3 sets of ordered symbols in the first picture
Reason: