Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 908

 


Hello!

Can I set the length of the Fibonacci extension lines in OBJ_EXPANSION? What does it depend on?

Regards, Alexander

 
Hi guys, can you tell me if it's possible to modify an open position by changing only the comment of the position? When I partially close a position, I can do it, but I can't change just the comment. For example, a situation has occurred in the market and I want to add some information to the comment of the open position
Совершение сделок - Торговые операции - MetaTrader 5
Совершение сделок - Торговые операции - MetaTrader 5
  • www.metatrader5.com
Торговая деятельность в платформе связана с формированием и отсылкой рыночных и отложенных ордеров для исполнения брокером, а также с управлением текущими позициями путем их модификации или закрытия. Платформа позволяет удобно просматривать торговую историю на счете, настраивать оповещения о событиях на рынке и многое другое. Открытие позиций...
 
Tango_X:
Hi all! guys, can you tell me if it's possible to modify an open position BY CHANGING ONLY THE COMMENT OF THIS POSITION? When I partially close a position, I get it done, but changing just the comment does not work. For example, a situation has occurred in the market and I want to add some information to the comment of the open position

the order comment cannot be changed in any way - from the word impossible....a the broker's server changes the comment, who at the transition through 0:00 h, almost everywhere at partial closing of the order, often at full closing of the order in the history of orders the comment of the order will be changed

You cannot change the order comment even when the order is partially closed - the order comment is available only once - only when the order is sent to the server (order opening)

like this ;)

 
Igor Makanu:

the order comment cannot be changed in any way - from the word impossible....a the broker's server changes the comment, who at the transition through 0:00 h, almost everywhere at partial closing of the order, often at full closing of the order in the history of orders the comment of the order will be changed

You cannot change the comment on the order when it is partially closed either - the order comment is available only once - only when the order is sent to the server (order opening)

like this ;)

First you open a position with the comment "hello" and then you close it partially with the comment "hello again".

Your comment?

//+------------------------------------------------------------------+
//|                                              PositionCloseBy.mq5 |
//|                              Copyright © 2016, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property description "PositionCloseBy(Sell_Ticket, Buy_Ticket) когда цена Sell_Ticket ниже цены  Buy_Ticket)"
#property description "позиция Buy = 0.01 лот, позиция Sell = 0.02 лота."
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
#property version   "1.00"
//---
CPositionInfo  m_position;                   // trade position object

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class MyClass : public CTrade
  {
public :
   bool              PositionClosePartial(const ulong ticket,const double volume,string const comm, const ulong deviation=ULONG_MAX);
  };

MyClass        m_trade;                      // trading object
bool           BuyIsOpen=false;              // false - позиция Buy ещё не открыта
bool           SellIsOpen=false;             // false - позиция Sell ещё не открыта
bool           CloseBy=false;                // false - CloseBy ещё не выполняли
ulong          BuyTicket=0;                  // тикет позиции Buy
ulong          SellTicket=0;                 // тикет позиции Sell
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   BuyTicket=0;
   SellTicket=0;

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(!BuyIsOpen)
     {
         if(m_trade.Buy(0.20,NULL,0,0,0,"hello:)"))
           {
            if(m_trade.ResultRetcode()==TRADE_RETCODE_DONE && m_trade.ResultDeal()!=0)
              {
               BuyTicket=m_trade.ResultDeal();
               BuyIsOpen=true;
              }
           }
     }
//---
   if(BuyIsOpen && !CloseBy)
     {
           if(m_trade.PositionClosePartial(PositionGetTicket(0),0.05,"hello adain:)",1))
           {
            Print("PositionCloseBy -> true. Result Retcode: ",m_trade.ResultRetcode(),
                  ", description of result: ",m_trade.ResultRetcodeDescription(),"===== ",PositionGetString(POSITION_COMMENT));
            CloseBy=true;
           }
         else
           {
            Print("PositionCloseBy -> false. Result Retcode: ",m_trade.ResultRetcode()," "
                  ", description of result: ",m_trade.ResultRetcodeDescription());
           }
     }
  }
//+------------------------------------------------------------------+
//| Partial close specified opened position (for hedging mode only)  |
//+------------------------------------------------------------------+
bool MyClass::PositionClosePartial(const ulong ticket,const double volume, const string comm, const ulong deviation)
  {
//--- check stopped
   if(IsStopped(__FUNCTION__))
      return(false);
//--- for hedging mode only
   if(!IsHedging())
      return(false);
//--- check position existence
   if(!PositionSelectByTicket(ticket))
      return(false);
   string symbol=PositionGetString(POSITION_SYMBOL);
//--- clean
   ClearStructures();
//--- check filling
   if(!FillingCheck(symbol))
      return(false);
//--- check
   if((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
     {
      //--- prepare request for close BUY position
      m_request.type =ORDER_TYPE_SELL;
      m_request.price=SymbolInfoDouble(symbol,SYMBOL_BID);
     }
   else
     {
      //--- prepare request for close SELL position
      m_request.type =ORDER_TYPE_BUY;
      m_request.price=SymbolInfoDouble(symbol,SYMBOL_ASK);
     }
//--- check volume
   double position_volume=PositionGetDouble(POSITION_VOLUME);
   if(position_volume>volume)
      position_volume=volume;
//--- setting request
   m_request.action   =TRADE_ACTION_DEAL;
   m_request.position =ticket;
   m_request.symbol   =symbol;
   m_request.comment  = comm;
   m_request.volume   =position_volume;
   m_request.magic    =m_magic;
   m_request.deviation=(deviation==ULONG_MAX) ? m_deviation : deviation;
//--- close position
   return(OrderSend(m_request,m_result));
  }
Блог слесаря-ремонтника и механика по наладке оборудования | Советы для ремонтников
Блог слесаря-ремонтника и механика по наладке оборудования | Советы для ремонтников
  • wmua.ru
С первого раза даже не поверил, что в таком небольшом чемоданчике можно разместить столько электроинструмента! В общем, как говорится, лучше один раз увидеть: С Праздником 8 Марта! С Праздником Весны! Милые дамы, женщины, мамы и бабушки. Поздравляю Вас с праздником весны, праздником жизни. Спасибо Вам за то, что Вы у нас есть. Спасибо Вам за...
 
Igor Makanu:

the order comment cannot be changed in any way - from the word impossible....a the broker's server changes the comment, who at the transition through 0:00 h, almost everywhere at partial closing of the order, often at full closing of the order in the history of orders the order comment will be changed

You cannot change the comment on the order when it is partially closed either - the order comment is available only once - only when the order is sent to the server (order opening)

like this ;)

Or we just open a position manually on the chart with one comment and then manually close the position partially with another comment. I would like to change only comments

Совершение сделок - Торговые операции - MetaTrader 5
Совершение сделок - Торговые операции - MetaTrader 5
  • www.metatrader5.com
Торговая деятельность в платформе связана с формированием и отсылкой рыночных и отложенных ордеров для исполнения брокером, а также с управлением текущими позициями путем их модификации или закрытия. Платформа позволяет удобно просматривать торговую историю на счете, настраивать оповещения о событиях на рынке и многое другое. Открытие позиций...
 
Tango_X:

First a position is created with the comment "hello" and then it closes partially with the comment "hello again".

Your comment?

99% of the questions in this thread are for MT4 platform, you have not specified a platform, so I have answered based on MT4 capabilities.

Unfortunately I don't use SBTrade.mqh, I can't say anything, for me I only write for MT5 using MT4Orders.mqhhttps://www.mql5.com/ru/code/16006

 
Tango_X:

First a position is created with the comment "hello" and then it closes partially with the comment "hello again".

Your comments?

This example has been available for a long time. The CTrade class now has its own methodPositionClosePartial

 
Please give me a code for an EA, it would not open by indicators, but by candle colours and by timeframe.
 

Why can a functionhttps://www.mql5.com/ru/docs/array/arraymaximum have a declaration in its parameters

void&   array[]

but I'm not allowed to declare it in parameters of my function?

What should I do if I want to write my own ArrayMaximum(), because MT4 and MT5 have parameters mixed up (or specially)?

 
secret:

Why can a functionhttps://www.mql5.com/ru/docs/array/arraymaximum have a declaration in its parameters

but I'm not allowed to declare it in parameters of my function?

What should I do if I want to write my own ArrayMaximum() ?

The answer is here.
Reason: