stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Orders Counter class
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4213
Page 2 of 2
Author:  rocketman99 [ Tue Apr 14, 2015 5:55 am ]
Post subject:  Orders Counter class

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.
Author:  dudest [ Tue Apr 14, 2015 6:17 am ]
Post subject:  Orders Counter class

Goodstuff rocketman!

Thanks!
Author:  theforexedge [ Tue Apr 14, 2015 6:47 am ]
Post subject:  Orders Counter class

rocketman

:hi:

thank you for starting this thread and posting the examples :good:

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
Author:  rocketman99 [ Tue Apr 14, 2015 8:47 am ]
Post subject:  Orders Counter class

theforexedge ยป Tue Apr 14, 2015 7:47 am wrote:rocketman

:hi:

thank you for starting this thread and posting the examples :good:

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
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 forex :cry: I do have the benefit many years of coding/scripting experience which helps, so I will try and share some of it.

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.
Author:  theforexedge [ Tue Apr 14, 2015 9:19 am ]
Post subject:  Orders Counter class

rocketman..

autodidactic what a great word...i like that :good:

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 :smile:
Author:  RedLineFred [ Tue Apr 14, 2015 11:25 am ]
Post subject:  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
Author:  rocketman99 [ Wed Apr 15, 2015 4:27 am ]
Post subject:  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:

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);

}
Then in your main EA you work as follows:

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
   }

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.
All times are UTC Page 2 of 2