Small Problem with my EA

 


Hello, I'm trying to write an EA but I have a problem when I do a backtest.
It seems to work properly for a moment and then it does something that I really don't understand.


The problem:

2 15:22:04.133 2018.11.07 02:42:47  DoubleScalp(1.2) EURUSD,M5: open #352 sell stop 0.02 EURUSD at 1.14519 ok
2 15:22:04.180 2018.11.07 02:42:47  DoubleScalp(1.2) EURUSD,M5: delete #352 sell stop 0.02 EURUSD at 1.14519 sl: 0.00000 tp: 0.00000 ok
2 15:22:04.180 2018.11.07 02:42:47  DoubleScalp(1.2) EURUSD,M5: open #353 sell stop 0.02 EURUSD at 1.14519 ok
2 15:22:04.180 2018.11.07 02:42:47  DoubleScalp(1.2) EURUSD,M5: delete #353 sell stop 0.02 EURUSD at 1.14519 sl: 0.00000 tp: 0.00000 ok
2 15:22:04.180 2018.11.07 02:42:47  DoubleScalp(1.2) EURUSD,M5: open #354 sell stop 0.02 EURUSD at 1.14519 ok
2 15:22:04.180 2018.11.07 02:42:47  DoubleScalp(1.2) EURUSD,M5: delete #354 sell stop 0.02 EURUSD at 1.14519 sl: 0.00000 tp: 0.00000 ok
2 15:22:04.180 2018.11.07 02:42:47  DoubleScalp(1.2) EURUSD,M5: open #355 sell stop 0.02 EURUSD at 1.14519 ok


Could Someone help me understand please?

Best Regard, Mike.

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
Ask questions on technical analysis, discuss trading systems and improve your MQL5 programming skills to develop your own trading strategies. Communicate and share your experience with traders from anywhere in the world, answer questions and help beginners — MQL5.community is...
Files:
 
Mickael Arditi: Could Someone help me understand please?
  1. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Use the debugger or print out your variables, including _LastError and prices and find out why.

  3. if(OrdersTotal()==0){
          Lots= …
    Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles

 
Mickael Arditi:

Hello, I'm trying to write an EA but I have a problem when I do a backtest.
It seems to work properly for a moment and then it does something that I really don't understand.

The problem:

It's in these parts:

   if(NormalizeDouble(AmountB+AmountBS,2)<NormalizeDouble(AmountS+LotsRef,2))
   {
      DeletePendB();
      Lots=AmountS-AmountB+LotsRef;
      OpenPos=BS_Pos;
      Type=OP_BUYSTOP; OpenPend();
      return(0);
   }
   
   if(NormalizeDouble(AmountS+AmountSS,2)<NormalizeDouble(AmountB+LotsRef,2))
   {
      DeletePendS();
      Lots=AmountB-AmountS+LotsRef;
      OpenPos=SS_Pos;
      Type=OP_SELLSTOP; OpenPend();
      return(0);
   }

Because for comparison of doubles/floats, a difference of 0.000000000000000.................0000000000000000000001 makes a difference :)

 


Thank you for your quickly answers!

it work properly now and i've learned Something new =)



Reason: