| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| MQL questions https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=237 |
Page 2 of 2 |
| Author: | gaheitman [ Thu Jan 12, 2012 5:20 pm ] |
| Post subject: | Re: MQL questions |
Since this is a coding question, I thought it might be fun to evolve a simple OCO EA in the forum. Below is the beginning of code that might one day handle all your OCO needs.... In a nutshell, all it does is this:
It is, of course, completely untested. I thought we should agree on what it should do before testing. Code: Select all |
|
| Author: | gaheitman [ Thu Jan 12, 2012 5:33 pm ] |
| Post subject: | Re: MQL questions |
Actually, it may be the call to IsTradeAllowed( ) at the end of the main loop. What I think that means is if any other script/ea is trading on that platform at the moment the function is called, the script will just end. I doubt it was what the original author intended. I think you should just delete the IsTradeAllowed() call from the conditional and see what we get tomorrow. Were the arrows gone? That code would still have been called. George |
|
| Author: | garyfritz [ Thu Jan 12, 2012 5:40 pm ] |
| Post subject: | Re: MQL questions |
Yes, I think the arrows were gone. I know they got deleted when I tested Alt-X. I was wondering if it was a timing issue too. Seems unlikely to happen 2 out of 3 times, though. |
|
| Author: | garyfritz [ Tue Jan 24, 2012 5:50 pm ] |
| Post subject: | Re: MQL questions |
George, I know you don't have anything else to do I used the OCO script for two trades yesterday. This time the long properly canceled its corresponding sell, but the short didn't cancel the corresponding buy! Which I think is opposite to what I saw before?? I'd like to get this working reliably, and ideally I'd like to see it in an EA. I have some enhancements I'd like to add but I can do that once we have a working EA. If you get a moment... |
|
| Author: | gaheitman [ Tue Jan 24, 2012 8:55 pm ] |
| Post subject: | Re: MQL questions |
OK, you talked me into it. Here is a version that doesn't care about MagicNumbers, it just looks for a buy and a sell on the same pair of whatever chart it is on. It tells you what it is doing in the comment field. You can temporarily stop monitoring by changing the extern StopMonitoring variable to false. If the program detects that there is an invalid pair it will turn off monitoring and send an alert. If it detects any open tickets, it closes all pendings. I tried to have it just check every minute, but I didn't like the delay, so it checks every tick. We can add that back if you are certain one minute in between is enough. I can also write something to wait a specified number of milliseconds. Test away, and let me know what you find. George |
|
| Author: | garyfritz [ Tue Jan 24, 2012 9:43 pm ] |
| Post subject: | Re: MQL questions |
Thanks, George! OK, so this EA waits for 2 orders to be placed (by something/someone else), then it manages those two. If I felt lazy and didn't want to place the orders manually, I imagine I could modify the OCO script you wrote before to create those orders, and just disable the order-monitoring part of the script. I'll give it a try. Now I need to expand this to a full EA, which opens the orders for this beastie to manage. Would you recommend doing it in minimal style like you did here, or do I need to use the full Steve EA Shell to handle orders &etc properly? |
|
| Author: | gaheitman [ Tue Jan 24, 2012 10:13 pm ] |
| Post subject: | Re: MQL questions |
As of now, we don't have the code to calculate whether to take a trade or not, that's all still coming from you. It would not be a big deal to modify what we have to allow you to enter a buy price and sell price for the two orders. It could place them for you so you wouldn't have to deal with the other script. Then you'd only have to drop the EA on a pair you intended to trade. It would do the rest. What is the post-open management logic that you use? George |
|
| Author: | garyfritz [ Wed Jan 25, 2012 2:16 am ] |
| Post subject: | Re: MQL questions |
Almost none. I wait for it to hit the TP or SL, or close it if it hasn't hit either one by 4:30pm ET the next day. Never had any luck improving on it with intraday fussing so I just let it run. The logic I use is pretty fully explained in this post. Only minor addition I can think of is that I want to specify a trading window. So e.g. I would still use the 5pmET - 5pmET H/L for my breakout prices, but I might not place the orders until 7pm ET. If the market exceeds the breakout prices before I place the orders, cancel trades for the day; otherwise place the orders at 7pm. Cancel the pending orders at 3am if they haven't been hit yet; if one or the other has been hit, then let the trade run to the TP/SL or until we close trades at 4:30pm ET. |
|
| All times are UTC | Page 2 of 2 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|