OrdersTotal() work on 2 or more Charts by opening trades

To add comments, please log in or register
Jack Buda
178
Jack Buda  

Hi all

I wonder if its possible to have OrdersTotal() on 2 different charts. I want to use OrdersTotal()==0 (if there's any alternative) for opening trades on different charts(Open 2 trades (buy & sell) on EUR/USD & 2 trades (buy & sell) GBP/USD). I tried several ways to for it to work but I'm not succeeding at all. please help if possible. Thank You

//Deleted so that people don't waste their time checking code that cannot compile
Keith Watford
Moderator
20380
Keith Watford  
Jack Buda:

Hi all

I wonder if its possible to have OrdersTotal() on 2 different charts. I want to use OrdersTotal()==0 (if there's any alternative) for opening trades on different charts(Open 2 trades (buy & sell) on EUR/USD & 2 trades (buy & sell) GBP/USD). I tried several ways to for it to work but I'm not succeeding at all. please help if possible. Thank You

Please check your code and modfy it so that it will compile.

You cannot have even tested it yourself as it does not compile

    if(OrderSelect(Loop,SELECT_BY_POS,MODE_TRADES)  

    if(OrdesTotal()==0)
     if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
     bool CloseOrder=false;

does nothing, you are missing some {}

Jack Buda
178
Jack Buda  
I removed notes that i have inserted maybe that's the reason why its not compiling. Where you highlighted in yellow do i need to change something?
Keith Watford
Moderator
20380
Keith Watford  
Jack Buda:
I removed notes that i have inserted maybe that's the reason why its not compiling. Where you highlighted in yellow do i need to change something?

Yes, isn't it obvious?

Jack Buda
178
Jack Buda  
I've Sorted it Out. It still wont open 2 trades per symbol/chart
Keith Watford
Moderator
20380
Keith Watford  
Where is your revised code?
HARRISON ODHIAMBO OUKA
169
HARRISON ODHIAMBO OUKA  
OrdersTotal() counts all the active trades within your terminal,,,,just create a function that calculates the active trades for a specific chat
Jack Buda
178
Jack Buda  
Keith Watford:
Where is your revised code?
extern double StopLoss=100;
extern int MagicNumber=15;
extern bool Symbols=true; 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
 {
  int Loop=-1;
  int Loop2=0;
  while(Loop<Loop2)
  { 
    bool CreateText=ObjectCreate("Balance:",OBJ_LABEL,0,0,0,0);
    bool OjectTextBal=ObjectSetText("Balance:","Balance:"+DoubleToStr(AccountBalance(),2),14,NULL,clrWhite);
    bool CornerText=ObjectSet("Balance:",OBJPROP_CORNER,1);
    bool CornerText2=ObjectSet("Balance:",OBJPROP_XDISTANCE,5);//6
    bool CornerText3=ObjectSet("Balance:",OBJPROP_YDISTANCE,376);
    
    double StopLossAsk,StopLossBid;
     
    StopLossAsk=Ask-StopLoss*Point;
    StopLossBid=Bid+StopLoss*Point;
   
   double ClosePips=1;
   
   int OpenTrade=OrdersTotal();
   for(int i=OrdersTotal()-1;i>=0;i--)
   {
    if(OrderSelect(Loop,SELECT_BY_POS,MODE_TRADES))
    {
     if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
     {
      if(OrderType()==OP_BUY&&OrderType()==OP_SELL)
      OpenTrade++;
     }
    }
   }
    
    if(OpenTrade==0)
    {
     if(Close[1]>Open[1])
     {                                
      int OpenBuy=OrderSend(Symbol(),OP_BUY,0.1,Ask,0,StopLossAsk,0,"",0,0,clrPurple);
      if(OpenBuy>0)
      {
       bool ModBuy=OrderModify(OpenBuy,OrderOpenPrice(),OrderOpenPrice()+StopLossAsk,0,0,clrNONE);
      } 
     }
    }
    
     if(OpenTrade==1)
     {
      if(Close[1]<Open[1])
       {
        int OpenSell=OrderSend(Symbol(),OP_SELL,0.1,Bid,0,StopLossBid,0,"",0,0,clrWhite);
        if(OpenSell>0)
        {
         bool ModSell=OrderModify(OpenSell,OrderOpenPrice(),OrderOpenPrice()+StopLossBid,0,0,clrNONE); 
        }
       } 
      }
     
    for (int a=OrdersTotal()-1;a>=0;a--)
    {
     if (OrderSelect(a,SELECT_BY_POS))
     if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
     bool CloseOrder=false;
     int Type=OrderType();
     {
      switch(Type)
      {
       case OP_SELL: if(OrderProfit()>=ClosePips) CloseOrder=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,clrAqua);break;
       case OP_BUY: if(OrderProfit()>=ClosePips) CloseOrder=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,clrAqua);break;
      }
     } 
    }
    RefreshRates();
    Sleep(10000);
  }
 }
Here is the code
Jack Buda
178
Jack Buda  
HARRISON ODHIAMBO OUKA:
OrdersTotal() counts all the active trades within your terminal,,,,just create a function that calculates the active trades for a specific chat
I've been doing that but no luck. I have not tried OrderType(), do you think it might work? For Example OrderType()<2 for Buy & OrderType()< for Sell
Keith Watford
Moderator
20380
Keith Watford  

Always use #property strict in your code

#property strict

extern double StopLoss=100;

This check does nothing except declare a bool variable

     if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
     bool CloseOrder=false;

Profit is in currency, not pips

if(OrderProfit()>=ClosePips)

What is the point of this loop? You don't change the values for Loop or Loop2, so how will it ever exit the loop?

  int Loop=-1;
  int Loop2=0;
  while(Loop<Loop2)
  { 

Do you really expect the order to be selected?

  int Loop=-1;
//
//
    if(OrderSelect(Loop,SELECT_BY_POS,MODE_TRADES))
Jefferson Metha
2238
Jefferson Metha  
Jack Buda:
Here is the code

Just looked at your code you have an error 

for(int i=OrdersTotal()-1;i>=0;i--)
   {
    if(OrderSelect(Loop,SELECT_BY_POS,MODE_TRADES))
    {
     if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
     {
      if(OrderType()==OP_BUY&&OrderType()==OP_SELL)
      OpenTrade++;
     }
    }
   }

You will never have a position thats both a BUY and a SELL. 
change that line to 

if(OrderType()==OP_BUY || OrderType()==OP_SELL)
To add comments, please log in or register