Here is a fairly simple explanation of the basics I described above. Stop reading at the end of chapter 2: https://www3.ntu.edu.sg/home/ehchua/pro ... asics.html
It uses JAVA as an example, but the concepts in MQL4 are exactly the same just with slightly different syntax.
Orders Counter class
-
dudest
- Trader
- Posts: 1847
- Joined: Tue May 08, 2012 2:37 pm
Orders Counter class
Goodstuff rocketman!
Thanks!
Thanks!
-
theforexedge
- Trader
- Posts: 220
- Joined: Thu Apr 26, 2012 10:31 pm
- Location: Torquay
Orders Counter class
rocketman
:hi:
thank you for starting this thread and posting the examples
i'm just in the process of learning to code for myself as I've become quite proficient in cut n paste coding, but wanted to fully understand what i'm actually doing
anyway keep the info coming as its all good brain food and if you can also recommend any good books to consume after I've finished reading the OOP Basics link you recently posted.
many thanks, Jason
:hi:
thank you for starting this thread and posting the examples
i'm just in the process of learning to code for myself as I've become quite proficient in cut n paste coding, but wanted to fully understand what i'm actually doing
anyway keep the info coming as its all good brain food and if you can also recommend any good books to consume after I've finished reading the OOP Basics link you recently posted.
many thanks, Jason
-
rocketman99
- Trader
- Posts: 91
- Joined: Wed Dec 19, 2012 1:19 am
Orders Counter class
Unfortunately I cannot recommend any books about coding. The internet is my reference and I have become quite proficient in Googling. The job that pays me money and keeps me alive requires me to be autodidactic. I don't make any money coding or trading forextheforexedge » Tue Apr 14, 2015 7:47 am wrote:rocketman
:hi:
thank you for starting this thread and posting the examples![]()
i'm just in the process of learning to code for myself as I've become quite proficient in cut n paste coding, but wanted to fully understand what i'm actually doing![]()
anyway keep the info coming as its all good brain food and if you can also recommend any good books to consume after I've finished reading the OOP Basics link you recently posted.
many thanks, Jason
As mentioned in an earlier post I will work on a barebones, simple-as shell example using some OOP concepts. I just need to add some time filters to the class to make it really useful. Once done I will also put it in post 1.
-
theforexedge
- Trader
- Posts: 220
- Joined: Thu Apr 26, 2012 10:31 pm
- Location: Torquay
Orders Counter class
rocketman..
autodidactic what a great word...i like that
making money in forex I'm good at, but standing on the shoulders of the selfless members here at SHF...and looking forward to the shellcode as its really helpful to see by example
i just picked-up a copy of expert advisor programming for Empty4 5 and plan to read it during my summer vacation:
http://expertadvisorbook.com/expert-adv ... atrader-5/
have a great day..
jason
autodidactic what a great word...i like that
making money in forex I'm good at, but standing on the shoulders of the selfless members here at SHF...and looking forward to the shellcode as its really helpful to see by example
i just picked-up a copy of expert advisor programming for Empty4 5 and plan to read it during my summer vacation:
http://expertadvisorbook.com/expert-adv ... atrader-5/
have a great day..
jason
- RedLineFred
- Trader
- Posts: 52
- Joined: Wed May 01, 2013 6:15 am
- Location: Brisbane, Australia
Orders Counter class
Thx Rocketman, much appreciated. The search for enlightenment continues.
I did find this book useful - look at the intro in Chapter 1 and Chapter 7, but as you say keep it simple.
http://www.atilim.edu.tr/~mcs215/Lectur ... s/book.pdf
I did find this book useful - look at the intro in Chapter 1 and Chapter 7, but as you say keep it simple.
http://www.atilim.edu.tr/~mcs215/Lectur ... s/book.pdf
-
rocketman99
- Trader
- Posts: 91
- Joined: Wed Dec 19, 2012 1:19 am
Orders Counter class
Here is a basic example of OOP that abstracts the crossover logic when getting indicator information.
Define the class - this should go into an include file to not pollute your main code:
Then in your main EA you work as follows:
This example shows how to:
Define a class
Private variables
Multiple constructors or overloading (the class handles both cross overs and level crosses dependent on the parameters passed)
Methods to do stuff
Note that this class is totally untested.
Define the class - this should go into an include file to not pollute your main code:
Code: Select all
class Crossover
{
private:
double l1_b0; // line1 bar0
double l1_b1; // line1 bar1
double l2_b0; // line2 bar0
double l2_b1; // line2 bar1
public:
//--- Parametric constructor
Crosover(double line1_bar0, double line1_bar1, double line2_bar0, double line1_bar1);
Crosover(double line1_bar0, double line1_bar1, double level);
bool CrossDown::Crossover(void);
bool CrossUp::Crossover(void);
};
// constructor for two lines crossing over
void Crossover::Crossover(double line1_bar0, double line1_bar1, double line2_bar0, double line1_bar1) {
l1_b0=line1_bar0;
l1_b1=line1_bar1;
l2_b0=line2_bar0;
l2_b1=line2_bar1;
}
// constructor for line crossing over a level
void Crossover::Crossover(double line1_bar0, double line1_bar1, double level) {
l1_b0=line1_bar0;
l1_b1=line1_bar1;
l2_b0=level;
l2_b1=level;
}
// line one crossing down over line 2 or level
bool CrossDown::Crossover(void) {
if(l1_b0>=l2_b0 && l1_b1<l2_b1) {
return(true)
}
return(false);
}
// line one crossing up over line 2 or level
bool CrossUp::Crossover(void) {
if(l1_b0<=l2_b0 && l1_b1>l2_b1) {
return(true)
}
return(false);
}
Code: Select all
int MPeriod1=50; // slow MA period
int MPeriod2=200; // fast MA period
double FMA=iMA(NULL,0,MPeriod1,0,MODE_SMA,PRICE_CLOSE,0);
double SMA=iMA(NULL,0,MPeriod2,0,MODE_SMA,PRICE_CLOSE,0);
double PFMA=iMA(NULL,0,MPeriod1,0,MODE_SMA,PRICE_CLOSE,1);
double PSMA=iMA(NULL,0,MPeriod2,0,MODE_SMA,PRICE_CLOSE,1);
Crossover Xover(FMA, PFMA, SMA, PSMA);
if(Xover.CrossDown()) { // fast crossed down over slow line
// do something
}
if(Xover.CrossUp()) { // fast crossed up over slow line
// do something
}
Define a class
Private variables
Multiple constructors or overloading (the class handles both cross overs and level crosses dependent on the parameters passed)
Methods to do stuff
Note that this class is totally untested.