Last Open Price issue

 

Have this code for building a grid of orders, grid is working properly but OrderOpenPrice don't change its value to match the last OP:

   for(int i=OrdersTotal()-1;i>=0;i--){
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)&&OrderSymbol()==Symbol()){                                              // OperationMode
         if(OrderType()==OP_BUY){
            if(GridMode==true){
               //------------------------------- Grid LONG deals ---!
		Print("Last OpenPrice is ",OrderOpenPrice()); <- RETURNS ALWAYS THE SAME VALUE.
               double NL=NormalizeDouble(OrderOpenPrice()-(GridSize*10)*Point,Digits);
               Print("Next LONG grid order at ",NL);
               if(Ask<=NL){
                  if(!OrderSend(Symbol(),OP_BUY,NormalizeDouble(OrderLots()*Martingale,2),Ask,3,0,0,CustomComment,MagicNumber,0,clrCyan)){
                     Print("OrderSend error ",GetLastError());
                     RefreshRates();
                     return;
                     }
                  }

Don't actually see a mistake in the loop, but as the print is not changing its value there must be an error.

Hope someone can help with this. Thanks in advance.

 
  1. David Diez: but as the print is not changing its value there must be an error.
    Print OrderTicket also.

  2. if(!OrderSend(Symbol(),OP_BUY …
    OrderSend does not return a boolean. Check your return codes properly.

  3. Martingale, guaranteed to blow your account eventually. If it's not profitable without, it is definitely not profitable with.
 

William Roeder:
  1. Print OrderTicket also.

  2. OrderSend does not return a boolean. Check your return codes properly.

  3. Martingale, guaranteed to blow your account eventually. If it's not profitable without, it is definitely not profitable with.

1. It works trough printing the orderticket, how is it? Can't do this without the ticket?

double NL=NormalizeDouble(OrderOpenPrice()-(GridSize*10)*Point,Digits); NO TICKET IN THE FORMULA
Print("Next LONG grid order at ",NL); VALUE TO PRINT EACH NEW GRID ORDER

2. This ordersend fits my needs.

3. There are many opinions about martingale, as many people making money by withdrawing weekly.

 
David Diez:

Have this code for building a grid of orders, grid is working properly but OrderOpenPrice don't change its value to match the last OP:

Don't actually see a mistake in the loop, but as the print is not changing its value there must be an error.

Hope someone can help with this. Thanks in advance.

datetime opentime = -1;
double openprice = 0;

for(int i=OrdersTotal()-1;i>=0;i--) {
   if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==_Symbol && OrderType()==OP_BUY && OrderOpenTime()>opentime) openprice = OrderOpenPrice();
}
   
if(openprice>0) Print("Last OpenPrice is ",openprice);
 
David Diez:

1. It works trough printing the orderticket, how is it? Can't do this without the ticket?

2. This ordersend fits my needs.

3. There are many opinions about martingale, as many people making money by withdrawing weekly.

  1. You said "something must be wrong." So print the ticket as well as price, so you find out what is wrong. What does that have to do with your NL computation? I said Print.
  2. So what? I said check your return codes. What does that have to do with your OrderSend?
  3. Argumentative. What part of "eventually" was unclear? It's (was) your money.
People try to help you and you get defensive. Not a good way to continue getting help.
 
They told you correctly. Look what a ticket. Maybe you have only one position BUY. So you get one price all the time. Or what mistakes you will see. Maybe several positions on the same price.
While you can only guess.
Reason: