Hi coders, need your advice for codes.
I have a Multi-Symbols EA and for exit section, the codes are as follows :-
I think the Print Output above "Cs BUY AUDCHF (2025.04.14 14:13/Tkt 285304721) /ExitSigVal:+0+0+0+0+0-0-0-0-0-1/k:6/temCase:1 /ExitSequence:-0-0-0-1" should be able to enlighten you how the whole exit section works.
I have the following questions needing your advice and seeking your help :-
1) For the loop "for(int k=0; k<StringLen(ExitSequence); k+=2)", could you please explain how the "k+=2" works ? If you can provide some illustrations to explain would be the best. I'm a beginner, I can only understand k++ or k-- only.
2) In this exit section, it uses only one "case 1 (switch)", I think it is unnecessary / redundant. Could you please help me to modify the codes so that :-
a) No more "case 1 (switch) + break", i.e. to remove the relevant codes totally
b) Must keep the ExitSig(sym,cTkt,cOpTm,cOpPx,cLot,cTPPx,cSLPx) codes as it is required in other functions.
Finally, as long as [StringSubstr(ExitSequence,k,1)=="-"] finds any "-" in the ExitSequence, the OrderClose should close the BUY orders immediately. The codes must ensure that the relevant BUY order are confirmed has been closed only then stop looping the OrderClose.
Thank you.
I have a Multi-Symbols EA and for exit section, the codes are as follows :-
Inserted Code
bool SequenceBreak=false;
if(OrderType()==OP_BUY && OrderMagicNumber()==mnBUY) {
string ExitSequence=StringSubstr(ExitSig(sym,cTkt,cOpTm,cOpPx,cLot,cTPPx,cSLPx),12,12);
// Output (ExitSequence)= -0-0-0-1
for(int k=0; k<StringLen(ExitSequence); k+=2)
if(StringSubstr(ExitSequence,k,1)=="-") {
int temCase=(int)StringToInteger(StringSubstr(ExitSequence,k+1,1));
switch(temCase) {
case 1: {
if(MarketInfo(sym,MODE_TRADEALLOWED)==true) {
//Print("Cs BUY "+sym+" ("+TimeToStr(TmNow)+"/Tkt "+IntegerToString(cTkt)+") /ExitSigVal:"+ExitSig(sym,cTkt,cOpTm,cOpPx,cLot,cTPPx,cSLPx)+
//"/k:"+IntegerToString(k)+"/temCase:"+IntegerToString(temCase)+" /ExitSequence:"+ExitSequence);
//Output : Cs BUY AUDCHF (2025.04.14 14:13/Tkt 285304721) /ExitSigVal:+0+0+0+0+0-0-0-0-0-1/k:6/temCase:1 /ExitSequence:-0-0-0-1
if(!OrderClose(cTkt,cLot,cBid,10)) Print("Error BUY CloseOrder : ",GetLastError());
else SequenceBreak=true;}
break;}
default : break;}
if(SequenceBreak) break;}} I think the Print Output above "Cs BUY AUDCHF (2025.04.14 14:13/Tkt 285304721) /ExitSigVal:+0+0+0+0+0-0-0-0-0-1/k:6/temCase:1 /ExitSequence:-0-0-0-1" should be able to enlighten you how the whole exit section works.
I have the following questions needing your advice and seeking your help :-
1) For the loop "for(int k=0; k<StringLen(ExitSequence); k+=2)", could you please explain how the "k+=2" works ? If you can provide some illustrations to explain would be the best. I'm a beginner, I can only understand k++ or k-- only.
2) In this exit section, it uses only one "case 1 (switch)", I think it is unnecessary / redundant. Could you please help me to modify the codes so that :-
a) No more "case 1 (switch) + break", i.e. to remove the relevant codes totally
b) Must keep the ExitSig(sym,cTkt,cOpTm,cOpPx,cLot,cTPPx,cSLPx) codes as it is required in other functions.
Finally, as long as [StringSubstr(ExitSequence,k,1)=="-"] finds any "-" in the ExitSequence, the OrderClose should close the BUY orders immediately. The codes must ensure that the relevant BUY order are confirmed has been closed only then stop looping the OrderClose.
Thank you.