Multi-Currency-Timeframe-Scanner. Help needed! - page 2

 
mar:

Hi Raptor,

there is one thing I don't get in my head... I would try it this way:

With iTime() I get the time-value of the bar which is addressed in the parameters. Let's assume it is AUDUSD, M15. So the result will be the (open)-time of the CURRENT M15 bar in the AUDUSD, correct?

My thinking-problem is this: I don't know with which timevalue I should compare it. When I use for example an Alert which should only be executed once a bar, I use static datetime Time0 = Time[0] and begin the int start() with if Time0==Time[0]... But in this case it seems to be different.

OK, here is how I do it . . .

   if(M1Bar1Time < iTime(NULL, PERIOD_M1, 1))      // we have a new M1 bar
      {
      NewM1Bar = true;  // true until the next tick
      
      //  update the value of M1 Bar 1 time
      M1Bar1Time = iTime(NULL, PERIOD_M1, 1);
      }

   if(M5Bar1Time < iTime(NULL, PERIOD_M5, 1))      // we have a new M5 bar
      {
      NewM5Bar = true;  // true until the next tick
      
      //  update the value of M5 Bar 1 time
      M5Bar1Time = iTime(NULL, PERIOD_M5, 1);
      }      
   
   if(M15Bar1Time < iTime(NULL, PERIOD_M15, 1))      // we have a new M15 bar
      {
      NewM15Bar = true;  // true until the next tick
      
      //  update the value of M15 Bar 1 time
      M15Bar1Time = iTime(NULL, PERIOD_M15, 1);
      }      

   if(H1Bar1Time < iTime(NULL, PERIOD_H1, 1))      // we have a new H1 bar
      {
      NewH1Bar = true;  // true until the next tick
      
      //  update the value of H1 Bar 1 time
      H1Bar1Time = iTime(NULL, PERIOD_H1, 1);
      }  

. . . does this help ?

 

Hey Raptor,

yes, it helps. It all makes (logically) sense to me. And I think I have to change NULL to CurrPair[i] and PERIOD_X to TimeframeNo[j] because I need the array-values. Right? Do I have to format M1Bar1Time global or static? I read it pretty often in the MQL4-docs but I still haven't understood for which purposes I need static and global variables. Do I have to set them 0 at the beginning at the code?

I think these are really basic questions but you can see that I still have to learn so much about the structure of MQL4. Therefore, believe it or not, I have absolutely no idea where to implement it into my code. The logic in itself is pretty clear to me but structure and syntax of MQL4 is really difficult for a beginner when you have never coded C.

 

I try and try but I don't get only a small step further. Therefore I would like to make an offer to anyone who reads that. If you would like to complete this code with Raptors idea, I would pay for that. For me it would be the best learning effect to see how it is done correctly. I really like to solve logic tasks but there are so many MQL4-specific issues I don't know and before I do the whole weekend trial and error with things I don't understand, I would rather like to pay someone for completing it.

The indicator should update each column only one time according to the column's timeframe. Like I discussed with Raptor, the M5 should only be updated every 5 minutes, the H4 should only updated every 4 hours and so on. Additionally I have put an Alert into the code which should pop up also once a bar when the conditions are met.

If you are interested to complete it, please let me know and I will send you the price with Paypal.

Thanks, guys!

Here is the complete current code:

//+------------------------------------------------------------------+
//|                                               Pinbar-Scanner.mq4 |
//|                                               Copyright 2013, MR |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MR"
#property link      ""

#property indicator_chart_window

int dist_X, dist_Y, i, j;
string Timeframe[] = {"M1", "M5", "M15", "M30", "H1", "H4", "D1", "W1"};
int TimeframeNo[] = {PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1};
string CurrPair[] = {"AUDCAD", "AUDCHF", "AUDJPY", "AUDNZD", "AUDUSD", "CADCHF", "CHFJPY", "EURAUD",
                     "EURCAD", "EURCHF", "EURGBP", "EURJPY", "EURNZD", "EURUSD", "GBPAUD", "GBPCAD",
                     "GBPCHF", "GBPJPY", "GBPNZD", "GBPUSD", "NZDJPY", "NZDUSD", "USDCAD", "USDCHF",
                     "USDJPY"};
color col;
bool PinbarLong, PinbarShort;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectsDeleteAll();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   static datetime Time0;
   
//---- Timeframe Objects ----
   dist_X = 80;
   for(i=0; i<=ArrayRange(Timeframe,0)-1; i++)
   {
      if (ObjectFind(Timeframe[i]+"txt") == -1)
      {
         ObjectCreate(Timeframe[i]+"txt", OBJ_LABEL, 0, 0, 0);
         ObjectSet(Timeframe[i]+"txt", OBJPROP_CORNER, 0);
         ObjectSet(Timeframe[i]+"txt", OBJPROP_XDISTANCE, dist_X);
         ObjectSet(Timeframe[i]+"txt", OBJPROP_YDISTANCE, 0);
         ObjectSetText(Timeframe[i]+"txt", Timeframe[i], 9, "Calibri", White);
         dist_X = dist_X+40;     
      }
   }
   
//---- Currency pairs objects ----
   dist_Y = 30;
   for(i=0; i<=ArrayRange(CurrPair,0)-1; i++)
   {
      if (ObjectFind(CurrPair[i]+"txt") == -1)
      {
         ObjectCreate(CurrPair[i]+"txt", OBJ_LABEL, 0, 0, 0);
         ObjectSet(CurrPair[i]+"txt", OBJPROP_CORNER, 0);
         ObjectSet(CurrPair[i]+"txt", OBJPROP_XDISTANCE, 0);
         ObjectSet(CurrPair[i]+"txt", OBJPROP_YDISTANCE, dist_Y);
         ObjectSetText(CurrPair[i]+"txt", CurrPair[i], 9, "Calibri", White);
         dist_Y = dist_Y+17;     
      }
   }
   
//---- Dot matrix ----   
   dist_X=80;
   dist_Y=4;
   for(j=0; j<=ArrayRange(Timeframe,0)-1; j++)
   {
      for(i=0; i<=ArrayRange(CurrPair,0)-1; i++)
      {
         ObjectCreate(CurrPair[i]+Timeframe[j], OBJ_LABEL, 0, 0, 0);
         ObjectSet(CurrPair[i]+Timeframe[j], OBJPROP_CORNER, 0);
         ObjectSet(CurrPair[i]+Timeframe[j], OBJPROP_XDISTANCE, dist_X);
         ObjectSet(CurrPair[i]+Timeframe[j], OBJPROP_YDISTANCE, dist_Y);
         
//-- Conditions --
         PinbarLong =   MathMin(iOpen(CurrPair[i], TimeframeNo[j], 1),iClose(CurrPair[i], TimeframeNo[j], 1))-
                        iLow(CurrPair[i], TimeframeNo[j], 1)
                        >= (iHigh(CurrPair[i], TimeframeNo[j], 1)-iLow(CurrPair[i], TimeframeNo[j], 1))*0.75;
         
         PinbarShort =  iHigh(CurrPair[i], TimeframeNo[j], 1)-
                        MathMax(iOpen(CurrPair[i], TimeframeNo[j], 1),iClose(CurrPair[i], TimeframeNo[j], 1))
                        >= (iHigh(CurrPair[i], TimeframeNo[j], 1)-iLow(CurrPair[i], TimeframeNo[j], 1))*0.75;
         
//--  Alert --          
         if (PinbarLong)
         {
            col=Lime;
            if (Time0 != Time[0])
            {
               Alert(CurrPair[i]+" "+Timeframe[j]+" Pinbar Long");
               Time0 = Time[0];
            }
         }
         else if (PinbarShort)
         {
            col=Red;
            if (Time0 != Time[0])
            {
               Alert(CurrPair[i]+" "+Timeframe[j]+" Pinbar Short");
               Time0 = Time[0];
            }
         }
         else
         {
            col=Gray;
         }
         
//-- Dot Matrix --
         ObjectSetText(CurrPair[i]+Timeframe[j], "-", 35, "Calibri", col);   
         dist_Y = dist_Y+17;
      }
      dist_Y=4;
      dist_X=dist_X+40;     
   }
   WindowRedraw();
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
mar:

Hey Raptor,

yes, it helps. It all makes (logically) sense to me. And I think I have to change NULL to CurrPair[i] and PERIOD_X to TimeframeNo[j] because I need the array-values. Right? Do I have to format M1Bar1Time global or static? I read it pretty often in the MQL4-docs but I still haven't understood for which purposes I need static and global variables. Do I have to set them 0 at the beginning at the code?

I think these are really basic questions but you can see that I still have to learn so much about the structure of MQL4. Therefore, believe it or not, I have absolutely no idea where to implement it into my code. The logic in itself is pretty clear to me but structure and syntax of MQL4 is really difficult for a beginner when you have never coded C.

You can use globals for the datetimes . . . or local statics, a local static means that the variable is only initialised once, not each time the function it is declared in is called.

The best way to learn is to do it, try and try and try again . . . add Print() statements to understand what is happening.
Reason: