Questions from a "dummy" - page 205

 
Renat:

After changing the language in Metaeditor, did you reboot it?

Let's check.

Everything works fine, I loaded mql5_russian.chm, put Russian in MetaEditor-e, reloaded, help pops up in Russian.
 

I have written this code to check the position:

CPositionInfo myposition;

if (myposition.Select(_Symbol))
{
   double Open_position=NormalizeDouble(myposition.PriceOpen(),_Digits);
   double SL_position  =NormalizeDouble(myposition.StopLoss(),_Digits);
   double TP_position  =NormalizeDouble(myposition.TakeProfit(),_Digits);
   Comment(" Open_position=",Open_position,"\n",
           " SL_position=",SL_position,"\n",
           " TP_position=",TP_position);
}

But for some reason in the comment the values appear with 4 decimal places. Instead of _Digits put 5 still 4 characters, put 3 - 3 characters.

 
paladin800: For some reason, values appear with 4 decimal places in the comments. Instead of _Digits put 5 still 4 digits, put 3 - 3 digits.
And if I just output myposition.PriceOpen(), what will it show?
 
paladin800:

I have written this code to check the position:

But for some reason in the comment the values appear with 4 decimal places. Instead of _Digits put 5 still 4 characters, put 3 - 3 characters.

You probably need the DoubleToString() function.

 
paladin800:

I have written this code to check the position:

But for some reason in the comment the values appear with 4 decimal places. Instead of _Digits put 5 still 4 characters, put 3 - 3 characters


The format for outputting fractional numbers in comments is as follows. Convert the dubs to string types and output them in the comments.
 
How do I set the initial account balance? I want to set the lot size depending on the total profit of the account. So how do I determine the initial balance correctly?
Документация по MQL5: Стандартные константы, перечисления и структуры / Состояние окружения / Информация о счете
Документация по MQL5: Стандартные константы, перечисления и структуры / Состояние окружения / Информация о счете
  • www.mql5.com
Стандартные константы, перечисления и структуры / Состояние окружения / Информация о счете - Документация по MQL5
 
tor4en: How can I determine the initial account balance? I want to specify lot size depending on total profit of my account. So, how to determine this initial balance correctly?

A deposit is accompanied by a record

DEAL_ENTRY_STATE

Sign of status entry

This is the direction to look in.

 

I'm confused about myposition.Type(). Did the following thing to check:

CPositionInfo myposition;
// ---
string classtype="no position";
string functype="no position";

if (PositionSelect(_Symbol))
{  // --- section SELL
   if (myposition.Type()==POSITION_TYPE_SELL)
       classtype="SELL";
   if (PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
       functype="SELL";
   // --- section BUY
   if (myposition.Type()==POSITION_TYPE_BUY)
       classtype="BUY";
   if (PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
       functype="BUY";
}
Comment ("classtype=",classtype,", functype=",functype);

The result of testing with the visualization is as follows:
1) there is no position: classtype=no position, functype=no position // as expected
2) there is a sell position: classtype=BUY, functype=SELL // classtype has incorrectly determined the position direction
3) there is a buy position: classtype=BUY, functype=BUY // as it should be

I tried putting if (myposition.Select(_Symbol)) instead of if (PositionSelect(_Symbol)), the result is the same. Maybe myposition.Type() should be written differently for it to correctly determine the direction of sell?

 
paladin800:

I'm confused about myposition.Type(). Did the following thing to check:

When testing with visualization, the result is as follows:
1) there is no position: classtype=no position, functype=no position // as required
2) there is a sell position: classtype=BUY, functype=SELL // classtype has erroneously determined the position direction
3) there is a buy position: classtype=BUY, functype=BUY // as it should be

I tried putting if (myposition.Select(_Symbol)) instead of if (PositionSelect(_Symbol)), the result is the same. Maybe myposition.Type() should be written differently for correct determination of the sell direction?

If you look closely at the CPositionInfo class "with X-ray", you may notice that the Type() method doesn't return the position type (unlike the PositionType() method).

   CPositionInfo myposition;
// ---
   string classtype="no position";
   string functype="no position";

   if(PositionSelect(_Symbol))
     {  // --- section SELL
      if(myposition.PositionType()==POSITION_TYPE_SELL)
         classtype="SELL";
      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
         functype="SELL";
      // --- section BUY
      if(myposition.PositionType()==POSITION_TYPE_BUY)
         classtype="BUY";
      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
         functype="BUY";
     }
   Print("classtype=",classtype,", functype=",functype);
  }
 
uncleVic:

If you look closely at the CPositionInfo "X-rayed" class, you will notice that the Type() method does not return a position type (unlike the PositionType() method).

Thank you very much. It worked with your tip! I was guided by the article How to Use the Standard Library Trade Classes When Writing an EA, and there in the section "1.6 CPositionInfo Class" there is myposition.Type(), which probably needs to be corrected.
Reason: