
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Please open a demo account on MetaQuotes-Demo server.
After this your terminal will update to the newest version that allows the use of these functions.
Wait, I declared iTime function, as the code I read had done so.
so I don't need to declare these functions ? (MT5 , build 1870)
There can be a conflict when your terminal updates, besides the proposed function isn't correct the one you show is already one that is part of the new beta.
Please read here about the new function being added: https://www.mql5.com/en/forum/257568
Here is a dirty fix that uses the CopyClose method:
This one should work for you.
But you might want to add trailing or some other whistles and bells..
You know, add some magic.
I downloaded the latest version of MetaTrader 5 and it works. I have been testing the strategy, and I have found that it doesn't work exactly like it should. For example, in the attached pic, you can see the trades are being executed at different hours of the day. Since this strategy acts exactly at the time the day finishes, all the trades should be executed at the same time, which should be around 23:00 hour (Madrid GMT). I have been through the code but I didn't find anything that could explain this. Would it be possible for you to have a look Marco?
Thanks!
Well you did not specify that anywhere.
You said and i quote:
Now understand that the daily close is equal to the bid price for the entire day, until the candle closes.
This means that if somewhere, during the day, the bid price goes either over A or below B, there will be a swap in direction.
So as a result you need to specifically state that it may only trigger upon a new candle arrival.
Luckily this can be achieved by adding a few lines of code.
Thank you very much Marco. Sorry for the misunderstanding, I thought that "when daily close is above a" clearly indicated that the trade would only be executed when the daily candle close (which represents the last value of the day) was above a (which was the maximum of the previous 20 daily candles close). I am glad that now it is clear :)
I have been testing your code and it seems to work quite well. I decided to take it to my Oanda real account, and I found out that Oanda doesn't support MT5. Now I have the following options:
- Change to a broker that supports MT5
- Try to develop a similar code in MT4 (which is supported by Oanda)
- Try to develop a similar code in Oanda Algorithm Lab (which is powered by QuanConnect)
Since you have helped me so much, I am going to ask for your advice again :)
Thanks!
*If you are happy with your current broker i would stick with them.
*It's not hard to convert this code to MQL4.
*I don't know Oanda Algo but i know that it can sometimes be hard to replicate certain things in other platforms.
On another note this Version 4 can still be improved think about adding a trailingstop and for example dynamic lotsizing to maximize profits.
I coded this thing because your strategy lack's the use of indicator's which makes it very special.
*If you are happy with your current broker i would stick with them.
*It's not hard to convert this code to MQL4.
*I don't know Oanda Algo but i know that it can sometimes be hard to replicate certain things in other platforms.
On another note this Version 4 can still be improved think about adding a trailingstop and for example dynamic lotsizing to maximize profits.
I coded this thing because your strategy lack's the use of indicator's which makes it very special.
Thanks for your reply Marco, I agree on the fact that if I am happy with my broker, I should stick with them.
Regarding the trailingstop, I did many simulations in Trading View with different variations of the strategy, including setting take profits, setting trailingstops, varying the number of days taken into account for the trade decision, etc. And this was the most profitable version based on historical data. That's why I am trying to implement it with auto trading.
I also simulated other strategies, many of them with indicators, and no one of them had the profitability of this strategy. It looks like sometimes simpler is better.
I know I have asked you a lot already, but I am not sure if it would be possible for you to code this strategy in MQL4?
Again, thanks a lot.
Yes but i have some more tasks too i will try to find a spare minute.
Alright here you go.
I wrote it rather quickly so there are no checks for min and max levels.
Consider it pseudocode, if you really want it rock solid it will need some additional work.
I did a quick test with default settings TP=0 SL=0;
MT4:
In any case as with the previous one it needs dynamic lotsizing to boost performance.
Here is the result for the MT5 version:
As you can see very similar results.
jaja, I love the no indicators pic :D
I have been checking the results obtained with your code (MT4 one), and I am afraid the code is not working 100% as per the strategy guidelines. For example, on the pic attached, you can see how the bar circled in red (4 April 2018) should have been the signal to close current short trade and open a long one, since its close is above the close of the previous 20 daily bars (you can easily check it on the graph). That means that there should be a buy order on the opening on the next daily candle (5 April 2018), but as you can see on the results, the buy order was filled on 16th April 2018, several days later.
Would it be possible for you to have a look and let me know?
Thanks again for all your help!