[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 621

 
Yes.
 
Roger:
Yeah.
:) Now the error 130 has appeared. The most strange thing is that with wrong stops (130) it still sets correct takei (calculated by ATR), but my stops were not set from the beginning...
Is there any way to understand it?
 
b0r1s:

Need help!!! How to choose the last losing order from the history???


//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает флаг убыточности последней позиции.                 |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
bool isLossLastPos(string sy="", int op=-1, int mn=-1) {
  datetime t;
  int      i, j=-1, k=OrdersHistoryTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (t<OrderCloseTime()) {
                t=OrderCloseTime();
                j=i;
              }
            }
          }
        }
      }
    }
  }
  if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY)) {
    if (OrderProfit()<0) return(True);
  }
  return(False);
}

if (isLossLastPos(NULL, -1, Magic искомого ордера)) {нашли - обрабатываем...}
 
ToLik_SRGV:

It's a little too complicated for you :))
Here is my code

Pass in method as parameters a delayed medjack and desirable trall.

I can't understand why your function gives error 1 (funny: error 1 = no error, but result unknown) and doesn't trawl. Sometimes it might catch some delay, but mostly >>>ERROR1 in the log and don't cough...

This is how I do it:

//==============================================================================================
   // Модификация ордеров
//============================================================================================== 
   int criterion = TakeProfitATR (1);                // Рассчитываем "достаточную" волатильность
   if (criterion>=15) trailingOrder(511, 20);        // и если она в "норме" - тралим ордера...
//==============================================================================================

// Функция для рассчёта Take Profit по ATR

//+------------------------------------------------------------------+
//|                  Take from ATR                                   |
//+------------------------------------------------------------------+
double TakeProfitATR (int tf)
  {
   double   atr   =iATR(NULL,tf,14,0);
   double   mltp  =15000;
   if (tf==1) mltp=15000;
   if (tf==5) mltp=45000;
   double   tp    =MathRound(atr*mltp);
   return  (tp);
  }
 
artmedia70:

I can't understand why your function gives error 1 (funny: error 1 = no error, but result unknown) and doesn't trawl. Sometimes it might catch some delay, but mostly >>>ERROR1 in the log and don't cough...

I call it this way:


Error 1 can occur because of this (from OrderModify() doc):

If unchanged values are passed as function parameters, then error 1 (ERR_NO_RESULT) will be generated.

So it's OK, there really is no error, you can ignore it.
 
artmedia70:

I can't understand why your function gives error 1 (funny: error 1 = no error, but result unknown) and doesn't trawl. Sometimes it might catch some pending error, but most of the time >>>ERROR1 is in the log and don't cough...

This is how I do it:


I added Limit`order(in last code I forgot about them :))) + error #1 processing (before modification new price is compared with current one, if they are the same, then do nothing):

//+------------------------------------------------------------------+
void trailingOrder(int magic, int trailing){
   int index = 0;
   while(trailing > 0 && OrdersTotal() != 0 && OrderSelect(index, SELECT_BY_POS)){
      if(OrderMagicNumber() == magic){
         if(OrderType() == OP_BUYSTOP){
            if(OrderOpenPrice() - Ask > Point*trailing){
               if((Ask+Point*trailing) - Ask >= MarketInfo(Symbol(), MODE_STOPLEVEL)*Point &&
                 (Ask+Point*trailing) - Ask > MarketInfo(Symbol(), MODE_FREEZELEVEL)*Point &&
                 (Ask+Point*trailing) != OrderOpenPrice()){
                  if(!OrderModify(OrderTicket(),Ask+Point*trailing,OrderStopLoss(),OrderTakeProfit(), 0))Print(">>> ERROR ", GetLastError());
               }else{
                  Print(">>> Слишком близко к рынку или передано неизмененное значение!");
               }
            }
            return;
         }
         if(OrderType() == OP_SELLSTOP){
            if(Bid - OrderOpenPrice() > Point*trailing){
               if(Bid - (Bid-Point*trailing) >= MarketInfo(Symbol(), MODE_STOPLEVEL)*Point &&
                 Bid - (Bid-Point*trailing) > MarketInfo(Symbol(), MODE_FREEZELEVEL)*Point &&
                 (Bid-Point*trailing) != OrderOpenPrice()){
                  if(!OrderModify(OrderTicket(),Bid-Point*trailing,OrderStopLoss(),OrderTakeProfit(), 0))Print(">>> ERROR ", GetLastError());
               }else{
                  Print(">>> Слишком близко к рынку или передано неизмененное значение!");
               }
            }
            return;
         }
         if(OrderType() == OP_SELLLIMIT){
            if(OrderOpenPrice() - Bid > Point*trailing){
               if((Bid+Point*trailing) - Bid >= MarketInfo(Symbol(), MODE_STOPLEVEL)*Point &&
                 (Bid+Point*trailing) - Bid > MarketInfo(Symbol(), MODE_FREEZELEVEL)*Point &&
                 (Bid+Point*trailing) != OrderOpenPrice()){
                  if(!OrderModify(OrderTicket(),Bid+Point*trailing,OrderStopLoss(),OrderTakeProfit(), 0))Print(">>> ERROR ", GetLastError());
               }else{
                  Print(">>> Слишком близко к рынку или передано неизмененное значение!");
               }
            }
            return;
         }
         if(OrderType() == OP_BUYLIMIT){
            if(Ask - OrderOpenPrice() > Point*trailing){
               if(Ask - (Ask-Point*trailing) >= MarketInfo(Symbol(), MODE_STOPLEVEL)*Point &&
                 Ask - (Ask-Point*trailing) > MarketInfo(Symbol(), MODE_FREEZELEVEL)*Point &&
                 (Ask-Point*trailing) != OrderOpenPrice()){
                  if(!OrderModify(OrderTicket(),Ask-Point*trailing,OrderStopLoss(),OrderTakeProfit(), 0))Print(">>> ERROR ", GetLastError());
               }else{
                  Print(">>> Слишком близко к рынку или передано неизмененное значение!");
               }
            }
            return;
         }
      }
      index++;
   }
}
//+------------------------------------------------------------------+
 

By the way, I found a mistake in the Tutorial about StopLevel and FreezeLevel distances for pendants:

Limitation on the minimum StopLevel distance.

The trade operation is not executed if any of these requirements is violated.

Order type Opening price of the order (OpenPrice) StopLoss (SL) TakeProfit (TP)
Buy
No modification allowedBid-SL StopLevelTP-Bid ≥ StopLevel
Sell
No modification allowedSL-Ask StopLevelAsk-TP StopLevel
BuyLimit
Ask-OpenPrice StopLevelOpenPrice-SL StopLevelTP-OpenPrice ≥ StopLevel
SellLimit
Bid-OpenPrice ≥ StopLevelSL-OpenPrice ≥StopLevelOpenPrice-TP StopLevel
BuyStop
OpenPrice-Ask StopLevelOpenPrice-SL StopLevelTP-OpenPrice StopLevel
SellStop
Bid-OpenPrice StopLevelSL-OpenPrice StopLevelOpenPrice-TP StopLevel

SellLimit is set above the current price, so this is correct:

OpenPrice - Bid ≥ StopLevel

 
How do I open two opposing orbits 50 pips apart?
 

is there any way to sort the instruments in the tabs at the bottom of the screen? because 8 instruments in 4 timeframes are scattered in a mess....

 
Rossi:

is there any way to sort the instruments in the tabs at the bottom of the screen? because 8 instruments in 4 timeframes are scattered in a mess....


grab the tab with the name of the chart and drag it to the right place