Download MetaTrader 5

This piece of code here doesn't seem to be working.

To add comments, please log in or register
Store your source codes in MQL5 Storage. It is secure!
Luciano Ola
1007
Luciano Ola 2014.02.10 11:30 
for(int l=OrdersTotal()-1;l>=0;l--)
          {
          if(OrderSelect(l,SELECT_BY_POS,MODE_TRADES))
           {
            if(OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol()&& OrderType()==OP_SELL)
            {  OOPS=OrderOpenPrice();OOTS=OrderOpenTime();      
            if(iTime(Symbol(),0,0)-OrderOpenTime()<=0 && OrderOpenTime()!=0 )OOTS=OrderOpenTime()+(iTime(Symbol(),0,0)-OrderOpenTime());
                 if(OpenSellOrdersThisPair(Symbol())>=1)ShiftToOpenS =(iTime(Symbol(),0,0)-OOTS)/(60*period);
                 SEnvPU = iEnvelopes(NULL,0,EnvelopeMA,2,0,Applied,0.01,MODE_UPPER,ShiftToOpenS);
                 
                 

            }
                 
           }

          }
Not sure what's wrong with it but when I use the variables defined here, especially ShiftToOpenS, it doesn't seem to work as expected.
Simon Gniadkowski
Moderator
17999
Simon Gniadkowski 2014.02.10 11:33  
MetaNt:
Not sure what's wrong with it but when I use the variables defined here, especially ShiftToOpenS, it doesn't seem to work as expected.
Add some Print()s and find out what variables are not as you expect . . .
Luciano Ola
1007
Luciano Ola 2014.02.10 11:38  
RaptorUK:
Add some Print()s and find out what variables are not as you expect . . .


I tried that before but in the form of an OOTS on my order labels and it does seem to be the OOTS that isn't working, but I don't know why, also the OOTS doesn't have an issue with every open order the fault seems to occur arbitrarily. The same is the case with my buy version of this code.
Simon Gniadkowski
Moderator
17999
Simon Gniadkowski 2014.02.10 11:54  
MetaNt:

I tried that before but in the form of an OOTS on my order labels and it does seem to be the OOTS that isn't working, but I don't know why, also the OOTS doesn't have an issue with every open order the fault seems to occur arbitrarily. The same is the case with my buy version of this code.

You need to review your code . . . some of it doesn't make a lot of sense, for example . . .

OOTS = OrderOpenTime() + ( iTime(Symbol(),0,0) - OrderOpenTime() );

// is the same as . . .

OOTS = iTime(Symbol(),0,0);

. . . so you have 2 unneeded function calls.

And you get rid of the remaining function call like this . . .

OOTS = Time[0];
Luciano Ola
1007
Luciano Ola 2014.02.10 12:04  
RaptorUK:

You need to review your code . . . some of it doesn't make a lot of sense, for example . . .

. . . so you have 2 unneeded function calls.

And you get rid of the remaining function call like this . . .


I can't do that because this gets recalculated every tick, OOTS= the open time of the bar that my order opened in. the function that I used was just incase the order opened after the bar opened. Now I see my mistake.
Simon Gniadkowski
Moderator
17999
Simon Gniadkowski 2014.02.10 12:11  
MetaNt:

I can't do that because this gets recalculated every tick, OOTS= the open time of the bar that my order opened in. the function that I used was just incase the order opened after the bar opened.
OrderOpenTime() for an Order does not change . . . X + Y - X is always Y
Luciano Ola
1007
Luciano Ola 2014.02.10 12:23  
RaptorUK:
OrderOpenTime() for an Order does not change . . . X + Y - X is always Y


Yes but I thought you suggested making OOTS ==

Time[0]

I only used the below, in order to round down to the nearest open bar time.

OOTS = OrderOpenTime() + ( iTime(Symbol(),0,0) - OrderOpenTime() )
Simon Gniadkowski
Moderator
17999
Simon Gniadkowski 2014.02.10 12:28  
MetaNt:


Yes but I thought you suggested making OOTS ==

I only used the below, in order to round down to the nearest open bar time.

But . . .

iTime(Symbol(),0,0) == Time[0]

. . . is true. Your iTime call gets the open time for bar 0 for the current chart symbol for the current timeframe . . . it's the same as Time[0] . . . unless you are constantly looping within start() ?

Luciano Ola
1007
Luciano Ola 2014.02.10 12:30  
RaptorUK:

But . . .

. . . is true. Your iTime call gets the open time for bar 0 for the current chart symbol for the current timeframe . . . it's the same as Time[0] . . . unless you are constantly looping within start() ?


No I understand this, I have recently been replacing functions of such forms with the array form, my issue is not with the alternative syntax as the problem with OOTS will still persist.
Luciano Ola
1007
Luciano Ola 2014.02.10 13:00  

I might have to use a bool to get this working.

Suggestions would be appreciated.

Luciano Ola
1007
Luciano Ola 2014.02.10 16:38  
or(int k=OrdersTotal()-1;k>=0;k--)
          {
          if(OrderSelect(k,SELECT_BY_POS,MODE_TRADES))
           {
            if(OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol()&& OrderType()==OP_BUY)
            { OOPB=OrderOpenPrice();      
             if((Time[0]-OrderOpenTime())<=0 && OrderOpenTime()!=0 && OrderOpenTime()!=NULL)OOTB=Time[0];  
            //else OOTB=OOTB;
                 if(OpenOrdersThisPair(Symbol())>=1)ShiftToOpenB=((Time[0]-OOTB)/60*PeriodSeconds());
                 BEnvPL = iEnvelopes(NULL,0,EnvelopeMA,2,0,Applied,0.01,MODE_LOWER,ShiftToOpenB);
                 
                  
                 
                       
                                               
            }
                 
           }

          }
          
for(int l=OrdersTotal()-1;l>=0;l--)
          {
          if(OrderSelect(l,SELECT_BY_POS,MODE_TRADES))
           {
            if(OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol()&& OrderType()==OP_SELL)            
            {OOPS=OrderOpenPrice();       
             if((Time[0]-OrderOpenTime())<=0 && OrderOpenTime()!=0 && OrderOpenTime()!=NULL)OOTS=Time[0];
              //else OOTS=OOTS;      
                 if(OpenOrdersThisPair(Symbol())>=1)ShiftToOpenS =((Time[0]-OOTS)/PeriodSeconds());
                 SEnvPU = iEnvelopes(NULL,0,EnvelopeMA,2,0,Applied,0.01,MODE_UPPER,ShiftToOpenS);
                 
                 
                 

            }
                 
           }

          }
Seems to be working now, however after 5 bars the shift goes from 5 to 16...
12
To add comments, please log in or register