noobie question

1. Can someone explain to me how this EA compute the lot size for each trade cause I understand litlle from mt4 languages.

//| Calculate optimal lot size |
// ------------------------------------------------------------------
dual LotsOptimized()
{
double lot=Lots;
int orders=HistoryTotal(); // background orders complete
int losses=0; // amount of losses orders without a fracture
//-- select lot dimensions
lot=NormalizeDouble(AccountFreeMargin()*MaximumRis k/1000.0,1);
//-- calcuulate amount of losses orders without a fracture
if(DecreaseFactorlt;0)

for(int I=orders-1;igt;=0;I--)

if(OrderSelect(I,SELECT_BY_POS,MODE_HISTORY)==fals e) Printing(Error in background!) ; split;
if(OrderSymbol()!) =Symbol()
if(lossesgt;1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);

//-- return lot dimensions
if(lotlt;0.01) lot=0.01;
return(lot);  Reply With Quote

2. From this particular line:
dual lot=Lots;
...
if(lossesgt;1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);

first, you've got first lot size, named Lots (look at extern variable, at the top of the code)
let's say Lots = 0.2.
Then there's DecreaseFactor, lets say DecreaseFactor=5
in case your successive losses equals to 2 (losses higher than 1)
then lot dimensions = 0.2 - 0.2*2/5 = 0.2 - 0.4/5 = 0.2 - 0.08 = 0.12
It's rounded to 1 decimal point =gt; NormalizeDouble(...,1)
0.12 =gt; 0.1

expect this help  Reply With Quote

3. Thank you I understand now Originally Posted by ;
from that point:
double lot=Lots;
...
if(lossesgt;1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);

first, you've got initial lot size, termed Lots (look at extern variable, at the top of the code)
let us state Lots = 0.2.
Then there is DecreaseFactor, lets say DecreaseFactor=5
if your successive losses equals to 2 (losses greater than 1)
then lot size = 0.2 - 0.2*2/5 = 0.2 - 0.4/5 = 0.2 - 0.08 = 0.12
it is rounded to 1 decimal point =gt; NormalizeDouble(...,1)
0.12 =gt; 0.1

expect this help  Reply With Quote

4. There's something that I donlt;t know. In case the account free margin is 3000 and the maximum risk is .01 the lot size should be
3000* .01 / / 1000 = .03 but the EA takes just a .01 lot size. At few event the EA open .1 lot when the account grow to 5000 but at this point it must open 5000*.01/1000 =.05 lot.
//| Calculate best lot size |
// ------------------------------------------------------------------
double LotsOptimized()
{
double lot=Lots;
int orders=HistoryTotal(); // background orders total
int losses=0; // number of losses orders with no fracture
//-- pick lot size
lot=NormalizeDouble(AccountFreeMarg in()*MaximumRisk/1000.0,1);
//-- calcuulate number of losses orders with no fracture
if(DecreaseFactorlt;0)

for(int I=orders-1;igt;=0;I--)
OrderType()gt;OP_SELL) remain;
//--
if(OrderProfit()gt;0) break;
if(OrderProfit()lt;0) losses ;

if(lossesgt;1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);

//-- return lot size
if(lotlt;0.01) lot=0.01;
return(lot);  Reply With Quote

5. I still dont understand the Ea doesn't open the lot size.

Cqn womeone inform me what the 1 stand for in the code....

Lot=NormalizeDouble(AccountFreeMarg in()*MaximumRisk/1000.0,1); Originally Posted by ;
There is something else I donlt;t know. In case the account free margin is 3000 and the max risk is .01 the lot size should be

3000* .01 / 1000 = .03 however, the EA takes only a .01 lot dimensions. At few event the EA open .1 lot when the account grow to 5000 but at this stage it must open 5000*.01/1000 =.05 lot.
//| Calculate best lot size |
// ------------------------------------------------------------------
double LotsOptimized()
{
double lot=Lots;
int orders=HistoryTotal(); // background orders total
int losses=0; //...  Reply With Quote

6. Hello,

it seems there is incorrect logic with my last reply. The function calculated lot dimensions not from Lots factor, but from :
lot=NormalizeDouble(AccountFreeMarg in()*MaximumRisk/1000.0,1);

firstly, about NormalizeDouble(. . ,1), it is going to yield worth with 1 digit accuracy.

For example, var1 = 5/8 = 0.625.
NormalizeDouble(var1,2) = 0.63 gt;gt;gt; 2 digit after decimal point
NormalizeDouble(var1,1) = 0.6 gt;gt;gt; 1 digit after decimal point

AccountFreeMargin=3000
MaximumRisk = 0.01
AccountFreeMargin*MaximumRisk/1000 = 3000*0.01/1000 = 0.03
lot=NormalizeDouble(0.03,1) = 0.0 !!! The 3 is omitted because it is in the second place, counted from the left following decimal point

afterward before returning the result:
//-- yield lot dimensions
if(lotlt;0.01) lot=0.01;
return(lot);
therefore, because the calculated lot above result 0 that is smaller then 0.01, the role returned 0.01;

last thing, you need to use if(DecreaseFactorgt;0) instead if(DecreaseFactorlt;0), and make sure that the worth of DecreaseFactor is a positive value (for example 3)

hope this help  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•