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;
}
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()
.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.