Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 348

 

extern int MartinStep = 2;
extern double LOT = 0.01;


double GetLot(){

int time = 0;double profit = 0; double lots = 0; double Lot = 0;
for(int i = OrdersHistoryTotal()-1;i>=0;i--){
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)){
if(OrderSymbol() == Symbol()&& OrderMagicNumber() == Magic){
if(time<OrderCloseTime()){
time=OrderCloseTime();
profit=OrderProfit();
lots = OrderLots();
}
}
}
}


if(profit == 0 &&time == 0)
{
Lot = LOT;
}
if(profit >= 0)
{
Lot = LOT;
}
if(profit < 0 )
{
Lot = NormalizeDouble (lots*MartinStep,2);
}

return(Lot);
}
Please help to correct errors in function. The EA opens several orders correctly, and then the log shows an error "invalid lots amount". I can not understand what is wrong.
 
Trader7777:


lots = OrderLots();

Lot = NormalizeDouble (lots*MartinStep,2);

Please help to correct errors in function. The EA opens several orders correctly, and then the log shows an error "invalid lots amount". I can not understand what is wrong.

Either I have never got to operator lots = OrderLots(); and lots still remain =0. Or lots*MartinStep exceeded maximal allowed lot size.
 

I figured it out, the error is here

if(profit >= 0)


I should have put an equal sign, because after an order that closed at 0, the EA did not know what to do)
 

Hi all! Can you tell me how to implement EA re-initialization at the end of the day? Well, in init() there are some actions that need to be repeated at a certain time. I don't want to rewrite them in start(). I am more interested in the theoretical possibility of restarting the EA. Thank you in advance.

 
Pyro:

Hi all! Can you tell me how to implement EA re-initialization at the end of the day? Well, in init() there are some actions that need to be repeated at a certain time. I don't want to rewrite them in start(). I am more interested in the theoretical possibility of restarting the EA. Thank you in advance.

Have you tried calling init() at a certain time?
 
Yes, it hadn't occurred to me:( Thank you!!!
 
Would you please tell me if the flags and static variables are reset or remain in the EA's memory when restarting the EA (remove it from the chart and then put it back on again)?
 
Forexman77:
Would you please tell me if the flags and static variables are reset or remain in the EA's memory when restarting the EA (remove it from the chart and then put it back on again)?

During initialization everything is reset, except Global Variables
 
Pyro:

Everything is reset during initialisation except Global Variables
And here it should be clarified that GV are terminal variables, not EA variables.
 
Pyro:

Everything is reset during initialisation except Global Variables
And if you just turn off the computer or the server is down on which the Expert Advisor is running?
Reason: