newgrid_2009_11_15_thorup

Download script
Author: Expert for tests
Profit factor:
0.49
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
10 Views
0 Downloads
0 Favorites
newgrid_2009_11_15_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 RangeMid = 1.5465 ;
extern double grid_separation = 0.005 ;
extern double TP_absolute = 0.005 ;
extern double AccountEquityPercent=100.01;
extern bool FIFO=false;
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;
   if(IsTesting()==true)
      {
      if(OrdersTotal()<max_trades)
         {
         for (i = 1; i<grid_lines; i++) 
            {
            if (Ask <= (RangeMid - grid_separation*i)+0.0001 && Ask >= (RangeMid - grid_separation*i)-0.0001)
               {
               Entertradebuy=1 ;
               }
            if (Bid <= (RangeMid + grid_separation*i)+0.0001 && Bid >= (RangeMid + 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(Ticket1!=1) Print("Error# "+GetLastError());         
            }
         if(Entertradesell==1)
            {
            Ticket2 = OrderSend(Symbol(), OP_SELL, Lots, Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
            if(Ticket2!=1) Print("Error# "+GetLastError());         
            }
         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 - grid_separation*i) < grid_separation)
            GlobalVariableSet("test_next_level_"+Symbol(), RangeMid - grid_separation*i) ;
            if(RangeMid + grid_separation*i - Bid < grid_separation)
            GlobalVariableSet("test_next_level_"+Symbol(), RangeMid + grid_separation*i) ;
            }
         next_level_=GlobalVariableGet("test_next_level_"+Symbol()) ;
         for (i = 1; i<grid_lines-1; i++)
            {
            pips_risked = pips_risked+(((RangeMid+grid_separation*grid_lines)-(RangeMid-grid_separation*(grid_lines-i))));
            money_risked = (pips_risked*100000*Lots)/2 ;
            }
         if(OrdersTotal() < max_trades)
         Comment("I am trading a grid from ", RangeMid-grid_separation*grid_lines, " to ", RangeMid+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(Ticket1!=1) Print("Error# "+GetLastError());         
            }
         if(Entertradesell==1)
            {
            Ticket2 = OrderSend(Symbol(), OP_SELL, LotsOptimized(), Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
            if(Ticket2!=1) Print("Error# "+GetLastError());         
            }
         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 - grid_separation*i) < grid_separation)
            GlobalVariableSet("test_next_level_"+Symbol(), RangeMid - grid_separation*i) ;
            if(RangeMid + grid_separation*i - Bid < grid_separation)
            GlobalVariableSet("test_next_level_"+Symbol(), RangeMid + grid_separation*i) ;
            }
         next_level_=GlobalVariableGet("test_next_level_"+Symbol()) ;
         for (i = 1; i<grid_lines-1; i++)
            {
            pips_risked = pips_risked+(((RangeMid+grid_separation*grid_lines)-(RangeMid-grid_separation*(grid_lines-i))));
            money_risked = (pips_risked*100000*LotsOptimized())/2 ;
            }
         if(OrdersTotal() < max_trades)
         Comment("I am trading a grid from ", RangeMid-grid_separation*grid_lines, " to ", RangeMid+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(Ticket1!=1) Print("Error# "+GetLastError());         
            }
         if(Entertradesell==1)
            {
            Ticket2 = OrderSend(Symbol(), OP_SELL, Lots, Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
            if(Ticket2!=1) Print("Error# "+GetLastError());         
            }
         for (i = 1; i<grid_lines; i++)
            {
            if(Ask - (RangeMid - grid_separation*i) < grid_separation)
            GlobalVariableSet("test_next_level_"+Symbol(), RangeMid - grid_separation*i) ;
            if(RangeMid + grid_separation*i - Bid < grid_separation)
            GlobalVariableSet("test_next_level_"+Symbol(), RangeMid + grid_separation*i) ;
            }
         next_level_=GlobalVariableGet("test_next_level_"+Symbol()) ;
         for (i = 1; i<grid_lines-1; i++)
            {
            pips_risked = pips_risked+(((RangeMid+grid_separation*grid_lines)-(RangeMid-grid_separation*(grid_lines-i))));
            money_risked = (pips_risked*100000*Lots)/2 ;
            }
         if(OrdersTotal() < max_trades)
         Comment("I am trading a grid from ", RangeMid-grid_separation*grid_lines, " to ", RangeMid+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(Ticket1!=1) Print("Error# "+GetLastError());         
            }
         if(Entertradesell==1)
            {
            Ticket2 = OrderSend(Symbol(), OP_SELL, LotsOptimized(), Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
            if(Ticket2!=1) Print("Error# "+GetLastError());         
            }
         for (i = 1; i<grid_lines; i++)
            {
            if(Ask - (RangeMid - grid_separation*i) < grid_separation)
            GlobalVariableSet("test_next_level_"+Symbol(), RangeMid - grid_separation*i) ;
            if(RangeMid + grid_separation*i - Bid < grid_separation)
            GlobalVariableSet("test_next_level_"+Symbol(), RangeMid + grid_separation*i) ;
            }
         next_level_=GlobalVariableGet("test_next_level_"+Symbol()) ;
         for (i = 1; i<grid_lines-1; i++)
            {
            pips_risked = pips_risked+(((RangeMid+grid_separation*grid_lines)-(RangeMid-grid_separation*(grid_lines-i))));
            money_risked = (pips_risked*100000*LotsOptimized())/2 ;
            }
         if(OrdersTotal() < max_trades)
         Comment("I am trading a grid from ", RangeMid-grid_separation*grid_lines, " to ", RangeMid+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 - grid_separation*i)
               {
               Entertradebuy=1 ;
               }
            if (Bid == RangeMid + 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(Ticket1!=1) Print("Error# "+GetLastError());         
            }
         if(Entertradesell==1)
            {
            Ticket2 = OrderSend(Symbol(), OP_SELL, Lots, Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
            if(Ticket2!=1) Print("Error# "+GetLastError());         
            }
         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 - grid_separation*i) < grid_separation)
            GlobalVariableSet("next_level_"+Symbol(), RangeMid - grid_separation*i) ;
            if(RangeMid + grid_separation*i - Bid < grid_separation)
            GlobalVariableSet("next_level_"+Symbol(), RangeMid + grid_separation*i) ;
            }
         next_level_=GlobalVariableGet("next_level_"+Symbol()) ;
         for (i = 1; i<grid_lines-1; i++)
            {
            pips_risked = pips_risked+(((RangeMid+grid_separation*grid_lines)-(RangeMid-grid_separation*(grid_lines-i))));
            money_risked = (pips_risked*100000*Lots)/2 ;
            }
         if(OrdersTotal() < max_trades)
         Comment("I am trading a grid from ", RangeMid-grid_separation*grid_lines, " to ", RangeMid+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(Ticket1!=1) Print("Error# "+GetLastError());         
            }
         if(Entertradesell==1)
            {
            Ticket2 = OrderSend(Symbol(), OP_SELL, LotsOptimized(), Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
            if(Ticket2!=1) Print("Error# "+GetLastError());         
            }
         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 - grid_separation*i) < grid_separation)
            GlobalVariableSet("next_level_"+Symbol(), RangeMid - grid_separation*i) ;
            if(RangeMid + grid_separation*i - Bid < grid_separation)
            GlobalVariableSet("next_level_"+Symbol(), RangeMid + grid_separation*i) ;
            }
         next_level_=GlobalVariableGet("next_level_"+Symbol()) ;
         for (i = 1; i<grid_lines-1; i++)
            {
            pips_risked = pips_risked+(((RangeMid+grid_separation*grid_lines)-(RangeMid-grid_separation*(grid_lines-i))));
            money_risked = (pips_risked*100000*LotsOptimized())/2 ;
            }
         if(OrdersTotal() < max_trades)
         Comment("I am trading a grid from ", RangeMid-grid_separation*grid_lines, " to ", RangeMid+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(Ticket1!=1) Print("Error# "+GetLastError());         
            }
         if(Entertradesell==1)
            {
            Ticket2 = OrderSend(Symbol(), OP_SELL, Lots, Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
            if(Ticket2!=1) Print("Error# "+GetLastError());         
            }
         for (i = 1; i<grid_lines; i++)
            {
            if(Ask - (RangeMid - grid_separation*i) < grid_separation)
            GlobalVariableSet("next_level_"+Symbol(), RangeMid - grid_separation*i) ;
            if(RangeMid + grid_separation*i - Bid < grid_separation)
            GlobalVariableSet("next_level_"+Symbol(), RangeMid + grid_separation*i) ;
            }
         next_level_=GlobalVariableGet("next_level_"+Symbol()) ;
         for (i = 1; i<grid_lines-1; i++)
            {
            pips_risked = pips_risked+(((RangeMid+grid_separation*grid_lines)-(RangeMid-grid_separation*(grid_lines-i))));
            money_risked = (pips_risked*100000*Lots)/2 ;
            }
         if(OrdersTotal() < max_trades)
         Comment("I am trading a grid from ", RangeMid-grid_separation*grid_lines, " to ", RangeMid+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(Ticket1!=1) Print("Error# "+GetLastError());         
            }
         if(Entertradesell==1)
            {
            Ticket2 = OrderSend(Symbol(), OP_SELL, LotsOptimized(), Bid, slip, 0, 0, "Sell(#" + 1 + ")", MagicNumber, 0, DeepPink) ;
            if(Ticket2!=1) Print("Error# "+GetLastError());         
            }
         for (i = 1; i<grid_lines; i++)
            {
            if(Ask - (RangeMid - grid_separation*i) < grid_separation)
            GlobalVariableSet("next_level_"+Symbol(), RangeMid - grid_separation*i) ;
            if(RangeMid + grid_separation*i - Bid < grid_separation)
            GlobalVariableSet("next_level_"+Symbol(), RangeMid + grid_separation*i) ;
            }
         next_level_=GlobalVariableGet("next_level_"+Symbol()) ;
         for (i = 1; i<grid_lines-1; i++)
            {
            pips_risked = pips_risked+(((RangeMid+grid_separation*grid_lines)-(RangeMid-grid_separation*(grid_lines-i))));
            money_risked = (pips_risked*100000*LotsOptimized())/2 ;
            }
         if(OrdersTotal() < max_trades)
         Comment("I am trading a grid from ", RangeMid-grid_separation*grid_lines, " to ", RangeMid+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);
      }
   }
   //+------------------------------------------------------------------+

Profitability Reports

PERFORMANCE BY SYMBOL

Expected payoff

Average expected payoff across the available backtests for each symbol.

Positive Negative
16 reports
USD/CAD Oct 2024 - Jan 2025
7.84
Total Trades 26
Won Trades 24
Lost trades 2
Win Rate 92.31 %
Expected payoff 27.09
Gross Profit 807.42
Gross Loss -103.02
Total Net Profit 704.40
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
EUR/USD Oct 2025 - Feb 2026
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
GBP/AUD Oct 2025 - Feb 2026
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
GBP/CAD Oct 2025 - Feb 2026
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%

Comments