Maximum Loss

 
if(TodayLastProf()>=-4){
// do this
}

double TodayLastProf(){
double sum;
for(int k=0; k<OrdersHistoryTotal(); k++){
if(OrderSelect(k,SELECT_BY_POS,MODE_HISTORY)){
if(OrderSymbol()==_Symbol && OrderMagicNumber()==magic_number){
if(TimeToStr(TimeCurrent(),TIME_DATE)==TimeToString(OrderCloseTime(),TIME_DATE)){
sum=OrderProfit()+OrderCommission()+OrderSwap();}}}}
return(sum);}

hello guy, the piece of code above gives the amount of loss or profit of a particular trade and i want my EA to stop trading after a certain loss is acquired for example if a loss of -$2 is made for two consecutive times which is equal to -$4 i want the EA to stop trading.

Secondly i notice that the function TodayLastProf() stores the last profit/loss of the last trade, how do i make it store the profit/loss of the last 2-3 trade, should i use an array?

 
Nkechi Sonia Kanu: how do i make it store the profit/loss of the last 2-3 trade,

Maybe sum them like your variable name suggests.

 
whroeder1:

Maybe sum them like your variable name suggests.

thanks but what do you suggest i sum? 
 
Nkechi Sonia Kanu: thanks but what do you suggest i sum? 

What you said you wanted

Nkechi Sonia Kanu: TodayLastProf() stores the last profit/loss of the last trade, how do i make it store the profit/loss
 
whroeder1:

What you said you wanted

ok can you give me an idea on how it can be done? 
 
what i needed in essence is just a way to calculate the loss or profit of positions closed and if the loss reach a certain amount then no more positions will opened for the rest of the day. 

can any one help or give me a clue to go about it

THANKS 
 
Nkechi Sonia Kanu: what i needed in essence is just a way to calculate the loss or profit of positions closed and if the loss reach a certain amount then no more positions will opened for the rest of the day. 
can any one help or give me a clue to go about it

By summing "+=", just as suggested!

sum+=OrderProfit()+OrderCommission()+OrderSwap();

Obviously, this is only a simplistic outlook, because the rest of your code would have to be changed to accommodate looking at all the trades and not just the last one.

You need to first learn the basics of coding (eg. by learning about "+=", otherwise you will never get it)!

Also, learn to make your code well spaced out and indented so as to make it more readable and detect possible problematic areas!

 
double sum;
Also set sum to zero before entering a loop.
 
Fernando Carreiro:

By summing "+=", just as suggested!

Obviously, this is only a simplistic outlook, because the rest of your code would have to be changed to accommodate looking at all the trades and not just the last one.

You need to first learn the basics of coding (eg. by learning about "+=", otherwise you will never get it)!

Also, learn to make your code well spaced out and indented so as to make it more readable and detect possible problematic areas!


sum+=OrderProfit()+OrderCommission()+OrderSwap();

THANK YOU so much i REALLY APPRECIATE your EFFORT.

i was about to say that your idea wont work but i just decided to try it out (at least no harm in trying) and to my surprise it workede just as i wanted the only thing i added was this "+" THANKS A LOT.....also i will try to space and indent my codes


ONCE AGAIN THANKS.

 
whroeder1:
Also set sum to zero before entering a loop.

double sum;

i thought the value of sum will automatically be 0

 
Nkechi Sonia Kanu: i thought the value of sum will automatically be 0

Only if you don't use strict, which you always should.