| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Orders Counter class https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4213 |
Page 1 of 2 |
| Author: | rocketman99 [ Sun Apr 12, 2015 3:41 am ] |
| Post subject: | Orders Counter class |
I have taken the COrdersCounter class and added a bunch of functionality that some might find useful. The original was published here: https://www.mql5.com/en/code/11786 Using the class to handle open orders and order history takes away much of the Empty4 complexity and I think makes for much more readable code. You can do things like this: Code: Select all I have attached a simple script as a sample that can be dropped on a chart to demonstrate some of the functions. |
|
| Author: | rocketman99 [ Sun Apr 12, 2015 3:41 am ] |
| Post subject: | Orders Counter class |
Constructor: COrdersCounter(int magic, string symbol, int counter_mode = MODE_TRADES)
void refreshData(void)
int getOrdersCount(int type)
int getOrderStatus(int ticket)
ProfitData getTotalProfit()
void setMagicNumber(int magic)
|
|
| Author: | renexxxx [ Sun Apr 12, 2015 6:07 am ] |
| Post subject: | Orders Counter class |
I applaud this work! We should all be using OO concepts for our EAs and indicators -- in order to be able to re-use code and write more readable code. In fact, we should strive to create a class library that should form the basis of any new project. Unfortunately, there is so much existing legacy code around, that I foresee that the resistance to such a direction will be high. |
|
| Author: | rocketman99 [ Sun Apr 12, 2015 6:42 am ] |
| Post subject: | Orders Counter class |
Thanks for the encouragement. Yes, I agree. I was starting to run into difficulty with maintaining my own shell code that I decided to just sit down and hack it apart and to use OO concepts. Well it turned out to be a breeze really and my code is VASTLY more readable. Some things that I am working on: Work with baskets - actually quite simple to implement and due to OO will not break existing code Filter on time so that you can query: orders over last period (for example last H4 or D1) length orders have been hanging around (in seconds and minutes) I also know that many people hate CamelCase as its wordy, but I find it makes reading logic so much simpler. |
|
| Author: | renexxxx [ Sun Apr 12, 2015 6:47 am ] |
| Post subject: | Orders Counter class |
For what it is worth, I am a big fan of CamelCase, having programmed in Java for the last 20 years or so. |
|
| Author: | dietcoke [ Sun Apr 12, 2015 8:37 am ] |
| Post subject: | Orders Counter class |
Thanks for posting this Rocketman. I shall study this and see how I can use this. As a non-programming "amateur". I learned mql4 by modifying existing code. Even now, much of what I write is based on something that has been previously published. OO code is great for this type of extending work but there is a dearth of published code around which uses the new features which is making it difficult for people like me to follow the same path now. OOP in mql4 can't take off until more good people like yourself are prepared to share their classes and resulting indicators and ea's Personally, I also find OO code a bit wierd looking and can't quite get my head around it. The program structure is different. For me, it's like learing a 3rd language from a textbook written in my 2nd language I'm sure I'm not alone in that. |
|
| Author: | rocketman99 [ Sun Apr 12, 2015 10:42 am ] |
| Post subject: | Orders Counter class |
I feel for you as a self taught coder (although with many many years of experience) OO also boggled my mind when I initially dabled in it. But I can say it makes coding really easy and is worth it in the long run. When I have some time I will put together some example EA's. Also feel free to ask questions regarding OO coding. Note I am no expert. |
|
| Author: | rocketman99 [ Mon Apr 13, 2015 10:17 pm ] |
| Post subject: | Orders Counter class |
I added the ability to work with baskets. This required modifying two lines of code. Where you specify the Symbol you can now specify a string of symbols - eg: "EURUSD USDJPY AUDUSD" using any delimeter. The update can be found in post 1. Code: Select all |
|
| Author: | RedLineFred [ Tue Apr 14, 2015 2:45 am ] |
| Post subject: | Orders Counter class |
Great work here, but as others have already stated, I too am more than a little confused by OO programming and concepts. Any pointers to where one can get educated on OO - web site, pdf or book? |
|
| Author: | rocketman99 [ Tue Apr 14, 2015 4:26 am ] |
| Post subject: | Orders Counter class |
I just did a quick google and understand your frustration - any explanation of OO, even so called basic ones quickly delve into things like inheretance and other bizarre OO concepts that you do not need to know about to get started. So let me try and explain. Think of a class as a template or blueprint (for example a house blueprint will have options or variables for number of floors, number of rooms etc). Once you define the object based on the class (build the actual house or construct it in OO terms) you use the blueprint (predefined class) and populate the internal class variables (template) to make it a unique house. These variables stick to this object and are unique to the object - each new house object automatically keeps track of its own details. This is where the beuty of OO comes in - you can have many house objects using the same class as the template. So when using the COrdersClass I can keep track of individual currencies without having to resort to arrays and other means. For example: Code: Select all Code: Select all Code: Select all For me the absolute minimum you need to understand to make OO worthwhile is:
Looking at the COrdersCounter class code, start with COrdersCounter::COrdersCounter(int magic, string symbol, int counter_mode = MODE_TRADES) This creates the object and populates the internal variables (this. syntax). void COrdersCounter::refreshData(void) This scans the order pools and works out all the other variables. All the remaining methods (functions) just pull variables out, or do further computations on the variables already updated by refreshData(). You now want to do some new wizbang thing with all those internal variables - well just add a new method. I hope this explanation helps just a little. As mentioned, try understanding just the four OO concepts above and ignore all the rest OO has to offer. |
|
| All times are UTC | Page 1 of 2 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|