Questions from a "dummy" - page 137

 
alph:

Could you give me some code for an EA to close a position after 5-6 hours? Or give me a link.

If you are interested, try it yourself. First, using the PositionSelect() function , check for an open position. If it is successful, find out the time of opening a position using PositionGetInteger(POSITION_TIME) and check your condition of 5-6 hours. When it is time to close the position, you find out the type of position (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE) and its volume PositionGetDouble(POSITION_VOLUME) . Then you set an opposite order with the same volume. You can see an example of the position closing method at MQL5\Include\Trade\Trade .mqh\PositionClose(const string symbol,ulong deviation=ULONG_MAX).

 
joo:
Thank you, that seems to be what we need.

Not really.

To get the "mouse click" event, OnChartEvent() must be used, but it cannot be used in scripts, what should I do? So there is no universal function?

 
joo:

Not really.

To get the "mouse click" event, OnChartEvent() must be used, but it cannot be used in scripts, what should I do? So there is no universal function?

Then use GetKeyState + GetPosition + known coordinates of graphical objects.
 
sergeev:
Then use GetKeyState + GetPosition + known coordinates of graphical objects.

VinApi?

That's it, I've lost my desire to make a universal function for browsing and selecting a file from a list (some kind of mini-file manager). :(

 
joo:

WINAPI?

That's it, I've lost the desire to make a universal function for browsing and selecting a file from a list (some kind of mini-file manager). :(

why a script? how do you want to make a function and wait for user's choice for more than one tick?
 
sergeev:
why the script then?
Because it doesn't care if the ticks are ticking or not.
 
Yedelkin:

See an example of method for closing a position at MQL5\Include\Trade\Trade.mqh\PositionClose(const string symbol,ulong deviation=ULONG_MAX).

Thank you.

But I'm not yet able to understand classes, although what I have is usually due to the fact that I've seen somewhere and figured it out.

 
joo:
because he doesn't care if the ticks are ticking or not.
so does the expert not care. why the script?
 
alph:

But with classes, I'm not yet getting the hang of it, although what I do get is usually at the expense of seeing it somewhere and figuring it out.

Well, any class method is just plain code. Try parsing this code here:

   MqlTradeRequest   m_request={0};         // request data
   MqlTradeResult    m_result={0};          // result data
   MqlTradeCheckResult m_check_result={0};  // result check data
   bool   partial_close=false;
   int    retry_count  =10;
   uint   retcode      =TRADE_RETCODE_REJECT;
  
     do
     {
      //--- checking
      if(PositionSelect(symbol))
        {
         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);
           }
        }
      else
        {
         //--- position not found
         m_result.retcode=retcode;
         return(false);
        }
      //--- setting request
      m_request.action      =TRADE_ACTION_DEAL;
      m_request.symbol      =symbol;
      m_request.deviation   =(deviation==ULONG_MAX) ? m_deviation : deviation;
      m_request.type_filling=m_type_filling;
      m_request.volume      =PositionGetDouble(POSITION_VOLUME);
      //--- check volume
      double max_volume=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX);
      if(m_request.volume>max_volume)
        {
         m_request.volume=max_volume;
         partial_close=true;
        }
      else
         partial_close=false;
      //--- order check
      if(!OrderCheck(m_request,m_check_result))
        {
         //--- copy return code
         m_result.retcode=m_check_result.retcode;
         return(false);
        }
      //--- order send
      if(!OrderSend(m_request,m_result))
        {
         if(--retry_count!=0) continue;
         if(retcode==TRADE_RETCODE_DONE_PARTIAL)
            m_result.retcode=retcode;
         return(false);
        }
      retcode=TRADE_RETCODE_DONE_PARTIAL;
      if(partial_close) Sleep(1000);
     }
   while(partial_close);
 
sergeev:
so the expert doesn't care. why a script?
If not a script, should all logic be performed/called to/from OnChartEvent()?