Function request

 

function request after 2 lose trades (one behind the other) change Lots

-i will change Lots after 2 lose trades(one behind the other)

can help me please ?

--

 

This should do it

Hi Alex

This post has a function, that you will have to customize a bit, but it should do it.

https://www.mql5.com/en/forum/173315

 

let's move things even further... it would be a cool thing to be able to adjust the lots either by increasing in case of a number of wins trades or by decreasing accordingly after a number of losses.

 
spahiu:
let's move things even further... it would be a cool thing to be able to adjust the lots either by increasing in case of a number of wins trades or by decreasing accordingly after a number of losses.

I've been working on something to increase the number of lots traded, but it's not a priority as I have other issues with the system to iron out. The idea was to have a user set variable on profit progression. The user would set how many times an investment should double(ie +100pips) before increasing the number of lots traded. So if the user input 3 as the progression, the expert would need to make +300 pips before the number of lots traded would increase. In effect, this give you the ability to take some profit from your investment before reinvesting winning capital by quadrupling your initial investment and then taking half of that and investing it. If for some reason you lose the second tier margin, it would reset you back one tier and you still have 2 chances to move to the second tier from the first tier, because of taking the triple profit on the first tier initial round.

Let me know what you think.

Mookfx

 

sounds interesting i will think about it,

i was considering increasing/decreasing lot sizes according to percentage of the last gain/loss... so if your last trade(s) made lets say 10% profit on Balance you would increase your next trades size with 10% same with the eventual losses...

 

Thanks

spahiu:
let's move things even further... it would be a cool thing to be able to adjust the lots either by increasing in case of a number of wins trades or by decreasing accordingly after a number of losses.

risk idea

i have EA the make consecutive loss =2 (since 2001 backtesting and 2 month forwarding testing* )

my idea is after consecutive loss =2 comming 99,9% one profit trade

theone profit trade = maxLots

maxLots = MathCeil(AccountBalance() * 99 / 10000) / 10;

if (maxLots < 0.1) maxLots = Lots;

if (maxLots > 1.0) maxLots= MathCeil(maxLots);

if (maxLots> 100) maxLots = 100;

only idea i will testing

* 2 month forwarding testing = 1:1 with backtesting--

sorry my bad english

 
void MoneyManagement()

{

int i,hstTotal=HistoryTotal();

int losses;

for(i=hstTotal-1;i>=0;i--)

{

//---- check selection result

if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)

{

Print("Access to history failed with error (",GetLastError(),")");

break;

}

if(OrderProfit()>0) break;

if(OrderProfit()<0) losses++;

if(losses==2) {

lotMM = MathCeil(AccountFreeMargin() * 50 / 10000) / 10; // 50 risk

if (lotMM < 0.1) lotMM = Lots;

if (lotMM > 1.0) lotMM = MathCeil(lotMM);

if (lotMM > 100) lotMM = 100;

}

}

risk idea only if EA make consecutive loss 2 !!! (since 2001)

--

Files:
 

your working with the number of losses...i'm intersted both in that and in the value of that loss/winn,

if you take a big loss you'll have to reduce the lots more significantly than you'll do with a smaller one..same goes for wins..this will boost winners and contain eventual drawdowns... using someone like interbankfx which allows micro-mini lots(0.01 lots) you can adjust trade size in a more dynamic fashion... but how are we going to read the last trades results?

 

but how are we going to read the last trades results?

? with HistoryTotal()

 
Alex.Piech.FinGeR:
but how are we going to read the last trades results? ? with HistoryTotal()

don't know...yet.

 

How about this?

Sorry I don't know how to post code just yet - but won't this do the trick?

void MoneyManagement()

{

int i,hstTotal=HistoryTotal();

int losses;

double val1;

for(i=hstTotal-1;i>=0;i--)

{

//---- check selection result

if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==fals e)

{

Print("Access to history failed with error (",GetLastError(),")");

break;

}

if(OrderProfit()>0){

val1 = 0;

break;

}

if(OrderProfit()<0) {

losses++;

val1 = val1 + orderProfit();

}

if(losses==2) {

lotMM = MathCeil(AccountFreeMargin() * 50 / 10000) / 10; // 50 risk

if (lotMM < 0.1) lotMM = Lots;

if (lotMM > 1.0) lotMM = MathCeil(lotMM);

if (lotMM > 100) lotMM = 100;

}

}

Reason: