Very Basic EA - Why won't it Backtest

 

I created a extremely basic EA to test the relationship between risk/reward ratio and winning %.

The basic idea is that the EA will alternate between buying and selling trades with specific TP and SL parameters. As soon as 1 trade closes, the trade in the opposite direction should open. The code looks fine to me, and compiles properly, but when I try to backtest it, it only places the first trade.

I think the issue may be with the Bought_Last or Sold_Last flags, but I can't figure out the solution for the life of me (been at it an hour and a half already). Could someone please point out my oversight?

//+------------------------------------------------------------------+
//|                                            RRR vs. Winning %.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        https://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "https://www.metaquotes.net"

int MagicNumber                  =     23894;
extern double Stop_Distance      =     100;
extern double TP_Distance        =     100;
int
   Time_0,                                               // New bar beginning time
   Total,                                                // Amount of orders in window
   points;                                               // 5 digit adjustment for points
double pips;                                             // 5 digit adjustment for pips
string Symb;                                             // Symbol abbreviation
extern bool Bought_Last          =      false,
Sold_Last                        =      false;
  

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
if (Digits==5 || Digits==3)                              // For 5 digit brokers
   {
   points=10;                                            // Make points = 10 units
   pips=Point*10;                                        // Pips are actually 10 units...
   }
   else                                                  // else...
   {
   points=1;                                             // Points = 1 unit
   pips=Point;                                           // Pips are just 1 unit
   }
   return(0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   //----Order Processing
       for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) 
       {
         if (
         OrderSelect(pos, SELECT_BY_POS)                          // Only my orders w/
         &&  OrderMagicNumber()  == MagicNumber                   // my magic number
         &&  OrderSymbol()       == Symbol() )                    // and my pair.
         {                                                        // Analyzing orders:
         if (OrderSymbol()!=Symb)continue;                        // Another security
         if (OrderType()>1)                                       // Pending order found
            {
            Print("Pending order detected. EA does not work.");
            return(0);                                            // Exit start()
            }
         Total++;                                                 // Counter of market orders
         }
       }
      if(Total>0)                                                 // Only one order at once
      {
      return(0);
      }

//----
Symb = Symbol();
if (Bought_Last == false && Total==0)
      {
      Bought_Last = true;
      Sold_Last = false;
      int ticket=OrderSend(Symb,OP_BUY,1,Ask,3*points,Ask-Stop_Distance*pips,Ask+TP_Distance*pips," ",MagicNumber);
         if(ticket>0)
            {
            OrderSelect(ticket,SELECT_BY_TICKET);
            Print("Order Send Successful " + ticket + " Long from " + OrderOpenPrice());
            }
            else
            {
            Print("Order Send Failed, Error " + GetLastError());
            }
      return(0);
      }
else
if (Sold_Last == false && Total==0)
      {
      Sold_Last = true;
      Bought_Last = false;
      ticket=OrderSend(Symb,OP_SELL,1,Bid,3*points,Bid+Stop_Distance*pips,Bid-TP_Distance*pips," ",MagicNumber);
         if(ticket>0)
            {
            OrderSelect(ticket,SELECT_BY_TICKET);
            Print("Order Send Successful " + ticket + " Long from " + OrderOpenPrice());
            }
            else
            {
            Print("Order Send Failed, Error " + GetLastError());
            }
      }
   return(0);
  }
//+------------------------------------------------------------------+

Thanks!

 
int start()
  {
   //----Order Processing
       for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) 
       {
         if (
         OrderSelect(pos, SELECT_BY_POS)                          // Only my orders w/
         &&  OrderMagicNumber()  == MagicNumber                   // my magic number
         &&  OrderSymbol()       == Symbol() )                    // and my pair.
         {                                                        // Analyzing orders:
         if (OrderSymbol()!=Symb)continue;                        // Another security
         if (OrderType()>1)                                       // Pending order found
            {
            Print("Pending order detected. EA does not work.");
            return(0);                                            // Exit start()
            }
         Total++;                                                 // Counter of market orders
         }
       }
      if(Total>0) 
Before starting the for loop what is the value of Total and what is Symb and why are you checking OrderSymbol() twice?
Reason: