Download MetaTrader 5

Learning mql4

To add comments, please log in or register
Order the development and track its status via your mobile phone.
snjage
16
snjage 2016.03.17 19:14 
I got this code from the mql4 programming book.
Can someone please explain to me why there is an addition of one in this line of the code 'One_Farm=One_Farm*(1+Perc_day/100)' and a subtraction of 1 in this one 'One_Farm=One_Farm*(1-Perc_exit/100);'
int start()                               // Special function start()
  {
//-------------------------------------------------------------------------------------
   int
   day,                                   // Current day of the month
   Mons;                                  // Search amount of months
   double
   One_Farm    =1000.0,                   // Sheep on the 1st farm
   Perc_day    =1,                        // Daily increase, in %
   One_Farm_max=50000.0,                  // Sheep limit
   Perc_exit   =10,                       // Monthly output, in %
   Purpose     =35000.0,                  // Required amount on farm 2
   Two_Farm;                              // Current amount of farm 2
//-------------------------------------------------------------------------------------
   while(Two_Farm < Purpose)              // External cycle on history
     {                                    // Start of the external cycle body
      //-------------------------------------------------------------------------------
      for(day=1; day<=30; day++)          // Cycle for days of month
         One_Farm=One_Farm*(1+Perc_day/100);//Accumulation on the 1st farm
      //-------------------------------------------------------------------------------
      Mons++;                             // Count months
      if (One_Farm < One_Farm_max)        // If the amount is below limit,.
         continue;                        // .. don't transfer the sheep
      Two_Farm=Two_Farm+One_Farm*Perc_exit/100;//Sheep on the 2nd farm
      One_Farm=One_Farm*(1-Perc_exit/100);// Remainder on the 1st farm
     }                                    // End of the external cycle body
//-------------------------------------------------------------------------------------
   Alert("The aim will be attained within ",Mons," months.");//Display on the screen
   return;                                // Exit function start()
  }
//-------------------------------------------------------------------------------------
To add comments, please log in or register