log in     sign up for free
 
There are many different classifications of exits other than your initial stop loss. These include exits that produce a loss but reduce your initial risk, exits that maximize profits, and exits that keep you from giving back too much money, and psychological exits.
Van K. Tharp
 
 
Home
systems (285)
 
 
Special offer: buy AmiBroker and EOD+Real-Time Data
Formula Library
 
AmiBroker
MetaTrader
MetaStock
TradeStation
Wealth-Lab
NinjaTrader
 
add your formula
System Library
 
 
Account login
Your email:
Password:
 
Log in
New to s4t? Sign up.
If you forgot your password click here.
Search the Web
 
Custom Search

10 points 3

Formula for: MetaTrader

mql4 expert advisor

 

 

Views:  2178

Added: November 26, 2006
 
Rate this code:  Rate: 1 Rate: 2 Rate: 3 Rate: 4 Rate: 5
This formula has not been rated yet
 

email this link

 
 
Tags: MetaTrader, mql4 expert advisor
 


The Adviser 10 points 3 uses the histogram of the standard indicator Moving Average Convergence/Divergence, MACD. The Expert Adviser is adjusted on work on M15 tameframe.

 

 



Code:

//+------------------------------------------------------------------+
//|                                                   10 points 3.mq4 |
//|                              Copyright © 2005, Alejandro Galindo |
//|                                              http://elCactus.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Alejandro Galindo"
#property link      "http://elCactus.com"
//----
extern double TakeProfit = 10;
extern double Lots = 1.2;
extern double InitialStop = 110;
extern double TrailingStop = 10;
//----
extern int MaxTrades = 12;
extern int Pips = 15;
extern int SecureProfit = 10;
extern int AccountProtection = 1;
extern int OrderstoProtect = 6;
extern int ReverseCondition = 261;
extern double EURUSDPipValue = 40;
extern double GBPUSDPipValue = 10;
extern double USDCHFPipValue = 10;
extern double USDJPYPipValue = 9.715;
extern int StartYear = 2005;
extern int StartMonth = 1;
extern int EndYear = 2009;
extern int EndMonth = 12;
extern int EndHour = 22;
extern int EndMinute = 30;
extern int mm = 0;
extern int risk = 12;
extern int AccountisNormal = 0;
//----
int  OpenOrders = 0, cnt = 0;
int  slippage = 5;
double sl = 0, tp = 0;
double BuyPrice = 0, SellPrice = 0;
double lotsi = 0, mylotsi = 0;
int mode = 0, myOrderType = 0;
bool ContinueOpening = True;
double LastPrice = 0;
int  PreviousOpenOrders = 0;
double Profit = 0;
int LastTicket = 0, LastType = 0;
double LastClosePrice = 0, LastLots = 0;
double Pivot = 0;
double PipValue = 0;
string text = "", text2 = "";
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//---- 
   if(AccountisNormal == 1)
          if(mm != 0) 
              lotsi = MathCeil(AccountBalance()*risk / 10000); 
             else
                 lotsi = Lots; 
   else 
       // then is mini
       if(mm != 0) 
           lotsi = MathCeil(AccountBalance()*risk / 10000) / 10; 
             else 
                 lotsi = Lots; 
//----
   if(lotsi > 100)
       lotsi = 100; 
   OpenOrders = 0;
//----
   for(cnt = 0; cnt < OrdersTotal(); cnt++)   
     {
       OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
          if(OrderSymbol() == Symbol())
                 OpenOrders++;
     }     
//----
   if(OpenOrders < 1) 
     {
          if(TimeYear(CurTime()) < StartYear) 
              return(0);  
          //----
       if(TimeMonth(CurTime()) < StartMonth) 
              return(0); 
          //----
       if(TimeYear(CurTime()) > EndYear) 
              return(0); 
          //----
       if(TimeMonth(CurTime()) > EndMonth ) 
              return(0); 
     }
//----
   if(Symbol() == "EURUSD") 
       PipValue = EURUSDPipValue; 
//----
   if(Symbol() == "GBPUSD") 
       PipValue = GBPUSDPipValue; 
//----
   if(Symbol() == "USDJPY") 
       PipValue = USDJPYPipValue; 
//----
   if(Symbol() == "USDCHF") 
       PipValue = USDCHFPipValue; 
//----
   if(PipValue == 0) 
       PipValue = 5; 
//----
   if(PreviousOpenOrders > OpenOrders) 
     {      
          for(cnt=OrdersTotal();cnt>=0;cnt--)
            {
              OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
                 mode = OrderType();
                 //----
           if(OrderSymbol() == Symbol()) 
                   {
                        if(mode == OP_BUY) 
                            OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), slippage, Blue); 
                        //----
               if(mode == OP_SELL) 
                            OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), slippage, Red); 
                        return(0);
                   }
            }
     }
   PreviousOpenOrders = OpenOrders;
//----
   if(OpenOrders >= MaxTrades) 
          ContinueOpening = False;
   else 
          ContinueOpening = True;
//----
   if(LastPrice == 0) 
     {
          for(cnt = 0; cnt < OrdersTotal(); cnt++)
            {    
              OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
                 mode = OrderType();    
                 //----
           if(OrderSymbol() == Symbol()) 
                   {
                        LastPrice = OrderOpenPrice();
                        //----
               if(mode == OP_BUY) 
                            myOrderType = 2; 
                        //----
               if(mode == OP_SELL) 
                            myOrderType=1;    
                   }
            }
     }
//----
   if(OpenOrders < 1) 
     {
          myOrderType = 3;
          //----
       if(iMACD(NULL, 0, 14, 26, 9, PRICE_CLOSE, MODE_MAIN,1) > 
             iMACD(NULL, 0, 14, 26, 9, PRICE_CLOSE, MODE_MAIN, 2)) 
              myOrderType = 2; 
          //----
       if(iMACD(NULL, 0, 14, 26, 9, PRICE_CLOSE, MODE_MAIN, 1) < 
             iMACD(NULL, 0, 14, 26, 9, PRICE_CLOSE, MODE_MAIN, 2)) 
              myOrderType=1; 
          //----
       if(ReverseCondition == 1)
                 if(myOrderType == 1) 
                     myOrderType = 2; 
                 else 
                     if(myOrderType == 2) 
                         myOrderType = 1; 
     }
   // if we have opened positions we take care of them
   for(cnt = OrdersTotal(); cnt >= 0; cnt--)
     {
       OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
          //----
       if(OrderSymbol() == Symbol()) 
            {    
                 if(OrderType() == OP_SELL) 
                        if(TrailingStop > 0) 
                               if(OrderOpenPrice() - Ask >= (TrailingStop + Pips)*Point)         
                                      if(OrderStopLoss() > (Ask + Point*TrailingStop))
                                        {            
                                          OrderModify(OrderTicket(), OrderOpenPrice(), 
                                                      Ask + Point*TrailingStop, 
                                                OrderClosePrice() - TakeProfit*Point - TrailingStop*Point, 
                                                      800, Purple);
                                             return(0);                          
                                        }
                 //----
           if(OrderType() == OP_BUY)
                        if(TrailingStop > 0) 
                            if(Bid - OrderOpenPrice() >= (TrailingStop + Pips)*Point) 
                                      if(OrderStopLoss() < (Bid - Point*TrailingStop)) 
                                        {                       
                                          OrderModify(OrderTicket(), OrderOpenPrice(), 
                                                      Bid - Point*TrailingStop, 
                                                   OrderClosePrice() + TakeProfit*Point + TrailingStop*Point,
                                                      800, Yellow);
                           return(0);
                                        }
            }
     }
   Profit = 0;
   LastTicket = 0;
   LastType = 0;
      LastClosePrice = 0;
      LastLots = 0;    
//----
      for(cnt = 0; cnt < OrdersTotal(); cnt++)
        {
          OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
          //----
       if(OrderSymbol() == Symbol()) 
            {            
                 LastTicket = OrderTicket();
                    //----
           if(OrderType() == OP_BUY) 
                        LastType = OP_BUY; 
                    //----
           if(OrderType() == OP_SELL) 
                        LastType = OP_SELL; 
                    LastClosePrice = OrderClosePrice();
                    LastLots = OrderLots();
                    //----
           if(LastType == OP_BUY) 
                      {            
                           if(OrderClosePrice() < OrderOpenPrice())
                                  Profit = Profit - (OrderOpenPrice() - OrderClosePrice())*OrderLots() / Point;
                           //----
               if(OrderClosePrice() > OrderOpenPrice()) 
                                  Profit = Profit + (OrderClosePrice() - OrderOpenPrice())*OrderLots() / Point;
                      }
                    //----
           if(LastType == OP_SELL) 
                   {
                        if(OrderClosePrice() > OrderOpenPrice()) 
                               Profit=Profit - (OrderClosePrice() - OrderOpenPrice())*OrderLots() / Point;
                        //----
               if(OrderClosePrice() < OrderOpenPrice()) 
                               Profit=Profit+(OrderOpenPrice()-OrderClosePrice())*OrderLots()/Point; 
                   }
            }
     }
      Profit = Profit*PipValue;
      text2 = "Profit: $" + DoubleToStr(Profit, 2) + " +/-";
//----
   if(OpenOrders >= (MaxTrades - OrderstoProtect) && AccountProtection == 1) 
     {        
          if(Profit >= SecureProfit) 
            {
              OrderClose(LastTicket, LastLots, LastClosePrice, slippage, Yellow);         
              ContinueOpening = False;
              return(0);
            }
     }
//----
   if(!IsTesting()) 
     {
          if(myOrderType == 3) 
              text = "No conditions to open trades"; 
          else 
              text="                         "; 
          Comment("LastPrice=", LastPrice, " Previous open orders=", PreviousOpenOrders, 
                  "nContinue opening=", ContinueOpening, " OrderType=", myOrderType, "n", 
                  text2, "nLots=", lotsi, "n", text);
     }
//----
   if(myOrderType == 1 && ContinueOpening) 
     {    
          if((Bid - LastPrice) >= Pips*Point || OpenOrders < 1) 
            {        
                 SellPrice = Bid;                
                 LastPrice = 0;
                 //----
           if(TakeProfit == 0) 
                     tp = 0; 
                 else 
                     tp = SellPrice - TakeProfit*Point; 
                 //----
           if(InitialStop == 0) 
                     sl=0; 
                 else 
                     sl=SellPrice+InitialStop*Point;  
                 //----
           if(OpenOrders != 0) 
                   {
                        mylotsi=lotsi;            
                        //----
               for(cnt = 1; cnt <= OpenOrders; cnt++)
                               if(MaxTrades > 12) 
                                   mylotsi = NormalizeDouble(mylotsi*1.5, 1); 
                               else 
                                   mylotsi = NormalizeDouble(mylotsi*2, 1); 
                   } 
                 else 
                     mylotsi = lotsi; 
                 //----
           if(mylotsi > 100) 
                     mylotsi = 100; 
                 OrderSend(Symbol(), OP_SELL, mylotsi, SellPrice, slippage, sl, tp, 
    

 





Code to difficult? Find somebody to help you with coding here.

 



Author: Collector
Source: http://www.mql4.com/

 

View similar (mql4 expert advisor for MetaTrader):

2-EMA expert
10 points 3
2ways system
...
 
 
all formulas for MetaTrader
all formulas

 

 

Email to friend

Top

 

     
However we try to maintain hiqhest possible level of service - most formulas, oscillators, indicators
and systems are submitted by anonymous users.
Therefore S4T™ does not take any responsibility for it's quality.
If you use any of this information, use it at your own risk. You are responsible for your own trading decisions.
Be sure to verify that any information you see on these pages is correct, and is applicable to your particular trade.
In no case will S4T™ be responsible for your trading gains or losses.
PayPalSecure payments by PayPal S4T™ is a part of TAURO EDUCATION NETWORK
 
Privacy note | (c) copyrights systems4trading.com 2006-2009