"INITIALIZATION EXPECTED".....WTF!! Some one PLEASE help me with this simple crap!

 

All I'm trying to do is make sure my EA only trades once per candle. This is my test code. Just copy and paste this whole thing into a blank EA and tell me what the heck I'm missing. THIS IS REALLY GETTING ON MY LAST FREAKIN NERVE! I'M LOSING HAIR OVER THIS! SOMEONE PLEASE HELP!!!!!

int previousbar = Bars;

int start()
  {   
   if(Bars == previousbar + 1)
   {
      Print("New Bar");
      previousbar++;
   }
   return(0);
  }
 
RJKool:

All I'm trying to do is make sure my EA only trades once per candle. This is my test code. Just copy and paste this whole thing into a blank EA and tell me what the heck I'm missing. THIS IS REALLY GETTING ON MY LAST FREAKIN NERVE! I'M LOSING HAIR OVER THIS! SOMEONE PLEASE HELP!!!!!


Number of bar in charts ->bars is limited by MT4 option. so if bars = maximum bar...you cant' use your code.

try with time[0] like

void start()
{

static int DerniereBarre = 0;
bool NouvelleBarre = false;



if (DerniereBarre == 0) 
   {
   DerniereBarre = Time[0];
   NouvelleBarre = false; 
   } 
   else if (EveryTick==true || DerniereBarre != Time[0]) 
   {
   NouvelleBarre = true;

   DerniereBarre = Time[0]; etc...
 
Matutin:


Number of bar in charts ->bars is limited by MT4 option. so if bars = maximum bar...you cant' use your code.

try with time[0] like


All I want to do is to have the freakin EA print "New Bar" once per candle, and at the begining of the new candle. This code you posted doesn't make since to me. I can't see what you're trying to do here. There's one part of the code that I didn't paste in my original post (because I was to freakin confused and upset to think straight). It's just the first line of code where (int previousbars = Bars - 1;).....Example below.

int previousbar = Bars -1;

int start()
  {   
   if(Bars == previousbar + 1)
   {
      Print("New Bar");
      previousbar++;
   }
   return(0);
  }

For some reason the MetaEditor will not let me assign the "Bars" value to "previousbar" global varible. But if I replace "Bars" with any integer that I type in like (int previousbar = 23 - 1;) it will compile with no errors. This doesn't make any freakin since to me. I have already tried the code useing the "Time[]" function and the same thing happens. Example code below....

datetime previousbar = Time[1];

int start()
{
  if(Time[0] > previousbar)
  {
    Print("New Bar");
    previousbar = Time[0];
  }
}
No matter what I do, it continues to give me the same type of error. All I want to do is to have the freakin EA print "New Bar" once per candle, and at the begining of the new candle.
 

try this...

// Identify new bars
   bool Fun_New_Bar()
      {
      static datetime New_Time = 0;
      bool New_Bar = false;
      if (New_Time!= Time[0])
         {
         New_Time = Time[0];
         New_Bar = true;
         }
      return(New_Bar);
      }
V
 
Viffer:

try this...

V


THANK YOU VIFFER! This is my new test code that identifies new candles and IT WORKS. I should be able to use this in my trading system to prevent multiple trades.

int start()
  {   
   if(Fun_New_Bar() == true)
   {
      Print("New Bar");
   }
   return(0);
  }

// Identify new bars
   bool Fun_New_Bar()
      {
      static datetime New_Time = 0;
      bool New_Bar = false;
      if (New_Time!= Time[0])
         {
         New_Time = Time[0];
         New_Bar = true;
         }
      return(New_Bar);
      }
I intend on useing these lines of code to run trade maintainence to set a new stop-loss at the beginning of each new candle. OH MY FREAKIN GOD....THANK YOU, THANK YOU VIFFER. I've been at this for two whole days.
 

This is what I use it works just fine for me. Your second example looks similar but in my case "timeold" doesn't require initialising because it will never be equal to Time[0] at the start

 static datetime timeold;

      if (timeold!=Time[0]){
         timeold=Time[0];

         //code for each candle goes here

      }
 
RJKool:


THANK YOU VIFFER! This is my new test code that identifies new candles and IT WORKS. I should be able to use this in my trading system to prevent multiple trades.

I intend on useing these lines of code to run trade maintainence to set a new stop-loss at the beginning of each new candle. OH MY FREAKIN GOD....THANK YOU, THANK YOU VIFFER. I've been at this for two whole days.

Loi... I know what it feels like... glad I could help.

V

Reason: