Download MetaTrader 5

Need help on this EA............. Please.

To add comments, please log in or register
rajibculaw
12
rajibculaw  

It is an EMA20 based buy sell EA. But it opens positions frequently. I need to correct it. One position (per pair per time frame) only. And they must follow the TP/SL and TSL rules. Pls help.

//+------------------------------------------------------------------+
//                        DO NOT DELETE THIS HEADER
//             DELETING THIS HEADER IS COPYRIGHT INFRIGMENT
//
//                   Copyright ©2011, ForexEAdvisor.com
//                 ForexEAdvisor Strategy Builder version 0.2
//                        http://www.ForexEAdvisor.com
//
// THIS EA CODE HAS BEEN GENERATED USING FOREXEADVISOR STRATEGY BUILDER 0.2
// on: 9/12/2017 4:53:37 PM
// Disclaimer: This EA is provided to you "AS-IS", and ForexEAdvisor disclaims any warranty
// or liability obligations to you of any kind.
// UNDER NO CIRCUMSTANCES WILL FOREXEADVISOR BE LIABLE TO YOU, OR ANY OTHER PERSON OR ENTITY,
// FOR ANY LOSS OF USE, REVENUE OR PROFIT, LOST OR DAMAGED DATA, OR OTHER COMMERCIAL OR
// ECONOMIC LOSS OR FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, STATUTORY, PUNITIVE,
// EXEMPLARY OR CONSEQUENTIAL DAMAGES WHATSOEVER RELATED TO YOUR USE OF THIS EA OR
// FOREXEADVISOR STRATEGY BUILDER    
// Because software is inherently complex and may not be completely free of errors, you are
// advised to verify this EA. Before using this EA, please read the ForexEAdvisor Strategy Builder
// license for a complete understanding of ForexEAdvisor' disclaimers. 
// USE THIS EA AT YOUR OWN RISK.
// 
// Before adding this expert advisor to a chart, make sure there are NO
// open positions.
//                      DO NOT DELETE THIS HEADER
//             DELETING THIS HEADER IS COPYRIGHT INFRIGMENT
//+------------------------------------------------------------------+


extern int MagicNumber=10005;
extern double Lots =0.05;
extern double StopLoss=30;
extern double TakeProfit=100;
extern int TrailingStop=10;
extern int Slippage=3;
//+------------------------------------------------------------------+
//    expert start function
//+------------------------------------------------------------------+
int start()
{
  double MyPoint=Point;
  if(Digits==3 || Digits==5) MyPoint=Point*10;
 
  double TheStopLoss=0;
  double TheTakeProfit=0;
  if( TotalOrdersCount()==0 )
  {
     int result=0;
     if((Low[1]>iMA(NULL,0,20,1,MODE_EMA,PRICE_CLOSE,1))&&(Open[1]>Close[1])) // Here is your open buy rule
     {
        result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue);
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
        return(0);
     }
     if((High[1]<iMA(NULL,0,20,1,MODE_EMA,PRICE_CLOSE,1))&&(Close[1]<High[1])) // Here is your open Sell rule
     {
        result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Red);
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
        return(0);
     }
  }
 
  for(int cnt=0;cnt<OrdersTotal();cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&  
         OrderSymbol()==Symbol() &&
         OrderMagicNumber()==MagicNumber
         ) 
        {
         if(OrderType()==OP_BUY) 
           {
              if((High[1]<iMA(NULL,0,20,1,MODE_EMA,PRICE_CLOSE,1))&&(Close[1]<High[1])) //here is your close buy rule
              {
                   OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
              }
            if(TrailingStop>0) 
              {                
               if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else
           {
                if((Low[1]>iMA(NULL,0,20,1,MODE_EMA,PRICE_CLOSE,1))&&(Open[1]>Close[1])) // here is your close sell rule
                {
                   OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
                }
            if(TrailingStop>0) 
              {                
               if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
   return(0);
}

int TotalOrdersCount()
{
  int result=0;
  for(int i=0;i<OrdersTotal();i++)
  {
     OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);
     if (OrderMagicNumber()==MagicNumber) result++;

   }
  return (result);
}

Sergey Golubev
Moderator
98199
Sergey Golubev  
Fernando Carreiro
2839
Fernando Carreiro  
rajibculaw: It is an EMA20 based buy sell EA. But it opens positions frequently. I need to correct it. One position (per pair per time frame) only. And they must follow the TP/SL and TSL rules. Pls help.

Your code was "generated" by a machine, and not coded by you! Therefore it is safe to assume that you don't know how to code and any advice we give will not be understood due to lack of knowledge and skill in the matter.

So, you can either take some time to learn to code yourself, or if you are in a hurry, just go to the Freelance section and place a job request to fix your EA or better still, to code a new one to your exact specifications.

whroeder1
15902
whroeder1  
  • We hate EA builder, fxDreema, EATree, etc.
  • You couldn't be bothered to learn MQL4/5, therefor there is no common language for us to communicate.
  • There are only two choices: learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem, but we are not going to debug your hundreds lines of code. You are on your own and will spend much longer than had you learned the language up front.
  • EA builder makes bad code counting up while closing multiple orders.
  • EA builder makes bad code Bars is unreliable (max bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum
  • EA builder makes bad code, not adjusting for 4/5 digit brokers, TP/SL and slippage.
  • EA builder makes bad code, not adjusting for ECN brokers.
  • EA builder makes bad code, not checking return codes.
  • EATree uses objects on chart to save values - not persistent storage (files or GV+Flush.) No recovery (crash/power failure.)
Alain Verleyen
Moderator
33256
Alain Verleyen  
whroeder1:
  • We hate EA builder, fxDreema, EATree, etc.
  • You couldn't be bothered to learn MQL4/5, therefor there is no common language for us to communicate.
  • There are only two choices: learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem, but we are not going to debug your hundreds lines of code. You are on your own and will spend much longer than had you learned the language up front.
  • EA builder makes bad code counting up while closing multiple orders.
  • EA builder makes bad code Bars is unreliable (max bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum
  • EA builder makes bad code, not adjusting for 4/5 digit brokers, TP/SL and slippage.
  • EA builder makes bad code, not adjusting for ECN brokers.
  • EA builder makes bad code, not checking return codes.
  • EATree uses objects on chart to save values - not persistent storage (files or GV+Flush.) No recovery (crash/power failure.)

I already asked you to change this. It's not a good way to communicate with people.

Forum on trading, automated trading systems and testing trading strategies

EA Places Too Many Trades When Signal Gets Triggered

Alain Verleyen, 2017.09.04 17:32

I will ask you, please, to change the tone of your standard reply about EA builder, "hate", "bothered to learn", "no common language", etc...this is way to offensive and aggressive.

Thanks by advance.


Sarfraz
160
Sarfraz  

Your Code is ok

Marco vd Heijden
Moderator
5489
Marco vd Heijden  

If your code triggers too many orders you can limit the total amount of allowed orders, or when it happens because price is close or on top of the rule value you can add a x number of trades per bar function so that it will only place one trade every 1 hour(H1) or one every 4 hours(H4) and etc.

To add comments, please log in or register