[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 619

 
kwadrad:

What can you do about it?

update the data before opening, normalise the price

Vinin:

I wrote right away that this closure is not recommended. An undocumented feature is being used. But any open position has a closing time of zero, and the closing price will be equal to the current closing price.

after all these experiences this is already obvious)

 
kwadrad:

What can be done about it?

Look carefully at the prices you set when you open a position. Surely there must be... Is Ask mixed up with Bid?
 
artmedia70:
Look carefully at the prices you set when opening a position. Surely there must be... Is Ask mixed up with Bid?

Yes, it is. I have.
 
kwadrad:

it is. Thank you.
You're welcome - it's the first thing newbies get confused about, I know that...
 
Has anyone made a simple trailing stop move a pending order behind the price instead of the stop level? Is it possible to do?
I have tried and tried, but all I got was that the pending order moves back and forth behind the price like a sick man...

Is it possible to rework the simple trailing function so that it deals with orders instead of stops? For example this one:

//+----------------------------------------------------------------------------+
//|  Сопровождение позиции простым тралом                                      |
//|  Параметры:                                                                |
//|    sy - наименование инструмента   ("" - текущий символ)                   |
//|    op - операция                   (-1 - любая позиция)                    |
//|    mn - MagicNumber                (-1 - любой магик)                      |
//+----------------------------------------------------------------------------+
  void TrailingPositionsSimplTR(string sy="", int op=-1, int mn=-1) {
  double p, pp;
  int    i, k=OrdersTotal();

  if (sy=="" || sy=="0") sy=Symbol();
  p=MarketInfo(sy, MODE_POINT);
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy && (op<0 || OrderType()==op)) {
        if (mn<0 || OrderMagicNumber()==mn) {
          if (OrderType()==OP_BUY) {
            pp=MarketInfo(sy, MODE_BID);
            if (!ProfitTrailing || (pp-OrderOpenPrice())>TrailingStopBuy*p) {
              if (OrderStopLoss()<pp-(TrailingStopBuy+TrailingStepSimplTR-1)*p) {
                ModifyOrder(sy, -1, pp-TrailingStopBuy*p, 0, clModifyBuy);//
              }
            }
          }
          if (OrderType()==OP_SELL) {
            pp=MarketInfo(sy, MODE_ASK);
            if (!ProfitTrailing || OrderOpenPrice()-pp>TrailingStopSell*p) {
              if (OrderStopLoss()>pp+(TrailingStopSell+TrailingStepSimplTR-1)*p || OrderStopLoss()==0) {
                ModifyOrder(sy, -1, pp+TrailingStopSell*p, 0, clModifySell);
              }
            }
          }
        }
      }
    }
  }
}
 
ToLik_SRGV:

Print() rounds up to 4 digits to correctly output to the console the type double(which returns iOpen() 5 decimal places, in this case), you should use DoubleToStr() function

string DoubleToStr( double value, int digits)
Converts a numeric value to a text string containing a character representation of a number in the specified precision format.

Parameters:

value - Величина с плавающей точкой.

digits - Формат точности, число цифр после десятичной точки (громное спасибо.


Thank you very much .
 
Roger:


Check out this EA, I have implemented it there

http://www.rogersignals.com/ru/experts.php?a=Support_Resistance

OK, thanks, I'll look into it...
 
artmedia70:
Has anyone made a simple trailing stop move a pending order behind the price instead of the stop level? Is it possible to do?
I tried and tried, but all I got was that the pending order moves back and forth behind the price like a sick person...

Is it possible to rework the simple trailing function so that it deals with orders instead of stops? For example this one:

Everything is too complicated :)))
Here's my code

//+------------------------------------------------------------------+
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){
                  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){
                  if(!OrderModify(OrderTicket(),Bid-Point*trailing,OrderStopLoss(),OrderTakeProfit(), 0))Print(">>> ERROR ", GetLastError());
               }else{
                  Print(">>> Слишком близко к рынку!");
               }
            }
            return;
         }
      }
      index++;
   }
}
//+------------------------------------------------------------------+
You pass in method as parameters a delayed medge, and a desired trall.
 
      for (i =0;i<OrdersTotal();i++)
      {
         if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true&&OrderMagicNumber()==MAGICMA&&OrderSymbol()==Symbol())
         {
            if (MathAbs(funk-OrderOpenPrice())>Point)
            {
               if (OrderType()==OP_BUYSTOP||OrderType()==OP_BUYLIMIT&&MathAbs(Ask-funk)>MarketInfo(Symbol(),MODE_STOPLEVEL)*Point)
               {
                  OrderModify(OrderTicket(),NormalizeDouble(funk,Digits),OrderStopLoss(),NormalizeDouble(funk+TakeProfiti*Point,Digits),0);
               }
               if (OrderType()==OP_SELLSTOP||OrderType()==OP_SELLLIMIT&&MathAbs(Bid-funk)>MarketInfo(Symbol(),MODE_STOPLEVEL)*Point)
               {
                  OrderModify(OrderTicket(),NormalizeDouble(funk,Digits),OrderStopLoss(),NormalizeDouble(funk-TakeProfiti*Point,Digits),0);
               }
            }
         }
      }
something like this, where the order is trawled by the calculated funk value
 
ToLik_SRGV:

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

Pass in method as parameters a delayed medjw, and desired trall.

Thank you! I think this is it!
Reason: