Thread: How to code?
View Single Post
  #1634 (permalink)  
Old 03-07-2009, 01:07 PM
MiniMe's Avatar
MiniMe MiniMe is offline
Senior Member
 
Join Date: Nov 2006
Location: Montréal
Posts: 1,453
MiniMe is an unknown quantity at this point
Lets say I have a few Buy orders and Sell orders

What I want do is :
- Exit all the trades " Basket" at 5 pips more than the breakeven price of the open trades

What I am trying to do in the first for loop is find the value of open trades + swap and convert it to pips , and this is the part where I am getting stuck

I have tried few ideas but I have reached a dead end, I know the problem is in the first for statement but I can't solve it, any help is highly appropriated




PHP Code:
 SymbolPL 0;
 
OrdLots  0;
 
Equity   0
 
MinPro   5;
 for(
0OrdersTotal(); i++)
   {
OrderSelect(iSELECT_BY_POSMODE_TRADES);
      if (
OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
      {if(
OrderType() == OP_BUY)  OrdLots += OrderLots();
       if(
OrderType() == OP_SELLOrdLots -= OrderLots();      
       
Equity += OrderProfit() +  OrderSwap();
      }
   } 
   
MinProMathRound (MathAbs(Equity /OrdLots)+MinPro); 

//--- Count the open trades 
   
int i;
   
int count=0;   
   for(
i=0;i<OrdersTotal();i++)
    { if(
OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(
OrderMagicNumber()==MagicNumber && OrderType()<2)
       { 
count++;
        }
    }

//--- find the profit in pips of the open trades 
  
RefreshRates();
   
double profits=0,openPrice=0,points=0;
   
string sym="";
   
int i;
   
int totalOrders=OrdersTotal();        
   for(
i=0;i<totalOrders;i++)
   {
      if(
OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(
OrderMagicNumber()==MagicNumber)
      {
         
sym=OrderSymbol();
         
openPrice=OrderOpenPrice();
         if(
OrderType()==0)
         {
            
profits+=(MarketInfo(sym,MODE_BID)-openPrice)/MarketInfo(sym,MODE_POINT);  
         }
         if(
OrderType()==1)
         {
            
profits+=(OrderOpenPrice()-MarketInfo(sym,MODE_ASK))/MarketInfo(sym,MODE_POINT);
         }   
      }  
   }
 
//--- Close when the open trades are 5 pips more than the breakeven price


     
if (count>&& profits>MinPro 

   for(
OrdersTotal()-1>=0i--)
      {
         
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if (
OrderSymbol() == Symbol()&& OrderMagicNumber()==MagicNumber )
         {
           
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Plum);
               
          }
      }    

__________________

Reply With Quote