- Bug in strategy tester
- Experts: The simplest RSI-based EA
- Need a little help on making my EA take only 1 trade then stop
So I made an EA solely for entries a couple weeks ago and now I'm looking to turn my robot to fully automated my problem here is I'm getting error now with TotalNooforders() with my code now when I applied an exit strategy using RSI. Please can someone help me here's the code
Hi,
I hope this can help :)
int TotalNoOfOrders() { int cnt=0, total, ticket; total = OrdersTotal(); for(int i=total-1; i>=0; i--) { ticket=OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderType()>=2 || OrderMagicNumber()!=MagicNumber) continue; cnt++; } return(cnt); }
and also, your opening order :
if ((ema > ema2)&&(adx > 50)) { if (OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Ask - stopLoss * Point, Ask + takeProfit * Point, "BossPips", MagicNumber, 0, Blue)) { Print("Buy order succeeded!"); }
might need some modification like this :
ResetLastError(); ticket=OrderSend(Symbol(),OP_BUY,NormalizeDouble(lots,2),Ask,your_slippage,your_sl,your_tp,your_log,MagicNumber,0,clrBlue); if(ticket<=0) { error=GetLastError(); //-- do something for errors .... } else { Print("Buy order succeeded!"); //-- do something for succesful order }
Good luck (^̮^)
So I made an EA solely for entries a couple weeks ago and now I'm looking to turn my robot to fully automated my problem here is I'm getting error now with TotalNooforders() with my code now when I applied an exit strategy using RSI. Please can someone help me here's the code
Hi, do you have double post here? https://www.mql5.com/en/forum/211537
You have been greatly assisted by the master coder there.
- 2017.07.18
- www.mql5.com
So I made an EA solely for entries a couple weeks ago and now I'm looking to turn my robot to fully automated my problem here is I'm getting error now with TotalNooforders() with my code now when I applied an exit strategy using RSI. Please can someone help me here's the code
extern int MagicNumber = 12345;
extern double lots = 0.10;
extern int stopLoss = 1000;
extern int takeProfit = 2000;
extern int Slippage = 0;
int TotalNoOfOrders(int cnt, int i)
{
for(;cnt<OrdersTotal(); cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true)
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
i++;
}
return(i);
}
void OnTick()
{
if (TotalNoOfOrders(0,0) > 0) {
return;
double ema = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_CLOSE, 0);
double ema2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, 0);
double adx = iADX(NULL, 0, 14, PRICE_CLOSE, 0, 0);
if ((ema > ema2)&&(adx > 50)) {
if (OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Ask - stopLoss * Point, Ask + takeProfit * Point, "BossPips", MagicNumber, 0, Blue)) {
Print("Buy order succeeded!");
}
}
if ((ema < ema2)&&(adx > 50)) {
if (OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Bid + stopLoss * Point, Bid - takeProfit * Point, "BossPips", MagicNumber,0, Red)) {
Print("Sell order succeeded!");
}
}
//---
{
if(OrderType()==OP_BUY)
{
if((iRSI(NULL,0,14,PRICE_HIGH,0)>70)) //here is my close buy rule
{
OrderClose(OrderSymbol(),OrderLots(),OrderClosePrice(),0,Red);
}
}
else
{
if(OrderType()==OP_SELL)
{
if((iRSI(NULL,0,14,PRICE_LOW,0)<30)) // here is my close sell rule
{
OrderClose(OrderSymbol(),OrderLots(),OrderClosePrice(),0,Red);
}
}
}
}
//+------------------------------------------------------------------+
}
}
I changed only the function TotalNoOfOrders, but if it will be doing what you want, I don't know.
Hi,
I hope this can help :)
and also, your opening order :
might need some modification like this :
Good luck (^̮^)
extern int MagicNumber = 12345; extern double lots = 0.10; extern int stopLoss = 1000; extern int takeProfit = 2000; extern int Slippage = 0; void OnTick() { if (TotalNoOfOrders() > 0) { return; double ema = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_CLOSE, 0); double ema2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, 0); double adx = iADX(NULL, 0, 14, PRICE_CLOSE, 0, 0); if ((ema > ema2)&&(adx > 50)) { if (OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Ask - stopLoss * Point, Ask + takeProfit * Point, "BossPips", MagicNumber, 0, Blue)) { Print("Buy order succeeded!"); } } if ((ema < ema2)&&(adx > 50)) { if (OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Bid + stopLoss * Point, Bid - takeProfit * Point, "BossPips", MagicNumber,0, Red)) { Print("Sell order succeeded!"); } } } } //--- if(OrderType()==OP_BUY) { if((iRSI(NULL,0,14,PRICE_HIGH,0)>70)) //here is your close buy rule { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red); } } else { if(OrderType()==OP_SELL) { if((iRSI(NULL,0,14,PRICE_LOW,0)<30)) // here is your close sell rule { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Red); } } } //+------------------------------------------------------------------+ int TotalNoOfOrders() { int cnt=0, total, ticket; total = OrdersTotal(); for(int i=total-1; i>=0; i--) { ticket=OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderType()>=2 || OrderMagicNumber()!=MagicNumber) continue; cnt++; } return(cnt); }
Hi, do you have double post here? https://www.mql5.com/en/forum/211537
You have been greatly assisted by the master coder there.Ok so I applied your code fully even with the modified code for opening trade but now I'm getting these errors? I have tried everything I know any help? Attached is the picture of the errors. And why do I see an error of return value of 'OrderClose' should be checked?
extern int MagicNumber = 12345; extern double lots = 0.10; extern int stopLoss = 1000; extern int takeProfit = 2000; extern int Slippage = 0; void OnTick() { if (TotalNoOfOrders() > 0) { return; double ema = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_CLOSE, 0); double ema2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, 0); double adx = iADX(NULL, 0, 14, PRICE_CLOSE, 0, 0); if ((ema > ema2)&&(adx > 50)) { ResetLastError(); ticket=OrderSend(Symbol(),OP_BUY,NormalizeDouble(lots,2), Ask, Slippage, Ask - stopLoss * Point, Ask + takeProfit * Point, "BossPips" ,MagicNumber,0, clrBlue); if(ticket<=0) { error=GetLastError(); //-- do something for errors .... } else { Print("Buy order succeeded!"); //-- do something for succesful order } } } if ((ema < ema2)&&(adx > 50)) { ResetLastError(); ticket=OrderSend(Symbol(),OP_SELL,NormalizeDouble(lots,2),Bid, Slippage, Bid + stopLoss * Point, Bid - takeProfit * Point, "BossPips" ,MagicNumber,0,clrRed); if(ticket<=0) { error=GetLastError(); //-- do something for errors .... } else { Print("Sell order succeeded!"); //-- do something for succesful order } } { if(OrderType()==OP_BUY) { if((iRSI(NULL,0,14,PRICE_HIGH,0)>70)) //here is your close buy rule { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red); } } else { if(OrderType()==OP_SELL) { if((iRSI(NULL,0,14,PRICE_LOW,0)<30)) // here is your close sell rule { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Red); } } } } } //+------------------------------------------------------------------+ int TotalNoOfOrders() { int cnt=0, total, ticket; total = OrdersTotal(); for(int i=total-1; i>=0; i--) { ticket=OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderType()>=2 || OrderMagicNumber()!=MagicNumber) continue; cnt++; } return(cnt); }
Ok so I applied your code fully even with the modified code for opening trade but now I'm getting these errors? I have tried everything I know any help? Attached is the picture of the errors.
Check again,
1. Where "}" is needed?
if (TotalNoOfOrders() > 0) { return; double ema = i
2. You don't have ticket as global variable.
if ((ema < ema2)&&(adx > 50)) { ResetLastError(); ticket=OrderSend(Symbol(),OP_SELL,NormalizeDouble(lots,2),Bid, Slippage, Bid + stopLoss * Point, Bid - takeProfit * Point, "BossPips" ,MagicNumber,0,clrRed); if(ticket<=0)
int TotalNoOfOrders() { int cnt=0, total, ticket; total = OrdersTotal(); for(int i=total-1; i>=0; i--) { ticket=OrderSelect(i,SELECT_BY
define ticket at above :
extern int takeProfit = 2000; extern int Slippage = 0; //------- int ticket, error; void OnTick() {
int TotalNoOfOrders() { int cnt=0, total; total = OrdersTotal(); for(int i=total-1; i>=0; i--) {
There, that was "a little Help", as you called it...
If you can't get it done, ask for a lot of help, not just a little, or you can please try Freelance here: https://www.mql5.com/en/job

There, that was "a little Help", as you called it...
If you can't get it done, ask for a lot of help, not just a little, or you can please try Freelance here: https://www.mql5.com/en/job
Thanks ͡ᵔ ͜ʖ ͡ᵔ )
Thanks ͡ᵔ ͜ʖ ͡ᵔ )
There, that was "a little Help", as you called it...
If you can't get it done, ask for a lot of help, not just a little, or you can please try Freelance here: https://www.mql5.com/en/job
Well I did mention I'm new to this and yes I did ask for a little help at first because I thought the TotalNoOfOrders was the only issue but then when I applied the code given to me by Yohana I got more errors and now my entry rules is coming up with the undeclared identifier and that wasn't happening before is what I'm saying. So ok yes I do need a lot of help now
Well I did mention I'm new to this and yes I did ask for a little help at first because I thought the TotalNoOfOrders was the only issue but then when I applied the code given to me by Yohana I got more errors and now my entry rules is coming up with the undeclared identifier and that wasn't happening before is what I'm saying. So ok yes I do need a lot of help now
I have sent you first error identification above.
Did you updated it and try again (^̮^)
----
Did you know, work in programming is exciting. But sometimes it can be frustrating if our logic has not got there yet.
Happy coding and never give up.


- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use