"Nesting" in MQL?

 

I am a newbie (like so many others here) to both MQL and Forex. I am working on building an MA crossover EA, and am challenged to understand how one can get an EA to identify the crossing over of MA's with the same time period, while one is offset by an MA shift of 2 as compared to the other MA.

Where I am challenged is in understanding how the EA can be coded to recognize the MA crossover occurence at different Bars (1 and 3). I have searched the forums for an understanding of how an MA is coded, and how use of the MA_shift vs shift would affect its results. From all that I have read, use of an MA_shift merely shifts the drawing of the MA onto a different bar. I have come across nothing that gives any direction of how an EA could be programed to recognize the differences in the MA results at different bars.

I have used MS Excel extensively (as I am sure lot of folks here have), including nesting formulas. Was thinking that the EA could be coded as follows to direct it to look at the position/value of the two different MAs at different bars:

if (iBars_1 && iMA_2 > iBars_1 && iMA_1) && (iBars_2 && iMA_2 < iBars_2 && iMA_1) // MA 3(-2) greater than MA 3(0)
{ // at bar 1 and 3 respectively
Opn_B=true; // Criterion for opening Buy
Cls_S=true; // Criterion for closing Sell
}
if (iBars_1 && iMA_2 < iBars_1 && iMA_1) && (iBars_2 && iMA_2 > iBars_2 && iMA_1)// MA 3(-2) less than MA 3(0)
{ // At bar 1 and 3 respectively
Opn_S=true; // Criterion for opening Sell
Cls_B=true; // Criterion for closing Buy
}

I have compiled the code above, receiving not error messages, other than an "unbalanced left parenthesis" error not related to this section of the EA code. Am I offbase in my thinking or approach to my strategy with the combining/linking of the iBars and iMA requiring the EA to compare the values at point in times?

I appreciate anyone's assistance on this. Have been comtemplating this for over a week, and just can't get my head around it anymore than the above.

CountingMan

_______________________________________________________________________________________________________________________

Nothing beats a try, but a failure.

 

a monster of code samples in codebase https://www.mql5.com/en/code.

do not know why you want abuse youself with time.

 
if ((iBars_1 > iMA_2 && iBars_1 > iMA_1) && (iBars_2 < iMA_2 && iBars_2 < iMA_1)) // MA 3(-2) greater than MA 3(0) 
{ // at bar 1 and 3 respectively 
Opn_B=true; // Criterion for opening Buy 
Cls_S=true; // Criterion for closing Sell 
} 
if ((iBars_1 < iMA_2 && iBars_1 < iMA_1) && (iBars_2 > iMA_2 && iBars_2 > iMA_1))// MA 3(-2) less than MA 3(0) 
{ // At bar 1 and 3 respectively 
Opn_S=true; // Criterion for opening Sell 
Cls_B=true; // Criterion for closing Buy 
}
hope this helps
 
fxcourt:
hope this helps


fxcourt,

Thanks for the code posting.

Does my thought process make sense? I am really trying to understand how MQL works so that I can bridge hurdles.

Thanks,

CountingMan

________________________________________________________

If you want to do something bad enough, you will find the wil, the way, and the means to get the job done.

Reason: