Random Order Entries and Exits?

 

Hi All,

I'm backtesting my EA, and have been trying to drill down on getting the right entry and exit points.


Quick background on the strategy: its a band system based on a moving averages, So when the previous candle straddles the lower band (high inside, low outside), buy on the next candle open.  The opposite occurs on the upper band for short orders.  Exit when price crosses the middle line.


So the EA trades and backtests well, but when I open the chart, the trade arrow seem random.  The entry and exits are nowhere near where the indicator that is supposed to trigger them.  


I've attached an image of the chart for you to see what I mean.


So the trade on the above image should have opened on the red candle with the long lower wick that touches the bottom line, and closed when the price crosses above the middle line during the long green candle 5 candles later.


Any ideas why the EA would be triggering randomly like this?  The code for the above order is below.


void OnTick()
  {
   int ticket = -1;
   double price;   
   
   
   //Open Buy Order
   RefreshRates();
   if(Bid <= iCustom(NULL, PERIOD_CURRENT, "LowerBand", "Current", 0, 1)
     {
      RefreshRates();
      price = Ask;   
      if(IsTradeAllowed())
        {
         ticket = myOrderSend(OP_BUY, price, TradeSize, "");
         if(ticket <= 0) return;
        }
      else
         myAlert("order", "");
     }
  }
 
enTRYsoP: So the trade on the above image should have opened on the red candle with the long lower wick that touches the bottom line, and closed when the price crosses above the middle line during the long green candle 5 candles later.

Where so you test for that? Your posted code triggers every tick where the current candle's wick is below the lower line. There is no middle line test in your code.

Wait for a new bar. Test the previous candle wick vs lower line and close vs middle line.