| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Utility Procedures / Code Snippets https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=166 |
Page 3 of 7 |
| Author: | gaheitman [ Sat Feb 04, 2012 11:34 am ] |
| Post subject: | More Looping Considerations |
The standard for loop looks something like this: Code: Select all When using these functions, it is common to include them in the for loop expressions, either in the initialization section or the conditional test. For example, to iterate over an array, we could do either Code: Select all The other concern is that sometimes the activity within the loop can change the number of items being iterated over. Deleting objects and closing orders comes to mind. In these cases, it's easy to miss out on evaluating items. Of course, if you are deleting items you should iterate over the list in reverse order anyway (but that's another post). I recommend capturing the number of items you intend to iterate over into a temporary variable before the iteration. It should be faster and will likely have less troublesome bugs to track down. Though there may be valid reasons to use a function call within the for loop's conditional expression, personally I think the code would be more readable if you structure the loop as a while loop instead of a for loop. George |
|
| Author: | Tommy [ Thu Feb 23, 2012 5:43 am ] |
| Post subject: | Re: Utility Procedures / Code Snippets |
Hi all, as I am clueless when it come to writing code, could anyone out there design a simple "market temperature" indicator based on the following idea: if current bar closes higher than previous bar close then value = 2 if current bar closes lower than previous bar close then value = -2 if current bar closes equal to previous bar close then value = 0 if current bar closes higher than current bar open then value = 2 if current bar closes lower than current bar open then value = -2 if current bar closes equal to current bar open then value = 0 if current bar closes higher than previous bar high then value = 1 if current bar closes within previous bar high/low range then value = 0 if current bar closes lower than previous bar low then value = -1 The indicator line or histogram would need a max reading of 5, a minimum of -5 and zero in the middle. Cheers, Tommy. PS please post the new indy on this forum so we can all try it out |
|
| Author: | dietcoke [ Thu Feb 23, 2012 1:35 pm ] |
| Post subject: | Some Functions I've found really useful |
First up. This is from one of Sqalou's ea's which is an elegant replacement for the multiplier code Steve uses for setting the pip mutliplier for 3 and 5 digit crims. this just puts the various mutipliers in an array and the correct one is referenced with "Digits". Very Clever! Code: Select all Code: Select all |
|
| Author: | dietcoke [ Thu Feb 23, 2012 1:39 pm ] |
| Post subject: | Re: Utility Procedures / Code Snippets |
This is a std deleter for mutiple objects. All they need is unique key at the same position in the object name(usually at the beginning). This is great for tidying up just the objects you want to delete in the deinit(). I've found the best way to use this is to create all your objects with the same prefix e.g "My_EA" then to delete them you use: del_obj("My_EA"); Code: Select all |
|
| Author: | dietcoke [ Thu Feb 23, 2012 1:43 pm ] |
| Post subject: | Re: Utility Procedures / Code Snippets |
These just make working with GlobalVariables easier on the fingers. There are functions which replicate GlobalVariableGet GlobalVariableSet GlobalVariableCheck GlobalVariableDel without all the unwanted extra typing. Code: Select all |
|
| Author: | dietcoke [ Tue Mar 06, 2012 7:50 pm ] |
| Post subject: | SwitchChartTimeFrame |
This function will switch the timeframe of the current chart to the timeframe passed as parameter. It is a modification of a fantastic script by zznbrm (http://www.forexfactory.com/showthread. ... ost3876444) which globally changes the timeframe on all open charts I've written it so the EA I'm developing can monitor in a higher timeframe and physically move into shorter timeframes and a completely different trading mode when a set up occurs. I know its possible to read indcators on different timeframes but using this function makes it much easier to code entirely different behaviours depending on the timefrme the chart is on. It also allows me to visually see which pairs are active simply by observing the chart timeframe Code: Select all |
|
| Author: | scalpz [ Thu Apr 26, 2012 12:43 am ] |
| Post subject: | Re: Utility Procedures / Code Snippets |
Beginner coder stuff. Reposted from how steve started coding thread. Is a better fit here. Found a couple of gold nuggets in relation to Steve's coding methods. Posting here so other cut & paste coders like me can see them when reading this thread. Post from straight after in same Fmfx-auto trader thread: And almost like Steve says, "Good luck. We need it." cheers Scalpz |
|
| Author: | scalpz [ Thu Apr 26, 2012 12:51 am ] |
| Post subject: | Re: Utility Procedures / Code Snippets |
And this 1 too. Found another nugget, this one from Squalou in Scoob's Forex Robot thread - And for you geeks (or those foolish enough to try to program), see "Warning, educational but geeky detail ahead:..." post by Sq at http://www.stevehopwoodforex.com/phpBB3 ... 469#p11469 cheers scalpz |
|
| Author: | tritom [ Sat Jul 21, 2012 7:09 pm ] |
| Post subject: | Re: Utility Procedures / Code Snippets |
Nice thingies here Adding this oneliner: Code: Select all well, it's almost always 2 with most crims but not always |
|
| Author: | Jimdandy [ Thu Jul 26, 2012 3:19 pm ] |
| Post subject: | Looking for mq4 of 10.2 TmaSlopeTrue NT |
George Wrote: "I suspect this isn't very costly when calling ArraySize(), but what about when calling OrdersTotal() or OrdersHistoryTotal()? Or even worse, our own functions like NumBarsClosingAboveAverage()" Thank you for this George.... I had not thought of this. I can see how this could get pretty heavy when you have 15 charts running and all of them running these loops on every tick.... I will keep this in mind and go thru some of my stuff and see where I can eliminate some cpu usage. Does anyone have the mq4 file for this indicator? I wanted to go in and hard code the colors that I use so as not to have to keep resetting it.... All I have found is the ex4 file.... I had a couple of other indies where one was coded "normal" and one was coded "true" but deleted them in favor of this "NT" one that you could toggle back and forth... I didn't realize at the time that all I had was the ex4 for it....Now I can't find the ones I deleted..... Everybody look through there pile of toys and see if you have... 10.2 TmaSlopeTrue NT v1.4B 4.30.mq4 I may find it yet.... Thanks for looking......PipPip......JimDandy.... |
|
| All times are UTC | Page 3 of 7 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|