[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 324

 

borilunad:

Here is a question: Sometimes it happens on Real that ERR_COMMON_ERROR comes out, when a position is closed by Stop Loss and the Expert Advisor tries to close it by Close, and since the function provides for 3 attempts to close it, it tries up to 3 times. How can I stop it from trying?

Perform OrderSelect and check the OrderCloseTime before trying to close. If it is already higher than 0, the order is closed.

 
sergeev:

before attempting to close, execute OrderSelect and check OrderCloseTime. If it is already greater than 0, the order is closed.


I have Select, and where should I place OrderCloseTime? After Select or in CloseOrder()?

Looked in Doc. I don't have History Select, only Trad. So I will try to put this History Select after the close condition and before CloseOrder(). Thank you!

 
Inside the selection, after the filters for symbol and magik (if any), that is, we check the order for closing time, if it is not equal to zero (the order is closed), we prohibit its re-closing
 
FAQ:
Inside the selection, after filters for symbol and magik (if there are any), that is, we check the order for closing time, if it is not equal to zero (the order is closed), then we prohibit to close it again


Thank you! I'll try the one above then!

Here, tried to insert, ran it in the demo, but something comes out more errors and different. I'm asking first, from the stove, on this code from Doka:

  if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
    {
     datetime ctm=OrderOpenTime();
     int      ticket=OrderTicket();
     if(ctm>0) Print("Время открытия ордера № ",ticket," ",ctm);
     ctm=OrderCloseTime();
     if(ctm>0) Print("Время закрытия ордера № ",ticket," ",ctm);
    }
  else
    Print("OrderSelect() вернул ошибку ",GetLastError());

What is superfluous here, to insert between Selecta Trades, symbol checks, magik... и ... order type. Maybe datetime cmt and int ticket to introduce at the start? And the printer writes other errors.

And add a closing condition:

if(ctm == 0) {CloseOrder(OrderTicket(),OrderLots(),Bid,slip,Yellow);return(0);} else continue;

Help please!

 

Hi, could you give me a hint?

I want to open an order not immediately with stp and sl, but set stp and sl after the order is opened by modifying it

I did so:

ticket=OrderSend(Symbol(),cmd,lots,NormalizeDouble(open,Digits),5*_pipsMultiplyer,_orderComment,GenerateMagicNumber(magicNumber,Symbol(),Period()),0,SpringGreen)
{
OrderSelect(ticket,SELECT_BY_TICKET);
}
{
OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Blue);
return(0);

}


I don't know what the hell I'm doing.

right?

 
RMX13:

Hi, could you give me a hint?

I want to open an order not immediately with stp and sl, but set stp and sl after the order is opened by modifying it

I did so:

ticket=OrderSend(Symbol(),cmd,lots,NormalizeDouble(open,Digits),5*_pipsMultiplyer,_orderComment,GenerateMagicNumber(magicNumber,Symbol(),Period()),0,SpringGreen)
{
OrderSelect(ticket,SELECT_BY_TICKET);
}
{
OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Blue);
return(0);

}


I don't know what the hell I'm doing.

right?



And I don't get it and more! Use the SRC to outline the code, see above?
 
int orderOpen(int cmd, double open, int stopLossPips, int takeProfitPips, int magicNumber){       
      double sl=0, tp=0;
      if(stopLossPips>0){
         stopLossPips = MathMax(stopLossPips,MarketInfo(Symbol(),MODE_STOPLEVEL)+3*_pipsMultiplyer);
      }
      if(takeProfitPips>0){
         takeProfitPips = MathMax(takeProfitPips,MarketInfo(Symbol(),MODE_STOPLEVEL)+3*_pipsMultiplyer);
      }
      int ticket=-1;
      if(_doTrade){        
         double lots  = OrderLotSize();
         if(lots>=MarketInfo(Symbol(), MODE_MINLOT)){          
            //wait context
            if(TradeIsBusy() < 0) {
                 return(-1); 
            }
            if(cmd==OP_BUYSTOP || cmd==OP_BUY || cmd==OP_SELLLIMIT){
               RefreshRates();
               if(cmd==OP_BUY){
                  open=Ask;
               }
               if(stopLossPips>0){
                  sl=NormalizeDouble(open-stopLossPips*Point,Digits);
               }
               if(takeProfitPips>0){
                  tp=NormalizeDouble(open+takeProfitPips*Point,Digits);
               }
               ticket=OrderSend(Symbol(),cmd,lots,NormalizeDouble(open,Digits),5*_pipsMultiplyer,sl,tp,_orderComment,GenerateMagicNumber(magicNumber,Symbol(),Period()),0,SpringGreen);              
            }else{
               RefreshRates();
               if(cmd==OP_SELL){
                  open=Bid;
               }
               if(stopLossPips>0){
                  sl=NormalizeDouble(open+stopLossPips*Point,Digits);
               }
               if(takeProfitPips>0){
                  tp=NormalizeDouble(open-takeProfitPips*Point,Digits);
               }
               ticket=OrderSend(Symbol(),cmd,lots,NormalizeDouble(open,Digits),5*_pipsMultiplyer,sl,tp,_orderComment,GenerateMagicNumber(magicNumber,Symbol(),Period()),0,Red);
            }
For a start, is this piece responsible for opening an order?
 
I figured it out all by myself.
 
borilunad:


Thank you! I'll try the above then!

Here, tried to insert, ran it in demo, but something comes out more errors and different. I'm asking first, from the stove, on this code from Doki:

What is superfluous here to insert between Selecta Trades, symbol checks, magik... и ... order type. Maybe datetime cmt and int ticket to introduce at the start? And the printer writes other errors.

And add a closing condition:

Please help!


Eh, as the saying goes: "learn the student" (c)

for(int i=OrdersTotal()-1;i>=0;i--){
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES){
      if(OrderSymbol()!=Symbol()){continue;}// фильтр по символу(если не наш символ, то пропускаем)
      if(OrderMagicNumber()!=magik){continue;}// фильтр по магику
      if(OrderCloseTime()!=0){continue;}// фильтр по времени закрытия (если не=0 то ордер уже закрыт)
      if(OrderType()<=OP_SELL){//закрытие для рыночных ордеров
         OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),MarketInfo(OrderSymbol(),MODE_SPREAD),CLR_NONE);
      }else{// закрытие для отложенных ордеров
         OrderDelete(OrderTicket());
      }
   }
}

Delete (comment) what is not needed.

 
               ticket=OrderSend(Symbol(),cmd,lots,NormalizeDouble(open,Digits),5*_pipsMultiplyer,_orderComment,GenerateMagicNumber(magicNumber,Symbol(),Period()),0,Red);
            OrderSelect(ticket,SELECT_BY_TICKET);
            OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0);

A piece of code which opens an order and sets stop loss and take profit

terminal generates the following errors: EURUSD,M30: OrderSend error 130

EURUSD,M30: invalid ticket for OrderModify function

EURUSD,M30: OrderModify error 4051

EURUSD,M30: OrderSend failed with error #4051 bid:1.23674000 ask:1.23683000 Open:1.23674000 SL:1.2423 TP:1.2283 MODE_STOPLEVEL:0.00000000 LOT:0.01000000

What is the problem?


Reason: