T
Hello All
I am relatively new to programming and trying to work on a function which returns lot size based on martingale strategy.
In summary, it looks at the previous MAXTRADES number of trades and for every loss trade it increments the lot size by +1. For example, for first 5 loss trades the lot size should be calculated as 1,2,3,4,5. I have come up with below logic, but does not seem to get it working. Can the experts please glance through the code and help in fixing it.
I know martingale is not right approach, but this is purely to learn money management coding techniques.
Thank you.
double extern LOTSIZE=1;
double extern MAXTRADES=5;
double Lots()
{
double LastTradeResult = 0;
double y=LOTSIZE;
for (double x = 0; x <= MAXTRADES; x++)
{
OrderSelect (x, SELECT_BY_POS, MODE_HISTORY);
if (OrderType()==OP_BUY)
{
LastTradeResult=(OrderClosePrice()-OrderOpenPrice())*10000;
}
else
{
LastTradeResult=(OrderOpenPrice()-OrderClosePrice())*10000;
}
if (LastTradeResult<0)
{
y=OrderLots()+1;
}
else
{
y=LOTSIZE;
}
}
return(y);
}
Hello All
I am relatively new to programming and trying to work on a function which returns lot size based on martingale strategy.
In summary, it looks at the previous MAXTRADES number of trades and for every loss trade it increments the lot size by +1. For example, for first 5 loss trades the lot size should be calculated as 1,2,3,4,5. I have come up with below logic, but does not seem to get it working. Can the experts please glance through the code and help in fixing it.
I know martingale is not right approach, but this is purely to learn money management coding techniques.
Thank you.
double extern LOTSIZE=1;
double extern MAXTRADES=5;
double Lots()
{
double LastTradeResult = 0;
double y=LOTSIZE;
for (double x = 0; x <= MAXTRADES; x++)
{
OrderSelect (x, SELECT_BY_POS, MODE_HISTORY);
if (OrderType()==OP_BUY)
{
LastTradeResult=(OrderClosePrice()-OrderOpenPrice())*10000;
}
else
{
LastTradeResult=(OrderOpenPrice()-OrderClosePrice())*10000;
}
if (LastTradeResult<0)
{
y=OrderLots()+1;
}
else
{
y=LOTSIZE;
}
}
return(y);
}