good EA with simple strategy but it not work here is the EA

To add comments, please log in or register
mol4u
20
mol4u  
i made EA with simple strategy but it not work

it dont open position and i dont know why

its strategy works well with most pairs and time frames (not more H4)

please help me





extern int MagicNumber = 0;
extern bool SignalMail = False;
extern bool EachTickMode = True;
extern double Lots = 1.0;
extern int Slippage = 0;
extern bool StopLossMode = False;
extern int StopLoss = 30;
extern bool TakeProfitMode = False;
extern int TakeProfit = 60;
extern bool TrailingStopMode = False;
extern int TrailingStop = 30;
#define SIGNAL_NONE 0
#define SIGNAL_BUY 1
#define SIGNAL_SELL 2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4
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 Var1 = iMA(NULL, 0, 20, 0, MODE_SMA, PRICE_MEDIAN, Current + 0);
double Var2 = iBands(NULL, 0, 20, 2, 0, PRICE_MEDIAN, MODE_UPPER, Current + 0);
double Var3 = iBands(NULL, 0, 20, 2, 0, PRICE_MEDIAN, MODE_LOWER, Current + 0);
double Var4 = iBands(NULL, 0, 20, 4, 0, PRICE_MEDIAN, MODE_UPPER, Current + 0);
double Var5 = iBands(NULL, 0, 20, 4, 0, PRICE_MEDIAN, MODE_LOWER, Current + 0);
double Buy1_1 = iHigh(NULL, PERIOD_M1, Current - 0.0005);
double Buy1_2 = Var2 ;
double Sell1_1 = iLow(NULL, PERIOD_M1, Current + 0.0005);
double Sell1_2 = Var3 ;
double CloseBuy1_1 = iLow(NULL, PERIOD_M1, Current + 0. 0005);
double CloseBuy1_2 = Var1 ;
double CloseBuy2_1 = iHigh(NULL, PERIOD_M1, Current + 0.0005);
double CloseBuy2_2 = Var4 ;
double CloseSell1_1 = iHigh(NULL, PERIOD_M1, Current - 0.0005);
double CloseSell1_2 = Var1 ;
double CloseSell2_1 = iLow(NULL, PERIOD_M1, Current - 0.0005);
double CloseSell2_2 = Var5 ;
//+------------------------------------------------------------------+
//| 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) |
//+------------------------------------------------------------------+
if (CloseBuy1_1 == CloseBuy1_2 || CloseBuy2_1 == CloseBuy2_2) Order = SIGNAL_CLOSEBUY;
//+------------------------------------------------------------------+
//| 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(TrailingStopMode && 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) |
//+------------------------------------------------------------------+
if (CloseSell1_1 == CloseSell1_2 || CloseSell2_1 == CloseSell2_2) Order = SIGNAL_CLOSESELL;
//+------------------------------------------------------------------+
//| 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(TrailingStopMode && 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 (StopLossMode) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
if (TakeProfitMode) 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 (StopLossMode) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
if (TakeProfitMode) 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);
Files:
bbb.mq4 11 kb
Caroline Carlin Arneodo
17
Caroline Carlin Arneodo  
Hello,

First of all, here is some of your code that isn't correct:

double Buy1_1 = iHigh(NULL, PERIOD_M1, Current - 0.0005);
double Buy1_2 = Var2 ;
double Sell1_1 = iLow(NULL, PERIOD_M1, Current + 0.0005);
double Sell1_2 = Var3 ;
double CloseBuy1_1 = iLow(NULL, PERIOD_M1, Current + 0.0005);
double CloseBuy1_2 = Var1 ;
double CloseBuy2_1 = iHigh(NULL, PERIOD_M1, Current + 0.0005);
double CloseBuy2_2 = Var4 ;
double CloseSell1_1 = iHigh(NULL, PERIOD_M1, Current - 0.0005);
double CloseSell1_2 = Var1 ;
double CloseSell2_1 = iLow(NULL, PERIOD_M1, Current - 0.0005);
double CloseSell2_2 = Var5 ;

Current + "x" (be it 0, 1, 2 or earlier) refer to the bar or candle being checked: that is, Current + 0 is the actual bar or candle, Current + 1 will be the previous bar or candle, Current + 2 the previous to the previous, etc.. There is no such thing as "Current + 0.0005". I presume you are willing to buy, sell or closebuy and closesell within 5 pips of the price.

Representation of price should be Bid or Ask depending on the case, and pips would be represented as x*Point (if 5 pips, that would be "5*Point"). Or, with the variables, (Buy1_1 - 5*Point), (Sell1_1 + 5*Point), etc... so you can use the EA with any currency pair not only those who have 4 decimals.

Here a possible correction:

double Buy1_1 = (iHigh(NULL, PERIOD_M1, Current + 0) - 5 * Point);
double Buy1_2 = Var2 ;
double Sell1_1 = (iLow(NULL, PERIOD_M1, Current + 0) + 5 * Point);
double Sell1_2 = Var3 ;
double CloseBuy1_1 = (iLow(NULL, PERIOD_M1, Current + 0) + 5 * Point);
double CloseBuy1_2 = Var1 ;
double CloseBuy2_1 = (iHigh(NULL, PERIOD_M1, Current + 0) + 5 * Point);
double CloseBuy2_2 = Var4 ;
double CloseSell1_1 = (iHigh(NULL, PERIOD_M1, Current + 0) - 5 * Point);
double CloseSell1_2 = Var1 ;
double CloseSell2_1 = (iLow(NULL, PERIOD_M1, Current + 0) - 5 * Point);
double CloseSell2_2 = Var5 ;

Maybe this is the only reason why it hasn't worked, I haven't checked other parameters though.
Hope it helps! :)
mol4u
20
mol4u  

thank you very much..i will test it

sorry for late reply

William Roeder
22444
William Roeder  


  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. What he said.
  3. Not adjusting for 4/5 digit brokers "Ask + Point * TrailingStop)"
  4. Not checking return codes.
  5. Using EA builder - not learning to code
Simon Gniadkowski
17274
Simon Gniadkowski  
mol4u:

thank you very much..i will test it

sorry for late reply

Late . . .  6 years too late and a pointless reply,  you just cause confusion for everyone else,  please don't reply to very old posts.
Alain Verleyen
40791
Alain Verleyen  
RaptorUK:
Late . . .  6 years too late and a pointless reply,  you just cause confusion for everyone else,  please don't reply to very old posts.

It would be useful that we can close some topics.
Simon Gniadkowski
17274
Simon Gniadkowski  
angevoyageur:
It would be useful that we can close some topics.

It would be even more useful if people who post learn to read the date of the post they are replying to . . .  but that is asking too much.  I'm not in favour of closing topics,  it is,  in my opinion,  a facility that gets badly abused.
Ubzen
5299
Ubzen  
RaptorUK: It would be even more useful if people who post learn to read the date of the post they are replying to . . .  but that is asking too much.  I'm not in favour of closing topics,  it is,  in my opinion,  a facility that gets badly abused.

Did we just have a topic closed in regards to 3rd party add-on's? It was off-topic for mql4 but better suited for mql5 general topic. I'm just wondering if one of you guys closed it? :)
Simon Gniadkowski
17274
Simon Gniadkowski  
ubzen:
Did we just have a topic closed in regards to 3rd party add-on's? It was off-topic for mql4 but better suited for mql5 general topic. I'm just wondering if one of you guys closed it? :)
We can't close topics,  we can delete posts but not close threads.
Alain Verleyen
40791
Alain Verleyen  
ubzen:
Did we just have a topic closed in regards to 3rd party add-on's? It was off-topic for mql4 but better suited for mql5 general topic. I'm just wondering if one of you guys closed it? :)
I have seen this topic also. Don't know where it's now.
Simon Gniadkowski
17274
Simon Gniadkowski  
angevoyageur:
I have seen this topic also. Don't know where it's now.
I think I posted on it . . .  I wonder who deleted it.
12
To add comments, please log in or register