EURUSD Negative Breakout v0.1





//+-----------------------------------------------------------+
//|                               EURUSD Negative Breakout EA |
//|                                               version 0.1 |
//|                               Original idea from mushy999 |
//|                                    EA conversion by Azmel |
//|                                 Copyright © Forex-TSD.com |
//+-----------------------------------------------------------+
//| INSTRUCTIONS: Attach the EA to EURUSD M5 chart.           |
//+-----------------------------------------------------------+
//| VERSION HISTORY                                           |
//| 0.1   - Initial release.                                  |
//+-----------------------------------------------------------+
#include <stdlib.mqh>

//EXTERNAL VARIABLES
extern int    Magic=327697;
extern double Lots=0.01;
extern int    TakeProfit=80;
extern int    StopLoss=1000;
extern int    HighCount=65;
extern int    FirstMAP=50;
extern int    SecondMAP=166;
extern int    FirstMAType0to4=2;
extern int    SecondMAType0to4=2;
extern int    FirstPriceType0to6=3;
extern int    SecondPriceType0to6=0;
extern int    PeriodsTillClose=310000;

int    counter;
int    counter2=0;
double Low100;
double High100;
int    i;
int    slippage=5;
int    ticket;
double FirstMA;
double SecondMA;
double Price[2];

int start()
{
   int iOrders=OrdersTotal()-1;
   counter2++;
   FirstMA=iMA(Symbol(),0,FirstMAP,1,FirstMAType0to4,FirstPriceType0to6,1);
   SecondMA=iMA(Symbol(),0,SecondMAP,1,SecondMAType0to4,SecondPriceType0to6,1);

   if(counter2 > PeriodsTillClose)
   {
     for(i=iOrders; i>=0; i--) 
     {
       if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderType()<=OP_SELL) && GetMarketInfo() && !OrderClose(OrderTicket(),OrderLots(),Price[1-OrderType()],slippage)) Print(OrderError());
     }
     counter2=0;
   }
   
   
   High100=0;
   for(i=1;i<=HighCount;i++)
   {
      High100=MathMax(High100,High[i]);
   }
   
   if(Ask>High100+1*Point && CountTrades()<=20 && DayOfWeek()!=5 && FirstMA < SecondMA)
   {
      Lots=AccountBalance() / 400000;
      counter2=0;
      ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,"GBPUSD Breakout",Magic,0,Blue);
   }

   return(0);
}

int CountTrades()
{
   counter=0;
   for(i=0;i<OrdersTotal();i++)
   {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderMagicNumber()==Magic)
      {
         counter++;
      }
   }
   return(counter);
}


//+------------------------------------------------------------------+
//| Function..: OrderError                                           |
//+------------------------------------------------------------------+
string OrderError() {
  int iError=GetLastError();
  return(StringConcatenate("Order:",OrderTicket()," GetLastError()=",iError," ",ErrorDescription(iError)));
}
 

//+------------------------------------------------------------------+
//| Function..: GetMarketInfo                                        |
//| Returns...: bool Success.                                        |
//+------------------------------------------------------------------+
bool GetMarketInfo() {
  RefreshRates();
  Price[0]=MarketInfo(OrderSymbol(),MODE_ASK);
  Price[1]=MarketInfo(OrderSymbol(),MODE_BID);
  double dPoint=MarketInfo(OrderSymbol(),MODE_POINT);
  if(dPoint==0) return(false);
  //giSlippage=(Price[0]-Price[1])/dPoint;
  return(Price[0]>0.0 && Price[1]>0.0);
}





Sample





Analysis



Market Information Used:

Series array that contains the highest prices of each bar


Indicator Curves created:


Indicators Used:

Moving average indicator


Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders
It Closes Orders by itself

It automatically opens orders when conditions are reached

Other Features: