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
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 stopif(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 stopif(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?
Доброго времени суток. Проблема с 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... :)
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...
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
А я в форексе не силён.....как учитывается спред?
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:
А я в форексе не силён.
Futures is not forex.
How is the spread taken into account?
It is usually deducted.
Фьючерсы -- это не Форекс.
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.
I supposed that this is prevented by check if( Bid-OrderOpenPrice()>Point*TrailingStop) but it seems to be wrong. What do you advise?
Доброго времени суток. Проблема с Trailing Stop'ом.
Не совсем корректно модифицируются ордера. Получается так,что уровень Stop Loss следует за ценой независимо от движения цены.
Допустим открывается ордер на покупку. Цена растет,срабатывает trailing stop и стоп лосс подтягивается. Потом цена пошла в обратном направлении,ордер не закрывается,
ордер не закрывается, а модифицируется и понидается уровень stop loss'a. В итоге сделка становится убыточной, хотя открылась она в правильном направлении.
Предполагал, что от этого предохраняет проверка if( Bid-OrderOpenPrice()>Point*TrailingStop ), но видимо это не так. Что посоветуете?