Download MetaTrader 5

Trend Alert Need to add Symbol

To add comments, please log in or register
fxtrader_
247
fxtrader_  

Hi All,

Is it passble to specify which Symbol the code can look in? for ex: I need it to look in "AUDCAD" Pair.

#property indicator_chart_window

   double prevbid=0;
   
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {

   for (int i=0;i<ObjectsTotal();i++) 
   {
      string name=ObjectName(i);
      if ((ObjectType(name)==OBJ_TREND) || (ObjectType(name)==OBJ_HLINE)) 
      {
         ObjectSet(name,OBJPROP_PRICE3,0);
      }
   }

//---
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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 &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---

   double value,prevvalue;
//----
   for (int i=0;i<ObjectsTotal();i++) {
      string name=ObjectName(i);
      if ((ObjectType(name)==OBJ_TREND) || (ObjectType(name)==OBJ_HLINE)) 
         {
         if (ObjectType(name)==OBJ_TREND) {value=ObjectGetValueByShift(name,0);} 
            else { value=ObjectGet(name,OBJPROP_PRICE1); }
            
         prevvalue=ObjectGet(name,OBJPROP_PRICE3);
         if ((prevbid!=0) && (prevvalue!=0))
            if (value_to_toggle && (((Bid>value) && (prevbid<=prevvalue )) || ((Bid<value) && (prevbid>=prevvalue))))
            
            
            {
               Alert("Trend Line Crossed    ", Symbol(), ", ", TimeToStr(CurTime(),TIME_DATE | TIME_MINUTES));

              // PlaySound("alert.wav");
            }            
         ObjectSet(name,OBJPROP_PRICE3,value);
      }
   }
   prevbid=Bid;


//--- return value of prev_calculated for next call
   return(rates_total);
  }
whroeder1
14786
whroeder1  
FxTrader_: Is it passble to specify which Symbol the code can look in? for ex: I need it to look in "AUDCAD" Pair.
  1. Do not trade multiple currencies
    • You can't use any predefined variables, can't use the tester, must poll (not OnTick,) and usually other problems.
    • Code it to trade the chart pair only. Look at the others if you must.
    • Then put it on other charts to trade the other pairs. Done.

  2. if ((ObjectType(name)==OBJ_TREND) || (ObjectType(name)==OBJ_HLINE)) 
          {
             ObjectSet(name,OBJPROP_PRICE3,0);
    Why are you setting price three? A Trend line only has two and a horizontal line only has one. Have you verified that that works?
  3. Objects are only on the current chart. You can't read others.
To add comments, please log in or register