newgrid_2009_11_15_floating_center_thorup

Author: Expert for tests
Profit factor:
3.20
Price Data Components
Series array that contains the lowest prices of each barSeries array that contains the highest prices of each bar
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategyIt Closes Orders by itself
7 Views
0 Downloads
0 Favorites
newgrid_2009_11_15_floating_center_thorup
#property copyright "Expert for tests"

extern int MagicNumber = 100001;
extern double Lots = 0.1 ;
extern bool MM=false;
extern double Balancefactor=4650;
extern bool microlots=false;
extern int max_trades = 30 ;
extern int grid_lines = 30 ;
extern double grid_separation = 0.005 ;
extern double TP_absolute = 0.005 ;
extern double AccountEquityPercent=100.01;
extern bool FIFO=false;
extern int LookBackDays = 90;
extern int slip = 3 ;
extern double pipvalue=0.1;
   
int BarCount;
int Current;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init() {
   return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit() {
   GlobalVariableDel("next_level_"+Symbol());
   GlobalVariableDel("test_next_level__"+Symbol());
   return(0);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start() {
 
   int Entertradebuy =0 ;
   int Entertradesell =0 ;
   double next_level_,test_next_level_,i ;
   double Ticket1, Ticket2;
   double pips_risked=0,money_risked=0;
   int iOrders=0;
   double RangeMid_center=RangeMid();
   if(IsTesting()==true)
      {
      if(OrdersTotal()<max_trades)
         {
         for (i = 1; i<grid_lines; i++) 
            {
            if (Ask <= (RangeMid_center - grid_separation*i)+0.0001 && Ask >= (RangeMid_center - grid_separation*i)-0.0001)
               {
               Entertradebuy=1 ;
               }
            if (Bid <= (RangeMid_center + grid_separation*i)+0.0001 && Bid >= (RangeMid_center + grid_separation*i)-0.0001)
               {
               Entertradesell=1 ; 
               }
            }
         }
      iOrders = OrdersTotal()-1;
      for (i = iOrders; i>=0; i--)
         {
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if (((OrderOpenPrice() <= Ask+0.0003 && OrderOpenPrice() >= Ask-0.0003) || (OrderOpenPrice() <= Bid+0.0003 && OrderOpenPrice() >= Bid-0.0003))&&OrderMagicNumber()==MagicNumber)
            {
            Entertradebuy=0  ;
            Entertradesell=0 ;
            }
         } 
      if(FIFO==false&&MM==false)
         {
         if(Entertradebuy==1)
            {
            Ticket1 = OrderSend(Symbol(), OP_BUY, Lots, Ask, slip, 0, 0, "Buy(#" + 1 + ")", MagicNumber, 0, DodgerBlue) ;
            }
         if(Entertradesell==1)
            {
            Ticket2 = OrderSend(Symbol(), OP_SELL, Lots, Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
            }
         for(i=0;i<OrdersTotal();i++)
            {
            OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
            if(OrderType()<=OP_SELL&&OrderMagicNumber()==MagicNumber&&OrderTakeProfit()==0)
               {
               if(OrderType()==OP_BUY)
                  {
                  OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()+TP_absolute,0,CLR_NONE);
                  }
               else
                  {   
                  OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()-TP_absolute,0,CLR_NONE);
                  }
               }
            }      
         for (i = 1; i<grid_lines; i++)
            {
            if(Ask - (RangeMid_center - grid_separation*i) < grid_separation)
            GlobalVariableSet("test_next_level_"+Symbol(), RangeMid_center - grid_separation*i) ;
            if(RangeMid_center + grid_separation*i - Bid < grid_separation)
            GlobalVariableSet("test_next_level_"+Symbol(), RangeMid_center + grid_separation*i) ;
            }
         next_level_=GlobalVariableGet("test_next_level_"+Symbol()) ;
         for (i = 1; i<grid_lines-1; i++)
            {
            pips_risked = pips_risked+(((RangeMid_center+grid_separation*grid_lines)-(RangeMid_center-grid_separation*(grid_lines-i))));
            money_risked = (pips_risked*100000*Lots)/2 ;
            }
         if(OrdersTotal() < max_trades)
         Comment("I am trading a grid from ", RangeMid_center-grid_separation*grid_lines, " to ", RangeMid_center+grid_separation*grid_lines, "\n",
                 "closest grid line to enter trade is ", test_next_level_ , "\n", 
                 "distance between grid lines is ", grid_separation*10000, " pips", "\n",
                 "number of grid lines is ", grid_lines, "\n",
                 "maximum number of trades is ", max_trades, "\n",
                 "TP is ", TP_absolute, "\n",
                 "---------------------------------------------------",  "\n",
                 "You are risking a potential ", money_risked, "USD")  ;     
         if(OrdersTotal() >= max_trades)
         Comment("I am full, I have ", max_trades, " positions opened");
         return(0);
         }
      if(FIFO==false&&MM==true)
         {   
         if(Entertradebuy==1)
            {
            Ticket1 = OrderSend(Symbol(), OP_BUY, LotsOptimized(), Ask, slip, 0, 0, "Buy(#" + 1 + ")", MagicNumber, 0, DodgerBlue) ;         
            }
         if(Entertradesell==1)
            {
            Ticket2 = OrderSend(Symbol(), OP_SELL, LotsOptimized(), Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
            }
         for(i=0;i<OrdersTotal();i++)
            {
            OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
            if(OrderType()<=OP_SELL&&OrderMagicNumber()==MagicNumber&&OrderTakeProfit()==0)
               {
               if(OrderType()==OP_BUY)
                  {
                  OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()+TP_absolute,0,CLR_NONE);
                  }
               else
                  {   
                  OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()-TP_absolute,0,CLR_NONE);
                  }
               }
            }      
         for (i = 1; i<grid_lines; i++)
            {
            if(Ask - (RangeMid_center - grid_separation*i) < grid_separation)
            GlobalVariableSet("test_next_level_"+Symbol(), RangeMid_center - grid_separation*i) ;
            if(RangeMid_center + grid_separation*i - Bid < grid_separation)
            GlobalVariableSet("test_next_level_"+Symbol(), RangeMid_center + grid_separation*i) ;
            }
         next_level_=GlobalVariableGet("test_next_level_"+Symbol()) ;
         for (i = 1; i<grid_lines-1; i++)
            {
            pips_risked = pips_risked+(((RangeMid_center+grid_separation*grid_lines)-(RangeMid_center-grid_separation*(grid_lines-i))));
            money_risked = (pips_risked*100000*LotsOptimized())/2 ;
            }
         if(OrdersTotal() < max_trades)
         Comment("I am trading a grid from ", RangeMid_center-grid_separation*grid_lines, " to ", RangeMid_center+grid_separation*grid_lines, "\n",
                 "closest grid line to enter trade is ", test_next_level_ , "\n", 
                 "distance between grid lines is ", grid_separation*10000, " pips", "\n",
                 "number of grid lines is ", grid_lines, "\n",
                 "maximum number of trades is ", max_trades, "\n",
                 "TP is ", TP_absolute, "\n",
                 "---------------------------------------------------",  "\n",
                 "You are risking a potential ", money_risked, "USD")  ;     
         if(OrdersTotal() >= max_trades)
         Comment("I am full, I have ", max_trades, " positions opened");
         return(0);
         }
      if(FIFO==true&&MM==false)
         {   
         if(Entertradebuy==1)
            {
            Ticket1 = OrderSend(Symbol(), OP_BUY, Lots, Ask, slip, 0, 0, "Buy(#" + 1 + ")", MagicNumber, 0, DodgerBlue) ;         
            }
         if(Entertradesell==1)
            {
            Ticket2 = OrderSend(Symbol(), OP_SELL, Lots, Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
            }
         for (i = 1; i<grid_lines; i++)
            {
            if(Ask - (RangeMid_center - grid_separation*i) < grid_separation)
            GlobalVariableSet("test_next_level_"+Symbol(), RangeMid_center - grid_separation*i) ;
            if(RangeMid_center + grid_separation*i - Bid < grid_separation)
            GlobalVariableSet("test_next_level_"+Symbol(), RangeMid_center + grid_separation*i) ;
            }
         next_level_=GlobalVariableGet("test_next_level_"+Symbol()) ;
         for (i = 1; i<grid_lines-1; i++)
            {
            pips_risked = pips_risked+(((RangeMid_center+grid_separation*grid_lines)-(RangeMid_center-grid_separation*(grid_lines-i))));
            money_risked = (pips_risked*100000*Lots)/2 ;
            }
         if(OrdersTotal() < max_trades)
         Comment("I am trading a grid from ", RangeMid_center-grid_separation*grid_lines, " to ", RangeMid_center+grid_separation*grid_lines, "\n",
                 "closest grid line to enter trade is ", test_next_level_ , "\n", 
                 "distance between grid lines is ", grid_separation*10000, " pips", "\n",
                 "number of grid lines is ", grid_lines, "\n",
                 "maximum number of trades is ", max_trades, "\n",
                 "AccountEquityPercent is ", AccountEquity()/AccountBalance()*100, "\n",
                 "---------------------------------------------------",  "\n",
                 "You are risking a potential ", money_risked, "USD")  ;     
         if(OrdersTotal() >= max_trades)
         Comment("I am full, I have ", max_trades, " positions opened");
         if(AccountEquity()/AccountBalance()*100>=AccountEquityPercent)
            {
            for(i=0;i<OrdersTotal();i++)
               {
               OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
               if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
                  {
                  if(OrderType() == OP_BUY)
                     {
                     OrderClose(OrderTicket(),OrderLots(),Bid,slip,Yellow);
                     }
                  else
                     {
                     OrderClose(OrderTicket(),OrderLots(),Ask,slip,Yellow);
                     }
                  }
               i--;
               }
            }
         return(0);
         }
      if(FIFO==true&&MM==true)
         {   
         if(Entertradebuy==1)
            {
            Ticket1 = OrderSend(Symbol(), OP_BUY, LotsOptimized(), Ask, slip, 0, 0, "Buy(#" + 1 + ")", MagicNumber, 0, DodgerBlue) ;         
            }
         if(Entertradesell==1)
            {
            Ticket2 = OrderSend(Symbol(), OP_SELL, LotsOptimized(), Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
            }
         for (i = 1; i<grid_lines; i++)
            {
            if(Ask - (RangeMid_center - grid_separation*i) < grid_separation)
            GlobalVariableSet("test_next_level_"+Symbol(), RangeMid_center - grid_separation*i) ;
            if(RangeMid_center + grid_separation*i - Bid < grid_separation)
            GlobalVariableSet("test_next_level_"+Symbol(), RangeMid_center + grid_separation*i) ;
            }
         next_level_=GlobalVariableGet("test_next_level_"+Symbol()) ;
         for (i = 1; i<grid_lines-1; i++)
            {
            pips_risked = pips_risked+(((RangeMid_center+grid_separation*grid_lines)-(RangeMid_center-grid_separation*(grid_lines-i))));
            money_risked = (pips_risked*100000*LotsOptimized())/2 ;
            }
         if(OrdersTotal() < max_trades)
         Comment("I am trading a grid from ", RangeMid_center-grid_separation*grid_lines, " to ", RangeMid_center+grid_separation*grid_lines, "\n",
                 "closest grid line to enter trade is ", test_next_level_ , "\n", 
                 "distance between grid lines is ", grid_separation*10000, " pips", "\n",
                 "number of grid lines is ", grid_lines, "\n",
                 "maximum number of trades is ", max_trades, "\n",
                 "AccountEquityPercent is ", AccountEquity()/AccountBalance()*100, "\n",
                 "---------------------------------------------------",  "\n",
                 "You are risking a potential ", money_risked, "USD")  ;     
         if(OrdersTotal() >= max_trades)
         Comment("I am full, I have ", max_trades, " positions opened");
         if(AccountEquity()/AccountBalance()*100>=AccountEquityPercent)
            {
            for(i=0;i<OrdersTotal();i++)
               {
               OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
               if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
                  {
                  if(OrderType() == OP_BUY)
                     {
                     OrderClose(OrderTicket(),OrderLots(),Bid,slip,Yellow);
                     }
                  else
                     {
                     OrderClose(OrderTicket(),OrderLots(),Ask,slip,Yellow);
                     }
                  }
               i--;
               }
            }
         return(0);
         }
      }
   else
      {   
      if(OrdersTotal()<max_trades)
         {
         for (i = 1; i<grid_lines; i++) 
            {
            if (Ask == RangeMid_center - grid_separation*i)
               {
               Entertradebuy=1 ;
               }
            if (Bid == RangeMid_center + grid_separation*i)
               {
               Entertradesell=1 ; 
               }
            }
         }
      iOrders = OrdersTotal()-1;
      for (i = iOrders; i>=0; i--)
         {
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if ((OrderOpenPrice() == Ask || OrderOpenPrice() == Bid)&&OrderMagicNumber()==MagicNumber)
            {
            Entertradebuy=0  ;
            Entertradesell=0 ;
            }
         } 
      if(FIFO==false&&MM==false)
         {
         if(Entertradebuy==1)
            {
            Ticket1 = OrderSend(Symbol(), OP_BUY, Lots, Ask, slip, 0, 0, "Buy(#" + 1 + ")", MagicNumber, 0, DodgerBlue) ;         
            }
         if(Entertradesell==1)
            {
            Ticket2 = OrderSend(Symbol(), OP_SELL, Lots, Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
            }
         for(i=0;i<OrdersTotal();i++)
            {
            OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
            if(OrderType()<=OP_SELL&&OrderMagicNumber()==MagicNumber&&OrderTakeProfit()==0)
               {
               if(OrderType()==OP_BUY)
                  {
                  OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()+TP_absolute,0,CLR_NONE);
                  }
               else
                  {   
                  OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()-TP_absolute,0,CLR_NONE);
                  }
               }
            }      
         for (i = 1; i<grid_lines; i++)
            {
            if(Ask - (RangeMid_center - grid_separation*i) < grid_separation)
            GlobalVariableSet("next_level_"+Symbol(), RangeMid_center - grid_separation*i) ;
            if(RangeMid_center + grid_separation*i - Bid < grid_separation)
            GlobalVariableSet("next_level_"+Symbol(), RangeMid_center + grid_separation*i) ;
            }
         next_level_=GlobalVariableGet("next_level_"+Symbol()) ;
         for (i = 1; i<grid_lines-1; i++)
            {
            pips_risked = pips_risked+(((RangeMid_center+grid_separation*grid_lines)-(RangeMid_center-grid_separation*(grid_lines-i))));
            money_risked = (pips_risked*100000*Lots)/2 ;
            }
         if(OrdersTotal() < max_trades)
         Comment("I am trading a grid from ", RangeMid_center-grid_separation*grid_lines, " to ", RangeMid_center+grid_separation*grid_lines, "\n",
                 "closest grid line to enter trade is ", next_level_ , "\n", 
                 "distance between grid lines is ", grid_separation*10000, " pips", "\n",
                 "number of grid lines is ", grid_lines, "\n",
                 "maximum number of trades is ", max_trades, "\n",
                 "TP is ", TP_absolute, "\n",
                 "---------------------------------------------------",  "\n",
                 "You are risking a potential ", money_risked, "USD")  ;     
         if(OrdersTotal() >= max_trades)
         Comment("I am full, I have ", max_trades, " positions opened");
         return(0);
         }
      if(FIFO==false&&MM==true)
         {   
         if(Entertradebuy==1)
            {
            Ticket1 = OrderSend(Symbol(), OP_BUY, LotsOptimized(), Ask, slip, 0, 0, "Buy(#" + 1 + ")", MagicNumber, 0, DodgerBlue) ;         
            }
         if(Entertradesell==1)
            {
            Ticket2 = OrderSend(Symbol(), OP_SELL, LotsOptimized(), Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
            }
         for(i=0;i<OrdersTotal();i++)
            {
            OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
            if(OrderType()<=OP_SELL&&OrderMagicNumber()==MagicNumber&&OrderTakeProfit()==0)
               {
               if(OrderType()==OP_BUY)
                  {
                  OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()+TP_absolute,0,CLR_NONE);
                  }
               else
                  {   
                  OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()-TP_absolute,0,CLR_NONE);
                  }
               }
            }      
         for (i = 1; i<grid_lines; i++)
            {
            if(Ask - (RangeMid_center - grid_separation*i) < grid_separation)
            GlobalVariableSet("next_level_"+Symbol(), RangeMid_center - grid_separation*i) ;
            if(RangeMid_center + grid_separation*i - Bid < grid_separation)
            GlobalVariableSet("next_level_"+Symbol(), RangeMid_center + grid_separation*i) ;
            }
         next_level_=GlobalVariableGet("next_level_"+Symbol()) ;
         for (i = 1; i<grid_lines-1; i++)
            {
            pips_risked = pips_risked+(((RangeMid_center+grid_separation*grid_lines)-(RangeMid_center-grid_separation*(grid_lines-i))));
            money_risked = (pips_risked*100000*LotsOptimized())/2 ;
            }
         if(OrdersTotal() < max_trades)
         Comment("I am trading a grid from ", RangeMid_center-grid_separation*grid_lines, " to ", RangeMid_center+grid_separation*grid_lines, "\n",
                 "closest grid line to enter trade is ", next_level_ , "\n", 
                 "distance between grid lines is ", grid_separation*10000, " pips", "\n",
                 "number of grid lines is ", grid_lines, "\n",
                 "maximum number of trades is ", max_trades, "\n",
                 "TP is ", TP_absolute, "\n",
                 "---------------------------------------------------",  "\n",
                 "You are risking a potential ", money_risked, "USD")  ;     
         if(OrdersTotal() >= max_trades)
         Comment("I am full, I have ", max_trades, " positions opened");
         return(0);
         }
      if(FIFO==true&&MM==false)
         {   
         if(Entertradebuy==1)
            {
            Ticket1 = OrderSend(Symbol(), OP_BUY, Lots, Ask, slip, 0, 0, "Buy(#" + 1 + ")", MagicNumber, 0, DodgerBlue) ;         
            }
         if(Entertradesell==1)
            {
            Ticket2 = OrderSend(Symbol(), OP_SELL, Lots, Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
            }
         for (i = 1; i<grid_lines; i++)
            {
            if(Ask - (RangeMid_center - grid_separation*i) < grid_separation)
            GlobalVariableSet("next_level_"+Symbol(), RangeMid_center - grid_separation*i) ;
            if(RangeMid_center + grid_separation*i - Bid < grid_separation)
            GlobalVariableSet("next_level_"+Symbol(), RangeMid_center + grid_separation*i) ;
            }
         next_level_=GlobalVariableGet("next_level_"+Symbol()) ;
         for (i = 1; i<grid_lines-1; i++)
            {
            pips_risked = pips_risked+(((RangeMid_center+grid_separation*grid_lines)-(RangeMid_center-grid_separation*(grid_lines-i))));
            money_risked = (pips_risked*100000*Lots)/2 ;
            }
         if(OrdersTotal() < max_trades)
         Comment("I am trading a grid from ", RangeMid_center-grid_separation*grid_lines, " to ", RangeMid_center+grid_separation*grid_lines, "\n",
                 "closest grid line to enter trade is ", next_level_ , "\n", 
                 "distance between grid lines is ", grid_separation*10000, " pips", "\n",
                 "number of grid lines is ", grid_lines, "\n",
                 "maximum number of trades is ", max_trades, "\n",
                 "AccountEquityPercent is ", AccountEquity()/AccountBalance()*100, "\n",
                 "---------------------------------------------------",  "\n",
                 "You are risking a potential ", money_risked, "USD")  ;     
         if(OrdersTotal() >= max_trades)
         Comment("I am full, I have ", max_trades, " positions opened");
         if(AccountEquity()/AccountBalance()*100>=AccountEquityPercent)
            {
            for(i=0;i<OrdersTotal();i++)
               {
               OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
               if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
                  {
                  if(OrderType() == OP_BUY)
                     {
                     OrderClose(OrderTicket(),OrderLots(),Bid,slip,Yellow);
                     }
                  else
                     {
                     OrderClose(OrderTicket(),OrderLots(),Ask,slip,Yellow);
                     }
                  }
               i--;
               }
            }
         return(0);
         }
      if(FIFO==true&&MM==true)
         {   
         if(Entertradebuy==1)
            {
            Ticket1 = OrderSend(Symbol(), OP_BUY, LotsOptimized(), Ask, slip, 0, 0, "Buy(#" + 1 + ")", MagicNumber, 0, DodgerBlue) ;         
            }
         if(Entertradesell==1)
            {
            Ticket2 = OrderSend(Symbol(), OP_SELL, LotsOptimized(), Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
            }
         for (i = 1; i<grid_lines; i++)
            {
            if(Ask - (RangeMid_center - grid_separation*i) < grid_separation)
            GlobalVariableSet("next_level_"+Symbol(), RangeMid_center - grid_separation*i) ;
            if(RangeMid_center + grid_separation*i - Bid < grid_separation)
            GlobalVariableSet("next_level_"+Symbol(), RangeMid_center + grid_separation*i) ;
            }
         next_level_=GlobalVariableGet("next_level_"+Symbol()) ;
         for (i = 1; i<grid_lines-1; i++)
            {
            pips_risked = pips_risked+(((RangeMid_center+grid_separation*grid_lines)-(RangeMid_center-grid_separation*(grid_lines-i))));
            money_risked = (pips_risked*100000*LotsOptimized())/2 ;
            }
         if(OrdersTotal() < max_trades)
         Comment("I am trading a grid from ", RangeMid_center-grid_separation*grid_lines, " to ", RangeMid_center+grid_separation*grid_lines, "\n",
                 "closest grid line to enter trade is ", next_level_ , "\n", 
                 "distance between grid lines is ", grid_separation*10000, " pips", "\n",
                 "number of grid lines is ", grid_lines, "\n",
                 "maximum number of trades is ", max_trades, "\n",
                 "AccountEquityPercent is ", AccountEquity()/AccountBalance()*100, "\n",
                 "---------------------------------------------------",  "\n",
                 "You are risking a potential ", money_risked, "USD")  ;     
         if(OrdersTotal() >= max_trades)
         Comment("I am full, I have ", max_trades, " positions opened");
         if(AccountEquity()/AccountBalance()*100>=AccountEquityPercent)
            {
            for(i=0;i<OrdersTotal();i++)
               {
               OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
               if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
                  {
                  if(OrderType() == OP_BUY)
                     {
                     OrderClose(OrderTicket(),OrderLots(),Bid,slip,Yellow);
                     }
                  else
                     {
                     OrderClose(OrderTicket(),OrderLots(),Ask,slip,Yellow);
                     }
                  }
               i--;
               }
            }
         return(0);
         }
      }
   }   
double LotsOptimized()
   {
   double lot = Lots;
   if(microlots==true)
      {
      lot = NormalizeDouble(MathFloor(AccountBalance()/Balancefactor)*0.01-0.005,2);
      if(lot < 0.01) lot = 0.01;
      return(lot);
      }
   else
      {    
      lot = NormalizeDouble(MathFloor(AccountBalance()/Balancefactor)*0.01-0.05, 1);
      if(lot < 0.1) lot = 0.1;
      return(lot);
      }
   }
double RangeMid()
   {
   double rangemid = 0;
      double lowest = 100000;
      lowest = iLow(Symbol(), PERIOD_D1, 0);
      for (int i = 0; i <= LookBackDays; i++)
         {
         if (iLow(Symbol(), PERIOD_D1, i) < lowest) lowest = iLow(Symbol(), PERIOD_D1, i);
         }
      double highest = 0;
      highest = iHigh(Symbol(), PERIOD_D1, 0);
      for (i = 1; i <= LookBackDays; i++)
         {
         if (iHigh(Symbol(), PERIOD_D1, i) > highest) highest = iHigh(Symbol(), PERIOD_D1, i);
         }
      rangemid = (highest + lowest) / 2.0;
      rangemid = NormalizeDouble(rangemid, Digits);
      return(rangemid);
   }
   //+------------------------------------------------------------------+

Profitability Reports

GBP/USD Jul 2025 - Sep 2025
5.02
Total Trades 55
Won Trades 52
Lost trades 3
Win Rate 94.55 %
Expected payoff 37.24
Gross Profit 2557.40
Gross Loss -509.40
Total Net Profit 2048.00
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
3.67
Total Trades 46
Won Trades 41
Lost trades 5
Win Rate 89.13 %
Expected payoff 22.43
Gross Profit 1418.37
Gross Loss -386.45
Total Net Profit 1031.92
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.91
Total Trades 79
Won Trades 65
Lost trades 14
Win Rate 82.28 %
Expected payoff -4.19
Gross Profit 3250.00
Gross Loss -3581.40
Total Net Profit -331.40
-100%
-50%
0%
50%
100%

Comments