Download MetaTrader 5
To add comments, please log in or register
Find out how social trading can improve your profits
Pierre Rougier
386
Pierre Rougier 2014.06.09 18:34 
Hello,

I suggest that we develop together a semi-automatic strategy EA.

Developing each of his side your answer, then post it here.
It is me who post the statements of EA to develop.

First step EA to develop :
The First step EA to develop is described by an attached drawing in PDF.

If points are unclear, do not hesitate to ask me questions.

 FirstStep

Pierre Rougier
386
Pierre Rougier 2014.06.09 21:04  

Hello,

My very first release.

Maybe some bugs still here.

 

//+------------------------------------------------------------------+
//|                                                  eaFirstStep.mq4 |
//|                                         Copyright 2014, Pierre8r |
//|                                              https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, Pierre8r"
#property link      "https://www.mql4.com"
#property version   "1.00"
#property strict

#include <stderror.mqh>
#include <stdlib.mqh>

extern int magicNumber=2014;

extern  double closeArea=1302.52;
extern  double neutralArea=1289.33;
extern  double openArea=1285.23;

double numlot=0.1;
bool isTradingStopped;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   isTradingStopped=false;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   if(Ask>closeArea)
     {
      computeCloseArea();
     }
   else if(Ask>neutralArea)
     {
     }
   else if(Ask>openArea)
     {
      computeOpenArea();
     }
   else
     {
      computeLossesArea();
     }

  }
//+------------------------------------------------------------------+
void computeCloseArea()
  {
   closeAllBuyOrders();
  }
//+------------------------------------------------------------------+
void computeOpenArea()
  {
   if(isTradingStopped==False)
     {
      if(isOpenBuyOrder()==False)
        {
         openBuyOrder();
        }
     }
  }
//+------------------------------------------------------------------+
void computeLossesArea()
  {
   closeAllBuyOrders();
   isTradingStopped=true;
  }
//+------------------------------------------------------------------+
void closeAllBuyOrders()
  {
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderType()==OP_BUY) && (OrderSymbol()==Symbol()))
        {
         closeOrder(OrderTicket());
        }
     }
  }
//+------------------------------------------------------------------+
bool isOpenBuyOrder()
  {
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderType()==OP_BUY) && (OrderSymbol()==Symbol()))
        {
         return(true);
        }
     }
   return(false);
  }
//+------------------------------------------------------------------+
void openBuyOrder()
  {
   int numOrdre=0;
   RefreshRates();
//      Print("openBuy()  -  Ask : ",  Ask, "  -  Bid : ",  Bid, "dBestBuyPrice : ",  dBestBuyPrice,  dBestBuyPrice - 0.001 );

   numOrdre=OrderSend(Symbol(),OP_BUY,numlot*1,Ask,3,NULL,0,"",magicNumber,0,CLR_NONE);
   if(numOrdre==0)
     {
      processError("Problme ouverture Ordre : "+ErrorDescription(GetLastError()));
     }
  }
//+------------------------------------------------------------------+
void closeOrder(int numOrdre)
  {

   if(OrderSelect(numOrdre,SELECT_BY_TICKET)==true)
     {
      RefreshRates();
      numlot=OrderLots();
      if(OrderClose(numOrdre,numlot,Bid,3))
        { processError("Passage fermeture Ordre - Changement etat de ordre");}
      else
        { processError("Probleme fermeture ordre "+ErrorDescription(GetLastError()));}
     }

  }
//+------------------------------------------------------------------+
void processError(string msgError)
  {
   Print("Error Message : ",msgError);
  }
//+------------------------------------------------------------------+
Pierre Rougier
386
Pierre Rougier 2014.06.11 14:59  
Hello,

Second step:
Same strategy as the strategy of the first step, but there is also the possibility of trader shorts.
By a switch should be allowed to choose only a long strategy, exclusively short, or make hedging.

Participate in this second step
Even if you post your answer later mine.
It will give me the feeling that this project is of interest to people other than me.

The ideal is to submit a full code.

 

Rang Strategy 

Ian Venner
2583
Ian Venner 2014.06.11 17:17  
What criteria are you using to identify the upper and lower limits of the neutral area and the other areas  ?
Pierre Rougier
386
Pierre Rougier 2014.06.11 17:26  

Hello,

It's a semi-automatic stuff.

You have to do your work before use this EA.
It's your choice to choose  where is the upper, lower, etc.

Pierre Rougier
386
Pierre Rougier 2014.06.11 19:55  

Second step :

 

//+------------------------------------------------------------------+
//|                                               eaRangStrategy.mq4 |
//|                                         Copyright 2014, Pierre8r |
//|                                              https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, Pierre Rougier"
#property link      "https://www.mql4.com"
#property version   "1.002"
#property strict

#include <stderror.mqh>
#include <stdlib.mqh>

extern int magicNumber=2014;

//--- Strategy
enum theStrategy
  {
   BuyStrategy=0,      // BuyStrategy
   SellStrategy=1,     // SellStrategy
   HedgingStrategy=2,  // HedgingStrategy
  };
//--- input parameters
input theStrategy  currentStrategy=HedgingStrategy;

extern  double highStopArea=1310.10;
extern  double highArea=1302.52;
extern  double neutralArea=1289.33;
extern  double lowArea=1285.23;
extern  double lowStopArea=1285.23;

double numlot=0.1;
bool isTradingStopped;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   isTradingStopped=FALSE;

   if(!ObjectCreate(0,"startHighStopArea",OBJ_HLINE,0,0,highStopArea))
     {
      Print(__FUNCTION__,": failed to create a horizontal line! Error code = ",GetLastError());
     }
   ObjectSet("startHighStopArea",OBJPROP_COLOR,clrRed);

   if(!ObjectCreate(0,"startHighArea",OBJ_HLINE,0,0,highArea))
     {
      Print(__FUNCTION__,": failed to create a horizontal line! Error code = ",GetLastError());
     }
   ObjectSet("startHighArea",OBJPROP_COLOR,clrBlue);

   if(!ObjectCreate(0,"startNeutralArea",OBJ_HLINE,0,0,neutralArea))
     {
      Print(__FUNCTION__,": failed to create a horizontal line! Error code = ",GetLastError());
     }
   ObjectSet("startNeutralArea",OBJPROP_COLOR,clrLime);

   if(!ObjectCreate(0,"startLowArea",OBJ_HLINE,0,0,lowArea))
     {
      Print(__FUNCTION__,": failed to create a horizontal line! Error code = ",GetLastError());
     }
   ObjectSet("startLowArea",OBJPROP_COLOR,clrRed);

   if(!ObjectCreate(0,"startOpenArea",OBJ_HLINE,0,0,lowStopArea))
     {
      Print(__FUNCTION__,": failed to create a horizontal line! Error code = ",GetLastError());
     }
   ObjectSet("startLowStopArea",OBJPROP_COLOR,clrRed);

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   if(isTradingStopped==False)
     {
      switch(currentStrategy)
        {
         case BuyStrategy :
            computeBuyStrategy();
            break;
         case SellStrategy :
            computeSellStrategy();
            break;
         case HedgingStrategy :
            computeHedgingStrategy();
            break;
         default:
            break;
        }
     }
  }
//+------------------------------------------------------------------+
void computeBuyStrategy()
  {

   if(Ask>highArea)
     {
      computeCloseBuyOrder();
     }
   else if(Ask>neutralArea)
     {
     }
   else if(Ask>lowArea)
     {
      computeOpenBuyOrder();
     }
   else
     {
      computeStopTrading();
     }
  }
//+------------------------------------------------------------------+
void computeSellStrategy()
  {

   if(Ask>highStopArea)
     {
      computeStopTrading();
     }
   else if(Ask>highArea)
     {
      computeOpenSellOrder();
     }
   else if(Ask>neutralArea)
     {
     }
   else
     {
      computeCloseSellOrder();
     }
  }
//+------------------------------------------------------------------+
void computeHedgingStrategy()
  {
   if(isTradingStopped==False)
     {
      computeBuyStrategy();
     }
   if(isTradingStopped==False)
     {
      computeSellStrategy();
     }
  }
//+------------------------------------------------------------------+
void computeOpenBuyOrder()
  {
   if(isTradingStopped==False)
     {
      if(isOpenBuyOrder()==False)
        {
         openBuyOrder();
        }
     }
  }
//+------------------------------------------------------------------+
void computeOpenSellOrder()
  {
   if(isTradingStopped==False)
     {
      if(isOpenSellOrder()==False)
        {
         openSellOrder();
        }
     }
  }
//+------------------------------------------------------------------+
void computeCloseBuyOrder()
  {

   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderType()==OP_BUY) && (OrderSymbol()==Symbol()))
        {
         closeOrder(OrderTicket());
        }
     }
  }
//+------------------------------------------------------------------+
void computeCloseSellOrder()
  {

   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderType()==OP_SELL) && (OrderSymbol()==Symbol()))
        {
         closeOrder(OrderTicket());
        }
     }
  }
//+------------------------------------------------------------------+
void computeStopTrading()
  {
   closeAllOrders();
   isTradingStopped=true;
  }
//+------------------------------------------------------------------+
void closeAllOrders()
  {
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderSymbol()==Symbol()))
        {
         closeOrder(OrderTicket());
        }
     }
  }
//+------------------------------------------------------------------+
bool isOpenBuyOrder()
  {
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderType()==OP_BUY) && (OrderSymbol()==Symbol()))
        {
         return(true);
        }
     }
   return(false);
  }
//+------------------------------------------------------------------+
bool isOpenSellOrder()
  {
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderType()==OP_SELL) && (OrderSymbol()==Symbol()))
        {
         return(true);
        }
     }
   return(false);
  }
//+------------------------------------------------------------------+
void openBuyOrder()
  {
   int numOrdre=0;
   RefreshRates();

   numOrdre=OrderSend(Symbol(),OP_BUY,numlot*1,Ask,3,NULL,0,"",magicNumber,0,CLR_NONE);
   if(numOrdre==0)
     {
      processError("Problme ouverture Ordre : "+ErrorDescription(GetLastError()));
     }
  }
//+------------------------------------------------------------------+
void openSellOrder()
  {
   int numOrdre=0;
   RefreshRates();

   numOrdre=OrderSend(Symbol(),OP_SELL,numlot*1,Ask,3,NULL,0,"",magicNumber,0,CLR_NONE);
   if(numOrdre==0)
     {
      processError("Problme ouverture Ordre : "+ErrorDescription(GetLastError()));
     }
  }
//+------------------------------------------------------------------+
void closeOrder(int numOrdre)
  {

   if(OrderSelect(numOrdre,SELECT_BY_TICKET)==true)
     {
      RefreshRates();
      numlot=OrderLots();
      if(OrderClose(numOrdre,numlot,Bid,3))
        { processError("Passage fermeture Ordre - Changement etat de ordre");}
      else
        { processError("Probleme fermeture ordre "+ErrorDescription(GetLastError()));}
     }

  }
//+------------------------------------------------------------------+
void processError(string msgError)
  {
   Print("Error Message : ",msgError);
  }
//+------------------------------------------------------------------+
Pierre Rougier
386
Pierre Rougier 2014.06.11 20:47  
Hello, 

Third step: 

Same strategy as the strategy of the second step, but it is possible to trade a channel.

 

 eaSemiAutomatique

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.06.12 00:47  
Actually I did try a similar one like the one above but honestly, you have to monitor the opened trades because when there are sudden movements, you gonna loss lots of pips. It is never meant to be as set and go.
Halley
198
Halley 2014.06.12 05:00  
deysmacro:
Actually I did try a similar one like the one above but honestly, you have to monitor the opened trades because when there are sudden movements, you gonna loss lots of pips. It is never meant to be as set and go.

Good idea. You are welcome to implement your advice into this system.
/
To add comments, please log in or register