Maximum DrawDown ?

 

Hi,

i am working on an ea, example i would like to set the Drawdown to cercent persent, then all trade close and take loss ?

can any one please give me some hint or sample code..

Thanlks

 

Sum up profits of all orders, compare to balance, and close all if...

You might use part of this code:

//----------- TakeProfit ------------------------------
void TakeProfit()
{//If the sum profit of all orders in one direction meets the profit target: Close all orders in that direction
   double Profit, SumBuyProfit, SumSellProfit;
   double ProfitTarget;//=(AutoLot()*(100+(Ask-Bid)/Point));   
   if(AutomaticProfitTarget)ProfitTarget=(AutoLot()*(100+(Ask-Bid)/Point));
   double LowestBuy = 999, HighestBuy = 0.0001;
   for (int Order = OrdersTotal() - 1; Order >= 0; Order--)//Run trough all open orders and sum up their profits
      {
      OrderSelect(Order, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
         {
         Profit = OrderProfit() + OrderSwap() + OrderCommission();//Sum of the order's profit and expences
         if (OrderType() == OP_BUY) SumBuyProfit  = SumBuyProfit  + Profit;//Sum up long profits
         if (OrderType() == OP_SELL) SumSellProfit = SumSellProfit + Profit;//Sum up short profits
         }
      }
   if(SumBuyProfit  >= ProfitTarget) CloseAllBuyProfit();//Close ALL long orders
   if(SumSellProfit >= ProfitTarget) CloseAllSellProfit();//Close ALL short orders
return (0);
}
//-----------------------------------------------------
Reason: