RedLineFred » Tue Apr 14, 2015 3:45 am wrote: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?
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
# track 3x currencies open orders
COrdersCounter eurusd(MagicNumber, "EURUSD", MODE_TRADES); eurusd.refreshData();
COrdersCounter usdjpy(MagicNumber, "USDJPY", MODE_TRADES); usdjpy.refreshData();
COrdersCounter audusd(MagicNumber, "AUDUSD", MODE_TRADES); audusd.refreshData();
Just running the above will keep track of all the following details inside each class automatically:
Code: Select all
int orders_magic; // Magic Number for the filtering orders. If 0, then doesn't filter.
string orders_symbol; // Currency symbol for the filtering orders. If "", then doesn't filter.
int orders_mode; // Type of the pool: MODE_TRADES(default) - trading, MODE_HISTORY - history pool
int buys; // Count of the buy positions
int sells; // Count of the sell poistions
int buy_limits; // Count of the buy limit orders
int sell_limits; // Count of the sell limit orders
int buy_stops; // Count of the buy stop orders
int sell_stops; // Count of the sell stop orders
datetime last_time; // Time of last pool ticket
datetime first_time; // Time of first pool ticket
int last_ticket; // Last ticket number
int first_ticket; // first ticket number
bool pool_scanned; // Does the order pool need scanning to update cache
ProfitData total_profit; // Profit of the counted orders
double total_volume; // Total volume - number of lots for all counted orders
double market_volume; // Total volume - number of lots for counted market positions
Now I can use all 3 currencies at the same time with minimal fuss:
Code: Select all
if(eurusd.OrderSLDuringBar(PERIOD_H4)) {
......... EURUSD hit SL!!! Sad.
}
if(usdjpy.OrderSLDuringBar(PERIOD_H4)) {
......... USDJPY hit SL!!! Sad.
}
if(audusd.OrderSLDuringBar(PERIOD_H4)) {
......... AUDUSD hit SL!!! Sad.
}
The power of OO comes in when I want to add another variable or function to the class - I just add it plus some methods (functions) to work with the new variables knowing that no other code will break. The original intended purpose of the class (to build a house) does not change. I mearly added a new option to have central heating, but I do not need to use the option.
For me the absolute minimum you need to understand to make OO worthwhile is:
- How to define a class and add variables to it
What is a private declaration
What is public declaration
What is a method and how to use them
Ignore all the rest about OO.
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.