View Single Post
  #5 (permalink)  
Old 06-29-2007, 05:14 PM
davidke20's Avatar
davidke20 davidke20 is offline
Senior Member
 
Join Date: Sep 2006
Location: 38° 53′ 51.61″ N, 77° 2′ 11.58″ W
Posts: 1,396
davidke20 is on a distinguished road
Quote:
Originally Posted by w4rn1ng View Post
Some time i do like that with my father, he and only he have the power to sell at bottoms and buy at tops! Let's imagine a perfect downtrend, a strong downtrend of that ones that nobody can say: "i think it will reverse soon!", well, if my father sell, it reverse immediately :P It's not so bad the idea to do the opposite of newbies traders, or just unluckies traders
Alright, here is the EA...
PHP Code:
//+-------------------------------------------------------------+
//|                                       w4rn1ng-antinoobs.mq4 |
//|                                 Copyright © 2007, davidke20 |
//+-------------------------------------------------------------+
#property copyright "Copyright © 2007, davidke20"
#property link      ""

extern double TakeProfit 100;
extern double Lots 0.1;
extern double TrailingStop 15;
extern double DaddyBuy=false;
extern double DaddySell=false;

//+-------------------------------------------------------------+
int start()
  {
   
total=OrdersTotal();
   if(
total<1
     {
      if(
DaddyBuy && DaddySell){Comment("Dad! WTF are you trying to do?!"}
      if(!
DaddyBuy && !DaddySell){Comment("OK dad! What trade should we take now?"}
      
// 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(!DaddyBuy && DaddySell)
        {
         
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"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(DaddyBuy && !DaddySell)
        {
         
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"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(cntSELECT_BY_POSMODE_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(DaddyBuy && !DaddySell)
                {
                 
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
                 
return(0); // exit
                
}
            
// check for trailing stop
            
if(TrailingStop>0)  
              {                 
               if(
Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(
OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(
0);
                    }
                 }
              }
           }
         else 
// go to short position
           
{
            
// should it be closed?
            
if(!DaddyBuy && DaddySell)
              {
               
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
               
return(0); // exit
              
}
            
// check for trailing stop
            
if(TrailingStop>0)  
              {                 
               if((
OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((
OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(
0);
                    }
                 }
              }
           }
        }
     }
   return(
0);
  } 
Hope this help

Regards

David

Last edited by davidke20; 06-29-2007 at 05:18 PM.
Reply With Quote