Wait for more than one trigger EA

 

Hello,

I would like to build an EA that enter a sell position when the RSI is over 80 and then the MACD Instagram crosses below O.

I have trouble to do 2 things ( I am not an expert at all!):

 

1) I don't know how to write a series of event (i.e. first wait for the RSI to be over 80 and then wait the MACD to cross. Only then enter a sell)

2) I don't know hot to specify the cross below 0 ( I can only state below 0)

 

See below. 

If you can help would be great!

Thank you!

 

 

 

/+------------------------------------------------------------------+
//                        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: 1/8/2017 1:50:03 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=10001;
extern double Lots =0.1;
extern double StopLoss=50;
extern double TakeProfit=50;
extern int TrailingStop=50;
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((iRSI(NULL,0,14,PRICE_CLOSE,0)>80)&&(iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0)<0)) // Here is your open sell 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);
     }
  }
  
  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(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(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);
}

 

You will get a caustic reply from WHRoeder.

There is no point in us offering advise as you had to use an EA builder to write the code. Unless you have a minimal knowledge of coding you will not understand.

Most of us in this sub-forum will not help out when a person asks for help with code produced by an EA builder.

We help people who put in the effort to produce code themselves.

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

  2. // THIS EA CODE HAS BEEN GENERATED USING FOREXEADVISOR STRATEGY BUILDER 0.2
    • We hate EA builder
    • You couldn't be bothered to learn mql4, 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.
    • 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:
      double   pip        = StringFind(_Symbol,"JPY") < 0 ? 0.01 : 0.0001;
      int      slippage   = 3 * int(pip / _Point);
    • 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/reboot.)

  3. Pizzo1976: I don't know how to write a series of event (i.e. first wait for the RSI to be over 80 and then wait the MACD to cross. Only then enter a sell)
    • If the RSI of bar 1 isn't over 80 return from start (wait for a new tick.)
    • If the MACD of bar 1 is below zero and MACD of bar 2 is above zero, it has crossed.

  4.      OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);
         if (OrderMagicNumber()==MagicNumber) result++;
 
whroeder1:
  1. Please edit your post.
    For large amounts of code, attach it

  2. // THIS EA CODE HAS BEEN GENERATED USING FOREXEADVISOR STRATEGY BUILDER 0.2

    • If the RSI of bar 1 isn't over 80 return from start (wait for a new tick.)
    • If the MACD of bar 1 is below zero and MACD of bar 2 is above zero, it has crossed.

  3.      OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);
         if (OrderMagicNumber()==MagicNumber) result++;

thank you both, I understand your comments

regards

 
Pizzo1976:

1) I don't know how to write a series of event (i.e. first wait for the RSI to be over 80 and then wait the MACD to cross. Only then enter a sell)

2) I don't know hot to specify the cross below 0 ( I can only state below 0)

You actually have 3 requirements:

Requirement 1: RSI is > 80 and

Requirement 2: MACD is < 0 and

Requirement 3: MACD was > 0 (or maybe >= 0... your preference)

You have most of the ingredients here already:

if((iRSI(NULL,0,14,PRICE_CLOSE,0)>80)&&(iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0)<0)) // Here is your open sell rule

You're only missing Requirement 3. Here are a couple of hints:

&& means AND (useful to know if you want to add another requirement)

Bars are numbered (indexed), starting at 0 for the current bar. So the previous bar is index 1. You set the index of the bar with the last parameter: 

iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0)

Give it a go, you may be surprised what you can fix yourself!

Reason: