Using the OnTrade event in MQL4
Вставка
- Опубліковано 17 вер 2024
- MQL5 includes an OnTrade event that fires when a trade change happens. This code will show you how to implement something similar in MQL4
Downloading the code
The code shown in the video is available to our premium discord members. Premium membership is a monthly subscription. To join our discord server and download this and other code
orchardforex.c...
Free downloads for Metatrader 4 and 5
MT4: www.orchardfor...
MT5: www.orchardfor...
Follow our regular market updates:
Web: www.orchardfor...
Twitter: / orchardforex
Facebook: / orchardforex-327549444...
Telegram: t.me/orchardforex
Discord: / discord
Amazing video! Waiting for the part 2 where you explain how the class can return to the user an information about what parameters changed (stop loss, new trade etc).
Another great video, I love how you delve into advanced concepts.
Thank you
25:50 Yes, I would like You to create a follow-up video showing more functionality of the StartScan. Thank You for a present video, very useful.
As usual, thank you. Very educating content.
Very good subject
Dying to see the next step: extracting changes.
And how you will manage a situation where N orders placed on other instruments are executed
How you will retrieve and sort the events
You probably want this. ua-cam.com/video/T0IcIIVaMT8/v-deo.html
Thanks. Excellent info!
Glad it was helpful!
Very nice tutorial! Just a short question. Since, as you mentioned, the OnTick function only fires the scan if there actually is a tick, it can lead to delays. How about a bool variable "running" set to true in OnInit and false in OnDeinit and a while(running) loop in the OnTick Function with a call of Sleep(100) at the end of the loop. So the scan would be fired every 100ms. May this removes the delay?
Is there a corresponding ontrade video for MT5?I could not find any
Thank you
thanks sir.
BEAUTIFULL:)
HI, very nice video.
i have replicated the content and i get message windows Something Happened. How i can show content of the operation i made ?
Thank's a lot
I can't help without full detail of the error. If this is a windows error then you may have a problem with your MT installation. If not then you should include the actual error message from MT. All I can suggest is to remove code and see what happens, then add code back gradually until you find the problem.
@@OrchardForex
No the question is not related to an error. Like in your example I get the correct message box with something happen. So is working. The question was … how I can get the detailed operation I made in mt4 for example in that message box or with a print.
Always thanks for you answer
@@00GRILL The id argument is the code for the event that triggered the OnChartEvent. sparam is the name of the object involved. You have to work out the details from there.
Thanks for the tutorial. In MT4 I receive an error message by dropping the EA on the chart: OnTradeTest EURUSD,M5: incorrect start position 0 for ArraySort function. Thanks for help.
I found the reason by myself. The Error appears if there is no order available. OrdersTotal() is 0! A simple if-statement before filling the array fixes the issue.
A following video would be great!
The error doesn't stop the EA running. There is already a follow up video but not about this. Sorry about the first response, I had a trade and didn't notice.
Thanks a lot Sir, better a 100 lot ;), I was wondering if in qml4 is possible to Drag a Button by only holding click. and not like the way 2click select drag of the ornidary objects(lines etc)
I've nver done this but you could try detecting the mouse down event and mouse release and just move the button in code. The double click is only there to first select the object, avoids accidental changes that way, so you could also just programatically make your objects already selected.
Great Stuff.. Would you like to give me example what we can achieve onTrade event
You would probably use this to manage trades, for example to take action when a stop order converts to a trade or when a take profit or stop loss is hit.
If I made EA which opens a buy position like at 2 and stop loss 1 , if the candle do a rapid pull down and hit stop loss and drag it to the end of candle and increase it, how can I write extra code to enforce the stop loss not to be moved down or dragged down in anyway during rapid pulldown
In short you can't. As a not recommended option you would have to not use the stop loss but instead write your own code to close the trade and set slippage to prevent the price moving too far. But this does not force the trade to close where you want it. If the price moves past the allowed slippage the trade is simply not closed and you are left with a losing trade.