EA works erratically

 
I have written an ea that activates at 8 am new york time.  It looks back at the previous 7 am hour candle.  Using this candle the ea sets the buystop 7 points above the 7 am high and a sell stop 10 points below the 7am low.  It sets the sl at the high and low of the 7 am candles.  This ea has been working fine for the past week and it has been consistently making money.  Except for this morning 8 am new york time 10/26, the buy stops and sells stops and stop losses were not set where they were suppose to have been set.  I cannot see a reason in my code why this happened. The 7 am 1 hour candle high and low respectively were 1.2796 and 1.2780.  This means the buy stop should have been set at 1.2803 and the sell stop at 1.2770.  Instead the account history shows it bought at 1.28103 and sold at 1.2780.  The stop loss for the buy should have been at 1.2780 and the sell stop should have been at 1.2780.  Instead the buy order closed at 1.27894 and the sell order closed at 1.28063.  According to the account history the long trade opened at 12:03:54 and closed at 12:04:09 15 sec later and the short trade opened 1 sec later at 12:04:10 and closed 3 seconds later at 12:04:13   This doesn't make any sense on many levels.  I have attached my code.  Could someone please tell me if the problem is in my code.  As I said it worked great all of this week except for today.  And when I run it now at a current hour candle, everything works as programmed.  Also, could someone tell me how I post the mql4 code in the right format in this thread.
Files:
 

Paul:
 This means the buy stop should have been set at 1.2803 and the sell stop at 1.2770.  Instead the account history shows it bought at 1.28103 and sold at 1.2780. 

The stop loss for the buy should have been at 1.2780 and the sell stop should have been at 1.2780.  Instead the buy order closed at 1.27894 and the sell order closed at 1.28063.  According to the account history the long trade opened at 12:03:54 and closed at 12:04:09 15 sec later and the short trade opened 1 sec later at 12:04:10 and closed 3 seconds later at 12:04:13   This doesn't make any sense on many levels.

I have attached my code.  Could someone please tell me if the problem is in my code.  As I said it worked great all of this week except for today.  And when I run it now at a current hour candle, everything works as programmed.  Also, could someone tell me how I post the mql4 code in the right format in this thread.

  1. Normally I'd post about using points and not PIPs .

    A PIP is defined as 0.00010 (or 0.0010 for Yen pairs.)
              Percentage in point - Wikipedia

    Code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points,) and metals. Compute what a PIP is and use it, not points.
              How to manage JPY pairs with parameters? - MQL4 and MetaTrader 4 - MQL4 programming forum

    buy_stop_price = high + (buy_points_buffer * Point * 10); 
    sell_stop_price = low - (sell_points_buffer * Point * 10);
    But you use point*10 everywhere. Perhaps your broker suddenly went to 6 digits. Market Watch -> right click -> Specification

  2. You buy at the Ask and sell at the Bid.
    • Your buy order's TP/SL are triggered when the Bid reaches it. Not the Ask.
    • Your sell order's TP/SL will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 and MetaTrader 4 - MQL4 programming forum - Page 3
    • The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools -> Options {control-O} -> charts -> Show ask line.)

  3. When you post code please use the SRC button! Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
 
whroeder1:
  1. Normally I'd post about using points and not PIPs .But you use point*10 everywhere. Perhaps your broker suddenly went to 6 digits. Market Watch -> right click -> Specification

  2. You buy at the Ask and sell at the Bid.
    • Your buy order's TP/SL are triggered when the Bid reaches it. Not the Ask.
    • Your sell order's TP/SL will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 and MetaTrader 4 - MQL4 programming forum - Page 3
    • The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools -> Options {control-O} -> charts -> Show ask line.)

  3. When you post code please use the SRC button! Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum

Thank you for your reply and suggestions.  I will go ahead and make some changes in my program.