Thread: How to code?
View Single Post
  #1880 (permalink)  
Old 07-04-2009, 08:36 PM
qu33nrock qu33nrock is offline
Junior Member
 
Join Date: Jul 2009
Posts: 1
qu33nrock is on a distinguished road
MM for EA plz

i want add this condition to my ea
if loss in curent day = 100 ---> close al position, dont take any OP until tomorow

if loss in curent day < 100 ---> may take any OP

anybody can help ???

this my EA

Code:
//+------------------------------------------------------------------+
/*
          EA Dengan sinyal dari signal ma
*/

extern double Lots = 0.01;





//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   double a1,      //ma 10 tf 4h
          a2,      //ma 10 tf 1h
          a3,      //ma 10 tf 15m
          a4,      //ma 10 tf 5m
          
          j,      //yesterday low price 
          k,      //yesterday high price
          
          b1,     //ma 30 tf 4h
          b2,     //ma 30 tf 1h
          b3,     //ma 30 tf 15m
          b4;     //ma 30 tf 5m
          
   int cnt, ticket, total;

   if(Bars<100)
     {
      Print("bars less than 100");
      return(0);  
     }

// to simplify the coding and speed up access
// data are put into internal variables
   a1 = iMA(NULL,240,10,0,MODE_EMA,PRICE_CLOSE,0);
   a2 = iMA(NULL,60,10,0,MODE_EMA,PRICE_CLOSE,0);
   a3 = iMA(NULL,15,10,0,MODE_EMA,PRICE_CLOSE,0);
   a4 = iMA(NULL,5,10,0,MODE_EMA,PRICE_CLOSE,0);
   
   b1 = iMA(NULL,240,30,0,MODE_EMA,PRICE_CLOSE,0);
   b2 = iMA(NULL,60,30,0,MODE_EMA,PRICE_CLOSE,0);
   b3 = iMA(NULL,15,30,0,MODE_EMA,PRICE_CLOSE,0);
   b4 = iMA(NULL,5,30,0,MODE_EMA,PRICE_CLOSE,0);  
   
   j = iLow(NULL,60,2);
   k = iHigh(NULL,60,2);

   total=OrdersTotal();
   if(total<1) 
     {
      // no opened orders identified
      if(AccountFreeMargin()<(1000*Lots))
        {
         Print("We have no money. Free Margin = ", AccountFreeMargin());
         return(0);  
        }
      // check for long position (BUY) possibility
      if(a1>b1&&
         a2>b2&&
         a3>b3&&
         a4>b4+10*Point)
        {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"macd sample",16384,0,Green);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
         else Print("Error opening BUY order : ",GetLastError()); 
         return(0); 
        }
      // check for short position (SELL) possibility
      if(a1<b1&&
         a2<b2&&
         a3<b3&&
         a4<b4-10*Point)
        {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"macd sample",16384,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
           }
         else Print("Error opening SELL order : ",GetLastError()); 
         return(0); 
        }
      return(0);
     }
   // it is important to enter the market correctly, 
   // but it is more important to exit it correctly...   
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         if(OrderType()==OP_BUY)   // long position is opened
           {
            // should it be closed?
            if(Bid>OrderOpenPrice()+100*Point)//if profit > 100
               {
                 OrderModify(OrderTicket(),OrderOpenPrice(),j,0,0,Green);
                 return(0);
               }
               if(Bid<OrderOpenPrice()-150*Point)//stop loss
               {
                 OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
                 return(0); // exit
               }
                        
           }
         else // go to short position
           {
            // should it be closed?
            if(Ask<OrderOpenPrice()-100*Point)//if profit > 100
               {
                 OrderModify(OrderTicket(),OrderOpenPrice(),k,0,0,Green);
                 return(0);
               }
            if(Ask>OrderOpenPrice()+150*Point)//stop loss
               {
                 OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
               return(0); // exit
               }
           
            
           }
        }
     }
   return(0);
  }
// the end.
Reply With Quote