1. You could use a variable to retain the last lots SaveLots=Lots; // this comes after OrderSend;
and
Lots=SaveLots+0.1; //before ordersend
2. You could do similar, with a global variable
Lots=GlobalVariableGet("SaveLots")+0.1;
...
GlobalVariableSet("SaveLots",Lots) ; // after ordersend
however, you have to make sure SaveLots is being set at 0, if not already existing (check with GlobalVariableCheck())
3. Most complicated and safe, use a function that works for sure
double GetLastOrderLots()
{
double lotsize=0.00;
int maxtime=-1;
int ntrades=OrdersTotal();
if (ntrades!=0)
{
for (int i=ntrades-1;i>=0;i--)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==True)
{
if (OrderOpenTime()>maxtime)
{
maxtime=OrderOpenTime();
lotsize=OrderLots();
}
}
}
}
return(lotsize);
}
1. You could use a variable to retain the last lots SaveLots=Lots; // this comes after OrderSend;
and
Lots=SaveLots+0.1; //before ordersend
2. You could do similar, with a global variable
Lots=GlobalVariableGet("SaveLots")+0.1;
...
GlobalVariableSet("SaveLots",Lots) ; // after ordersend
however, you have to make sure SaveLots is being set at 0, if not already existing (check with GlobalVariableCheck())
3. Most complicated and safe, use a function that works for sure
double GetLastOrderLots()
{
double lotsize=0.00;
int maxtime=-1;
int ntrades=OrdersTotal();
if (ntrades!=0)
{
for (int i=ntrades-1;i>=0;i--)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==True)
{
if (OrderOpenTime()>maxtime)
{
maxtime=OrderOpenTime();
lotsize=OrderLots();
}
}
}
}
return(lotsize);
}
Thank you very much.
It seems complicated to me but I will try and I sure I will get it eventually.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi you all,
My EA works best when I increment the lots by 0.1 after each order. I want to send it to the Championship, so I came up with a formula to stop the lots at 5.
I am new to Mql4, there may be a better way, but this is all I can think off. The following code works fine with the strategy tester, but I have noticed that when I start the EA on the demo account, the lots does not increment and each order open with 0.4 lots.
input parameters
extern double Lots=0.3;
..................
{
Lots = Lots + 0.1;
if(Lots>4.9)
Lots=5;
ticketNum=OrderSend(Symbol( ), OP_BUY,Lots, Ask,2,0,0, "lou",1964, 0, Blue);
}
I have modified the above code with the code below. Now it works fine on demo, but when I use the strategy tester, it works fine the first time but the other times, it starts the lots where it left off ( example:it starts with 0.4, 0.5, etc.. but if it stops at 3.6, the next time I start the tester my lots will starts at 3.7).
input parameters
extern double Lots=0.3;
..................
{
Lots = OrderLots( ) + 0.1;
if(Lots>4.9)
Lots=5;
ticketNum=OrderSend(Symbol( ), OP_BUY,Lots, Ask,2,0,0, "lou",1964, 0, Blue);
}
Can anybody help?
Thank you