open orders with 10pip gap - page 4

 
    //datetime lastTime  = 0;
    double highest_open_price=0;
    //int      lastTicket = -1; // None open.
    int      highest_Ticket = -1; // None open.
    for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(0, SELECT_BY_POS,MODE_TRADES)                 // Only my orders w/
    &&  OrderMagicNumber()  == 0           // my magic number
    &&  OrderSymbol()       == Symbol()                 // and my pair.
    //&&  OrderOpenTime()     >=  lastTime
    &&  ?????????()     >=  highest_open_price
    ){
      highest_open_price= ????????();
      highest_Ticket = OrderTicket();
    }

 

 As I said - simple substitution

 
GumRai:

 

 As I said - simple substitution



thank GumRai: but my further question is i believe that ?????????()  is OrderOpenTime()

now how do i make it work with my trading logic like you point early




      
rsi1=iRSI(NULL,0,14,PRICE_CLOSE,1);
rsi2=iRSI(NULL,0,14,PRICE_CLOSE,0); 
     
 if(rsi2>70 && Ask > High[1] + (10*pips2dbl) )
  {
      Opn_S=true;
     } 
     else 
   if(rsi2>70 && Ask < High[1] + (10*pips2dbl)) 
      {
      Opn_S=false;
     }

 Here you give value to Opn_S, but you do nothing with it







   lastTicket=OrderSend(Symbol(),OP_BUY,mylot(),Ask,0,0,0,"My Comment",magic,0,Green);

 Here there are no conditions for opening an order and you over-write the value of lastTicket.

 

Your code has no logic, it is just 3 sections of code that are totally unrelated to each other  

 ===========================================================================================================================




HHH

why i ask is i arranged the result like this BELOW code......it resulted to what i wanted but the problem is it opens multiple orders in a single line. see the RESULT PICS above

// Orders accounting 
   datetime lastTime  = 0;
    double highest_open_price=0;
    lastTicket = -1; // None open.
    int      highest_Ticket = -1; // None open.
    for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(0, SELECT_BY_POS,MODE_TRADES)                 // Only my orders w/
    &&  OrderMagicNumber()  == 0           // my magic number
    &&  OrderSymbol()       == Symbol()                 // and my pair.
    &&  OrderOpenTime()     >=  lastTime
    &&  OrderOpenTime()     >=  highest_open_price
    ){
      highest_open_price= OrderOpenTime();
      highest_Ticket = OrderTicket();
    }





        
 if(Bid > High[1] && OrderOpenTime()     > highest_open_price)
  {
      Opn_S=true;
     }   
CurrentTime= Time[1];





if(Opn_S==true)               // No opened orders +
        {                                       // criterion for opening Sell
         RefreshRates();                   // Refresh rates     
         lastTicket=OrderSend(Symbol(),OP_SELL,mylot(),Bid,0,0,0,"My Comment",magic,0,Red);
         if(lastTicket>0)
      
           {
            Comment("Opened order Sell ","#",lastTicket);
            return(0);                                 // Exit start()
           }
         if(Fun_Error(GetLastError())==1) // Processing errors
            continue;                             // Retrying
         return(0);                                   // Exit start()
        }
      break;                                    // Exit while
     }
//--------------------------------------------------------------- 9 --------------------------------------
   return(0);                                       // Exit start()
  }


 

There is no logic as your code is 3 sections that do not relate to each other.

I can only conclude that you have copied and pasted sections of code from other EAs in the vain hope that they will work together 

" i believe that ?????????()  is OrderOpenTime()"

Proves that you have no idea what the loop does and you did not write it. 

 

GumRai please this is my whole code mainly opens only sell. like you said all this disconnections came as a result of allowing my ea to open multiple order and looping thing before is just simple lopped my orders like this


{
   int cnt;
   int NumTrades;   // Number of buy and sell trades in this symbol
   
   NumTrades = 0;
   for (cnt = OrdersTotal()-1 ; cnt >=0 ; cnt--)
     {
     if(OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES)==true)
      if ( OrderSymbol() != Symbol()) continue;
      if ( OrderMagicNumber() != magic)  continue;
      
      if(OrderType() == OP_BUY )  NumTrades++;
      if(OrderType() == OP_SELL ) NumTrades++;
             
     }
    
  }




then getting my ea to work with my loop by just adding  if(NumTrades==0 && Opn_B==true) // No new orders +

this ensures my ea to open just 1 order on a giving chart but now i want to expand my ea to open more than one order i remove  NumTrades==0 

to let the ea open order unrestricted with my ordersend as little i know now i know we can loop through order for so many reason and when it comes
to the looping for highest order on the chart i dont know that well,but can do it if example is giving. please bear with my little coding knowledge and put me through

below is my ea please assist me 
 
please am waiting for your response
 

I am not sure if that EA is just poorly written, incomplete or a working EA with chunks of code removed.

You say it opens mainly sells, well I don't see that it can ever open a buy.

The main condition to open a buy is

if(Opn_B==true)

 The only other place in the code that Opn_B appears in the code is

Opn_B=false

 So there is nowhere that it can be set to true.

Incidently

   while(true) // Orders closing loop

 A loop that only opens orders - great commenting.

 

   double highest_open_price=0;
   int    highest_Ticket=-1;
   for(int pos=OrdersTotal()-1; pos>=0; pos--)
      if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES) // Only my orders w/
         && OrderMagicNumber()==0           // my magic number
         && OrderSymbol()==Symbol() // and my pair.
         && OrderOpenPrice()>=highest_open_price)
        {
         highest_open_price=OrderOpenPrice();
         highest_Ticket=OrderTicket();
        }
 
GumRai:

I am not sure if that EA is just poorly written, incomplete or a working EA with chunks of code removed.

You say it opens mainly sells, well I don't see that it can ever open a buy.

The main condition to open a buy is

 The only other place in the code that Opn_B appears in the code is

 So there is nowhere that it can be set to true.

Incidently

 A loop that only opens orders - great commenting.

 

 

 

 

thanks for reviewing my code and spotting out recommendation and corrections

GumRai: that is why i told you then that many people may not understand it but i do, and you are able to understand because you understand code very well,

furthermore i have my reason for making the ea open only sell  , my problem with this request made my ea rough but when i got the solution i will reorganize every thing again.

look at the ea i remove conditions to close and also buy condition, which makes the ea looks incomplete

.why is because i want to make sure it fulfill this conditions......opening order in

highest open price in current chart symbol       and open 10pip above it if its buy/open 10pips bellow if its sell.

i remove close conditions because i don't want backtest to close trades while testing to make sure the code is right before other condition is put in place .

once the solution is reach i will organize my ea again with appropriate closing condition that is why am asking you to help me with this problem though your helping.




 

Well, I have given you the code to find the order with the highest open price.

It is now a simple matter of checking if price is at least 10 pips above this value and, if so, open another order

 

please GumRai: how can i place the loop in the ea,because the way i did it didnt work in backtest......

how did i do it?  i used  highest_open_price and highest_Ticket to write some of my conditions in the ea but it didnt give me desired result on back test

maybe am missing something?


  double highest_open_price=0;
   int    highest_Ticket=-1;
   for(int pos=OrdersTotal()-1; pos>=0; pos--)
      if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES) // Only my orders w/
         && OrderMagicNumber()==0           // my magic number
         && OrderSymbol()==Symbol() // and my pair.
         && OrderOpenPrice()>=highest_open_price)
        {
         highest_open_price=OrderOpenPrice();
         highest_Ticket=OrderTicket();
        }
 
Yes, you are missing showing the code. How are we supposed to know what you have/haven't done?
Reason: