- Closing a trader at close of the corrente bar
- Indicator alert showing different result
- Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes
-
So do it. Bar ends at Time[0] + PeriodSeconds().
- You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
No free help 2017.04.21Or pay someone. Top of every page is the link Freelance.
Hiring to write script - General - MQL5 programming forum 2018.05.12We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
No free help 2017.04.21
I have coded an ea that trades at the close of the current candle. However my system is traded on the daily chart. The spreads are much higher at the open of a new bar. Therefore I would like to perform all my trading actions before the candle closes.
You can adapt this code to your own Expert program.
double i; int m,s,k; m=Time[0]+Period()*60-CurTime(); i=m/60.0; s=m%60; m=(m-m%60)/60; Comment( m + " minutes " + s + " seconds left to bar end"); if(m==50) // Time to Bar Closing { // Your Open Codes.. }
You can adapt this code to your own Expert program.
Why didn't you use PeriodSeconds() like William did?
m=Time[0]+Period()*60-CurTime();
This does not work for MQL5.
William Roeder
You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
Agree. Please provide a sample of your code.
-
So do it. Bar ends at Time[0] + PeriodSeconds().
- You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
No free help 2017.04.21Or pay someone. Top of every page is the link Freelance.
Hiring to write script - General - MQL5 programming forum 2018.05.12We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
No free help 2017.04.21
i thought it would be a simple solution thats only a couple of lines of code so someone would be glad to help me out. But i will share my attempt
I have coded an ea that trades at the close of the current candle. However my system is traded on the daily chart. The spreads are much higher at the open of a new bar. Therefore I would like to perform all my trading actions before the candle closes.
Please let me be some sort of intrusive on your idea.
A better idea, would be you check the spread values, since you want to avoid high spreads which happens on the end of the day.
Check the spread of the previous candles, on a timeframe inferior than D1. Calculate a median/average value for reference.. act on the current D1 candle Zero as usual, and only make operations if the spread is about the same median/average values you have calculated. (E.g.: If spread is like about 40% above the average spread values, do not let the EA place orders.. etc..)
It is more guaranteed this way, than work based on time, time of the candle, since the broker has no default for increasing the spread.. it is a decision at the broker will, at any time.
Please let me be some sort of intrusive on your idea.
A better idea, would be you check the spread values, since you want to avoid high spreads which happens on the end of the day.
Check the spread of the previous candles, on a timeframe inferior than D1. Calculate a median/average value for reference.. act on the current D1 candle Zero as usual, and only make operations if the spread is about the same median/average values you have calculated. (E.g.: If spread is like about 40% above the average spread values, do not let the EA place orders.. etc..)
It is more guaranteed this way, than work based on time, time of the candle, since the broker has no default for increasing the spread.. it is a decision at the broker will, at any time.
Interesting idea, thanks :D
input string tradetime = "23:50:00"; //Trade Entry Time void OnTick() { datetime time_current = TimeCurrent(); if(time_current = tradetime) { OnBar(); //OnBar = function to check indicators and enter trade }The OnBar function should be called once every day at 23:50:00
But it is being called every twenty minutes when i test the EA
-
So do it. Bar ends at Time[0] + PeriodSeconds().
- You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
No free help 2017.04.21Or pay someone. Top of every page is the link Freelance.
Hiring to write script - General - MQL5 programming forum 2018.05.12We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
No free help 2017.04.21
input string tradetime = "23:50:00"; //Trade Entry Time void OnTick() { datetime time_current = TimeCurrent(); if(time_current = tradetime) { OnBar(); //OnBar = function to check indicators and enter trade }The OnBar function should be called once every day at 23:50:00
But it is being called every twenty minutes when i test the EA
here is my attempt The OnBar function should be called once every day at 23:50:00
But it is being called every twenty minutes when i test the EA
You cannot compare TYPE string to TYPE datetime
Compare different data TYPE is possible only in Perl language ;)
Documentation about how to compare datetime is below:
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use