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); } //+------------------------------------------------------------------+
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.
What criteria are you using to identify the upper and lower limits of the neutral area and the other areas ?
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.
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); } //+------------------------------------------------------------------+
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.
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.
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.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
If points are unclear, do not hesitate to ask me questions.