Download MetaTrader 5
To add comments, please log in or register
Develop applications to order. Make profit using Freelance service!
noob1990
10
noob1990 2016.02.18 08:40 

Hi,

 

I am having problems with my code, I am personally opening 1 trade at a time per EA window but i have been told that numerous trades open for other people.

Currently i have this code here:

 in start()

double stoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL);

double stoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL);

   OrderBuy=0;

   OrderSell=0;

   for(int cnt=0; cnt<OrdersTotal() ; cnt++)

 I have replaced it with this now:

 int start()

double stoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL);

   OrderBuy=0;

   OrderSell=0;

   for(int cnt=0; cnt<OrdersTotal() != 0; cnt++)

 

Will this fix my issue? 

Keith Watford
Moderator
7950
Keith Watford 2016.02.18 08:52  

No, it won't.

As you have not showed any code that may be causing problems, I doubt that anyone can help you

for(int cnt=0; cnt<OrdersTotal() ; cnt++)

Obviously this is a condition for a loop, but we have no idea what you do in the loop.

 for(int cnt=0; cnt<OrdersTotal() != 0; cnt++)

Most likely, if you have more than 1 open order, it will only loop once.

OrdersTotal() != 0

will probably equate to 1 as it is a boolean test. I'm surprised that you don't get a warning when compiling.

whroeder1
13624
whroeder1 2016.02.18 13:29  
  1. Post real code (that compiles) using SRC.
  2. for(int cnt=0; cnt<OrdersTotal() != 0; cnt++)
    for(int cnt=0;  0 <     N        != 0; cnt++) // if OrdersTotal > 0
    for(int cnt=0;    true           != 0; cnt++)
    for(int cnt=0;      1            != 0; cnt++) // true = 1
    for(int cnt=0;           true        ; cnt++) // Infinite loop!
    true = 1 and false = 0 so you get
    if( 3 < 2 < 1 )
    if( false < 1 )
    if(     0 < 1 )
    if(     true  )
    if( 3 > 2 > 1 )
    if(  true > 1 )
    if(     1 > 1 )
    if(     false )

Keith Watford
Moderator
7950
Keith Watford 2016.02.19 05:34  
for(int cnt=0; cnt<OrdersTotal() != 0; cnt++)

Surely, if any orders are open

OrdersTotal() != 0

Will be true, so equate to 1, which will make the condition the same as

for(int cnt=0; cnt<1; cnt++)

First pass of the loop, cnt < 1, so loop code will be executed and cnt is incremented

2nd pass of the loop will not happen because cnt=1 , not smaller than 1

RicoDaily
5
RicoDaily 2016.02.19 11:47  

I have this issue where my if i run my code it makes the order so many times that the terminal crashes. 

was working perfectly until I injected a code . but issue was not fixed when I removed the injected code. 

/
To add comments, please log in or register