MQII Question

 
I realize that this is not the correct site for MQII questions, but, I wasn't sure where else to go to get support.

I'm trying to create an expert which both closes part of an order and then moves it's SL to B/E at nearby levels. But, I'm running into the 10-second limitation. Is there any known workaround to this in MQII?

Thanks.

stockwet
 
You can use flags, see example (WasClosedNow flag)
/*[[
    Name := MA20 cross
    Author := Copyright й 2003, Metaquotes Software Corp
    Link := https://www.metaquotes.net//
    Lots := 1.00
    Stop Loss := 0
    Take Profit := 0
    Trailing Stop := 0
]]*/
 
Variables: PrevTime(0);
Variables: MaCurrent(0),MaPrevious(0);
Variable: cnt(0), WasClosedNow(False);
 
If Not WasClosedNow And PrevTime=Time Then exit;
PrevTime=Time;
 
MaCurrent=iMA(20,MODE_SMA,1);
MaPrevious=iMA(20,MODE_SMA,2);
 
If Close[2]>MaPrevious And Close[1]<MaCurrent And WasClosedNow=False Then Begin
    print("Close crosses down MA20");
    SetOrder(OP_SELL,1,Bid,3,0,0,RED);
    Exit;
End;
 
If (Close[2]<MaPrevious And Close[1]>MaCurrent) Or WasClosedNow Then Begin
    If (Close[2]<MaPrevious And Close[1]>MaCurrent) then print("Close crosses up MA20")
    Else print("Some trades is to be closed");
    For cnt=1 to TotalTrades Begin
        If OrderValue(cnt,VAL_SYMBOL)=Symbol And
           OrderValue(cnt,VAL_TYPE)==OP_SELL Then Begin
            CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Bid,3,Violet);
            WasClosedNow=True;
            Exit; // close only 1 order at same time! and exit
        End;
    End;
    WasClosedNow=False;
    // open position at next time
    SetOrder(OP_BUY,Lots,Ask,3,0,0,GREEN);
End;
 
I'm doing something similar. The problem I'm running into is that after the CloseOrder block, I set my flag. But, the flag gets set whether or not the order actually goes through or not. So, I can see in my journal that the order was requested (close #5479138 1.00 lots at 236.0700 [slippage 3]), but, the order didn't actually close. So, I don't want the flag set unless the operation actually goes through.

I did try this:
if ModifyOrder(OrderValue(i,VAL_TICKET),OrderValue(i,VAL_OPENPRICE), OrderValue(i, VAL_OPENPRICE)+(Point*s),OrderValue(i,VAL_TAKEPROFIT),Red)
then 
{
  setFlag = True;
  Print(setFlag);
}

But, that didn't seem to have any effect at setting the flag at all, even though it compiled.

 
I'm also getting this "empty stack when poping" message that I can't seem to find any information on.
 
Are You sure that ModifyOrder returns anything? It returns nothing, therefore You get "empty stack..."

This function cannot be used as if expression
Reason: