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...
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
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 }
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.
Loi... I know what it feels like... glad I could help.
V
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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!!!!!