Learning mql4. Intro and questions of a student.

 

Intro: As I have been reading through this forum for some time now, I feel I owe a great many of you thanks for the help and effort you have afforded to so many before me here. I plan to be stay around for the long haul so I do feel the need to introduce myself to the board here. I‘ll keep it short and simple but we’ll see how that goes: Been learning trading and investing for the past 10 years or so. Grew up with my father as a financial advisor so been interested in the markets for a long time and got an early start learning. I went to school for finance as well and am currently studying for the series 7.


As for why I am here, I have been learning and trading forex for a couple years now. For the past few months have really tried to dedicate as much free time as I can to learn programming for MT4 so I can code my own indicators and EA’s. After making it through a couple tutorials and toying with my own basic indicators, I realized that I still had too many basic questions I didn’t want to fill up the board with. I figured I would give myself a better base to learn MQL4 and taught myself C++. By no means am I a master, but I learned a lot and it definitely helped understand what I’m looking at here. By the way, up to this point, other than learning C++ and trying to learn mql4, my only experience in programming or computer languages has been learning html and php for a small web-based business I started and writing my own programs for TI calculators in math classes, all of which I learned on my own as well. But I am quite confident that with a little advice and mentoring on what to study and know, I can learn and understand this language and hopefully contribute something back to the forum here in the process.


What I am looking for is a little basic advice as far as the best path to take to learn mql4 and be fully competent in understanding the language. For me, if I’m not in full understanding of everything I’m looking at, something is clearly missing.


So as I said, up to this point along my journey learning mql4 I have:

-wasted too long using indicators I didn’t fully understand

-went through tutorial articles on mql4.com

-spent time learning to write my own basic breakout indicators (with many stumbles along the way)

-learned the basics of C++


Next on my to-do list is:

-Go through the book on mql4.com


What I’m looking for are some recommended ideas on what to tackle next as far as:

-literature?

-articles?

-recommended existing EA’s/Indicators that would be good to dissect and learn from?

-basically anything that you think would be beneficial for someone new to learn.


As I said, forex is something I plan to stay focused on for the long term so anything that helps me learn and understand is well worth my time. Again, thanks to all the helpful individuals on this forum and I apologize for the length of my first post.

 

Hi there. My advice would be to:


Read the book.

Pick one of the sample mq4 files.

Use the Documentation section in the forum to annotate what each line does.

Pick a simple strategy.

Write the pseudocode.

Code it yourself (with our support if necessary).

Make use of the Print() statement all over your code to keep yourself appraised of the logic flow and the content of key variables.

Test it against an Excel model.

Refine it.

Add ancilliary services such as email notification, recovery from failure etc.


Welcome.


CB

 
cloudbreaker wrote >>

Hi there. My advice would be to:

Read the book.

Pick one of the sample mq4 files.

Use the Documentation section in the forum to annotate what each line does.

Pick a simple strategy.

Write the pseudocode.

Code it yourself (with our support if necessary).

Make use of the Print() statement all over your code to keep yourself appraised of the logic flow and the content of key variables.

Test it against an Excel model.

Refine it.

Add ancilliary services such as email notification, recovery from failure etc.

Welcome.

CB

I appreciate the quick reply. Thats exactly the type of pointers I was looking for. I'll be sure to provide updates as my adventure here progresses. Thanks again.

 

No worries, you may also be interested to have a look at another newbie's recent journey.

'adventures of a newbie'


CB

 

Ok, slowly working my way through the mql4 book. Been breaking down each practice problem and making sure I completely understand everything before I move on. Right now I am on problem 27 in the Arrays/Variables chapter. I understand most the logic of this problem except the static variable in the user defined function.<br>


I must not completely understand the static variables because the way I'm thinking this would work right now is:

-everytime the user defined function is executed at each tick, it will set static datetime New_Time=0;

-but then everytime it got to the if() function and checked if New_time != Time[0]

-wouldn't that always be not true and in turn always set New_Bar to true?


Unless that line declaring the static variable and setting it to equal 0 is only executed one time, and then it pulls the value for New_Time from memory when the function was last run. That would make sense to me.


So could someone please fill me in on what I'm not understading about the way this works or why New_Time wouldn't be set back to 0 everytime the user defined function is used?


Thanks.



// newbar.mq4
// The code should be used for educational purpose only.
//--------------------------------------------------------------------
extern int Quant_Bars=15; // Amount of bars
bool New_Bar=false; // Flag of a new bar
//--------------------------------------------------------------------
int start() // Special funct. start()
{
double Minimum, // Minimal price
Maximum; // Maximal price
//--------------------------------------------------------------------
Fun_New_Bar(); // Function call
if (New_Bar==false) // If bar is not new..
return; // ..return
//--------------------------------------------------------------------
int Ind_max =ArrayMaximum(High,Quant_Bars,1);// Bar index of max. price
int Ind_min =ArrayMinimum(Low, Quant_Bars,1);// Bar index of min. price
Maximum=High[Ind_max]; // Desired max. price
Minimum=Low[Ind_min]; // Desired min. price
Alert("For the last ",Quant_Bars, // Show message
" bars Min= ",Minimum," Max= ",Maximum);
return; // Exit start()
}
//--------------------------------------------------------------------
void Fun_New_Bar() // Funct. detecting ..
{ // .. a new bar
static datetime New_Time=0; // Time of the current bar
New_Bar=false; // No new bar
if(New_Time!=Time[0]) // Compare time
{
New_Time=Time[0]; // Now time is so
New_Bar=true; // A new bar detected
}
}

 
The reason is that it has been declared as a static. Had it not been declared a static, then it would have been initialised with 0 each time the function was run. Being declared inside the function also means it is only accessible from that code block. CB
 
cloudbreaker wrote >>
The reason is that it has been declared as a static. Had it not been declared a static, then it would have been initialised with 0 each time the function was run. Being declared inside the function also means it is only accessible from that code block. CB

Thanksfor the reply. Was able to see what you mean by changing things around and using alerts to see the effect. Would have probably been able to figure that one out once the markets opened and could check out the effects of the changes in the code at each tick. I have a trading simulator, is there any way to use that or anything similar to that which I can add EA's to for learning purposes while the markets are closed? Was just trying to see if I could do that but the ea was using current prices rather than the historical prices the simulator was using. Thanks.

 
Ok, I have finally read just about every chapter and worked through each problem in the book to make sure I understand everything as I go. Also have read many articles along the way. I'm to the point that I'm starting to write some very basic indicators and just testing things out as I go to make sure its all right. I chose a simple MA crossover for the first indicator and EA I'm playing around with. As I progresss here, I want to make sure I am understanding using doubles properly as far as 4 vs. 5 digit brokers. It seems that in order to keep 5 digits, you have to use DoubleToStr. For example:
   double dPrice;
   
   dPrice = Bid;
   
   Alert(DoubleToStr(dPrice,Digits));
Is this the only way to keep 5 digit precision when I calculate my MA's? I was assuming I could use NormalizeDouble(dPrice, Digits) to keep everything just as a double and avoid switching between String but I'm not getting the 5 digits I was looking for that way. Sorry if this doesn't make any sense. Im still learning and trying to figure everything out from the beginning without asking too many dumb questions. I appreciate any advice and help again. Thanks.
 
Thre reason for using double is because of the way the computer represents and handles numbers internally. When it comes to doing floating point arithmatic (numbers with a decimal point) accuracy becomes less than we would like with the standard size of bits (8 or 16 or 32) used internally. So to increase accuracy and remove rounding errors the computer uses double the standard number of bits to do its calculation. Its not the precision that is the problem its the rounding errors that occur when many calculations and conversions are done on that number. Too many of these errors and the answer is meaningless.
 
I should add that NormalizedDouble function is a rounding function used to format your calculations to become the price information that the dealer's server finds acceptable.
 
Ickyrus wrote >>
I should add that NormalizedDouble function is a rounding function used to format your calculations to become the price information that the dealer's server finds acceptable.

Ickyrus,

Thanks for the response. I'm still not certain on how I go about making sure I'm using the correct double values for my calculations. What I mean is when I print just the value of Bid, there are only 4 digits after the decimal point. I'm trying to figure out how I should write everything so that both my calculations and the values that get sent to the dealers server are correct. The only way I could get it to print all 5 digits after the decimal was by using the code pasted above with the DoubleToStr. How should I write that so that the correct values are being used within the program and displayed correctly?