| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| My shell EA code https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=79 |
Page 4 of 23 |
| Author: | gaheitman [ Fri Dec 09, 2011 9:36 pm ] |
| Post subject: | Re: My shell EA code |
I think that's a valid suggestion. One of the turtles books I read said that getting out of a trade after x amount of time was better than waiting for some other signal. If you want to close individual trades after x minutes of being open, that's a change to "LookForTradeClosure()". If you want to stop all trading x minutes after the first trade of the day is triggered, that could easily be added to the StrategyDoneForTheDay() procedure that I'll be calling. George |
|
| Author: | gaheitman [ Sun Dec 11, 2011 9:38 am ] |
| Post subject: | DoneForTheDay() |
A couple of concepts that need explaining. The procedure is based on the concept of a "Trading Day" as defined by the trader or strategy. The user will set a Reset Time (hh:mm) which acts as the beginning of the trading day. The procedure keeps track of the beginning and ending of the current trading day based on the reset time. For example, if it is 2011-12-07 14:00 (server time) and the reset time is 13:00, the procedure will consider the trading day to have just begun an hour earlier and last for another 23 hours. Mondays and Fridays are a special case in that the trading day can possibly span the weekend. The calculation looks for the previous/next trading day. At the start of a Trading Day, the procedure captures the current account balance for use in percent changes to the account. In the case when the EA isn't actually watching at the time of the Trading Day start, account balance will be calculated by taking the then current account balance and subtracting the OrderProfit() value for trades that closed after the daily reset. This subtraction is done without concern for MagicNumber or Symbol settings and ignores any open trades. The DFTDUseEquity setting only impacts the calculation of balance gain/loss, pip gain/loss and percent gain/loss. Winning/Losing/Max trades must be closed trades. The action DFTDUseTightStop currently just turns on TrailingStops. You will need to set the appropriate stop in the original setting for TrailingStops. All the *Loss settings expect you to enter the values as positive numbers. You "lose 80 pips", you don't "lose -80 pips". For the ADR test, the daily range that is being compared to the calculated ADR is the range of the actual D1 bar that we are on, not the Trading Day defined by the Reset Time. I did it this way because the market is looking at the daily bar, and doesn't care about your trading day. Instead of using bool variables to determine if we want to use one of the specific criterion, it just checks for non-zero values. So if you set it to something, it will use it. There is an overall setting to use DoneForTheDay(), bool UseDoneForTheDay, for when it is called in IsTradingAllowed() It's also important to note that much of the logic in the procedure depends on the trade history covering the trading day. If the trades don't appear in the trading history, the procedure can't know about them and won't act on them. This is of particular importance at the change of a day/week/month since those are common history filter settings. I have added a blank procedure StrategyDoneForTheDay() that is called at the end of DoneForTheDay() to allow for a non-generic test. It currently just returns false. For the coders out there, I've added a new procedure called SaveOrder() which saves the current selected order as well as the TicketNo. It looks like this. Code: Select all I also added code to calculate the ADR. It is: Code: Select all OK, the actual code to calculate DoneForTheDay() is attached. I have not yet written the notification code, so the only options when you are done for the day is to close all orders, close all pending orders, and/or turn on trailing stops. I tried to make the code as insulated as possible so that it would be easier to add to existing bots. That being said, I'm not happy with the information we can get from it in it's current state. For example, I would like to be able to report in DisplayUserFeedback() why we have stopped and when we will be restarting. Anyhow, I was able to test various scenarios last week while the market was still open, but I am sure there are some bugs left in there. No doubt some very obvious ones that I can't see because I typed them in. I will continue to test this week and will update any fixes I make. Please take a look at the code and let me know if anything jumps out. If you'd like to try things out in DEMO or Strategy Tester, feel free. I would not use it in live, however. George |
|
| Author: | dietcoke [ Sun Dec 11, 2011 1:52 pm ] |
| Post subject: | Re: My shell EA code |
Super stuff George. I noticed one thing in the ADR function. Code: Select all day+1+offset Should it not be offset+1-day? Can you think of a good way to, incorporate Sunday stub bars into Mondays range(if outside?) into this function. |
|
| Author: | rbetancor [ Sun Dec 11, 2011 3:30 pm ] |
| Post subject: | NewBar MTF version |
Hi all, maybe this function could be usefull to someone else apart from me It's the 'typical' NewBar function, but adapted to be MTF. Code: Select all |
|
| Author: | gaheitman [ Sun Dec 11, 2011 6:17 pm ] |
| Post subject: | Re: My shell EA code |
I lifted this code from the PriceTrap indicator I wrote a few days ago, so it is a generalized function and can calculate the ADR for any bar. The code actually counts away from the current price since we don't know if we have Sunday bars or not. Offset doesn't change like it would in an indicator, and in the EA it will always be zero (and it should be outside of the main loop, but I missed that). We add the +1 because we have to take the calculation from the previous day, or we would be including today's data which is unfinished. So, ignoring offset, we are counting backwards one day at a time. If it isn't a Sunday, we increment cnt and stop once cnt is equal to Days. We could add the Sunday data to Monday without much trouble. I'm not sure how much it would change the calculation. George |
|
| Author: | AnotherBrian [ Wed Dec 21, 2011 3:53 am ] |
| Post subject: | Re: My shell EA code |
I read Steve`s posts and I find my self imaging how he sounds with the accent (I know Steve, I`m the one with the accent...) and I can`t focus any longer.... f`n funny...but at the same time not so funny.... and again, don`t hold back now!!! |
|
| Author: | SteveHopwood [ Wed Dec 21, 2011 10:52 pm ] |
| Post subject: | Re: My shell EA code |
Latest update in post 1. I have made the adjustments to the JS/RS functions that TIG highlighted in our Gday thread, and reintroduced AddBEP to the JS function. |
|
| Author: | SteveHopwood [ Sun Jan 01, 2012 9:27 pm ] |
| Post subject: | Re: My shell EA code |
Trader Posts: 411 Joined: Wed Nov 16, 2011 7:22 am Location: An insignificant village in England PostPosted: Sat Dec 31, 2011 7:54 pm Latest update in post 1. I have added an Atr function for sl/tp. To save effort further down the line, this meant creating separate tp/sl calculation functions that are called from within LookForTradingOpps and InsertMissingxxxx I added the sl/tp calculation function calls to HasBuy/SellFilled. I decided to update the volatility calculator by leaving out the Saturday/Sunday candles. I got into a terrific tangle, then realised I was probably re-inventing the wheel. I have replaced the calculation loop with a call to ATR and used the existing multiplier to turn the result into more easily recognisable pips. One or two other bits and bats, including enforcing BreakEven if JS/TS are used. |
|
| Author: | gaheitman [ Tue Jan 17, 2012 9:48 am ] |
| Post subject: | Common Errors |
I've been working on a function to call at the beginning of Init() to look for common errors that we've run in to when deploying new EAs. Currently it checks for the following:
Code: Select all |
|
| Author: | magft [ Tue Jan 17, 2012 11:05 am ] |
| Post subject: | Re: My shell EA code |
George great bit of work. One thing i notice is if a StopLoss or TakeProfit value is set and it is below the broker stop level you get error 130 invalid stop errors so would be good to check. Maybe check the other trade management values if set to true make sure no zero values, your basically adding error checking Steve left out to stop noobs doing silly things. I think it is a good idea to keep building this excellent routines but maybe add to the Shell EA but name it different and add them all in in, like DFTD and checktrading times or see if Steve is happy to have it updated as you have done some great work. Mike |
|
| All times are UTC | Page 4 of 23 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|