Hi coders, I need your help and advice how to merge 2 different conditions of loops into 1 loop (but both loops are linking to each others) so that I can get the 1st bar's shift of a strong bull move. Kindly look at my picture to understand what I intend to achieve ...
1st loop of conditions :-
2nd loop of conditions : I would like to get at least 4 minimum big long green bars ( Cs0-Op0>=cATR0, i.e. cntGreen>=4 ) for a strong bull trend starting from MA2Dp1UpSf-1 and ends at next MA 2-drop.
If running two loops independently, due to different loops' conditions, the 1st bar's shift that I'm aiming for is varying and keep on changing, therefore in my opinion, the only way is to merge the 2 loops into 1 loop, only then can get the correct 1st bar's shift for the last 100 bars. Is it possible to have a sub-loop inside a master loop to get the 1st bar's shift ? Please help with your codes, thank you.
1st loop of conditions :-
Inserted Code
int MA2Dp1UpSf=0; for(int i=1; i<=100; i++) { double MA0=iMA(NULL,1,5,0,3,0,i); double MA1=iMA(NULL,1,5,0,3,0,i+1); double MA2=iMA(NULL,1,5,0,3,0,i+2); double MA3=iMA(NULL,1,5,0,3,0,i+3); if(MA0>MA1 && MA1<=MA2 && MA2<=MA3) MA2Dp1UpSf=i; // MA 2-drop 1-Up }
2nd loop of conditions : I would like to get at least 4 minimum big long green bars ( Cs0-Op0>=cATR0, i.e. cntGreen>=4 ) for a strong bull trend starting from MA2Dp1UpSf-1 and ends at next MA 2-drop.
Inserted Code
int cntGreen=0; for(int i=MA2Dp1UpSf-1; i>=1; i--) { double Op0=iOpen(NULL,1,i); double Hi0=iHigh(NULL,1,i); double Cs0=iClose(NULL,1,i); double ATR0=iATR(NULL,1,5,i); double MAn1=iMA(NULL,1,5,0,3,0,i-1); double MAn2=iMA(NULL,1,5,0,3,0,i-2); double MAn3=iMA(NULL,1,5,0,3,0,i-3); if(Cs0-Op0>=cATR0 && MAn1<=MathMax(MAn2,MAn3)) cntGreen++; // Count No. of Big Green bars and stops at next MA 2-drop }
If running two loops independently, due to different loops' conditions, the 1st bar's shift that I'm aiming for is varying and keep on changing, therefore in my opinion, the only way is to merge the 2 loops into 1 loop, only then can get the correct 1st bar's shift for the last 100 bars. Is it possible to have a sub-loop inside a master loop to get the 1st bar's shift ? Please help with your codes, thank you.