Great clear explanations, even for complete beginners like me. Without great clear explanations like this I wouldn't have found the confidence to start to start learning MT5. Ive scoured the internet and Its extremely hard to get great material for MQL5 learning online, and this stuff is great quality. Each step is well explained for those who have never attempted anything like coding before. Your efforts in providing this material are much appreciated mate, Thank you
Hi Orchard, Thank you very much for the content of your video, we can tell you're passionate about programming, I've just joined your discord, is it possible to have a link to download the code for this video?
Hello professor, many thanks for teaching mql programming. I have a question, why you don't use something like this instead? "if(iVolume(Symbol(), ChartPeriod(0), 0)
I have a question regarding CPU optimization. What I user NewBar() multiple times in an indicator (for different timeframes), and use that indicator on several (lets say 10) windows in the MetaTrader. Maybe I would even have a few MT open. Let's say I kick off my indicator code only on new bar. That means that NewBar() will be tested for every new tick, on every symbol/window in the few MT I have opened. Doesn't that use too much CPU? HOW CAN I OPTIMIZE THAT? Also is there a way to monitor CPU usage or RAM usage by a MT advisor or indicator that I make?
Thank you for this video, however in the OnInit() where the call NewBar(True) is made, the previous_time = 0, is set to D'1970.01.01.00:00:00, that differs with the current_time resulting in returning true. So OnInit() doesn't wait for the candle to finish, it returns true.
When I enter OnInit() the previous_time is set to the current_time and NewBar() returns true, which is correct When I enter OnTick() it picked up a later candle changed previous_time and NewBar() returned true. The 2nd time I enter OnTick(), only then did NewBar() returned false. Now I replayed this a few times and the same results occurred every time. My Strategic Tester is set for 1 week back testing on a EURUSD M30 chart@@OrchardForex
Hi Mr. Orchard, do you freelance code? I have seen your videos and even though I have learned and solved some "basic" problems with my codes I'm still quite newbie in this field.
Hey Professor, Could you give us a lesson on how to get information from MT5 into MT4? Also could you give us some examples how to use "continue" ? Thanks
What sort of information would you want to transfer? Continue is easy, it just goes to the end of the loop and starts the next iteration (or you could say to the beginning, just depends on how you view it). In a for loop it will execute the iterator then go on to the exit condition, in a while loop it goes straight to the exit condition.
@@OrchardForex My Idea was transfer informations from the book of offer built in MT5, so called DOM or Depth Of the Market.. Thanks for your explanation 👍I really get it.
Great video, just curious about declaring static variables.. I noticed in your video you’ve initialised previous_time to 0 in the first call, if initial values are not specified are they by default set at 0?
Hello prof, you can help with a code for searching signal at the birth of a new bar on the current timeframe but if no positions were opened within one hour, signal should be searched at 15M timeframe. also is there a way to make ChartSetSymbolPeriod synchronous as I’ve read it’s asynchronous. Thanks.
Hi, i tried this in order to stop the EA from opening a position in the same candle if another position was closed in that same candle and it worked. However, the EA stopped opening some of the trades it is supposed to. Any suggestion how to fix that?
Great content, just wondering how you will prevent a market close error on the daily timeframe if your broker does swap fee calculations during 23:58 to 00:02? If this new bar function is called for trade openings you will never place a trade due to the market close error, daily new bar being triggered at 00:00
A possible solution I was pondering was to check if your brokers trade session is open using the SymbolInfoSessionTrade() function before running the IsNewBar function and then forcing a new bar calc on timeframes larger or equal to the daily, let's say every 12 hr timeframe...
Meaning a daily will get processed twice a day at 00:00 and 12:00. If your broker does swap fees the 00:00 will get cancelled by the SymbolInfoSessionTrade function calc
There is nothing you can do while the market is closed so the easy way out is to test for closed market in OnTick, even before testing for NewBar, then just return if market is closed.
@@OrchardForex Yes agreed this will stop the market close error, but if a new order only gets executed on a new bar, new bar for the daily is at 00:00, meaning a daily will never place orders... A new bar calc for the daily, weekly and monthly needs to be checked on the 12 hr timeframe for it to work.
If you call NewBar without passing any variable it will not pass the first if statement and will always return without comparing the current and previous time
If you prefer this to my earlier suggestion then that's your choice but for anyone else reading this simple solutions are generally better. I recommend at the beginning of OnTick add one line to test for market open like if (SymbolInfoInteger(Symbol(), SYMBOL_TRADE_MODE) != SYMBOL_TRADE_MODE_FULL) return; bool newBar = NewBar( true ); You can change or add more conditions as you like.
Great clear explanations, even for complete beginners like me. Without great clear explanations like this I wouldn't have found the confidence to start to start learning MT5. Ive scoured the internet and Its extremely hard to get great material for MQL5 learning online, and this stuff is great quality. Each step is well explained for those who have never attempted anything like coding before. Your efforts in providing this material are much appreciated mate, Thank you
Glad it was helpful!
Tnx for video 👍 very useful. I learn new stuff everyday from your videos.
Thank you so much for this wonderful video. Not only great coding but also clear explanation. Thank you
Thank you
Great content as always ❤️
Thank you 🙌
Hi Orchard,
Thank you very much for the content of your video, we can tell you're passionate about programming, I've just joined your discord, is it possible to have a link to download the code for this video?
Hello professor, many thanks for teaching mql programming. I have a question, why you don't use something like this instead? "if(iVolume(Symbol(), ChartPeriod(0), 0)
I have a question regarding CPU optimization.
What I user NewBar() multiple times in an indicator (for different timeframes), and use that indicator on several (lets say 10) windows in the MetaTrader. Maybe I would even have a few MT open.
Let's say I kick off my indicator code only on new bar.
That means that NewBar() will be tested for every new tick, on every symbol/window in the few MT I have opened. Doesn't that use too much CPU?
HOW CAN I OPTIMIZE THAT?
Also is there a way to monitor CPU usage or RAM usage by a MT advisor or indicator that I make?
Thank you for this video, however in the OnInit() where the call NewBar(True) is made, the previous_time = 0, is set to D'1970.01.01.00:00:00, that differs with the current_time resulting in returning true. So OnInit() doesn't wait for the candle to finish, it returns true.
Yes. And what would happen next?
When I enter OnInit() the previous_time is set to the current_time and NewBar() returns true, which is correct
When I enter OnTick() it picked up a later candle changed previous_time and NewBar() returned true.
The 2nd time I enter OnTick(), only then did NewBar() returned false.
Now I replayed this a few times and the same results occurred every time.
My Strategic Tester is set for 1 week back testing on a EURUSD M30 chart@@OrchardForex
It seems that the problem is with the Strategy Tester and not the code, thank you for your instructional videos I have learned quite a lot from them.
Hi Mr. Orchard, do you freelance code? I have seen your videos and even though I have learned and solved some "basic" problems with my codes I'm still quite newbie in this field.
hi thanks for the great contents you provide. can you please show us how to code a simple MT5 copy trader EA. we will appreciate a lot. thanks
Hi Sir i like your video content.Can you please make a video on a robot that use the zig zag indicator
Hey Professor,
Could you give us a lesson on how to get information from MT5 into MT4? Also could you give us some examples how to use "continue" ?
Thanks
What sort of information would you want to transfer? Continue is easy, it just goes to the end of the loop and starts the next iteration (or you could say to the beginning, just depends on how you view it). In a for loop it will execute the iterator then go on to the exit condition, in a while loop it goes straight to the exit condition.
@@OrchardForex My Idea was transfer informations from the book of offer built in MT5, so called DOM or Depth Of the Market..
Thanks for your explanation 👍I really get it.
tnks a lot!
You're welcome
webcam - nice touch
Thank you
Great video, just curious about declaring static variables.. I noticed in your video you’ve initialised previous_time to 0 in the first call, if initial values are not specified are they by default set at 0?
If variables are not initialised they could contain anything that was in that memory space previously.
@@OrchardForex okay thanks for letting me know
Hello prof, you can help with a code for searching signal at the birth of a new bar on the current timeframe but if no positions were opened within one hour, signal should be searched at 15M timeframe.
also is there a way to make ChartSetSymbolPeriod synchronous as I’ve read it’s asynchronous.
Thanks.
I don't have any videos like that. ChartSetSymbolPeriod is async. You will just have to check in a loop for the change.
Hi, i tried this in order to stop the EA from opening a position in the same candle if another position was closed in that same candle and it worked. However, the EA stopped opening some of the trades it is supposed to. Any suggestion how to fix that?
You probably have a strategy that tries to open mid candle. Then this isn't the right approach for you.
Great content, just wondering how you will prevent a market close error on the daily timeframe if your broker does swap fee calculations during 23:58 to 00:02? If this new bar function is called for trade openings you will never place a trade due to the market close error, daily new bar being triggered at 00:00
A possible solution I was pondering was to check if your brokers trade session is open using the SymbolInfoSessionTrade() function before running the IsNewBar function and then forcing a new bar calc on timeframes larger or equal to the daily, let's say every 12 hr timeframe...
Meaning a daily will get processed twice a day at 00:00 and 12:00. If your broker does swap fees the 00:00 will get cancelled by the SymbolInfoSessionTrade function calc
There is nothing you can do while the market is closed so the easy way out is to test for closed market in OnTick, even before testing for NewBar, then just return if market is closed.
@@OrchardForex Yes agreed this will stop the market close error, but if a new order only gets executed on a new bar, new bar for the daily is at 00:00, meaning a daily will never place orders... A new bar calc for the daily, weekly and monthly needs to be checked on the 12 hr timeframe for it to work.
@@shaunbosch2262 No, this works and new orders will be placed as soon as the market opens.
If you call NewBar without passing any variable it will not pass the first if statement and will always return without comparing the current and previous time
That's correct. Call once at the beginning of OnTick passing in true and all other calls pass in nothing.
How can we make HFT EA please
This seems to work for daily market close error, inp_timeframe being an input to the EA
ENUM_DAY_OF_WEEK day_of_week;
//+------------------------------------------------------------------+
//| Function: Execute code only on a new bar, and not every tick |
//+------------------------------------------------------------------+
bool isNewBar(int symbol_loop)
{
return(Trade_Session_Open());
static datetime last_time = 0;
ENUM_TIMEFRAMES timeframe = inp_timeframe;
if(timeframe == PERIOD_D1 || timeframe == PERIOD_W1 || timeframe == PERIOD_MN1)
{
timeframe = PERIOD_H12;
}
datetime lastbar_time = (datetime) SeriesInfoInteger(symbol_array[symbol_loop], timeframe, SERIES_LASTBAR_DATE);
if(last_time != lastbar_time)
{
last_time = lastbar_time;
return(true);
}
return(false);
}
//+------------------------------------------------------------------+
//| Function: Check if trade session is open and excl. Sat and Sun |
//+------------------------------------------------------------------+
bool Trade_Session_Open()
{
datetime time_now = TimeCurrent();
MqlDateTime time;
TimeToStruct(time_now, time);
uint week_day_now = time.day_of_week;
uint seconds_now = (time.hour * 3600) + (time.min * 60) + time.sec;
if(week_day_now == 0)
day_of_week = SUNDAY;
if(week_day_now == 1)
day_of_week = MONDAY;
if(week_day_now == 2)
day_of_week = TUESDAY;
if(week_day_now == 3)
day_of_week = WEDNESDAY;
if(week_day_now == 4)
day_of_week = THURSDAY;
if(week_day_now == 5)
day_of_week = FRIDAY;
if(week_day_now == 6)
day_of_week = SATURDAY;
datetime from, to;
uint session = 0;
while(SymbolInfoSessionTrade(_Symbol, day_of_week, session, from, to))
{
session++;
}
uint trade_session_open_seconds = uint(from) + 60;
uint trade_session_close_seconds = uint(to) - 60;
if(trade_session_open_seconds < seconds_now && trade_session_close_seconds > seconds_now && week_day_now >= 1 && week_day_now
If you prefer this to my earlier suggestion then that's your choice but for anyone else reading this simple solutions are generally better. I recommend at the beginning of OnTick add one line to test for market open like
if (SymbolInfoInteger(Symbol(), SYMBOL_TRADE_MODE) != SYMBOL_TRADE_MODE_FULL) return;
bool newBar = NewBar( true );
You can change or add more conditions as you like.
Thanks 👌🏻
@@OrchardForex Much simpler solution and works great thank you very much