| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Utility Procedures / Code Snippets https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=166 |
Page 1 of 7 |
| Author: | gaheitman [ Sun Dec 18, 2011 6:55 am ] |
| Post subject: | Utility Procedures / Code Snippets |
Here's a place to publish procedures, code snippets, or especially clever one-liners ( One thing to keep in mind, if you post it here, expect to see "Why did you...", "You should have...", "Hey, it's easier if you..." kinds of posts. I expect to get more than my share "But why would you want to do that in the first place?" posts. On to the code.... |
|
| Author: | gaheitman [ Sun Dec 18, 2011 7:18 am ] |
| Post subject: | Dependency Checker |
While reading through the Co-integration thread I decided to code a function to check to see if the rterm.exe file was where the user said it was. I did that, let it sit for a while, and then decided to put together a generic dependency checker. I tell you that, so you know why I decided to implement one of the procedures the way I did. First, the API imports: Code: Select all Code: Select all Now the functions: Code: Select all Code: Select all Notice the path starts with "." (period). For those of you who didn't start your life in MS-DOS, the "." stands for the current directory. This saves us from having to know the full install path of Empty4. If the file check fails, the user will get a popup dialog stating they are missing a file and suggesting they return to the forum to get it. The code works on my machine to open up a browse window to the forum thread, I'm curious if it works for others. Here's the notification dialog: Finally, the main procedure. This is the example I plan on adding to the Engulfing reversal bars EA. Code: Select all Thoughts? Questions? UPDATE: I added a script to test. It will check for ffcalh and a fake file that it won't find. If you choose "Yes" it should bring you to this post. George |
|
| Author: | youcrazykids [ Mon Dec 19, 2011 1:44 am ] |
| Post subject: | Oscillator in main chart window |
Hi all This'll turn out to be a cracking little thread, methinks. Here's a little code snippet, which displays an oscillator in the main chart window, instead of a separate window. When adding indicators which usually exist in separate windows, the chart soon becomes compressed, which I don't like. So, had a play around and came up with this. Maybe it's been thought of before, and if so, my apologies! I've used the Stochastic oscillator as an example. It could easily be edited to display RSI, CCI, or most indicators with definable limits. The routine is far from finished, so if anyone has any suggestions, I'd gladly try to ammend/adapt/improve the code. Code: Select all - On startup, two horizontal lines are painted onto the chart window. These are user-definable limit lines, for visual purposes. - If the chart moves or is zoomed in/out, these lines will adjust their position relative to the window. So, providing there are sufficient incoming ticks, these lines will rearrange themselves. - A loop calculates the stochastic main and signal lines for each particular bar, and paints them onto the chart, joining them up with the values for the previous bar. That's about it, really! I hope someone finds it useful. Cheers youcrazykids [/size] |
|
| Author: | gaheitman [ Mon Dec 19, 2011 7:40 am ] |
| Post subject: | Re: Oscillator in main chart window |
Nice! Have you tried to use WindowBarsPerChart() and WindowFirstVisibleBar() to get it to only calculate/draw the current screen? As it is now, I think it recalculates everything on each tick. You might be able to use IndicatorCounted() and just update on new bars and whenever WindowPriceMax/Min changes. George |
|
| Author: | AnotherBrian [ Tue Dec 20, 2011 3:23 pm ] |
| Post subject: | Prettify / Beautify / format your MQ4 code |
After writing some code for what I thought would be a small program, turned out to be many lines of confusion because I didn't pay much attention to formatting. So I consulted Google to find a way to automatically format the code for me. I found jEdit to be very easy, and free. jEdit DOWNLOAD After you install it and have it running, go to the menu "Plugins" and turn on the Astsyle plugin. Copy and rename your MQ4 file to a cpp extension and load it into jEdit. Changing the file extension tells jEdit how to format it and what words to highlight/colour. There's probably a setting in jEdit where you can add the MQ4 extension but I didn't look for it. Go to the same menu and select the plugin and your code will be formatted. Save it and change the extension back to MQ4, so Empty4 can read it. I didn't see a formatter in the Empty4 editor, am I missing something here? Is there an easier way to automatically format your code? If so, I'd like to know what it is!! |
|
| Author: | magft [ Tue Dec 20, 2011 5:01 pm ] |
| Post subject: | Re: Prettify / Beautify / format your MQ4 code |
gspe from FF sent me settings for jedit to allow proper editing the only thing i couldn't get to work was the compiling part so still have to switch back over to the editor. I'll dig out the settings and post them if you want but if you search FF for jedit you should find the thread. Mike |
|
| Author: | magft [ Tue Dec 20, 2011 5:08 pm ] |
| Post subject: | Re: Utility Procedures / Code Snippets |
Just been playing around with the CoInt EA by Mediator streamling some of the code, as had old code from 7-bit's arb-o-mat, and my version kept hogging 50% cpu. So after doing this editing i found i got it down to 8-16%! Turns out though that my account analyser indicator was causing alot of the cpu usage. It is viusally nice but obviously not useful in the long run as it is so i have extracted the max floating DD bit and put into the EA, as this is the main useful bit i look at! Anyway, here is the code that creates global variables with the info in if you want to use it in other EAs. Code: Select all |
|
| Author: | AnotherBrian [ Wed Dec 21, 2011 12:07 am ] |
| Post subject: | Re: Prettify / Beautify / format your MQ4 code |
[/quote] gspe from FF sent me settings for jedit to allow proper editing the only thing i couldn't get to work was the compiling part so still have to switch back over to the editor. I'll dig out the settings and post them if you want but if you search FF for jedit you should find the thread. Mike[/quote] Hi Mike I found the link, is it as simple as putting the xml file in the same directory as all the other xml files in the jEdit directory? I tried that and doesn't work, no highlights.... Can you save me hours of reading the manual? http://fx-engineering.blogspot.com/2011/01/jedit.html |
|
| Author: | gaheitman [ Wed Dec 21, 2011 11:04 am ] |
| Post subject: | Re: Prettify / Beautify / format your MQ4 code |
I've just started looking at AStyle. (http://astyle.sourceforge.net/) It's command line only, but seems to work fairly well and has plenty of options. I use the command line options "-A2 -s3 -f --mode=c", though I'm not sure I really need the "-f". George |
|
| Author: | markft [ Sun Dec 25, 2011 4:06 pm ] |
| Post subject: | Re: Prettify / Beautify / format your MQ4 code |
I have started using UniversalIndentGUI (http://universalindent.sourceforge.net/). This is a GUI wrapper around a number of command line indenter including astyle. The killer function is it lets you preview the result e.g. similar to eclipse. It can then generate a .astylerc and a .bat file that contains your settings so you can copy the batch file to the experts directory on your Empty4 platforms and run it for each of them. My .astylerc settings are: -y --break-elseifs --pad=oper --pad=paren-in --style=ansi --brackets=break |
|
| All times are UTC | Page 1 of 7 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|