1

I manage to get normal lot exponent but I need to change it a bit by grouping example in the picture. Can someone guide me how to get the lot exponent but with a grouping technique Group=5 Exponent=1.8?

double GroupExponent(int type)
{
   double lot=0,exponent=1.8,group=5,initialLot=0.01;
   if(type==OP_SELL)                         
   .............                            //<---- Do i need to loop this area ?
      lot= initialLot * MathPow(exponent,TotalSell());   
   return lot;
}

int TotalSell()
{
   int Sell=0;
   for(int trade=OrdersTotal()-1; trade>=0; trade--)
   {
      if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))continue;
      if(OrderSymbol()==Symbol() && OrderType()==OP_SELL))
         Sell++;
   }
   return Sell;
}

enter image description here

Roller
  • 35
  • 7

2 Answers2

1

No, you don't need a cycle. You can attain your layer system like this:

double GroupExponent(int type)
{
   double lot=0,exponent=1.8,initialLot=0.01;
   int group = 5;
   if(type==OP_SELL)                         
   {
      lot = NormalizeDouble(initialLot * MathPow(exponent, (TotalSell() - 1) / group), 2);
   }
   return lot;
}

int TotalSell()
{
   int Sell=0;
   for(int trade=OrdersTotal()-1; trade>=0; trade--)
   {
      if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))continue;
      if(OrderSymbol()==Symbol() && OrderType()==OP_SELL))
         Sell++;
   }
   return Sell;
}

Note: This will work as intended only if Layer == 1 equals TotalSell() == 1. If Layer == 1 equals TotalSell() == 0, then there is no need to subtract 1 from TotalSell() inside MathPow().

Enivid
  • 210
  • 2
  • 9
  • yes! this is what im looking for..thank you! – Roller Nov 28 '20 at 11:53
  • So, for a case there was zero SELL-side trades, your code will exponentiate the base == 1.8 to the power of -1 / 5 ? That seems awfully wrong & irresposible, doesn't it? It produces about 5 SHORTs, 0.89 Lots each on a first shot, totaling something around 4.45 Lots just on the first layer of the composite scheme - was this corrent? I doubt. – user3666197 Nov 28 '20 at 12:15
  • @user3666197, the question doesn't provide any condition for layer #0, but the -1 / 5 for ints in MQL4 results in 0. Sorry, I don't understand what you mean by producing SHORTs. – Enivid Nov 28 '20 at 12:59
  • In MQL4 the exponent is documented to cast the second operand to double, so there is zero-warranty that your code did not get compiled without doing so for operands there.Even a one-shot test in script is not enough to avoid these risks, as the published API is clear in this -- double MathPow( double base, double exponent ); -- so one has zero-warranty any next MQL4-compiler build will produce the machine code in any particular fashion (we all remember the day,when MQL4 string simply ceased to be a string anymore & silently started to become struct, so if I say a risk I know how big it is) :o) – user3666197 Nov 28 '20 at 16:57
  • BTW, in the domain of professional trading, the term **short** is clear & sound ( for some hundred years already ) buying an instrument is going long, selling it is going short, so 5 shorts are those 5 positions in the group, exactly as they were required. – user3666197 Nov 28 '20 at 17:00
  • @user3666197 I understand perfectly all the words in your commentary about producing shorts. What I don't understand is the meaning of the sentences you use them in. Who produces shorts? Why does it produce shorts? How did you arrive at the numbers 0.89 and 4.45? – Enivid Nov 28 '20 at 18:19
  • @user3666197 As for the code, the only problems there are that the group is declared as double and the ambiguity between the "layer" and "TotalSell()" from the question's text. I will now address both of them in the edit. PS: if the divisor is integer, the integer division is used even if the result is assigned to a double variable according to MQL4 documentation. – Enivid Nov 28 '20 at 18:22
0

Q : "How to group a lot exponent in MQL4 / MT4?"

Well, technically speaking, the Exponent = 1.8 is not an exponent per-se, but rather a scaling constant, that gets exponentiated by plain ordinals.

See the calculation formula of the Lot-sizings, that match the Table above:

|
|>>> for                                   aLayerNUMBER in range( 1, 11 ):
...      aVolumeInLOTs = 0.01 * ( 1.8 ** ( aLayerNUMBER - 1 ) )
...      print "LAYER: {0: >2d} - {1: >5.2f} Lots".format( aLayerNUMBER,
...                                                        aVolumeInLOTs
...                                                        )
... 
LAYER:  1 -  0.01 Lots
LAYER:  2 -  0.02 Lots
LAYER:  3 -  0.03 Lots
LAYER:  4 -  0.06 Lots
LAYER:  5 -  0.10 Lots
LAYER:  6 -  0.19 Lots
LAYER:  7 -  0.34 Lots
LAYER:  8 -  0.61 Lots
LAYER:  9 -  1.10 Lots
LAYER: 10 -  1.98 Lots
+0:01:07.587141
13:31:06
|
|>>>

In MQL4 there will go, most often this :
double aVolumeInLOTs = NormalizeDouble( 0.01 * MathPow( 1.8, aLayerNUMBER - 1 ), 2 );

The groupings are groups of (here) 5 trades, each having the same size / volume,
again in the exponentiated progression of ( 0.01, 0.02, 0.03, 0.06, 0.10, 0.19, 0.34, 0.61, 1.10, 1.98, 3.57, 6.42, 11.56, 20.82, 37.48, 67.46, 121.43, 218.59, 393.46, ... )

The last piece of the puzzle is a reason, where to stop producing the 5-trades' groups ( why stopping right at the fourth group-of-5-s, sized 0.06 Lots each, and not proceeding anywhere further ).

That information was not present in the Question and remains thus an un-decidable for us, obviously, unless more pieces of information were added.

user3666197
  • 1
  • 6
  • 50
  • 92
  • its ok..this missing part is just by dividing with group -----> lot= initialLot * MathPow(exponent,TotalSell()/group); this will get the result objectives ;) – Roller Nov 28 '20 at 12:06