how can i get the highest after orderopenprice was opened. - page 5

 

You mean:

double LastOpenPrice(int ordertype)    { 
double OpenPrice;                            
datetime lastOpen;    
for ( int pos = OrdersTotal()- 1 ; pos >= 0 ; pos--)       
if ( OrderSelect (pos, SELECT_BY_POS) // Only my orders w/
    &&OrderMagicNumber() == MagicNumberLong || MagicNumberShort // my magic number
    &&OrderSymbol() == Symbol()    // and my pair.
    &&OrderType() == ordertype       
    &&OrderOpenTime() > lastOpen )  {        
            if(OpenPrice = OrderOpenPrice()&&OpenPrice!=0)          
               break;          }
               return (OpenPrice);} //  
Please i need to see your sulotion
 
Hand:

Please i need to see your sulotion

NO . . . you NEED to learn . . . make some effort yourself for a change, read the book ( https://book.mql4.com// ) read the Documentation ( https://docs.mql4.com// ) . . . having different Magic numbers for long and sort trades is idiotic and NOT necessary . . .
 

maybe by this way it will work .

if ( ( (LastOpenPrice(OP_SELL)+0.0030)<MarketInfo("EURUSD",MODE_BID) )&&( LastOpenPrice(OP_SELL)>0) ) <--------------- 0+0.0030=0.0030<Bid: TRUE // i think it will work
{ BUY("EURUSD",B_EURUSD_LS_1,B_EURUSD_TP_1,B_EURUSD_SL_1,B_EURUSD_TS_1,"if (

 
Hand:

maybe by this way it will work .

if ( ( (LastOpenPrice(OP_SELL)+0.0030)<MarketInfo("EURUSD",MODE_BID) )&&( LastOpenPrice(OP_SELL)>0) ) <--------------- 0+0.0030=0.0030<Bid: TRUE // i think it will work
{ BUY("EURUSD",B_EURUSD_LS_1,B_EURUSD_TP_1,B_EURUSD_SL_1,B_EURUSD_TS_1,"if (

when I ask "what is your game plan?" I really mean it. To re-phrase, what is your STRATEGY?

If you do NOT want to TRADE when there is no last open price, can you consider as such?

if(LastOpenPrice(OP_SELL) <=0) { return? do what? -----case of selling

if(LastOpenPrice(OP_BUY) <=0) { return?...or do what? ------ case for buying

then, the rest of the code proceeds....

with such an error as this one, I am afraid you can't "fill the holes" here and there in your codes. Your strategy looks ruined.

This sort of error "informs" you need to revise strategy at a higher level ---> WHEN to trade (and when not to). Do you have answers, ideas, etc, to that?

 
Hand:

You mean:

Please i need to see your sulotion

I completely forgotten to mention about this but this the most important for the entirety, and eternity of things, related. It's just total madness that YOU bonk the thought to see MY=YOUR solution, for which I don't.

Where on planet earth, are you at? who do you think I am? Your guardian angel, shaman, personal genie, etc?

Whatever you come to put into your head, I really can't help, just for your info.

 

guys,

Please check the below functions (if correct or not) i need to do this conditions

if ( lastOpenedOpenPriceBuy()-lastOpenedOpenPriceSell() )>=0.0060

{ do something }

double lastOpenedOpenPriceBuy()
  {
   double ret = 0;
   datetime time=0;
   for(int i=0; i<OrdersTotal(); i++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()==OP_BUY && OrderOpenTime()>time) {
         time = OrderOpenTime();
         ret = OrderOpenPrice();
      }
   }
   
   return(ret);
  }


double lastOpenedOpenPriceSell()
  {
   double ret = 0;
   datetime time=0;
   for(int i=0; i<OrdersTotal(); i++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()==OP_SELL && OrderOpenTime()>time) {
         time = OrderOpenTime();
         ret = OrderOpenPrice();
      }
   }
   
   return(ret);
  }



double lastClosedClosePrice()
  {
   double ret = 0;
   datetime time = 0;
   for(int i=OrdersHistoryTotal()-1; i>=0; i--) {
      OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
      if(OrderType()<2 && OrderCloseTime()>time) {
         time = OrderCloseTime();
         ret = OrderClosePrice();
      }
   }
   
   return(ret);
  }



double beforelastClosedClosePrice()
  {
   double ret = 0;
   double ret2 = 0;
   datetime time = 0;
   for(int i=OrdersHistoryTotal()-1; i>=0; i--) {
      OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
      if(OrderType()<2 && OrderCloseTime()>time) {
         time = OrderCloseTime();
         ret = ret2;
         ret2 = OrderClosePrice();
      }
   }
   if(ret==0) {
      ret = ret2;
   }
   
   return(ret);
  }
 

I can help with the first one, maybe others can come in for the rest.

<-------------------- can consider to use if(OrdersTotal()>0..then proceed  ---------------->
double lastOpenedOpenPriceBuy()  <----- what a name...confusing, maybe.
  {
   double ret = 0;
   datetime time=0; <---- can consider setting Lowest Limit to -9999, at least -1, rather than 0.  
   for(int i=0; i<OrdersTotal(); i++) { <----- do consider counting down.
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES); <------ This returns some BOOLEAN result.then what? -----(?)
      if(OrderType()==OP_BUY && OrderOpenTime()>time) { <------ This can return runtime OrderSelect ERR bec. of above line (?). ------ (!) 
         time = OrderOpenTime(); 
         ret = OrderOpenPrice();
      }
   }
   
   return(ret);<------ return double as UnNormalized price. you sure about this?
  }

 

Please note that:

when i put this condiction

if (  ((lastOpenedOpenPriceBuy()-0.0030)>MarketInfo("EURUSD",MODE_BID))  ) 
   {  SELL("EURUSD",S_EURUSD_LS_1,S_EURUSD_TP_1,S_EURUSD_SL_1,S_EURUSD_TS_1,"if (  ( (lastOpenedOpenPriceBuy()-0.0030)>MarketInfo(EURUSD,MODE_BID) )  )") ;}

it doen not work,but when i added one more condiction

if (  (lastOpenedOpenPriceBuy()>0)&&((lastOpenedOpenPriceBuy()-0.0030)>MarketInfo("EURUSD",MODE_BID))  ) 
   {  SELL("EURUSD",S_EURUSD_LS_1,S_EURUSD_TP_1,S_EURUSD_SL_1,S_EURUSD_TS_1,"if (  ( (lastOpenedOpenPriceBuy()-0.0030)>MarketInfo(EURUSD,MODE_BID) )  )") ;}
it looks like fine (lastOpenedOpenPriceBuy()>0)
 
<-------------------- can consider to use if(OrdersTotal()>0..then proceed  ---------------->
double lastOpenedOpenPriceBuy()  <----- what a name...confusing, maybe.
  {
   double ret = 0;
   datetime time=0; <---- can consider setting Lowest Limit to -9999, at least -1, rather than 0.  No order open time could <= 0
   for(int i=0; i<OrdersTotal(); i++) { <----- do consider counting down. Nothing different.
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES); <------ This returns some BOOLEAN result.then what? -----(?) If in the loop, the order must exist, when the order exist, the OrderSelect won't cause error. If not in the loop, this line won't be executed.
      if(OrderType()==OP_BUY && OrderOpenTime()>time) { <------ This can return runtime OrderSelect ERR bec. of above line (?). ------ (!) Same reason as last line.
         time = OrderOpenTime();          ret = OrderOpenPrice
();       }    }       return(ret);<------ return double as UnNormalized price. you sure about this? Already define ret = 0 at the first line.   }
 

Boy oh boy, you're simply amazing. Thks for pointing those out esp, this:

OrderSelect(i, SELECT_BY_POS, MODE_TRADES); <------If in the loop, the order must exist, when the order exist, the OrderSelect won't cause error. If not in the loop, this line won't be executed.

I reckon this line of yours has some Houdini powers to vanish out of the loop when no orders, re-appearing when there are. 


Reason: