Chart Live

Showing posts with label Expert Advisors. Show all posts
Showing posts with label Expert Advisors. Show all posts

Simple Scalping EA

Description:

Very simple scalping EA, no Indicators. Logic is based on very fast price movements.
Here is my scalping EA idea works most of the time, but needs to be better programmed.
If some1 can help to modify it so it can be used on many pairs at the same time.

Idea is very simple, no indicators at all.
it keeps updating BuyStop and SellStop orders with each price movements.
And when the market becomes heavy or news it won't get a chance to get updated quick... which means very fast price movement in one of the directions. This practically guarantees 10-15 pips movement.

If some1 can help me to code it properly it would be very cool.. For the last 3 month i have a ratio of this working 4-6 wins vs 1 loss. ( and i noticed the loss mostly because i programmed wrong). Stop Loss should be adjusted to 5-7 pips ( if broker allowed)Works fine on Alpari US.
PS. For some reason and i cant identify the problem- after executing the order it may not send another order till i disable and re=enable EA ( gotta be a bug somewhere). Would appreciated any help.)
oops. One more thing, i used the coding template from IBFX scripts and modified for my use.
 //---------------------------
//|                                                  Scalping EA.mq4 |
//|                       Copyright ?2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Interbank FX, LLC" //( original template)
 
#property copyright "PicassoInActions , 123@donothing.us" //( original idea)
 
 
#include <stderror.mqh> 
//+------------------------------------------------------------------+
//| Global Variables / Includes                                      |
//+------------------------------------------------------------------+
datetime   CurrTime = 0;
datetime   PrevTime = 0;
     int  TimeFrame = 0;
     int      Shift = 1;
     
     int  SymDigits;
  double  SymPoints;
     int  POS_n_BUY;
     int  POS_n_SELL;
     int  POS_n_BUYSTOP;
     int  POS_n_SELLSTOP;
     int  POS_n_total;
  double  OrderLevelB;
  double  OrderLevelS;
 
//+------------------------------------------------------------------+
//| Expert User Inputs                                               |
//+------------------------------------------------------------------+
extern double               Lots = 0.01;
extern double            MinLots = 0.01;
extern    int              magic = 1111;
extern    int         TakeProfit = 30; 
extern    int           StopLoss = 50; 
extern    int          MaxBuyPos = 1;//maximum Buy positions at once
extern    int         MaxSellPos = 1;//maximum Sell positions at once
extern    int           Distance = 100;
extern    int               Near = 15;
extern    int                Far = 100;

 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
 return(0);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit() 
{ 
 return(0); 
}
 
//+------------------------------------------------------------------+
//| Expert start function                                            |
//+------------------------------------------------------------------+
int start() 
{    
 int cnt, total;
 int ticketB, ticketS, ticketC,ticketM;//ticket number of Buy,Sell,Close,Modify
 int MaxOpenPos = MaxBuyPos + MaxSellPos;

//----Count Positions 
 count_position(); 
 RefreshRates();
 
//----Open Pending Orders 
 if(POS_n_BUYSTOP + POS_n_BUY < MaxBuyPos && POS_n_SELL == 0) 
 {
  ticketB=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Distance*Point,1,0,0,"Scalping EA",magic,0,Green);
  if(ticketB>0)
  {
   if(OrderSelect(ticketB,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY Stop order sent : ",OrderOpenPrice());
  }
  else 
  {
   Print("Error sending BUY Stop order : ",GetLastError()); 
   return(0); 
  }
  return(0);   
 }
 
 if(POS_n_SELLSTOP + POS_n_SELL < MaxSellPos && POS_n_BUY == 0) 
 {
  ticketS=OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-Distance*Point,1,0,0,"Scalping EA",magic,0,Red);
  if(ticketS>0)
  {
   if(OrderSelect(ticketS,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL Stop order sent : ",OrderOpenPrice());
  }
  else 
  {
   Print("Error sending SELL Stop order : ",GetLastError()); 
   return(0); 
  }
  return(0);  
 }
 
//---- delete the useless positions && achieve the hidden TakeProfit and StopLoss
  total=OrdersTotal();
  for(cnt=total-1;cnt>=0;cnt--)
  {
   OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
   if(OrderMagicNumber() != magic) break;
//----   
   if(OrderType()==OP_BUYSTOP && POS_n_SELL != 0  && OrderSymbol() == Symbol())  OrderDelete(OrderTicket());
   if(OrderType()==OP_SELLSTOP && POS_n_BUY != 0 && OrderSymbol() == Symbol())  OrderDelete(OrderTicket());
//----
   RefreshRates();
   if(OrderType()==OP_BUY  && OrderSymbol() == Symbol())
   {
    if(Ask >= OrderOpenPrice() + TakeProfit*Point || Bid <= OrderOpenPrice() - StopLoss*Point)
    ticketC = OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
//    if(Bid <= OrderOpenPrice() - StopLoss*Point) {Lots=2*Lots;ticketC = OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);}
//    if(Ask >= OrderOpenPrice() + TakeProfit*Point) {Lots=MinLots;ticketC = OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);}
    if(ticketC <= 0) {Print("Error closing order : ",GetLastError()); }
   }  
   
//----   
   RefreshRates();
   if(OrderType()==OP_SELL && OrderSymbol() == Symbol())
   {
    if(Bid <= OrderOpenPrice() - TakeProfit*Point || Ask >= OrderOpenPrice() + StopLoss*Point)
    ticketC = OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);
//    if(Ask >= OrderOpenPrice() + StopLoss*Point) {Lots=2*Lots;ticketC = OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);}
//    if(Bid <= OrderOpenPrice() - TakeProfit*Point) {Lots=MinLots;ticketC = OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);}
    if(ticketC <= 0) {Print("Error closing order : ",GetLastError()); }
   }  
  }

//----Update Pending Orders in accordance with Price Movements
  RefreshRates();
  total=OrdersTotal();
  for(cnt=total-1;cnt>=0;cnt--)
  {
   OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
   if(OrderMagicNumber() != magic) break;
//----   
   if(OrderType()==OP_BUYSTOP  && OrderSymbol() == Symbol())
   {
    if((OrderOpenPrice()-Ask)<=Point*Near || (OrderOpenPrice()-Ask)>=Point*Far )
    {
     ticketM=OrderModify(OrderTicket(),Ask+Distance*Point,0,0,0,CLR_NONE );
     if(ticketM <= 0) {Print("Error modify order : ",GetLastError()); }
    }
   }


//----
   if(OrderType()==OP_SELLSTOP && OrderSymbol() == Symbol())   
   {
    if((Bid-OrderOpenPrice())<=Point*Near || (Bid-OrderOpenPrice())>=Point*Far )
    {
     ticketM=OrderModify(OrderTicket(),Bid-Distance*Point,0,0,0,CLR_NONE );
     if(ticketM <= 0) {Print("Error modify order : ",GetLastError()); }
    }
   }
  }
}


//+------------------------------------------------------------------+
//| Seperate Functions                                               |
//+------------------------------------------------------------------+
void count_position()
{
    POS_n_BUY  = 0;
    POS_n_SELL = 0;
    
    POS_n_BUYSTOP = 0;
    POS_n_SELLSTOP = 0;
    
    for( int i = 0 ; i < OrdersTotal() ; i++ )
    {
     if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) == false || OrderMagicNumber() != magic) break;
//     if( OrderSymbol() != Symbol() )   continue; 

     if( OrderType() == OP_BUY  && OrderSymbol() == Symbol() && OrderMagicNumber()==magic) POS_n_BUY++;
     
     else
     if( OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber()==magic) POS_n_SELL++;
     
     else   
     if( OrderType() == OP_BUYSTOP  && OrderSymbol() == Symbol() && OrderMagicNumber()==magic)
     {
      POS_n_BUYSTOP++;
      OrderLevelB = OrderOpenPrice();
     }
     
     else
     if( OrderType() == OP_SELLSTOP  && OrderSymbol() == Symbol() && OrderMagicNumber()==magic)
     {
      POS_n_SELLSTOP++;
      OrderLevelS = OrderOpenPrice();
     }        
    }
        
    POS_n_total = POS_n_BUY + POS_n_SELL + POS_n_BUYSTOP + POS_n_SELLSTOP;
}
//-----------------------------


 http://codebase.mql4.com/7881
Teori Rekonstruksi by: Ame Suzako

EA Envelope 2.11

Kemunculan kembali EA Envelope cukup mengesan, karena EA ini merupakan salah satu EA paling stabil profit. EA yang pernah berjaya pada tahun 2005 akhirnya dapat ditemukan kembali di salah satu site. Walaupun EA sudah usang, tapi performa dari transaksinya masih bisa diandalkan hingga kini.

EA sendiri memiliki 2 indikator bawaan dari metatrader. Indikator tersebut terdiri dari MA dan envelopes. Dengan rinciannya sebagai berikut :

- MA (periode 114, exponential, close)
- Envelopes (periode 114, exponential, close)

Pada waktu pembuatan EA dilakukan perubahan-perubahan yang dilakukan. Sehingga uji coba dan perkembangan selanjutnya terakhir kali pada tahun 2005. Anda dapat mengunjungi diskusi melalui forum. EA pernah dishare pada tanggal 26 Desember 2005.

Prinsip Kerja EA
Cara kerja dari EA Envelopes versi 2.11 adalah dengan mengikuti indikator Envelopes dan EMA yang sudah ditanamkan pada proses pembuatan EA. Prinsip kerja yang dilakukan EA dalam open posisi adalah sebagai berikut :

BUY bila harga di atas MA dengan pending order didaerah envelopes warna merah
SELL bila harga di bawah MA dengan pending order didaerah envelopes warna biru



Karakteristik

EA Envelopes versi 2.11 merupakan “EA Full Otomatis”. Segala transaksi yang dilakukan EA akan dapat dikendalikan oleh EA sendiri. Strategi yang ada pada EA menggunakan martingale. EA sudah dilengkapi dengan moneymanagement, secara otomatis setiap modal meningkat maka open posisi akan membesar.

Rekomendasi Setting
TF : 30 menit
Setting lain : ikuti EA

Kelebihan
Kelebihan dari EA Envelopes versi 2.11 adalah :
1. Mampu bekerja setiap hari
2.  Sudah disertakan SL dan TP
3. Ada Risk management
4. Tersedia money management
5. Cocok digunakan dipair GU dan EU

Kekurangan
Kekurangan dari EA Envelopes versi 2.11 adalah :
1. Tak setiap hari selalu melakukan open posisi
2. False signal

Download
EA Envelopes versi 2.11 dapat di download di bawah ini :
EA Envelopes versi 2.11 (11 kb)
referensi : http://superiorinvestment.wordpress.com/dasar-charting/envelope-bands/moving-average-envelope/

Astiina, by: Amie Suzako

Ea YEA3 - simple Candle

Description:

Strategy is based on simple rules. It can work on any currency pair. Best results are obtained with the lowest set TS. The strategy works with any broker, but works better with brokers who allow you to set the low TS.
If the closing price of the previous candle was higher than the current - EA opens sell.
If the closing price of the previous candle was lower than the current - EA will open buy.
Out of the market with TP or TS.
//-------------------------------------------------------------------------//
#define SIGNAL_NONE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4
 
#property copyright "Copyright 2011, Adam Pogorzelski"
#property link      "http://www.afterburner.pl/"
 
extern int MagicNumber = 1972;
extern bool SignalMail = False;
extern bool EachTickMode = False;
extern double Lots = 5.0;
extern int Slippage = 3;
extern bool UseStopLoss = True;
extern int StopLoss = 500;
extern bool UseTakeProfit = False;
extern int TakeProfit = 10;
extern bool UseTrailingStop = True;
extern int TrailingStop = 6;
 
int BarCount;
int Current;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init() {
   BarCount = Bars;
 
   if (EachTickMode) Current = 0; else Current = 1;
 
   return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit() {
   return(0);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start() {
   int Order = SIGNAL_NONE;
   int Total, Ticket;
   double StopLossLevel, TakeProfitLevel;
 
 
 
   if (EachTickMode && Bars != BarCount) TickCheck = False;
   Total = OrdersTotal();
   Order = SIGNAL_NONE;
 
   //+------------------------------------------------------------------+
   //| Variable Begin                                                   |
   //+------------------------------------------------------------------+
 
 
double Buy1_1 = iClose(NULL, 0, Current + 0);
double Buy1_2 = iOpen(NULL, 0, Current + 1);
 
double Sell1_1 = iClose(NULL, 0, Current + 0);
double Sell1_2 = iOpen(NULL, 0, Current + 1);
 
 
 
   
   //+------------------------------------------------------------------+
   //| Variable End                                                     |
   //+------------------------------------------------------------------+
 
   //Check position
   bool IsTrade = False;
 
   for (int i = 0; i < Total; i ++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
         IsTrade = True;
         if(OrderType() == OP_BUY) {
            //Close
 
            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Buy)                                           |
            //+------------------------------------------------------------------+
 
            
 
            //+------------------------------------------------------------------+
            //| Signal End(Exit Buy)                                             |
            //+------------------------------------------------------------------+
 
            if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
               if (!EachTickMode) BarCount = Bars;
               IsTrade = False;
               continue;
            }
            //Trailing stop
            if(UseTrailingStop && TrailingStop > 0) {                 
               if(Bid - OrderOpenPrice() > Point * TrailingStop) {
                  if(OrderStopLoss() < Bid - Point * TrailingStop) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         } else {
            //Close
 
            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Sell)                                          |
            //+------------------------------------------------------------------+
 
            
 
            //+------------------------------------------------------------------+
            //| Signal End(Exit Sell)                                            |
            //+------------------------------------------------------------------+
 
            if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
               if (!EachTickMode) BarCount = Bars;
               IsTrade = False;
               continue;
            }
            //Trailing stop
            if(UseTrailingStop && TrailingStop > 0) {                 
               if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
                  if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         }
      }
   }
 
   //+------------------------------------------------------------------+
   //| Signal Begin(Entry)                                              |
   //+------------------------------------------------------------------+
 
   if (Buy1_1 > Buy1_2) Order = SIGNAL_BUY;
 
   if (Sell1_1 < Sell1_2) Order = SIGNAL_SELL;
 
 
   //+------------------------------------------------------------------+
   //| Signal End                                                       |
   //+------------------------------------------------------------------+
 
   //Buy
   if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      if(!IsTrade) {
         //Check free margin
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }
 
         if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;
 
         Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
                Print("BUY order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
            } else {
                Print("Error opening BUY order : ", GetLastError());
            }
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         return(0);
      }
   }
 
   //Sell
   if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      if(!IsTrade) {
         //Check free margin
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }
 
         if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;
 
         Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
                Print("SELL order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
            } else {
                Print("Error opening SELL order : ", GetLastError());
            }
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         return(0);
      }
   }
 
   if (!EachTickMode) BarCount = Bars;
 
   return(0);
}
//+------------------------------------------------------------------+

Reference: http://codebase.mql4.com/7908

Astiina, by: Amie Suzako

Ea Candle trader v1

Description:

This Expert Advisor uses candlestick signals to trade.
When semi automated it can achieve great results.
We recommend only enabling it when the market is trending. The EA is great for both scalping and big tp strategies depending on chart timeframe used

//+------------------------------------------------------------------+
//|                                                         Vita.mq4 |
//|                            Copyright © 2011, www.FxAutomated.com |
//|                                       http://www.FxAutomated.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, www.FxAutomated.com"
#property link      "http://www.FxAutomated.com"
 
//---- input parameters
extern string    CandleTrader_v1="www.fxautomated.com for more info and products";
extern double    Lots=0.1;
extern int       Slip=5;
extern double    TakeProfit=500;
extern double    StopLoss=50;
extern bool      Continuation=true;
extern bool      ReverseClose=true;
extern string    SignalsAndManagedAccounts="www.TradingBug.com";
 
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
int digits=MarketInfo("EURUSD",MODE_DIGITS);
if(digits==5){int StopMultd=10;} else{StopMultd=1;}
int Slippage=Slip*StopMultd;
 
int MagicNumber1=2001,MagicNumber2=2002,i,closesell=0,closebuy=0;
 
double TP=NormalizeDouble(TakeProfit*StopMultd,Digits);
double SL=NormalizeDouble(StopLoss*StopMultd,Digits);
 
 
double slb=NormalizeDouble(Ask-SL*Point,Digits);
double sls=NormalizeDouble(Bid+SL*Point,Digits);
 
 
double tpb=NormalizeDouble(Ask+TP*Point,Digits);
double tps=NormalizeDouble(Bid-TP*Point,Digits);
 
//-------------------------------------------------------------------+
//Check open orders
//-------------------------------------------------------------------+
if(OrdersTotal()>0){
  for(i=1; i<=OrdersTotal(); i++)          // Cycle searching in orders
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
        {
          if(OrderMagicNumber()==MagicNumber1) {int halt1=1;}
          if(OrderMagicNumber()==MagicNumber2) {int halt2=1;}
 
        }
     }
}
//-------------------------------------------------------------------+
 
//-----------------------------------------------------------------
// Bar checks
//-----------------------------------------------------------------
 if(iOpen(NULL,0,1)<iClose(NULL,0,1)) int BarOneUp=1;
 if(iOpen(NULL,0,1)>iClose(NULL,0,1)) int BarOneDown=1;
 
 if(iOpen(NULL,0,2)<iClose(NULL,0,2)) int BarTwoUp=1;
 if(iOpen(NULL,0,2)>iClose(NULL,0,2)) int BarTwoDown=1;
 
 if(iOpen(NULL,0,3)<iClose(NULL,0,3)) int BarThreeUp=1;
 if(iOpen(NULL,0,3)>iClose(NULL,0,3)) int BarThreeDown=1;
 
 if(iOpen(NULL,0,4)<iClose(NULL,0,4)) int BarFourUp=1;
 if(iOpen(NULL,0,4)>iClose(NULL,0,4)) int BarFourDown=1;
//-----------------------------------------------------------------------------------------------------
 
//-----------------------------------------------------------------------------------------------------
// Opening criteria
//-----------------------------------------------------------------------------------------------------
 
// Open buy direct
if(BarOneUp==1&&BarTwoDown==1&&BarThreeDown==1&&halt1!=1){
 int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,slb,tpb,"Candle bug buy order",MagicNumber1,0,Blue);
 if(ReverseClose==true)closesell=1;
 }
 
// Open buy by continuation
if(BarOneUp==1&&BarTwoDown==1&&BarThreeUp==1&&BarFourUp==1&&halt1!=1&&Continuation==true){
  openbuy=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,slb,tpb,"Candle bug buy continuation order",MagicNumber1,0,Blue);
  if(ReverseClose==true)closesell=1;
 }
 
 
// Open sell direct
if(BarOneDown==1&&BarTwoUp==1&&BarThreeUp==1&&halt2!=1){
 int opensell=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,sls,tps,"Candle bug sell order",MagicNumber2,0,Green);
 if(ReverseClose==true)closebuy=1;
 }
 
// Open sell by continuation
if(BarOneDown==1&&BarTwoUp==1&&BarThreeDown==1&&BarFourDown&&halt2!=1&&Continuation==true){
  opensell=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,sls,tps,"Candle bug sell continuation order",MagicNumber2,0,Green);
  if(ReverseClose==true)closebuy=1;
 }
//-------------------------------------------------------------------------------------------------
 
//-------------------------------------------------------------------------------------------------
// Closing criteria
//-------------------------------------------------------------------------------------------------
 
if(closesell==1||closebuy==1){// start
 
if(OrdersTotal()>0){
  for(i=1; i<=OrdersTotal(); i++){          // Cycle searching in orders
  
      if (OrderSelect(i-1,SELECT_BY_POS)==true){ // If the next is available
        
          if(OrderMagicNumber()==MagicNumber1&&closebuy==1) { OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,CLR_NONE); }
          if(OrderMagicNumber()==MagicNumber2&&closesell==1) { OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,CLR_NONE); }
 
        }
     }
}
 
 
}// stop
 
if(openbuy<1||opensell<1){ Sleep(1000*60*60*4);}
 
//-------------------------------------------------------------------
   return(0);
  }
//+------------------------------------------------------------------+

Reference: http://codebase.mql4.com/8125

Astiina, by: Amie Suzako