A maximum problem

 

if I want to get the AccountProfit() high point and store in an double profit;, how can I do it ? thanks

extern double a=0;

double pf=AccountProfit();

if(a==0)a=pf;

else

if(a>pf)a=pf;

 
double Acc_Profit;

int start()
  {
   if (AccountProfit() > Acc_Profit)
      {
      Acc_Profit = AccountProfit();
      }
   return(0);
  }
 
qjol:

thanks,try it right now~
 
qjol:

excuse me,can u help me ? Is that any problem below ??

extern double Lots = 0.01;

extern double trillingstart =15;

extern double trillingrate =40;

extern double MN = 1998;

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

double pf[];

double lr[];

int start()

{

double lock =((OrdersTotal()+ trillingrate )*0.01);

if(AccountProfit()> trillingstart && AccountProfit()<(lock*lr()))close();

return(0);

}

//+------------------------------------------------------------------+

void close()

{

int total = OrdersTotal();

for(int i=total-1;i>=0;i--)

{

OrderSelect(i, SELECT_BY_POS);

int type = OrderType();

bool result = false;

switch(type)

{

case OP_BUY : if ( OrderProfit() != 999) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );

break;

case OP_SELL : if ( OrderProfit() != 999) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );

}

}

return;

}


double Acc_Profit;


int lr()

{

if (AccountProfit() > Acc_Profit)

{

Acc_Profit = AccountProfit();

}

return(Acc_Profit);

}

 

double Acc_Profit; supposed to be at the top before int start()

 
qjol:

double Acc_Profit; supposed to be at the top before int start()


but it seems doesn't work normally, I plan to close all the orders when the current accprofit lower than the( height profit)* (OrdersTotal()+ trillingrate )% since I make teh first order in thr trend ... can u test it if convinion
 
oxeno:
if I want to get the AccountProfit() high point and store in an double profit;, how can I do it ?
double balance = AccountBalance(), highBalance = balance;
    for(int iPos=OrdersHistoryTotal()-1; iPos >= 0 ; iPos--) if (
        OrderSelect(iPos, SELECT_BY_POS, MODE_HISTORY)      // Only orders w/
    &&  OrderMagicNumber() == Magic.Number                  // my magic number
    &&  OrderSymbol()      == chart.symbol                  // and my pair.
    &&  OrderType()        <= OP_SELL// Avoid cr/bal forum.mql4.com/32363#325360
    ){
        double  profit = OrderProfit() + OrderSwap() + OrderCommission();
        balance -= profit; if (highBalance < balance) highBalance = balance;
    }
 
WHRoeder:

oh!thank you !