Lot calculation by Vince - page 8

 
Roman.:

For those who are interested - it was possible to reach working (average) values of the variable optimal f, by the method of geometric mean according to R. Vince in the EA included in the standard delivery of MA-based MT (see screenshot). Based on the conditions and order of calculation of optimum f by the book, its value is 0.36. After finishing the code, I will post the function here with the description and the order of using it to calculate the volumes of lots opened in future trades according to R. Vince's book.

Congratulations on your success! :))
 
MaxZ:
Congratulations on your success! :))

Thank you. Looks like I'll have to do a TWR array, just to be safe, as you advised.
 
MaxZ:
Congratulations on your success! :))


inflection point f = 0.36, i.e. as f increases further, the TWR variable - decreases - R. Vince is right! :-)))

 

Um, how can all this be attached to a working EA with the simplest definition of lot size in % of depo? Or maybe I'm not making enough profit)))

I mean, is it all mind games or has a practical application with a positive effect?

 
Dezil:

Um, how can all this be attached to a working EA with the simplest definition of lot size in % of depo? Maybe I'm not making enough profit)).

I mean all this is a mind game or has a practical application with a positive effect?


Sure, read R Vince - see the posts above in the trailer, I haven't even tested it on a demo myself yet... We'll see... :-)))

I'll post the fiya here as soon as I finish, with a description.

 
Roman.:


Sure, read R. Vince - see the posts above in the trailer, I haven't even tested it on a demo myself yet... We'll see... :-)))

As soon as I'm done, I'll post the fic here with a description.


Could you tell me what to read from Vince's work? What is the title of the work?
 
Dezil:

Can you tell me what to read from Vince? What is the title of the work?

Download the trailer from my post on page 2 of the thread from here - pages 30-32.
 
Roman.:

I think I've figured out where the mistake lies...

Let's go back to the original code, which we've already twisted a few times:

   for (f = 0.01; f<=1.0; f=f+0.01)//цикл перебора переменной f для поиска оптимального ее значения,при котором TWR-максимально
     {  
          
          for ( orderIndex = 1;orderIndex<Qnt; orderIndex++) //при заданной f проходим по всем закрытым ордерам
            {                                                // и считаем относительный конечный капитал (TWR)
             TWR = TWR*(1+f*(-Mas_Outcome_of_transactions[orderIndex]/(D))); // TWR - это произведение всех HPR
             //if (TWR>TWR_Rez) {TWR_Rez = TWR; Print(" TWR = ",TWR_Rez, " при f = ", f);}  
             //   else break;       
            }
          if (TWR>TWR_Rez) {
              TWR_Rez = TWR;
              G=MathPow (TWR_Rez, 0.001988); // 1/503 сделки по данной торговой системе, как в книжке: в степени 1/N 
              Print(" TWR = ",TWR_Rez," G = ",G, " при f = ", f);} // если текущий TWR > результирующего, 
              else break;    // то результирующий делаем равным текущему, иначе переходим на след итерацию цикла по f                                  
      }    

Could it be that the TWR variable is not reset to "1" at each iteration of f?

 
MaxZ:

I think I've figured out where the mistake lies...

Let's go back to the original code, which we've already twisted a few times:

Maybe it's all about the TWR variable not being reset to "1" at each iteration of f?


Yes, a competent point by the way... Possibly...quite possibly. I'll check it this afternoon and post here. Thank you.

Then it's not necessary to create a TWR array (like this one - the fresh version - either...

Here I tried all sorts of exorcisms to proportionally reduce its value in the product (because its absolute value is not important, it's the comparison by more/smaller that matters), so as to prevent overflow when calculating the optimum f.

for (f = 0.01; f<=1.0; f=f+0.01)//цикл перебора переменной f для поиска оптимального ее значения,при котором TWR-максимально
     {  
          
          for ( orderIndex = 1;orderIndex<Qnt; orderIndex++) //при заданной f проходим по всем закрытым ордерам
            {                                                // и считаем относительный конечный капитал (TWR)
             //TWR = MathPow(TWR*(1+f*(-Mas_Outcome_of_transactions[orderIndex]/(D))),0.33); // TWR - это произведение всех HPR                    
             Mas_TWR[orderIndex] = (1+f*(-Mas_Outcome_of_transactions[orderIndex]/(D))); // заполняем массив значениями HPR                               
            }
          //Print ("Mas_TWR[Qnt]= ", Mas_TWR[Qnt]); 
          
          for ( orderIndex = 1;orderIndex<Qnt; orderIndex++)         
              {
               TWR = MathSqrt(TWR*Mas_TWR[orderIndex]);}
               
          if (TWR>TWR_Rez)
              {
                TWR_Rez = TWR;               
                //G = MathPow(TWR_Rez, 1/N);
                     // G1 = G1*MathPow(Mas_TWR[orderIndex], 1/N);
                     //G=MathPow (TWR_Rez, 0.0054054); // 1/185 сделки по данной торговой системе, как в книжке: в степени 1/N 
                Print(" TWR_Rez = ",DoubleToStr(TWR_Rez,8), " при f = ", f); 
                                                       // если текущий TWR > результирующего
              } 
          else 
              {
                TWR_Rez = TWR;
               // G=MathPow (TWR_Rez, 1/N);
                Print(" А это уже меньше: TWR_Rez = ",DoubleToStr(TWR_Rez,8), " при f = ", f);                                                     
              }       
      }      
             
   Print("Закрытых позиций = ", Qnt, " Нетто Профит/лосс = ", SUMM, " У последней ",Qnt, " закрытой позы профит/лосс = ", 
        Mas_Outcome_of_transactions[Qnt]);     
 

I was too lazy to paste the code into the EA and check it myself! :)))

I don't have a proper Expert Advisor yet. I have only a few ideas. That's why I took a standard Moving Average without optimizing it and chose a profitable period.

The last code I tried, when I understood that TWR will not reset to "1", was as follows:

//+------------------------------------------------------------------+
//---------переменные для расчета лота по оптимальному f Ральфа Винса
int Mas_Outcome_of_transactions [10000]; // Массив профитов/убытков закрытых позиций

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//--- Расчет оптимального f ---
   int Qnt = 0, Orders = OrdersHistoryTotal();        // Счётчик количества ордеров   
   ArrayInitialize(Mas_Outcome_of_transactions, 0);   // Обнуление массива
   double f, D, SUMM, TWR, G, G_Rez, Pow = 1/NormalizeDouble(Orders, 0);
   int orderIndex;
   
   for (orderIndex = 0; orderIndex < Orders; orderIndex++)
   {   
      if (!OrderSelect(orderIndex, SELECT_BY_POS, MODE_HISTORY))
      {
         Print("Ошибка при доступе к исторической базе (",GetLastError(),")");
         continue;
      }
   
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != magic || OrderCloseTime()==0)
         continue; 
         
      int lastType = OrderType();
      double lastLots = OrderLots();
      double lastProfit = OrderProfit() + OrderSwap();
      
      if (orderIndex == 0 || lastProfit < D)
         D = lastProfit;
      
      Mas_Outcome_of_transactions[Qnt] = lastProfit;  // Заполняем массив профитом/лоссом по всем закрытым позициям 
      SUMM=SUMM+lastProfit;
      Qnt++;                                          // увеличиваем счетчик закрытых ордеров    
   }
   
   Print("D = ", DoubleToStr(D, 2), " Pow = ", DoubleToStr(Pow, 8));
   
   for (f = 0.01; f<=1.0; f=f+0.01)                   // цикл перебора переменной f для поиска оптимального ее значения,
   {                                                  // при котором G - максимально
      G = 1;
      for ( orderIndex = 1; orderIndex < Qnt; orderIndex++) // при заданной f проходим по всем закрытым ордерам
      {                                                     // и считаем среднее геометрическое от TWR
         TWR = 1+f*(-Mas_Outcome_of_transactions[orderIndex]/(D));
         G *= MathPow(TWR, Pow);
      }
      if (G > G_Rez)
      {
         G_Rez = G;
         Print("G = ", G, " при f = ", f);
      }           // если текущий G > результирующего, то результирующий делаем равным текущему
      else break; // иначе переходим на следующую итерацию цикла по f
   }
   
   Print("Закрытых позиций = ",   Qnt,
         " Нетто Профит/лосс = ", SUMM,
         " У последней ",         Qnt,
         " закрытой позы профит/лосс = ", Mas_Outcome_of_transactions[Qnt-1]);
   
   return(0);
}

No TWR array.

You'll be waiting a long time for an overflow! ;D Although maybe it wouldn't have happened at all...