Download MetaTrader 5
To add comments, please log in or register
Read the Forum and improve your rating!
Andrew
71
Andrew 2014.06.09 07:48 

Hi folks,

I've been working on a signals indicator similar to the tutorial available here: https://www.mql5.com/en/articles/1503

I've managed to incorporate my (simple) trend definition of 2 MA's and that is changing the signal to green & red accordingly.

For a second signal, I'm attempting to highlight and opening range breakout, I've got a seperate indi that plots the opening range on a 5m TF for each trading session, and i'm trying to get the signal table indicator to flash green for price above the opening range, and red below the opening range.

I've added in all the time, declarations etc. and am a bit stuck as to why the indicator (the second "traffic light" Opening Range) isn't working? The code I'm having trouble with starts at around line 130.

Any help would be greatly appreciated,

Regards,

Andrew

#property copyright "Andrew Caldwell"
#property link      "http://about.me/caldwellandrew"
 
#property indicator_chart_window

extern int scaleX=20,
           scaleY=20,
           offsetX=35,
           offsetY=20,
           fontSize=20,
           corner=0,
           sydney = 2,
           tokyo = 3,
           frankfurt = 9,
           london = 10,
           newyork = 15,
           symbolCodeBuy=110, // a symbol code for a buy signal
           symbolCodeSell=110, // sell signal
           symbolCodeNoSignal=110, // no signal
           barsToProcess = 1000;
           
extern color signalBuyColor=Lime, // color of the symbol of a buy signal
             signalSellColor=Red, // for a sell signal
             noSignalColor=Goldenrod, // no signal
             textColor=Gold; // color of all writings
           
int period[]={5};

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
{
// table of signals
         ObjectCreate("MAsignal",OBJ_LABEL,0,0,0,0,0);
         ObjectSet("MAsignal",OBJPROP_CORNER,corner);
         ObjectSet("MAsignal",OBJPROP_XDISTANCE,1*scaleX+offsetX);
         ObjectSet("MAsignal",OBJPROP_YDISTANCE,0*scaleY+offsetY);
         ObjectSetText("MAsignal",CharToStr(symbolCodeNoSignal), fontSize,"Wingdings",noSignalColor);
      
         ObjectCreate("ORsignal",OBJ_LABEL,0,0,0,0,0);
         ObjectSet("ORsignal",OBJPROP_CORNER,corner);
         ObjectSet("ORsignal",OBJPROP_XDISTANCE,1*scaleX+offsetX);
         ObjectSet("ORsignal",OBJPROP_YDISTANCE,1*scaleY+offsetY);
         ObjectSetText("ORsignal",CharToStr(symbolCodeNoSignal), fontSize,"Wingdings",noSignalColor);
         
         ObjectCreate("PDHLsignal",OBJ_LABEL,0,0,0,0,0);
         ObjectSet("PDHLsignal",OBJPROP_CORNER,corner);
         ObjectSet("PDHLsignal",OBJPROP_XDISTANCE,1*scaleX+offsetX);
         ObjectSet("PDHLsignal",OBJPROP_YDISTANCE,2*scaleY+offsetY);
         ObjectSetText("PDHLsignal",CharToStr(symbolCodeNoSignal), fontSize,"Wingdings",noSignalColor);
      
 // names of timeframes   
         ObjectCreate("TF_label",OBJ_LABEL,0,0,0,0,0);
         ObjectSet("TF_label",OBJPROP_CORNER,corner);
         ObjectSet("TF_label",OBJPROP_XDISTANCE,1*scaleX+offsetX);
         ObjectSet("TF_label",OBJPROP_YDISTANCE,offsetY-10);
         ObjectSetText("TF_label","M5",8,"Tahoma",textColor);
   
 // names of indicators  
         ObjectCreate("MASignal_label",OBJ_LABEL,0,0,0,0,0);
         ObjectSet("MASignal_label",OBJPROP_CORNER,corner);
         ObjectSet("MASignal_label",OBJPROP_XDISTANCE,offsetX-35);
         ObjectSet("MASignal_label",OBJPROP_YDISTANCE,0*scaleY+offsetY+8);
         ObjectSetText("MASignal_label","Trend",8,"Tahoma",textColor);
      
         ObjectCreate("ORsignal_label",OBJ_LABEL,0,0,0,0,0);
         ObjectSet("ORsignal_label"+2,OBJPROP_CORNER,corner);
         ObjectSet("ORsignal_label",OBJPROP_XDISTANCE,offsetX-35);
         ObjectSet("ORsignal_label",OBJPROP_YDISTANCE,1*scaleY+offsetY+8);
         ObjectSetText("ORsignal_label","OR",8,"Tahoma",textColor);
      
         ObjectCreate("PDHLsignal_label",OBJ_LABEL,0,0,0,0,0);
         ObjectSet("PDHLsignal_label",OBJPROP_CORNER,corner);
         ObjectSet("PDHLsignal_label",OBJPROP_XDISTANCE,offsetX-35);
         ObjectSet("PDHLsignal_label",OBJPROP_YDISTANCE,2*scaleY+offsetY+8);
         ObjectSetText("PDHLsignal_label","PDHL",8,"Tahoma",textColor);
      
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+

int deinit()
{
         ObjectDelete("MAsignal");
         ObjectDelete("ORsignal");
         ObjectDelete("PDHLsignal");
         ObjectDelete("TF_label");
         ObjectDelete("MAsignal_label");
         ObjectDelete("ORsignal_label");
         ObjectDelete("PDHLsignal_label");
   return(0);
}
 
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
 
int start()
{

//Trend 50ema>||<14ema...

   {
      if(iMA(Symbol(),0,50,0,0,0,0)<iMA(Symbol(),0,14,0,0,0,0)) 
         ObjectSetText("MAsignal",CharToStr(symbolCodeBuy),fontSize,
         "Wingdings",signalBuyColor);
      else
         ObjectSetText("MAsignal",CharToStr(symbolCodeSell),fontSize,
         "Wingdings",signalSellColor); 
   }

// WPR Example of Buy/Sell/None...

 //  {
 //     if(MathAbs(iWPR(Symbol(),period[x],13,0))<20.0)
  //       ObjectSetText("signal"+x+"1",CharToStr(symbolCodeBuy),fontSize,
 //        "Wingdings",signalBuyColor);   
 //     else if(MathAbs(iWPR(Symbol(),period[x],13,0))>80.0)
 //        ObjectSetText("signal"+x+"1",CharToStr(symbolCodeSell),fontSize,
 //        "Wingdings",signalSellColor);   
 //     else
 //        ObjectSetText("signal"+x+"1",CharToStr(symbolCodeNoSignal),fontSize,
  //       "Wingdings",noSignalColor);      
 //  }
   
// OR attempt... :(

{
if (Bars <= 10) return(0);
   
   int counted = IndicatorCounted();
   if (counted < 0) return(-1);
   if (counted > 0) counted--;
   
   int i = Bars - counted;
   int timeRange = 0;
   double ORHigh = 0;
   double ORLow = 0;
   
   while (i >= 0)
   {
      int currentTime = Time[i];
      int dayNumber = TimeDayOfWeek(currentTime) + 1;
      
      if (TimeHour(currentTime) == sydney && TimeMinute(currentTime) == 0)
       {
         ORHigh = iHighest(NULL,0,MODE_HIGH,1,Time[i]);
         ORLow = iLowest(NULL,0,MODE_LOW,1,Time[1]);
      else if (TimeHour(currentTime) == tokyo && TimeMinute(currentTime) == 0)
      {
         ORHigh = iHighest(NULL,0,MODE_HIGH,1,Time[i]);
         ORLow = iLowest(NULL,0,MODE_LOW,1,Time[1]);
      }
      
      else if (TimeHour(currentTime) == frankfurt && TimeMinute(currentTime) == 0)
      {
         ORHigh = iHighest(NULL,0,MODE_HIGH,1,Time[i]);
         ORLow = iLowest(NULL,0,MODE_LOW,1,Time[1]);
         }
    }
        
        {
      if(High[i]>ORHigh)
      ObjectSetText("ORsignal",CharToStr(symbolCodeBuy),fontSize,
      "Wingdings",signalBuyColor);   
      else if(Low[i]<ORLow)
      ObjectSetText("ORsignal",CharToStr(symbolCodeSell),fontSize,
      "Wingdings",signalSellColor);   
      else
      ObjectSetText("ORsignal",CharToStr(symbolCodeNoSignal),fontSize,
      "Wingdings",noSignalColor);      
} 
         
   }
         
         return(0);
         }
   
/
To add comments, please log in or register