Modular version behaves differently

 

I customized Lesson16.pdf https://c.mql5.com/forextsd/forum/161/lesson16.pdf to be more modular for the way I want to test different trading strategies. Unfortunately, I am not getting the same results as the unmodified lesson.

Would you please take a look and advise me as to why mine behaves so differently on the same data in the Strategy Tester? The actual performance is not the issue right now; only the disagreement in selected entry/exit trade(s).

It does not close the original open order, except when the tester ends. So I only have 1 round trip trade!

The only differences I suspect would be where I make a second call for: shortEma, longEma, isCrossed (as cg_l16_Crossed(shortEma,longEma);), and total; since I have the code split into more modular functions. I am also assuming that I process the same price data since I am in testing mode -- and that for live trading my present code may miss a tick if it is slower.

Thoughts?

Files:
 

Wrong code sequence, but still...

Okay, I did notice I was not selecting the order as the first step in the for loop of the exit test exitStrategy_cg_l16 (the 2 bold if conditions were reversed), but even when I do as below, I get the same incongruent results. I also commented out the magic number condition.

for(int cnt=0; cnt<total; cnt++)

{

if(selectOrderByIndex(cnt))

{

if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())// && OrderMagicNumber()==cg_l16)

{

if(OrderType()==OP_BUY) // long position is opened
 

OrdersTotal()

It seems to have been the way I handled total = OrdersTotal().

If anyone would explain why, that would be terrific. I still don't understand why the first way I posted didn't perform the same.

Attached is my modular version of Coders Guru Lesson 16 which appears to perform the same.

Files:
 
ftsdPadawan:
It seems to have been the way I handled total = OrdersTotal().

If anyone would explain why, that would be terrific. I still don't understand why the first way I posted didn't perform the same.

Attached is my modular version of Coders Guru Lesson 16 which appears to perform the same.

ftsdPadawan

May I seggest you read 'Code Complete' published by MicrowSoft Press, The information in it is language independent. Don't know if its still in print but you are sure to get a used copy of it on the net, if not. It will show you how to really construct code in module blocks. It will also tell you what coding Style has to do with readablity. What you have done here was to break the code up into peices, far from what would be consided good programing style.

[Edit] Another good read is, 'Rapid Development' also published by MicrowSoft Press.

 

cockeyedcowboy,

Do you have any idea why my original post did not perform the same way as Lesson 16 and my last post?

How would you suggest writing Lesson 16 to accommodate different strategies (which may not use a simple "isCrossed" flag)?

Does 'Code Complete' apply to MQL4? Because my original plan was to call functions after their name was determined dynamically, but that is not possible in MQL4 (no function pointers or "eval" type techniques, nor OOP).

Regards.

Is there really a W in MicrowSoft Press?

 
ftsdPadawan:
cockeyedcowboy,

Do you have any idea why my original post did not perform the same way as Lesson 16 and my last post?

How would you suggest writing Lesson 16 to accommodate different strategies (which may not use a simple "isCrossed" flag)?

Does 'Code Complete' apply to MQL4? Because my original plan was to call functions after their name was determined dynamically, but that is not possible in MQL4 (no function pointers or "eval" type techniques, nor OOP).

Regards.

Is there really a W in MicrowSoft Press?

a w in microsoft? look ok to me either way LOL Iam bad in spelling just in english.

Code Complete is language independent it teaches programing style good for any language.

dont know what went wrong with your code. I don't look at code that is choped up like that was. It would take less time to re-write the code then try to read it. Sorry.

send link to lesson, I've not read it.

Edit never mind found the link in your first post. will respond when I've read it.