one order every day

To add comments, please log in or register
Oussama Mansour
2192
Oussama Mansour  
  int orderstotal()
     {
      int cnt=0;
      
      for(int i=0;i<OrdersTotal();i++)
        {
         if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         if(OrderSymbol()==Symbol() && MagicNumber==OrderMagicNumber()&&OrderOpenTime()>iTime(Symbol(),PERIOD_D1,0))
           {
            cnt++;
           }
        }
      return(cnt);
     }

Is it correct ? 

I tried to select one order everyday .

Marius Ovidiu Sunzuiana
1497
Marius Ovidiu Sunzuiana  
Oussama Mansour:

Is it correct ? 

I tried to select one order everyday .

OrdersTotal()-1

Keith Watford
Moderator
17193
Keith Watford  
Marius Ovidiu Sunzuiana:

OrdersTotal()-1

Why the minus 1?

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

is correct

Oussama Mansour
2192
Oussama Mansour  
Keith Watford:

Why the minus 1?

is correct

it still open more trades .

Enrique Dangeroux
448
Enrique Dangeroux  
Count down instead of up. Make it a habit for all dealings with orders and positions.
Marco vd Heijden
Moderator
12380
Marco vd Heijden  
Oussama Mansour:

Is it correct ? 

I tried to select one order everyday .

Need more info what do you mean by select one order everyday ? 

Oussama Mansour
2192
Oussama Mansour  
Marco vd Heijden:

Need more info what do you mean by select one order everyday ? 

I wanted to allow one order each day only .

Marco vd Heijden
Moderator
12380
Marco vd Heijden  
datetime time;
if(time!=iTime(Symbol(),PERIOD_D1,0))
 {
  if(OrderSelect(0, SELECT_BY_POS, MODE_TRADES))
   {
    Print(TimeToString(time)+" Selected OrderTicket: "+(string)OrderTicket()); 
   }
  time=iTime(Symbol(),PERIOD_D1,0);
 }
Keith Watford
Moderator
17193
Keith Watford  
Marius Ovidiu Sunzuiana:

OrdersTotal()-1

Keith Watford:

Why the minus 1?

is correct

Oussama Mansour:

it still open more trades .

I was replying to Marius's post.

William Roeder
19155
William Roeder  
Oussama Mansour: is it correct ?
  1. Why did you post your MT4 question in the Root / MT5 General 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. iTime(Symbol(),PERIOD_D1,0)
    On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073 errors before accessing candle values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4

    The function linked to, opens a hidden chart for the symbol/TF in question (if not already open,) thus updating history, and temporarily placing the symbol on Market Watch (if not already there,) so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero on the first call.

  3. or just compute current date
              Find bar of the same time one day ago - Simple Trading Strategies - MQL4 programming forum

  4. Minus one (p=n-1) if you are counting down. (p < n) if you are counting up. Either are OK in this case.


  5. Marco vd Heijden:
    if(OrderSelect(0, SELECT_BY_POS, MODE_TRADES))
    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 programming forum
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles

Marco vd Heijden
Moderator
12380
Marco vd Heijden  
William Roeder:


  1. 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 programming forum
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles

if(time!=iTime(Symbol(),PERIOD_D1,0))
 {
  if(OrderSelect(0, SELECT_BY_POS, MODE_TRADES))
   {
    Print(TimeToString(time)+" Selected OrderTicket: "+(string)OrderTicket()); 
   }
  time=iTime(Symbol(),PERIOD_D1,0);
 }

This code prints a Order Ticketnumber.

Explain to me how this can possibly harm other EA's and or Other EA's running (other) Magic Numbers.

This code isn't incompatible, in fact is is compatible to every other EA(including itself on other charts and manual trading.)

12
To add comments, please log in or register