BUTTONS_SW_TRO_MODIFIED.mq4


BUTTONS_SW_TRO_MODIFIED.mq4 download link will appear after 10 seconds.



BUTTONS_SW_TRO_MODIFIED.mq4 Programming source code.

//+------------------------------------------------------------------+
//|  BUTTONS_TRO_MODIFIED                                            |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 0
#property strict

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

extern bool TURN_OFF    = false ;
extern bool SHOW_CANDLE_COLOR = true;  
  

extern string  sOption = "Type ALL in Symbols for all symbols ";
extern string  Symbols="ALL";
//extern string  Symbols="AUDJPY;AUDUSD;EURUSD;EURGBP;EURJPY;GBPUSD;GBPJPY;NZDUSD;USDCAD;USDCHF;USDJPY"; // List of symbols (separated by ";")
extern string  Suffix="";

extern string  UniqueID="changer";     // Indicator unique ID

extern int     ButtonsInARow = 14;      // Buttons in a horizontal row
extern int     Corner        = 2;      // Corner
extern int     XShift        = 35;    // Horizontal shift
extern int     YShift        = 20;     // Vertical shift
extern int     XSize         = 65;     // Width of buttons
extern int     YSize         = 16;     // Height of buttons
extern int     FSize         = 8;     // Font size
extern string  FontType      = "Consolas" ; // Font
extern color   Bcolor=clrLightGray;        // Button color
extern color   Dcolor=clrDarkSlateBlue;        // Button border color
extern color   Tncolor=clrBlack;       // Text color - normal
extern color   Sncolor= clrBlue;    // Text color - selected
extern bool    Transparent= true;     // Transparent buttons?
extern color colorUp       = Lime ;
extern color colorDn       = Red ; 


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

string aSymbols[], tSymbols, xySymbol,yxSymbol,symbol  ;
string CurrencyTable[] = {"AUD","CAD","CHF","EUR","GBP","JPY","NZD","USD"};  
           
color FG, BG, XG, FGbuttonTF, BGbuttonTF;           
string TF[] = { "1","5","15","30","H1","H4","D","W","M"   } ;
int    CP[] = { PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1, PERIOD_MN1 };
int CCPER,win ;  
string text ;                                                             
//+------------------------------------------------------------------+

bool IsLoaded( string list, string lookfor )
{
   if(StringFind( list , lookfor, 0) ) { return(true) ; } else { return(false) ; } 
}
                                                              
//+------------------------------------------------------------------+
int OnInit()
{
   
   if( TURN_OFF ) { OnDeinit(0); return(0) ; } 
   
   IndicatorShortName("Buttons");
   
   win =    WindowFind("Buttons");  
   
   FG = Tncolor ; 
   BG = Bcolor ;  
   
   FGbuttonTF = Tncolor ; 
   BGbuttonTF = Bcolor ; 
   
   symbol = Symbol() ;
   
   if(StringFind(AccountInfoString(ACCOUNT_COMPANY),"TW",0) >= 0 && StringFind(Symbol(),"i",0) >= 0) { Suffix = "i" ; }  else  
   if(StringFind(AccountInfoString(ACCOUNT_COMPANY),"Gain",0) >= 0) { Suffix = "pro" ; }  
      
 
   int pairlen = StringLen(symbol);
   if(XSize < pairlen*10) { XSize = pairlen*10 -20; }
   
   tSymbols = Symbols;
   
   if(tSymbols == "ALL" ) 
   {
      Symbols = "" ;
      for(int c=0;c<8;c++)
      {
         for(int d=c+1;d<8;d++)
         {
            xySymbol = CurrencyTable[c]+CurrencyTable[d]+Suffix;
            yxSymbol = CurrencyTable[d]+CurrencyTable[c]+Suffix;
            if( MarketInfo(xySymbol,MODE_BID) != 0.0 && IsLoaded( Symbols, xySymbol ) ) { Symbols = Symbols + xySymbol + ";" ; } 
            else if( MarketInfo(yxSymbol,MODE_BID) != 0.0 && IsLoaded( Symbols, yxSymbol ) ) { Symbols = Symbols + yxSymbol + ";" ; }          
         }      
            
      }
   
   }

      int xpos=0,ypos=0,maxx=0,maxy=0;
 
   if(tSymbols != "NONE" )
   {
      
      Symbols=StringTrimLeft(StringTrimRight(Symbols));
      if(StringSubstr(Symbols,StringLen(Symbols)-1,1)!=";")
         Symbols=StringConcatenate(Symbols,";");
   
    
   
      int s=0,i=StringFind(Symbols,";",s);
      string current;
      while(i>0)
        {
         current=StringSubstr(Symbols,s,i-s);
         ArrayResize(aSymbols,ArraySize(aSymbols)+1);
         aSymbols[ArraySize(aSymbols)-1]=current;
         s = i + 1;
         i = StringFind(Symbols,";",s);
        }
   
      ShellsortStringArray(aSymbols, 0, false) ;
    
 //     int xpos=0,ypos=0,maxx=0,maxy=0;
      for(i=0; i0 && MathMod(i,ButtonsInARow)==0) { xpos=0; ypos+=YSize+1; } 
         text = StringSubstr(aSymbols[i],0,StringLen(aSymbols[i])-StringLen(Suffix));
         createButton(UniqueID+":symbol:"+string(i),text,XShift+xpos,YShift+ypos); 
         xpos+=XSize+1; 
      }

/*   
      xpos=0; ypos+=YSize*2;
      for(i=0; i0 && MathMod(i,ButtonsInARow)==0) { xpos=0; ypos+=YSize+1; } createButton(UniqueID+":time:"+string(i),sTfTable[i],XShift+xpos,YShift+ypos); xpos+=XSize+1; }
 */  
    
      setSymbolButtonColor();
      
   }

      xpos=0; ypos+=YSize*2;
      for(int i=0; i0 && MathMod(i,ButtonsInARow)==0) { xpos=0; ypos+=YSize+1; } createButton(UniqueID+":time:"+string(i),sTfTable[i],XShift+xpos,YShift+ypos); xpos+=XSize+1; }
   
      
   setTimeFrameButtonColor();
   
   return(0);
  } 
  

//+------------------------------------------------------------------+
void ShellsortStringArray(string &a[], int size=0, bool desc=false)  {
//+------------------------------------------------------------------+
// Performs a shell sort (rapid resorting) of string array 'a'
//  default is ascending order, unless 'desc' is set to true
  int n=ArraySize(a);
  if (size>0)  n=size;
  int j,i, m;
  string mid;
  for(m=n/2; m>0; m/=2)  {
    for(j=m; j=0; i-=m)  {
        if (desc)   {
          if (a[i+m] <= a[i])
            break;
          else {
            mid = a[i];
            a[i] = a[i+m];
            a[i+m] = mid;
        } }  
        else  {
          if (a[i+m] >= a[i])
            break;
          else {
            mid = a[i];
            a[i] = a[i+m];
            a[i+m] = mid;
        } }  
  } } } 
  return ;
}
  
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  
   switch(reason)
     {
      case REASON_CHARTCHANGE :
      case REASON_RECOMPILE   :
      case REASON_CLOSE       : break;
      default :
        {
         string lookFor       = UniqueID+":";
         int    lookForLength = StringLen(lookFor);
         for(int i=ObjectsTotal()-1; i>=0; i--)
           {
            string objectName=ObjectName(i);  if(StringSubstr(objectName,0,lookForLength)==lookFor) ObjectDelete(objectName);
           }
        }
     }
  }
//+------------------------------------------------------------------+ 
void createButton(string name,string caption,int xpos,int ypos)
  {
   if(ObjectFind(name)!=0)
      ObjectCreate(name,OBJ_BUTTON,win,0,0);
   ObjectSet(name,OBJPROP_CORNER,0);
   ObjectSet(name,OBJPROP_XDISTANCE,xpos);
   ObjectSet(name,OBJPROP_YDISTANCE,ypos);
   ObjectSet(name,OBJPROP_XSIZE,XSize);
   ObjectSet(name,OBJPROP_YSIZE,YSize);
   ObjectSetText(name,caption,FSize,FontType,Tncolor);
   ObjectSet(name,OBJPROP_FONTSIZE,FSize);
   ObjectSet(name,OBJPROP_BORDER_TYPE,BORDER_FLAT);
   ObjectSet(name,OBJPROP_COLOR,FG);
   ObjectSet(name,OBJPROP_BGCOLOR,BG);
   ObjectSet(name,OBJPROP_BACK,Transparent);
   ObjectSet(name,OBJPROP_BORDER_COLOR,Dcolor);
   ObjectSet(name,OBJPROP_STATE,false);
   ObjectSet(name,OBJPROP_HIDDEN,true);
   ObjectSet(name,OBJPROP_CORNER,Corner);
   
  }
//+------------------------------------------------------------------+ 
void setSymbolButtonColor()
  {
   string lookFor       = UniqueID+":symbol:";
   int    lookForLength = StringLen(lookFor);
   for(int i=ObjectsTotal()-1; i>=0; i--)
     {
      FG = Tncolor ; 
      BG = Bcolor ;  
      
      string objectName=ObjectName(i);
      if(StringSubstr(objectName,0,lookForLength)==lookFor)
        {
         string symbol=ObjectGetString(0,objectName,OBJPROP_TEXT)+Suffix;
         
         if(SHOW_CANDLE_COLOR)
         {  
                  if( iClose( symbol, PERIOD_CURRENT, 0 )  >= iOpen( symbol, PERIOD_CURRENT, 0 ) )
                  { BG = colorUp ; } else { BG = colorDn ; }        

                  if(symbol==_Symbol) { XG = FG; FG = BG; BG = XG ; }
                  ObjectSet(objectName,OBJPROP_COLOR,FG);
                  ObjectSet(objectName,OBJPROP_BGCOLOR,BG);                    
         }
         else
         {
            if(symbol!=_Symbol)
               ObjectSet(objectName,OBJPROP_COLOR,Tncolor);
            else  ObjectSet(objectName,OBJPROP_COLOR,Sncolor);
         }
         
         
         
        }
     }
  } 
//+------------------------------------------------------------------+
void setTimeFrameButtonColor()
  {
   string lookFor       = UniqueID+":time:";
   int    lookForLength = StringLen(lookFor);
   
   for(int i=ObjectsTotal()-1; i>=0; i--)
   {
      
      FGbuttonTF = Tncolor ; 
      BGbuttonTF = Bcolor ;  
      
      string objectName=ObjectName(i);
      if(StringSubstr(objectName,0,lookForLength)==lookFor)
        {
         
         string sTime = ObjectGetString(0,objectName,OBJPROP_TEXT) ;
         int time = stringToTimeFrame(sTime);
 
         if(time != _Period)
         {
    
            if(SHOW_CANDLE_COLOR)
            {     
                  if( iClose( symbol, time, 0 )  >= iOpen( symbol, time, 0 ) )
                  { BGbuttonTF = colorUp ; } else { BGbuttonTF = colorDn ; }        
                  ObjectSet(objectName,OBJPROP_COLOR,FGbuttonTF);
                  ObjectSet(objectName,OBJPROP_BGCOLOR,BGbuttonTF);
            }    
            else
            {   
                 ObjectSet(objectName,OBJPROP_COLOR,Tncolor);  
                         
            }
            
          }
          else
          {
            if(SHOW_CANDLE_COLOR)
            {     
                  if( iClose( symbol, time, 0 )  >= iOpen( symbol, time, 0 ) )
                  { BGbuttonTF = colorUp ; } else { BGbuttonTF = colorDn ; }   
                  XG = FGbuttonTF; FGbuttonTF = BGbuttonTF; BGbuttonTF = XG ;            
                  ObjectSet(objectName,OBJPROP_COLOR,FGbuttonTF);
                  ObjectSet(objectName,OBJPROP_BGCOLOR,BGbuttonTF);
            }           
            else { ObjectSet(objectName,OBJPROP_COLOR,Sncolor); } 
          
          }
         
        }
     }
  }


//+------------------------------------------------------------------+ 
string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200}; 
//+------------------------------------------------------------------+
string timeFrameToString(int tf)
  {
   for(int i=ArraySize(iTfTable)-1; i>=0; i--)
      if(tf==iTfTable[i]) return(sTfTable[i]);
   return("");
  } 
//+------------------------------------------------------------------+
int stringToTimeFrame(string tf)
  {
   for(int i=ArraySize(sTfTable)-1; i>=0; i--)
      if(tf==sTfTable[i]) return(iTfTable[i]);
   return(0);
  }
//+------------------------------------------------------------------+
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
  {
   if(id==CHARTEVENT_OBJECT_CLICK && ObjectGet(sparam,OBJPROP_TYPE)==OBJ_BUTTON)
     {   
      if(StringFind(sparam,UniqueID+":symbol:",0)==0) ChartSetSymbolPeriod(0,ObjectGetString(0,sparam,OBJPROP_TEXT)+Suffix,_Period);
      if(StringFind(sparam,UniqueID+":time:"  ,0)==0) ChartSetSymbolPeriod(0,_Symbol,stringToTimeFrame(ObjectGetString(0,sparam,OBJPROP_TEXT)));
      if(StringFind(sparam,UniqueID+":back:"  ,0)==0) ObjectSet(sparam,OBJPROP_STATE,false);
     }
  }
//+------------------------------------------------------------------+
int start() 
{ 
   
   if(SHOW_CANDLE_COLOR)
   {
      setTimeFrameButtonColor() ;
      setSymbolButtonColor() ;
   }
   return(0); 


}
//+------------------------------------------------------------------+

Comments

Copied title and URL