How can I code this?

 

I want the EA to place two opposite pending orders in order to what I put below but it makes the same order type in YELLOW or RED case. For example in the RED case the EA would place SELLSTOP(1.2) & SELLSTOP(0.7) not BUYSTOP(0.7). Please help if know my mistake.

        op = OrderOpenPrice(); sl = OrderStopLoss(); tp = OrderTakeProfit(); type = OrderType();
        lot = NormalizeDouble(OrderLots() * LotMultiplier, DecimalPoints);
        level = GetCycleLevel(Time[i]);
        if (type == OP_BUY && level < MaxCycleLevels)
          SetOrder(OP_SELLSTOP, 1.2, sl, 0, sl- 0.0005, Time[i]);
          SetOrder(OP_BUYSTOP, 0.7, sl, sl-0.0005, 0, Time[i]);
        if (type == OP_SELL && level < MaxCycleLevels)
          SetOrder(OP_BUYSTOP, 1.2, sl, 0, sl+ 0.0005, Time[i]);
          SetOrder(OP_SELLSTOP, 0.7, sl, sl+ 0.0005, 0, Time[i]);
 
farrokhfa:

I want the EA to place two opposite pending orders in order to what I put below but it makes the same order type in YELLOW or RED case. For example in the RED case the EA would place SELLSTOP(1.2) & BUYSTOP(0.7) not BUYSTOP(0.7). Please help if know my mistake.

Are you sure ?

        if (type == OP_BUY && level < MaxCycleLevels) 
        {
          SetOrder(OP_SELLSTOP, 1.2, sl, 0, sl- 0.0005, Time[i]);
          SetOrder(OP_BUYSTOP, 0.7, sl, sl-0.0005, 0, Time[i]);
        }
        if (type == OP_SELL && level < MaxCycleLevels)
        {
          SetOrder(OP_BUYSTOP, 1.2, sl, 0, sl+ 0.0005, Time[i]);
          SetOrder(OP_SELLSTOP, 0.7, sl, sl+ 0.0005, 0, Time[i]);
        }
 
angevoyageur:

Are you sure ?

angevoyageur:

Are you sure ?

Sorry. For example in the RED case the EA would place SELLSTOP(1.2) & SELLSTOPSTOP(0.7) not BUYSTOP(0.7). Please help if know my mistake.
 
farrokhfa:
Sorry. For example in the RED case the EA would place SELLSTOP(1.2) & SELLSTOPSTOP(0.7) not BUYSTOP(0.7). Please help if know my mistake.
Don't you see I already answered ?
 
angevoyageur:
Don't you see I already answered ?
oh, yes I didn't see that. Now I did what you said but it ignores BUYSTOP(0.7). Means I have just SELLSTOP(1.2). what could be the mistake?
 
farrokhfa:
oh, yes I didn't see that. Now I did what you said but it ignores BUYSTOP(0.7). Means I have just SELLSTOP(1.2). what could be the mistake?
Who knows ? What errors are reported ? What's the code of SetOrder function() ?
 
angevoyageur:
Who knows ? What errors are reported ? What's the code of SetOrder function() ?

the SetOrder() function is:

int SetOrder(int type, double lot, double price, double sl, double tp, int magic)
{
  int ticket = -1;
  ticket = OrderSend(Symbol(), type, lot, price, 0, sl, tp, DoubleToStr(magic, 0), magic);
  int err = GetLastError();
  if (ticket == -1 && err > 0)
    Print("err=", err, ", type=", type, ", price=", price, ", lot=", lot, ", sl=", sl, ", tp=", tp, ErrorDescription(err));
  return (ticket);
}


and Error 130 is reported.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Codes of Errors and Warnings / Compilation Errors
Documentation on MQL5: Standard Constants, Enumerations and Structures / Codes of Errors and Warnings / Compilation Errors
  • www.mql5.com
Standard Constants, Enumerations and Structures / Codes of Errors and Warnings / Compilation Errors - Documentation on MQL5
 
farrokhfa:

the SetOrder() function is:


and Error 130 is reported.

I only realise now that you are talking about mql4. Please post your question about mql4 on mql4.com forum.

Error 130 means you have a problem with your stops, check your sl and tp.

MQL4: automated trading forum
  • www.mql5.com
MQL4: automated trading forum
Reason: