| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| My shell EA code https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=79 |
Page 1 of 23 |
| Author: | SteveHopwood [ Wed Nov 23, 2011 11:56 pm ] |
| Post subject: | My shell EA code |
This thread does not offer a, "Create your own EA instantly" shell. You cannot use my shells if you are not already a proficient CrapQl4 coder. It offers the shells that I use to create trading robots quickly and easily. Studying them also means that you can read my EA code more easily; you can adapt my code more quickly to your own ends once you understand my coding style. Note that I only ever use: Bare Bones; Bob Stuff; Bugger All Included versions with and without all the gridding/hedging/offsetting paraphernalia. All the developments I have added apply to these only. Bare Bones is not much of a bare bones any more, but does contain the stuff that I automatically add to all the EA's I code so the user has the choice of using them or not. There are a lot of useful functions in 'Shell auto trading robot code by Steve Hopwood.mq4' that I dip into and copy as and when needed, but never use it to create an auto-trader. Attached are the latest EA shells I use to create the trading robots I code. You will find them in the "Shell codes updated 9th Dec 2017.zip". Previous versions of the shells are in the "Shell codes.zip" file. Instructions for use are included early on in the code. You strip out what you do not want and add any extras that you do want. I have posted a tutorial describing how to add indicator calls to my shells - http://www.stevehopwoodforex.com/phpBB3 ... =50&t=4519 Have a read if you are unsure. I am not claiming to be some sort of coding genius. Far from it; there are professional coders here whose work makes me look silly. I am a pianist who has learned to code in pursuit of some wealth to make up for the wealth I do not derive from the job I love so much. En route, I have picked up a few coding skills that I offer to anyone who can make use of them. Advice I offer to beginner coders is:
Feel free to use the code here in any way that suits you, so long as you distribute your code free of charge to the users. Charge for using it, and I will sue the socks off you. The code contains substantial contributions from a number of other coders; they will not be happy to discover you selling this stuff commercially. Coding the trading decision [*]void ReadIndicatorValues() contains calls to indicator reading functions, then sets BuySignal/SellSignal to 'true' when trading conditions are met. [*]void LookForTradingOpportunities() sends the trade if there is a trade signal. Here is where I put extra conditions that are not easily accommodated by ReadIndicatorValues().
I have gradually refined void LookForTradingOpportunities() so it is really easy to code the trade trigger. SendLong and SendShort are initially set to 'false', then turned to 'true' if all the trade conditionals succeed. To avoid the new EA sending a buy immediately you load it onto a chart and before adding the individual system's conditionals, I have added this just after cycling through the conditionals: Code: Select all Closing/modifying/deleting trades There are two multi-purpose functions to deal with the usual OrderModify(), OrderDelete() and OrderClose() functions:
For example, CloseBasketTrades() has this call: Code: Select all Code: Select all Example of ModifyOrder() for moving the stop loss: Code: Select all Matt's Order Reliable code It seems that the latest garbage from those cretins at Crapperquotes occasionally breaks Matts's code. I have added an extra layer of security. PostTradeAttemptWaitMinutes and its partner TimeToStartTrading are in the hidden variables of the General Inputs section. The shells will set TimeToStartTrading = TimeCurrent() + (PostTradeAttemptWaitMinutes * 60); when there is a OrderSend() attempt, regardless of whether OR has picked up a receipt return from the broker's server. The snippet of code that calls LookForTradingOpportunities() includes a check that TimeCurrent() is >= TimeToStartTrading. Bare bones version This has all the additional stuff removed; use this when you know you will not need it. Bare bones with Recovery This has Nanningbob's Recovery added. Bugger all included This has nothing not actually needed for trading apart from: stealth; trading hours; average spread calculation. Bob stuff version Includes: SuperSlope, HGI and the H4 240 MA trend detection. Retro-fitting Slope This contains the code and information you need to add Slope to an existing EA. 'Rogue' trades and the safety features Sometimes a concatenation of unexpected combination of inputs plus a bit of coding logic failure creates a sequence of trades that open and close immediately - often only a tick apart. What is happening is this:
For convenience, I have elected to call these trades 'rogue' trades. Whenever I refer to rogue trades, I am discussing those I just described. We need to hunt down and correct the code/logic that is causing the behaviour, but this might not manifest itself immediately. A number of us had been using Flying Slope for a few weeks before one of our members hit on just the combination of input choice and my faulty algorithm to produce a sequence of rogues, through no fault of his own. We need to prevent this from draining an unsupervised account. I have introduced some safety features:
This is a user guide template that you can use to quickly create a user guide if you want to release your EA here at SHF. It contains a brief description of most of the EA functions, so you remove those you do not want and add in anything new. Inside the zip is the Open Office document that you can edit to produce your own pdf. OpenOffice is freeware and every bit as good as any of its paid-for rivals. Download it from http://www.openoffice.org/ Enhanced chart feedback lifesys (Paul) sent me the code to display text in user-adjustable labels instead of the near-useless CrapTx Comment(). Fantastic, Paul; thanks from all of us. Another approach Mahmut is taking a slightly different approach to all this and has posted what he is getting up to at http://www.stevehopwoodforex.com/phpBB3 ... 7762#p7762 Try his approach and see if it suits you better; Mahmut is an exceptionally clever programmer.. And another approach fxdytrader has put this at http://www.stevehopwoodforex.com/phpBB3 ... 966#p32966 Private EA coding I receive may requests to code EA's. I will do so free of charge so long as I am able to share the EA and trading system here. Most of what I have learned to do as a coder, I have learned from contributors here. Sharing my work with them is my way of giving back in return for what I have gained. Having said that, I need to have some interest in the project to take it on; a period of successful live trading with the system guarantees my interest. If you are unable to persuade me to code your EA for free and for sharing here, then you will have to pay me for the work at the rate I quote in the next paragraph. I will also code EA's for traders who want their EA kept private. For this, I charge a fee of $100 payable into my Paypal account. I charge so little because I am not a professional programmer. EA's I code for you will have bugs that we will have to hunt down and eradicate. I may easily misunderstand the brief that you send me. I shall need your patience as I work towards the difference between what I think you have asked for, and what you have actually asked for. Should you need a more professional programmer, then contact renexxxx. He will charge a lot more but will send you code that is an accurate and bug-free representation of your brief. |
|
| Author: | SteveHopwood [ Wed Nov 23, 2011 11:59 pm ] |
| Post subject: | Oops |
Sorry about the disappeared posts from the original thread, I managed to delete the entire thread a few minutes ago. If I had a firing brain cell, I would be unstoppably lethal. |
|
| Author: | SteveHopwood [ Thu Nov 24, 2011 11:12 am ] |
| Post subject: | Re: My shell EA code |
Latest update in post 1, again courtesy of TIG (The Invaluable George). George made the obvious suggestion of solving the mptm features only kicking in when HiddenPips > 0, is to remove the stipulation in CountOpenTrades() that HP must be >0 before drawing the tp/sl lines. Obvious to him, that is, not to me. He also suggested a pretty cool way of working out when the stops need moving in the jumping/trailing stop functions; I have commented them so you know which ones belong to George. In making these changes, I noticed that the stop line is moved to reflect the new stop, not the new stop +- HiddenPips/ I shall alter this later. |
|
| Author: | gaheitman [ Thu Nov 24, 2011 2:23 pm ] |
| Post subject: | Restricted Currency Direction |
Steve, I'd like to offer up the following as a possible addition to the shell code to allow for restricting trading by currency to a set direction. You already have this for single currency bots, but not for multi-currency ones. In short, the code is modeled after your TradeDirectionBySwap() code and is intended to be called after TradeDirectionBySwap() in the IsTradingAllowed() function. It uses two extern variables to hold a list of currencies to only trade long or only trade short. The code compares the long side of the TradePair against the two lists and sets TradeLong and TradeShort accordingly. It then does the same with the short side, inverting the meaning since it is the short side of the pair. Here are the proposed additions as they would appear in the code. Additions to Extern variables: Code: Select all Code: Select all Code: Select all Code: Select all Now, I'm off to find some Turkey! George |
|
| Author: | SteveHopwood [ Sat Nov 26, 2011 4:22 pm ] |
| Post subject: | Re: My shell EA code |
George, I am not ignoring your recent post and will act on this at some point soon. Latest update in post 1 guys. In preparation for forexpippy EA, I have added risk-based lot sizing. |
|
| Author: | SteveHopwood [ Sat Nov 26, 2011 6:16 pm ] |
| Post subject: | Re: My shell EA code |
One more update, in the spirit of tightening up the code. I have changed 'trend' to 'OverallTrend' and added separate trend variables to all the other trend detection code - RsiTrend, AaTrend etc. TrendDetectionModule() then sets up each of the individual trends. We then combine them in whatever combination the system requires, into OverallTrend; this is then used in the trading decision. |
|
| Author: | magft [ Sun Nov 27, 2011 10:51 pm ] |
| Post subject: | Re: My shell EA code |
Steve I have done an update to the time checking routine to allow the times to be specified as 00:00 format. The attached script should help show the method, though i haven't fully tested for our down under associates. Mike |
|
| Author: | youcrazykids [ Mon Nov 28, 2011 6:29 pm ] |
| Post subject: | Re: My shell EA code |
Hi all Although nothing startling, I've found a way of displaying comments and screen messages, without them being obscured by bars on the chart. To do this, in the init() function, I add two text labels to the chart, at coordinates 0,0. The Webdings character set contains a solid block, which you can scale up to 150pts, to create a "box". So, a couple of these stacked vertically, then coloured black, does the trick. The comment text sits atop these, and they both stay fixed relative to the window, not the scrolling chart. Here's the code, and a screenshot. Feel free to adopt/adapt/ridicule it as you wish Code: Select all youcrazykids[/size] |
|
| Author: | SteveHopwood [ Mon Nov 28, 2011 6:42 pm ] |
| Post subject: | Re: My shell EA code |
youcrazykids, no way am I going to ridicule this. Thanks. I shall look at it and perhaps adopt it. Mike, sorry but I only saw your latest when looking at yck's post; I missed it when you posted it. Does the code work for our cousins in upside-down land? Cheers guys |
|
| Author: | magft [ Tue Nov 29, 2011 11:32 am ] |
| Post subject: | Re: My shell EA code |
George has posted a much cleaner version that seems to work on my Fratelli EA thread so i'm posting the script here for your thoughts. |
|
| All times are UTC | Page 1 of 23 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|