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

 
Craft >>:

А я в форексе не силён.....как учитывается спред?


The difference between the best buy (bid) and sell (ask) prices at the same moment in time - i.e. supply and demand. If you make a Buy trade on forex, you buy at the Bid price, and when you close the order, you sell at the Ask price, the difference between the Bid and Ask and will be the value of the spread, usually from 2 to 6 pips for different currencies and in different brokerage companies
 

I think this is accounted for in the code, in OrderSend the bid with the ask is prescribed:

//--------------------------------------------------------------- 8 --
   // Открытие ордеров
   while(true)                                  // Цикл закрытия орд.
     {
      if (Total==0 && Opn_B==true)              // Открытых орд. нет +
        {                                       // критерий откр. Buy
         RefreshRates();                        // Обновление данных
         Alert("Попытка открыть Buy. Ожидание ответа..");
         Ticket=OrderSend(Symb,OP_BUY,Lts,Ask,2,0,0);//Открытие Buy
         if (Ticket > 0)                        // Получилось :)
           {
            Alert ("Открыт ордер Buy ",Ticket);
            return;                             // Выход из start()
           }
         if (Fun_Error(GetLastError())==1)      // Обработка ошибок
            continue;                           // Повторная попытка
         return;                                // Выход из start()
        }
      if (Total==0 && Opn_S==true)              // Открытых орд. нет +
        {                                       // критерий откр. Sell
         RefreshRates();                        // Обновление данных
         Alert("Попытка открыть Sell. Ожидание ответа..");
         Ticket=OrderSend(Symb,OP_SELL,Lts,Bid,2,0,0);//Открытие Sel
         if (Ticket > 0)                        // Получилось :)
           {
            Alert ("Открыт ордер Sell ",Ticket);
            return;                             // Выход из start()
           }
         if (Fun_Error(GetLastError())==1)      // Обработка ошибок
            continue;                           // Повторная попытка
         return;                                // Выход из start()
        }
      break;                                    // Выход из while
     }
 
Craft >>:

А я в форексе не силён.

Futures is not forex.

How is the spread taken into account?

It is usually deducted.

 
Swetten >>:

Фьючерсы -- это не Форекс.

I see, decided to fill the gap. So this code can't be adapted for futures?
 
You can. You need to know the point price and the spread.
 

OK mates - help. Here is the specification of the contract:

What/how do I need to consider?

 

The cost of the tick and the size of the tick -- that's where the problem lies.

I mean, what you get is: A "pip" is five ticks. Five ticks (one "pip" in forex terms) cost 3, roughly speaking, rubles.

That is, the discretization (right?) is not 1:1, but 1:5 for one minimal change of price.

In general, it is better to wait for the older comrades.

 

Good afternoon. Problem with Trailing Stop.

Not quite correctly modified orders. It turns out that the stop loss level follows the price regardless of price movement.

Let's say we open a buy order. The price grows, trailing stop triggers and stop loss is pulled up. Then the price moves in the opposite direction and the order is not closed,

The order is not closed and is modified and the stop loss level is lowered. As the result the deal becomes unprofitable, although it was opened in the right direction.

  total=OrdersTotal();
      
  for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         if(OrderType()==OP_BUY)   // long position is opened
           {
          
            // check for trailing stop
         
            if(TrailingStop>0)  
              {               
               if( Bid-OrderOpenPrice()>Point*TrailingStop )
                 { 
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     
                     OrderModify(OrderTicket(),OrderOpenPrice(), Bid-StopLoss,Bid + TakeProfit/*OrderTakeProfit()*/,0,Green);
                     
                     return(0);
                    }
                 }
              }
           }
         else // go to short position
           {
             
            // check for trailing stop
          
            if(TrailingStop>0 )  
              { 
                            
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  
                    if((OrderStopLoss()>(Ask+Point*TrailingStop)) )
                      {
                      
                     
                       OrderModify(OrderTicket(),OrderOpenPrice(),Ask+StopLoss,Ask-TakeProfit/*OrderTakeProfit()*/,0,Red);
                       
                       return(0);
                      }
                 }
              }
           }           
           
        }     

I supposed that this is prevented by check if( Bid-OrderOpenPrice()>Point*TrailingStop) but it seems to be wrong. What do you advise?

 
vanson >>:

Доброго времени суток. Проблема с Trailing Stop'ом.

Не совсем корректно модифицируются ордера. Получается так,что уровень Stop Loss следует за ценой независимо от движения цены.

Допустим открывается ордер на покупку. Цена растет,срабатывает trailing stop и стоп лосс подтягивается. Потом цена пошла в обратном направлении,ордер не закрывается,

ордер не закрывается, а модифицируется и понидается уровень stop loss'a. В итоге сделка становится убыточной, хотя открылась она в правильном направлении.

Предполагал, что от этого предохраняет проверка if( Bid-OrderOpenPrice()>Point*TrailingStop ), но видимо это не так. Что посоветуете?

See how it's done in the ready-made library of different trailing functions. You can learn from it, or you can use it straight away... May the author forgive me. Although they are available in the public domain... :)
Files:
 
How can you tell if the price has crossed a certain level upwards or downwards, in order to open when it has happened? I am using the price and not the indicators. Thank you for your feedback...