Seperating Orderstotal() between pairs

Back to topics list To post a new topic, please log in or register
avatar
11
zerosen 2015.08.17 04:00
 

Hi, I have been back testing my EA for a while now and would like to trade it live. 

 

However, when I run it live, 3 different pairs for example,  I realised that that the orderstotal() was interfering with one another.

if(OrdersTotal()==0)
     {
//---  Buystop and Sellstop     
int ticket=OrderSend(Symbol(),OP_SELLSTOP,LotSize,OfferOpen,3,OfferStopLoss,OfferTakeProfit,"SELLSTOP",0,0,clrGreen);
int ticket2=OrderSend(Symbol(),OP_BUYSTOP,LotSize,BidOpen,3,BidStopLoss,BidTakeProfit,"BUYSTOP",0,0,clrGreen);

 

Is there a way for the OrdersTotal() to count only those of its pair? 

 

   if(OrdersTotal()==1)
     {  
     for (int i=1; i<=OrdersTotal(); i++)       //Cycle for all orders..
     {  
         //---  Selecting of Open Order
         if(OrderSelect(i-1,SELECT_BY_POS,MODE_TRADES)==true) 

 I also use this in the later part of the codes. Would it affect?

 

avatar
Moderator
3419
GumRai 2015.08.17 05:36 #
 
     int count_trades=0;  
     for (int i==OrdersTotal()-1;i>=0; i--)
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
            count_trades++; 
Use a Magic Number in your EA to make sure that you are only counting trades placed by the EA on the chart symbol
avatar
11
zerosen 2015.08.17 15:14 #
 
GumRai:
Use a Magic Number in your EA to make sure that you are only counting trades placed by the EA on the chart symbol

 Thanks !! 

Can I ask,  would the order counted this way get reset if i close the program for maintenance? 


Would the computer slow down tremendously if not shut down for half a year?


Or is there a way to shut down and resume the EA where it started? 

avatar
Moderator
3419
GumRai 2015.08.17 15:26 #
 
zerosen:

 Thanks !! 

Can I ask,  would the order counted this way get reset if i close the program for maintenance? 

Would the computer slow down tremendously if not shut down for half a year?

Or is there a way to shut down and resume the EA where it started? 

It counts the orders at the time, nothing is reset, if there are 2 orders and another order opens between calls then it will count 3

My computer slows down if I don't have a clear out every 3 days, I don't know about yours.

You cannot resume an EA from where it started, only from where it processed the last tick it received

avatar
11
zerosen 2015.08.17 15:47 #
 
GumRai:

It counts the orders at the time, nothing is reset, if there are 2 orders and another order opens between calls then it will count 3

My computer slows down if I don't have a clear out every 3 days, I don't know about yours.

You cannot resume an EA from where it started, only from where it processed the last tick it received

 Thanks !! 

But how do i use it?

//---  If No Order/Position
if(OrdersTotal()==0)
     {
//---  Buystop and Sellstop     
int ticket=OrderSend(Symbol(),OP_SELLSTOP,LotSize,OfferOpen,3,OfferStopLoss,OfferTakeProfit,"SELLSTOP",0,0,clrGreen);
int ticket2=OrderSend(Symbol(),OP_BUYSTOP,LotSize,BidOpen,3,BidStopLoss,BidTakeProfit,"BUYSTOP",0,0,clrGreen);
     }
     else
//---  If 1 Order
   if(OrdersTotal()==1)
     {  
     for (int i=1; i<=OrdersTotal(); i++)       //Cycle for all orders..
     {  
         //---  Selecting of Open Order
         if(OrderSelect(i-1,SELECT_BY_POS,MODE_TRADES)==true) 
         {
                  //---  If a buystop was triggered         
                  if(OrderType()==OP_SELLSTOP)

 This is my current program now. So if i incorporate what you have taught me, I still get undeclared identifier for MagicNumber and i. Also "semicolon expected" but i suspect it is the same issue as the previous. How could i solve this?

Do i include  int i=0; int MagicNumber=0; into the program or are there other ways? 

 

int count_trades=0;
     for (int i==OrdersTotal()-1;i>=0; i--)
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
            count_trades++; 
//---  If No Order/Position
if(count_trades ==0)
     {
//---  Buystop and Sellstop     
int ticket=OrderSend(Symbol(),OP_SELLSTOP,LotSize,OfferOpen,3,OfferStopLoss,OfferTakeProfit,"SELLSTOP",0,0,clrGreen);
int ticket2=OrderSend(Symbol(),OP_BUYSTOP,LotSize,BidOpen,3,BidStopLoss,BidTakeProfit,"BUYSTOP",0,0,clrGreen);
     }
     else
//---  If 1 Order
   if(count_trades==1)
     {  
     for (int i==OrdersTotal()-1;i>=0; i--)       //Cycle for all orders..
     {  
         //---  Selecting of Open Order
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) 
         {
                  //---  If a buystop was triggered         
                  if(OrderType()==OP_SELLSTOP)
avatar
11
zerosen 2015.08.23 10:29 #
 
zerosen:

 Thanks !! 

But how do i use it?

 This is my current program now. So if i incorporate what you have taught me, I still get undeclared identifier for MagicNumber and i. Also "semicolon expected" but i suspect it is the same issue as the previous. How could i solve this?

Do i include  int i=0; int MagicNumber=0; into the program or are there other ways? 

 

Nvm, i got it. Thanks for the help
Back to topics list  

To add comments, please log in or register