Variable problem

 

Hi,


I need to store the ticket from a short order while it's running... but my variable

LastTicketShort_Scalp 

doesn't work?



Please Help


       int LastTicketShort_Scalp = 0;
       int LastTicketLong_Scalp = 0;
   
       for (int za=OrdersTotal()-1; za >= 0; za --) 
   {
      OrderSelect(za, SELECT_BY_POS, MODE_TRADES);

  
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==140 && OrderType() == OP_SELL ) 
      {LastTicketShort_Scalp = OrderTicket();                // Problem is here... Variable is not updated.
      Print("LastTicketShort_Scalp : ", OrderTicket() );     // Not printing?
      }
       
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==140 && OrderType() == OP_BUY ) 
      {LastTicketLong_Scalp = OrderTicket(); 
      Print("LastTicketLong_Scalp : ", OrderTicket() ); 
        }
          
   }
   
   
   
   for(int ia=OrdersHistoryTotal()-1;ia>=0;ia--)
 {
   OrderSelect(ia, SELECT_BY_POS,MODE_HISTORY);
   int LastClosedTicketShort_Scalp = 0;
   
   if(OrderSymbol()==Symbol() && OrderMagicNumber()==140 )
     
     LastClosedTicketShort_Scalp = OrderTicket();
     Print(" LastClosedTicketShort_Scalp : ", OrderTicket() );
     Print(" LastTicketShort_Scalp : ", LastTicketShort_Scalp );   // printing and variable = 0 instead of Ticket = 1
     
       {
                // Open Order
        }
 
      
  }
 
FrenchyTrader:

Hi,


I need to store the ticket from a short order while it's running... but my variable

doesn't work?

Maybe you don't have an open short trade that matches the Symbol and Magic Number . ..
 

Yes I'm sure I do... this is the first trade I have when I start backtest.


Also I have tried to call only with

if(OrderSymbol()==Symbol() )

But still not working better.



Please help.

 
FrenchyTrader:

Yes I'm sure I do... this is the first trade I have when I start backtest.


Also I have tried to call only with

But still not working better.



Please help.

OrderSelect() return a bool, maybe you can begin by checking this value.
 

Ok I can store the current short trade ticket.

So I can match when it's closed when I look into Historical data:


for(int ia=OrdersHistoryTotal()-1;ia>=0;ia--)
 {
   OrderSelect(ia, SELECT_BY_POS,MODE_HISTORY);
 //  int LastClosedTicket_Scalp = 0;
   
   if(OrderSymbol()==Symbol() && OrderMagicNumber()==140 ){
    int  LastClosedTicket_Scalp = OrderTicket();
    int  LastClosedType = OrderType();
    double  LastProfit = OrderProfit();
     
    Print(" Curent Sell Order ticket : ",LastTicketShort_Scalp, " LastClosedTicket_Scalp : ", OrderTicket() ); 



     }
     
       
 if(Strategy_2 == true && Trend_Bullish == true  ){
  if ( Bid < lowValue && countLongTrades_Scalping() == 0 && LastClosedType == OP_SELL && LastProfit > 0 && LastClosedTicket_Scalp == LastTicketShort_Scalp ) 
                                                                                                           // = > Ticket 1        ==          Ticket 1            
{openLongTrade_Scalping();} 
        
         }
      
  }

So After a wining Short trade Magic 140... I Open a Long trade Magic 140. => That's fine.


Prolem:

When this one is closed... the last closed order from historical data should be OP_BUY and ticket 1+1 So EA shouldn't open long trade anymore.


But it does because the print gives me this:

2013.09.16 16:18:06 2013.09.16 18:18 Heartbeat_Grid_FX EURUSD,M1: Curent Sell Order ticket : 1 LastClosedTicket_Scalp : 1
2013.09.16 16:18:06 2013.09.16 18:18 Heartbeat_Grid_FX EURUSD,M1: Curent Sell Order ticket : 1 LastClosedTicket_Scalp : 2
2013.09.16 16:18:06 2013.09.16 18:18 Heartbeat_Grid_FX EURUSD,M1: Curent Sell Order ticket : 1 LastClosedTicket_Scalp : 3

2013.09.16 16:18:06 2013.09.16 18:18 Heartbeat_Grid_FX EURUSD,M1: Curent Sell Order ticket : 1 LastClosedTicket_Scalp : 4

2013.09.16 16:18:06 2013.09.16 18:18 Heartbeat_Grid_FX EURUSD,M1: Curent Sell Order ticket : 1 LastClosedTicket_Scalp : 6


It prints for all the orders he founds into historical data... that macthes

  if(OrderSymbol()==Symbol() && OrderMagicNumber()==140 )

So he found the ticket 1 and then open a new long position... but he shouldn't because it should bring me ONLY the last order closed.


Please help me to select only the last order that match the condition.


Cheers

 
I mean the history trades.. not historical data : )
 
FrenchyTrader: but he shouldn't because it should bring me ONLY the last order closed.
You are in a orderSelect LOOP. selecting ALL orders. If you want "only the last" you must exit the loop (break) not continue (closing curly brace)
Reason: