Прошу помощи у профов написал код для трейлинга в MQL4 но почему-то на Buy работает а на Sell нет - страница 2
Вы упускаете торговые возможности:
- Бесплатные приложения для трейдинга
- 8 000+ сигналов для копирования
- Экономические новости для анализа финансовых рынков
Регистрация
Вход
Вы принимаете политику сайта и условия использования
Если у вас нет учетной записи, зарегистрируйтесь
Спасибо, попробую!
Попробовал, ничего не изменилось, по прежнему modify происходит только на buy, грешил на отступы брокера но ведь они на sell и buy одинаковы, да и в спецификации к инструменту отступы =0 а я даю 10 и все равно не происходит modify на sell, ордера по sell профиту в роботе работают но опять повторюсь без modify!
Что вам мешает использовать то что уже написано,
Пример;
for(int cnt=0;cnt<total;cnt++)
{
if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
continue;
if( OrderSymbol()==Symbol()) // check for symbol
{
//--- long position is opened
if(OrderType()==OP_BUY)
{
//--- check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
//--- modify order and exit
if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green))
Print("OrderModify error ",GetLastError());
return;
}
}
}
}
else
{
//--- check for trailing stop
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
//--- modify order and exit
if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red))
Print("OrderModify error ",GetLastError());
return;
}
}
}
}
}
}
.......MACD Sample
Что вам мешает использовать то что уже написано,
Пример;
for(int cnt=0;cnt<total;cnt++)
{
if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
continue;
if( OrderSymbol()==Symbol()) // check for symbol
{
//--- long position is opened
if(OrderType()==OP_BUY)
{
//--- check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
//--- modify order and exit
if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green))
Print("OrderModify error ",GetLastError());
return;
}
}
}
}
else
{
//--- check for trailing stop
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
//--- modify order and exit
if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red))
Print("OrderModify error ",GetLastError());
return;
}
}
}
}
}
}
.......MACD Sample
Что вам мешает использовать то что уже написано,
Пример;
for(int cnt=0;cnt<total;cnt++)
{
if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
continue;
if( OrderSymbol()==Symbol()) // check for symbol
{
//--- long position is opened
if(OrderType()==OP_BUY)
{
//--- check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
//--- modify order and exit
if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green))
Print("OrderModify error ",GetLastError());
return;
}
}
}
}
else
{
//--- check for trailing stop
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
//--- modify order and exit
if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red))
Print("OrderModify error ",GetLastError());
return;
}
}
}
}
}
}
.......MACD Sample
Что вам мешает использовать то что уже написано,
Пример;
for(int cnt=0;cnt<total;cnt++)
{
if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
continue;
if( OrderSymbol()==Symbol()) // check for symbol
{
//--- long position is opened
if(OrderType()==OP_BUY)
{
//--- check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
//--- modify order and exit
if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green))
Print("OrderModify error ",GetLastError());
return;
}
}
}
}
else
{
//--- check for trailing stop
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
//--- modify order and exit
if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red))
Print("OrderModify error ",GetLastError());
return;
}
}
}
}
}
}
.......MACD Sample
не совсем то что нужно, прийдется переделывать да и мой код гораздо проще нужно понять в чем ошибка!!!
Прошу помощи у профов написал код для трейлинга в MQL4 но почему-то на Buy работает а на Sell нет
подскажите в чем прикол а то я уже голову сломал!!!
Выводите ваши переменные на Print() или в Comment(). Увидите, какие значения они принимают, найдёте ошибки.
Так будет всё тралить. Организацию обработки ошибок посмотрите в предложенных выше примерах.
{
for(int i=OrdersTotal()-1;i>=0;i--)
{Orders=OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true;//выбор ордера
Ticket_ordera_TRSTOP=OrderTicket();
if ((OrderType()==OP_SELL)&&(Ask<(OrderOpenPrice()-NormalizeDouble(TR_otstup*Point,5))&&((TrallStopLoss_Ask>(Ask+NormalizeDouble(Point*TR_otstup,5)))||(TrallStopLoss_Ask==0))))
{
TrallStopLoss_Ask=Ask+Point*TR_otstup;
Orders=OrderModify(Ticket_ordera_TRSTOP,OrderOpenPrice(),(Ask+NormalizeDouble(Point*TR_otstup,5)),OrderTakeProfit(),0,clrDarkViolet);
//Print ("ошибка трейлинга- "+GetLastError());
}
if ((OrderType()==OP_BUY)&&(Bid>(OrderOpenPrice()+NormalizeDouble(TR_otstup*Point,5)))&&(TrallStopLoss_Bid<(Bid-NormalizeDouble(Point*TR_otstup,5))))
{
TrallStopLoss_Bid=Bid-Point*TR_otstup;
Orders=OrderModify(Ticket_ordera_TRSTOP,OrderOpenPrice(),(Bid-NormalizeDouble(Point*TR_otstup,5)),OrderTakeProfit(),0,clrDarkViolet);
//Print ("ошибка трейлинга- "+GetLastError());
}
}
}
Выводите ваши переменные на Print() или в Comment(). Увидите, какие значения они принимают, найдёте ошибки.
Так будет всё тралить. Организацию обработки ошибок посмотрите в предложенных выше примерах.
{
for(int i=OrdersTotal()-1;i>=0;i--)
{Orders=OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true;//выбор ордера
Ticket_ordera_TRSTOP=OrderTicket();
if ((OrderType()==OP_SELL)&&(Ask<(OrderOpenPrice()-NormalizeDouble(TR_otstup*Point,5))&&((TrallStopLoss_Ask>(Ask+NormalizeDouble(Point*TR_otstup,5)))||(TrallStopLoss_Ask==0))))
{
TrallStopLoss_Ask=Ask+Point*TR_otstup;
Orders=OrderModify(Ticket_ordera_TRSTOP,OrderOpenPrice(),(Ask+NormalizeDouble(Point*TR_otstup,5)),OrderTakeProfit(),0,clrDarkViolet);
//Print ("ошибка трейлинга- "+GetLastError());
}
if ((OrderType()==OP_BUY)&&(Bid>(OrderOpenPrice()+NormalizeDouble(TR_otstup*Point,5)))&&(TrallStopLoss_Bid<(Bid-NormalizeDouble(Point*TR_otstup,5))))
{
TrallStopLoss_Bid=Bid-Point*TR_otstup;
Orders=OrderModify(Ticket_ordera_TRSTOP,OrderOpenPrice(),(Bid-NormalizeDouble(Point*TR_otstup,5)),OrderTakeProfit(),0,clrDarkViolet);
//Print ("ошибка трейлинга- "+GetLastError());
}
}
}
Всем большое спасибо проблема решена тема закрыта!!!
Отдельное спасибо sile: за решение проблемы!!!