Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 102

 
Dozol:


Roger, I can't understand it!

Threw a horizontal line on the chart, fix its price, delete the line - it is no longer needed. Immediately we set an order at that price.

What is the mistake? And why a Sell Stop will not open?

Why keep following the price if I only need the price value of the horizontal line?

Explain!!! Help! More details, please!

Sellstop was wrong, it will open.

Now about the lines. When I trade live, I look at the chart and place a horizontal line, conditions are appropriate, the line is deleted and the order is opened. How is this better than a simple hotkey script? In the tester, to draw the line, you have to enable visualization and observe the chart. I do not even understand why we should add it to the tester.

 
borilunad:
Sorry! Then get on the potty and go to sleep! Have a good morning! ;)
Okay. I'll figure it out myself, it's not such an unsolvable riddle. But so far all I can think of is crutches. The crutch method is not a good method...
 
Good people, can you tell me what's wrong. In a sell trade, which opens on the first tick of the 0 bar, the stop loss should be set 30 pips (5 digits) above the High of the first candle. Wrote it this way, but the stop loss is not set at all.
     Price = NormalizeDouble(Bid, Digits); // округляем до нужного нам числа цифр после запятой
     if(StopLoss > 0)
     if(Bid < iHigh(Symbol(),0,1)) 
     {
       StopLoss = iHigh(Symbol(),0,1)+30*Point;
       SL= Price + StopLoss*Point;
       SL = NormalizeDouble(SL, Digits); // округляем до нужного нам числа цифр после запятой
      }
 
artmedia70:

And on your fingers? How can time and price tell you to close on the take? I can certainly think it myself, but it's 7.43 in the morning and I haven't gone to bed yet.


If it's 7.43 and I haven't gone to bed... So, I'm going to assume it's grail!
 
alexey1979621:
Good people, tell me what is wrong. In a sell trade, which opens on the first tick of the 0 bar, the stop loss should be set 30 pips (5 digits) above the High of the first candle. Wrote so, but stop loss is not placed at all.

StopLoss = iHigh(Symbol(),0,1)+30*Point;

This is the stop loss level you want, for example, 1.5000+30*0.00001 = 1.5003.


SL= Price + StopLoss*Point; 
Why else would you add StopLoss*Point to Price(1.5003*0.00001=0.000015). SL becomes almost equal to Price, that's why the StopLoss is not set.
 
The stop loss is still not set, but the take profit works. Stop loss and take profit code attached
Price = NormalizeDouble(Bid, Digits);  
     if(StopLoss > 0)
     if(Bid < iHigh(Symbol(),0,1)) 
      {
       StopLoss = iHigh(Symbol(),0,1)+30*Point;
       SL = NormalizeDouble(SL, Digits); 
      }
       else SL = 0;
       if(TakeProfit > 0)
      {
       TP = Price - TakeProfit*Point;
       TP = NormalizeDouble(TP, Digits); 
      }
       else TP = 0;
      { 
      ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SL,TP,"Pattern_1",Magic,0,Red);
      return;
      }
 
artmedia70:
1. Look for the last closed position (MODE_HISTORY).
2. If it closed at (or close to) the takeaway --> Remember its open time -->
3. Look through all open positions (MODE_TRADES) and compare their open time with the remembered (from point 2) --> If the remembered time of opening the position closed by the mark (from point 2) is the longest from the time of opening of other open positions --> It means that the last open position was closed by the mark -->
4. Crop/delete all the rest.


Hm. It seems to be written. But the result is not the same.

Here's what came out for me:

//+-------------------------------------------------------------------------------------+
//| Получаем состояние последней позиции (Открыта или закрыта)                          |
//+-------------------------------------------------------------------------------------+
datetime GetLastOrderState()
{
   datetime lastOrderCloseTime = -1,               // Время закрытия последнего открытого ордера
            lastOOTMarket = -1,          // Время открытия последнего открытого ордера рыночного
            lastOOTHist = -1;            // Время открытия последнего открытого ордера из истории
   
   for (int i=OrdersHistoryTotal()-1; i>=0; i--)
   {
      if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderType() > 1) continue;               // Все удалённые отложки нас не интересуют..
  
      if (lastOrderCloseTime < OrderCloseTime())   // Находим время закрытия..
          lastOrderCloseTime = OrderCloseTime();   // ..последней закрытой позиции в истории
      
      if (MathAbs(OrderTakeProfit() - OrderOpenPrice()) < i_tp * pt) return(0);
      
      lastOOTHist = OrderOpenTime();   // Тогда время открытия последней закрытой позиции из истории
   }
   
   Comment("Время открытия последнего открытого ордера = ", lastOOTHist);
  
   for (int h=OrdersTotal()-1; i>=0; i--)
   {   
      if (!OrderSelect(h, SELECT_BY_POS, MODE_TRADES)) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderSymbol() != Symbol()) continue;
      {
         if (lastOOTMarket < OrderOpenTime())
             lastOOTMarket = OrderOpenTime();
  
         if (lastOOTMarket < lastOOTHist)      // Если время открытия последнего открытого ордера (рыночного) ниже последнего открытого ордера из истории..
             lastOrderCloseTime = OrderCloseTime(); // Значит это искомый ордер
      }
   }

   Comment("Время закрытия последнего открытого ордера = ", lastOrderCloseTime);
   return (lastOrderCloseTime);
}
 
alexey1979621:
Good people, can you tell me what's wrong. In a sell trade, which opens on the first tick of the 0 bar, the stop loss should be set 30 pips (5 digits) above the High of the first candle. Wrote it this way, but the stop loss is not set at all.

What you have here is nothing at all. Let's start with the fact that short closes always on the ASC, not on the BID.
 
alexey1979621:
The stop loss is still not set, but the take profit works. Stop loss and take profit code attached

Price = NormalizeDouble(Bid, Digits);  
     if(StopLoss > 0)
     if(Bid < iHigh(Symbol(),0,1))               // Здесь еще STOPLEVEL нужно проверять, иначе частые ошибки будут
      {
       StopLoss = iHigh(Symbol(),0,1)+30*Point;  // Здесь вместо переменной StopLoss попробуйте поставить SL
       SL = NormalizeDouble(SL, Digits); 
      }
       else SL = 0;
       if(TakeProfit > 0)
      {
       TP = Price - TakeProfit*Point;
       TP = NormalizeDouble(TP, Digits); 
      }
       else TP = 0;
      { 
      ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SL,TP,"Pattern_1",Magic,0,Red);
      return;
      }
 
hoz:


Hmm. It seems to have been written. But the output is wrong...

This is what I got:

When searching for the last closed order, the most recent one should be found first, but the check for closing it at take should be taken out of the loop, otherwise it checks every closed order for closing at take and, if so, it remembers the time of the first one closed at take in the loop, not the most recent one.