share utility code - page 3

 
TIMisthebest:

hi;

below code can use for " send email & send massage to mobile & send sound and alarm " .i write below and use it in all my indicator.

example : https://www.mql5.com/en/code/1868/34272#!tab=code

Thanks.

example link Does not work.

 


.
.
.
int total_symbol=0; // Number of symbols name on the server
string empty_symbol="EMPTY";
string SYMBOLS_NAMES[SYMBOLS_COUNT];
.
.
.
//*************************************************************************
void OnInit()
  {
   SYMBOLS_NAMES[0]="EMPTY";
   InitSymbolNames();
.
.
.
}
//+------------------------------------------------------------------+
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     &TickVolume[],
                const long     &Volume[],
                const int      &Spread[])
{
.
.
.
InitSymbolNames();
.
.
.
//--- done
   return(rates_total);
}
//+------------------------------------------------------------------+
void InitSymbolNames()
  {
   AddSymbolToMarketWatch(SYMBOLS_NAMES[1],"EUR","eur","GBP","gbp");
  }
//+------------------------------------------------------------------+
string AddSymbolToMarketWatch(string &name,string PART_1,string part_1,string PART_2,string part_2)
  {
   name=empty_symbol;                // Symbol name
   total_symbol=SymbolsTotal(false);          //--- Total symbols on the server
//--- Iterate over the entire list of symbols
   for(int i=0;i<total_symbol;i++)
     {      
      if(
         (SymbolInfoString(SymbolName(i,false),SYMBOL_CURRENCY_BASE)==PART_1&&SymbolInfoString(SymbolName(i,false),SYMBOL_CURRENCY_PROFIT)==PART_2)
         ||
         (SymbolInfoString(SymbolName(i,false),SYMBOL_CURRENCY_BASE)==part_1&&SymbolInfoString(SymbolName(i,false),SYMBOL_CURRENCY_PROFIT)==part_2)
        )
        {
         name=SymbolName(i,false);  //--- If this symbol is available,
         SymbolSelect(name,true);   //--- add it to the Market Watch window and
         return(name);              //--- return its name
         break;
        }
     }
   return(name);
  }
//********************************************************************************************************************

& thanks for help

 
Close all open position 
void CloseAllPosition(int magic)
{
   while (checkOpenPosition(magic))
   {
      for (int i = PositionsTotal()-1; i >= 0; i--)
      {
         if (PositionGetInteger(POSITION_MAGIC) == magic)
         {
            CTrade trade;
            trade.SetExpertMagicNumber(magic);
            trade.PositionClose(PositionGetSymbol(i));
           
         }
      
      }
  
   }
 
}

bool checkOpenPosition(int magic)
    {
       for(int i=PositionsTotal()-1;i>=0;i--)
       {
           PositionSelect(PositionGetSymbol(i));
            if (PositionGetInteger(POSITION_MAGIC) == magic)
              return(true  );   
       }
       return(false);
 } 

Reason: