Download MetaTrader 5

How can I code this?

To add comments, please log in or register
Farrokh Faghih
316
Farrokh Faghih  

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]);
Alain Verleyen
Moderator
31182
Alain Verleyen  
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]);
        }
Farrokh Faghih
316
Farrokh Faghih  
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.
Alain Verleyen
Moderator
31182
Alain Verleyen  
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 ?
Farrokh Faghih
316
Farrokh Faghih  
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?
Alain Verleyen
Moderator
31182
Alain Verleyen  
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() ?
Farrokh Faghih
316
Farrokh Faghih  
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
Alain Verleyen
Moderator
31182
Alain Verleyen  
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
To add comments, please log in or register