urgent help needed please

Back to topics list To post a new topic, please log in or register
avatar
89
chudanever 2015.06.23 16:28
 

pls why is my order select  printing "no order selected" i have try everything both google search yet i can fix this problem

i use this orderselect on sell and it works fine but on buy it does not work pls help me,

below is my code. pls note that i use this orderselect to open only buy order below ask price. thanks

    OpenPrice =0;
     Ticket =0;
      lastTradeLots =0;
     
   for(int i=0; i < OrdersTotal(); i++) // Loop through orders
     {
      if(OrderSelect(i,SELECT_BY_POS, MODE_TRADES)) // If there is the next one
        {  
         if(OrderSymbol()!=Symb)continue;     // Another security
         if( Type == OP_BUY )
         if(OrderMagicNumber()!= magicbuy )continue;     // Another security
         if(OrderLots() > lastTradeLots && OrderTicket() > Ticket && OrderOpenPrice() > OpenPrice )
         if(Opn_B==false)continue;
         
       Total++;
      
         Ticket=OrderTicket();                  // Number of selected order
         Type   =OrderType();                    // Type of selected order
         OpenPrice =OrderOpenPrice();               // OPENPrice of selected order
         lastTradeLots   =OrderLots();                     // Amount of lots
        }
     }
     
  
          
  rsi1=iRSI(NULL,0,14,PRICE_OPEN,0);  

  Opn_B=rsi1<=30 && Ask <= OpenPrice ;
  Print("OpenTrade: error '"+ErrorDescription(GetLastError()));
  
avatar
12992
WHRoeder 2015.06.23 22:05 #
 
  1. Do not call GetLastError() (or _LastError) unless you have an error. Delete that Print, it is after the loop and is useless.
  2. In the presence of multiple orders (one EA multiple charts, multiple EA's, manual trading) you must count down when closing/deleting/modifying in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum
  3.          if( Type == OP_BUY )
             if(OrderMagicNumber()!= magicbuy )continue;     // Another security
    This rejects orders with another magic only if Type == OP_BUY. Otherwise it ignores the magic. Shouldn't you be testing against OrderType()

  4. if(Opn_B==false)continue;
    You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.
  5. Your code
     I would simplify
    for(int i=0; i < OrdersTotal(); i++) // Loop through orders
      {
       if(OrderSelect(i,SELECT_BY_POS, MODE_TRADES)) // If there is the next one
         {  
          if(OrderSymbol()!=Symb)continue;     // Another security
          if( Type == OP_BUY )
          if(OrderMagicNumber()!= magicbuy )continue;     // Another security
          if(OrderLots() > lastTradeLots && OrderTicket() > Ticket && OrderOpenPrice() > OpenPrice )
          if(Opn_B==false)continue;
        Total++;
    if(Opn_B && Type == OP_BUY) // Constant inside the loop.
    for(int i=OrdersTotal() - 1; i >= 0; --i) if(
       OrderSelect(i,SELECT_BY_POS)
    && OrderMagicNumber() == magicbuy
    && OrderSymbol()      == Symb
    && OrderLots()        > lastTradeLots 
    && OrderTicket()      > Ticket 
    && OrderOpenPrice()   > OpenPrice 
    ){
      Total++;
avatar
89
chudanever 2015.06.24 02:26 #
 

thanks WHRoeder for your correction well correlated. now......

why i write my ea separately is because of debugging errors and also to be able to use different magic numbers because of my lotstep

1.even though i know there are better ways. i know i will bring out time to joint my ea to one single ea and not handle orders separately.

2. i started call for error when i discovered that my sell loop works but  buying loop on backtest and live test fails with

error 4105 meaning "no selected order".


Now WHRoeder like you corrected can i make the code fit my style like this below..........can it work this way

remember i buy low


// Orders accounting 
     Symb=Symbol();                           
     OpenPrice=0;
     Ticket =0;
      lastTradeLots=0;
     
for(int i=OrdersTotal() - 1; i >= 0; --i) 
if( OrderSelect(i,SELECT_BY_POS)
&& OrderMagicNumber() == magicbuy
&& OrderType()        == OP_BUY                 <===============================
&& OrderSymbol()      == Symb
&& OrderLots()        > lastTradeLots 
&& OrderTicket()      > Ticket 
&& OrderOpenPrice()   > OpenPrice               <===============================        
)
  Total++;
  {  
     }
      { 


//My criteria for opening buy orders
 
  rsi1=iRSI(NULL,0,14,PRICE_OPEN,0);  
  Opn_B=rsi1<=30 && Ask<=OpenPrice;              <===============================




                                                                       or can i do it like this will it work 


// Orders accounting 
     Symb=Symbol();                           
     OpenPrice=0;
     Ticket =0;
      lastTradeLots=0;


if(Opn_B && Type == OP_BUY &&  rsi1<=30 && Ask<=OpenPrice) // Constant inside the loop.
for(int i=OrdersTotal() - 1; i >= 0; --i) if(
   OrderSelect(i,SELECT_BY_POS)
&& OrderMagicNumber() == magicbuy
&& OrderSymbol()      == Symb
&& OrderLots()        > lastTradeLots 
&& OrderTicket()      > Ticket 
&& OrderOpenPrice()   > OpenPrice 
){
  Total++;




avatar
12992
WHRoeder 2015.06.24 03:03 #
 
  1. I have no idea. Your code is unreadable.
    )
      Total++;
      {  
         }
          { 
    If ends ")" but only does Tottal++. Empty "{}" does nothing. Opening "{" starts a block independent of the loop. Unreadable.
  2. "no selected order" has been answered - Don't look at LastError after the fact.
avatar
313
JD4 2015.06.24 05:18 #
 
That is one good thing they have done here that I have seen in practice in Java (and I presume C variations do as well, as Java is based on it) is the whitespace allowed for programming clarity, instead of the strict spacing rules that some other programming languages have.
avatar
89
chudanever 2015.06.24 10:11 #
 
WHRoeder:
  1. I have no idea. You code is unreadable. If ends ")" but only does Tottal++. Empty "{}" does nothing. Opening "{" starts a block independent of the loop. Unreadable.
  2. "no selected order" has been answered - Don't look at LastError after the fact.




1.am sorry actually the braces is doing nothing there,i have remove it.

2. also second question answered work perfectly ok......thanks i appreciate


final step question pls WHRoeder in my

//My criteria for opening buy orders
 
  rsi1=iRSI(NULL,0,14,PRICE_OPEN,0);  
  Opn_B=rsi1<=30 && Ask <= OpenPrice;              <===============================

i don't know trying to get the value of my orderselect which is
OrderOpenPrice()   > OpenPrice 

openprice being a double that get its value from OrderOpenPrice()

and the advantage/value of openprice is  0  which is last position on the current chart.

and the value is gotten from orderselect if selected, so that i can use it on my whole code parts the way i like or seems fit.

because it resets the  variable  to 0 after each close ticket/positions on current chart.


now my question is why did   double "openprice" refuse to work with my code on buying position

 Opn_B=rsi1<=30 && Ask <= OpenPrice; <===============================

instead it work with 

Opn_B=rsi1<=30 && Ask <= OrderOpenPrice(); <===============================

which is variable and does not reset to 0 after each close order/position INSTEAD IT LOOKS for stopped price to continue.

But sell position loop WORKS well with the double "OpenPrice" and resets to 0 for another level in the current chart 



my question is why is it fails on buying levels low and work well on sell levels high. pls assist me with code examples as you normally do .thanks

avatar
12992
WHRoeder 2015.06.24 14:09 #
 
OpenPrice=0;
:
&& OrderOpenPrice()   > OpenPrice          <== OrderOpenPrice is always greater than zero. Test does nothing.
:
Opn_B=rsi1<=30 && Ask<=OpenPrice;        <== Ask is always greater than zero. Opn_B always false.

avatar
89
chudanever 2015.06.24 20:28 #
 
WHRoeder:


OpenPrice=0;
:
&& OrderOpenPrice()   > OpenPrice          <== OrderOpenPrice is always greater than zero. Test does nothing.
:
Opn_B=rsi1<=30 && Ask<=OpenPrice;        <== Ask is always greater than zero. Opn_B always false.


ok....i thought before that

OrderOpenPrice()   > OpenPrice    : for buy high 

while OrderOpenPrice()   < OpenPrice  : for sell low    loops.....

but now i have pick corrections that  OrderOpenPrice() > OpenPrice is 0 for all OrderType().
will i say its constant not changing          thank you very much for the code example





      but WHRoeder why is 


//My criteria for opening buy orders 
 
  rsi1=iRSI(NULL,0,14,PRICE_OPEN,0);  
  Opn_B=rsi1<=30 && Ask < OpenPrice;     <====== do not open any order /FAILS

            WHILE

//My criteria for opening buy orders
 
  rsi1=iRSI(NULL,0,14,PRICE_OPEN,0);  
  Opn_B=rsi1<=30 && Ask < OrderOpenPrice();     <======  opens AN order /WORKS


BUT the right one is suppose to be OpenPrice since it got its value ALREADY from OrderOpenPrice()  
and also reset to 0 at any close levels for another entry point

why is that so or is there any solution to that or something am missing.....because 
OrderOpenPrice()  stores even the last close order/open on current chart and continues when price comeback to it.

so how can i use OpenPrice  instead of OrderOpenPrice()  .......thanks for your support already,
 
avatar
89
chudanever 2015.06.25 13:18 #
 

updated....processing........Done.

thanks WHRoeder i finally found the answer to this question on you previous answer 
and it was over helpful and quit easy.thanks again for your help God bless you.
Back to topics list  

To add comments, please log in or register