Questions from a "dummy" - page 33

 
Renat:
i>=0
Thank you. Shame on me.)) So many times I used this enumeration in mql4 and made a mistake on such a simple thing.
 

It is not possible to select a position. For example:

   double Stop_Loss   = NormalizeDouble(OrderGetDouble(ORDER_SL),_Digits);
   double Open_Price  = NormalizeDouble(OrderGetDouble(ORDER_PRICE_OPEN),_Digits);
   
   double Amount_Risk = 0.0;
         
   for(count = PositionsTotal()-1; count >= 0; count--)
      {
       if(PositionSelect(SymbolName(count,true)))
         {
          int tp_pos;
          tp_pos = (ENUM_ORDER_TYPE)PositionGetInteger(POSITION_TYPE);
          if(tp_pos == ORDER_TYPE_BUY || tp_pos == ORDER_TYPE_SELL) 
            {
             Amount_Risk = MathAbs(Open_Price - Stop_Loss);
             Print("PositionTotal(): ",PositionsTotal(), " Amount_Risk: ",Amount_Risk);
            }
          if(GetLastError() != 0) Print(ErrorDescription(GetLastError()),", ",GetLastError());
         }
      }

There is an error in the logbook:

How to do it correctly?

Документация по MQL5: Торговые функции / PositionSelect
Документация по MQL5: Торговые функции / PositionSelect
  • www.mql5.com
Торговые функции / PositionSelect - Документация по MQL5
 
tol64:

It is not possible to select a position. For example:

Correct the error first, do not confuse order type and position type:

 tp_pos = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
 
tol64:

It is not possible to select a position. For example:

There is an error in the logbook:

How to do it correctly?

It would be easier for you to ask where you got it wrong...

To make it work, the construct

if(PositionSelect(SymbolName(count,true))) should be replaced with:

if(PositionSelect(PositionGetSymbol(count))

and further you confuseENUM_ORDER_TYPE with ENUM_POSITION_TYPE

 
Rosh:

Correct the error first, don't confuse order type and position type:

Vladix:

It would be easier for you to ask where you are not mistaken...

Thank you and I apologise for my really gross errors. This is a temporary phenomenon and the misunderstanding will soon pass.)
 

Please advise how to solve this problem:

I am developing Expert Advisors, libraries and indicators for MT5 on two computers.

What is the easiest way to organize the transfer of developments from one computer to another, preferably with automatic synchronization. I.e. to automatically take the freshest file and replicate it.

Computers are on the same network. There is a shared folder which is shared over the internet.

 
use VCS
 
TheXpert:
use VCS
I didn't specify Windows7 computers. The hardest part is figuring out how it stacks the files in the file system. With XP it was all clear, there was one directory where everything was in, but here everything is scattered.
 
Andrian22:
I didn't specify Windows7 computers. The hardest part is figuring out how it stacks files in the file system. With XP it was all clear, there was one directory where everything was, but here everything is scattered.
See Help Getting Started - Launch Terminal - "Guest Mode" (with the /portable switch)
 
Vladix:

It would have been easier for you to ask where you got it right...

To make it work, the construct

if(PositionSelect(SymbolName(count,true))) should be replaced with:

if(PositionSelect(PositionGetSymbol(count))

I looked at the different variants and noticed that they are all identical in terms of the end result. That is, each of these options:

 if(PositionSelect(Symbol()))
 if(PositionSelect(PositionGetSymbol(count)))
 if(PositionSelect(SymbolName(count,true)))

... will return the same result.

And in my case it didn't affect the result in any way))) Finished the script:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
 for(int count = 0; count < PositionsTotal(); count++)
   {
    double Amount_Risk = 0.0;
    string Type_pos;
    
    if(PositionSelect(Symbol()))
    //if(PositionSelect(PositionGetSymbol(count)))
    //if(PositionSelect(SymbolName(count,true)))
      {
       int tp_pos = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
       string Symbol_pos = PositionGetSymbol(count);
       double Acc_Blnc   = AccountInfoDouble(ACCOUNT_BALANCE);
       double Order_Lots = PositionGetDouble(POSITION_VOLUME);
       double Stop_Loss  = NormalizeDouble(PositionGetDouble(POSITION_SL),_Digits);
       double Open_Price = NormalizeDouble(PositionGetDouble(POSITION_PRICE_OPEN),_Digits);
       
       switch(tp_pos)
         {
          case 0 : Type_pos = "LONG";  break;
          case 1 : Type_pos = "SHORT"; break;
         }
       
       Amount_Risk += MathAbs(((((Open_Price - Stop_Loss)*10000)*(Order_Lots*10))/Acc_Blnc)*100);
       
       Print("PositionTotal(): ",PositionsTotal(),", Symbol: ",Symbol_pos,", Position: ",Type_pos,", Amount_Risk: ",DoubleToString(Amount_Risk,2),"%");

       if(GetLastError() != 0) Print(ErrorDescription(GetLastError()),", ",GetLastError()); ResetLastError();
      }
   }
}

Now everything works correctly. Variants mentioned above are commented out and you can compare. The result is always the same in the log: