A control to not repeat the operation - page 2

 

Ok, my fault. Try to explain better.

 

I want the ea to send me an email whenever those conditions are met (rsi> 50 on 4 tf + heiken ashi green on the same tf and the way around for sell). But i don't want to have tons of email saying the same thing without any change.  

For example: rsiD >50 and RsiW>50 it should send me an email. But after 1 hour if conditions are the same i don't want any message.

In the next day, if rsiD<50 and RSiw>50 no messages but if it goes up again and turns RsiD>50 and RsiW>50 i want a message.

 

THe idea behind signal as a bool is the conditions could be ok for email to be sent or not.

 

Bool res was a part of an ea which sends email. I thought it would be necessary.

 

Thanks man, sorry for misunderstanding.  

 

Many thanks WHRoeder.

 

Is ok this way?

 

//Main Code

if (IsNewBar())   // NewBar yes or not

                          
if ((Rsi1>50 && Rsi4>50 && RsiD>50 && RsiW>50 && CWHH>OWHH && CDHH>ODHH && C4HH>O4HH && C1HH>O1HH && LastSignal!=Buy) 
   {
                                 //MT4 SendMail function   
      bool res = SendMail("MT4: OrderSent", +"Instrument: " + Symbol()                  + "\n"
                                            +"BUY" + Symbol()                           + "\n"
                                            +"RSI H1: " + string(var3)                  + "\n"
                                            +"RSI H4: " + string(var4)                  + "\n"
                                            +"RSI D1: " + string(var5)                  + "\n"
                                            +"RSI W1: " + string(var6)                  + "\n"
                                            +"Heiken Ashi W1C: " + string(CWHH)         + "\n"
                                            +"Heiken Ashi W1O: " + string(OWHH)         + "\n"
                                            +"Heiken Ashi D1C: " + string(CDHH)         + "\n"
                                            +"Heiken Ashi D1O: " + string(ODHH)         + "\n"
                                            +"Heiken Ashi 4HC: " + string(C4HH)         + "\n"
                                            +"Heiken Ashi 4HO: " + string(O4HH)         + "\n"
                                            +"Heiken Ashi 1HC: " + string(C1HH)         + "\n"
                                            +"Heiken Ashi 1HO: " + string(O1HH)         + "\n"
                                            );
     
 
     LastSignal=Buy;
                                
  
                             }
else if (Rsi1<50 && Rsi4<50 && RsiD<50 && RsiW<50 && CWHH<OWHH && CDHH<ODHH && C4HH<O4HH && C1HH<O1HH && LastSignal!=Sell){

 //MT4 SendMail function
           
      bool res = SendMail("MT4: OrderSent", +"Instrument: " + Symbol()                  + "\n"
                                            +"SELL" + Symbol()                           + "\n"
                                            +"RSI H1: " + string(var3)                  + "\n"
                                            +"RSI H4: " + string(var4)                  + "\n"
                                            +"RSI D1: " + string(var5)                  + "\n"
                                            +"RSI W1: " + string(var6)                  + "\n"
                                            +"Heiken Ashi W1C: " + string(CWHH)         + "\n"
                                            +"Heiken Ashi W1O: " + string(OWHH)         + "\n"
                                            +"Heiken Ashi D1C: " + string(CDHH)         + "\n"
                                            +"Heiken Ashi D1O: " + string(ODHH)         + "\n"
                                            +"Heiken Ashi 4HC: " + string(C4HH)         + "\n"
                                            +"Heiken Ashi 4HO: " + string(O4HH)         + "\n"
                                            +"Heiken Ashi 1HC: " + string(C1HH)         + "\n"
                                            +"Heiken Ashi 1HO: " + string(O1HH)         + "\n"
                                            );
    LastSignal=Sell;

}
        }
           
return(0);
                
        }

bool IsNewBar()
{
datetime curbar= Time[0];

if(lastbar!=curbar)
{
lastbar=curbar;
return(true);
}
return(false);
}

      
 

I tried to compile this

 

// External variables

extern int MagicNumber = 23310;
static datetime lastbar;
enum signals ={Buy, Sell, NA};
static signals LastSignal = NA;




// Start function
void init()
{
lastbar=Time[1];
return(0);
}

int start()
        { 
        
double Rsi1=iRSI(Symbol(), PERIOD_H1, 10, PRICE_CLOSE,0 );
double Rsi4=iRSI(Symbol(), PERIOD_H4, 10, PRICE_CLOSE,0 );
double RsiD=iRSI(Symbol(), PERIOD_D1, 10, PRICE_CLOSE,0 );
double RsiW=iRSI(Symbol(), PERIOD_W1, 10, PRICE_CLOSE,0 );

double OWHH = iCustom(Symbol(),PERIOD_D1,"Heiken Ashi",Red,White,Red,White,2,1); //Open WEEKLY
double CWHH = iCustom(Symbol(),PERIOD_D1,"Heiken Ashi",Red,White,Red,White,3,1); //Close WEEKLY
double ODHH = iCustom(Symbol(),PERIOD_D1,"Heiken Ashi",Red,White,Red,White,2,1); //Open daily
double CDHH = iCustom(Symbol(),PERIOD_D1,"Heiken Ashi",Red,White,Red,White,3,1); //Close daily
double O4HH = iCustom(Symbol(),PERIOD_H4,"Heiken Ashi",Red,White,Red,White,2,1); //Open4h
double C4HH = iCustom(Symbol(),PERIOD_H4,"Heiken Ashi",Red,White,Red,White,3,1); //Close 4h
double O1HH = iCustom(Symbol(),PERIOD_H1,"Heiken Ashi",Red,White,Red,White,2,1); //Open1H
double C1HH = iCustom(Symbol(),PERIOD_H1,"Heiken Ashi",Red,White,Red,White,3,1); //Close 1H

//Main Code

if (IsNewBar()){   // NewBar yes or not

                          
if (Rsi1>50 && Rsi4>50 && RsiD>50 && RsiW>50 && CWHH>OWHH && CDHH>ODHH && C4HH>O4HH && C1HH>O1HH && LastSignal!=Buy) 
   {
                                 //MT4 SendMail function   
      bool res = SendMail("MT4: OrderSent", +"Instrument: " + Symbol()                  + "\n"
                                            +"BUY" + Symbol()                           + "\n"
                                            +"RSI H1: " + string(Rsi1)                  + "\n"
                                            +"RSI H4: " + string(Rsi4)                  + "\n"
                                            +"RSI D1: " + string(RsiD)                  + "\n"
                                            +"RSI W1: " + string(RsiW)                  + "\n"
                                            +"Heiken Ashi W1C: " + string(CWHH)         + "\n"
                                            +"Heiken Ashi W1O: " + string(OWHH)         + "\n"
                                            +"Heiken Ashi D1C: " + string(CDHH)         + "\n"
                                            +"Heiken Ashi D1O: " + string(ODHH)         + "\n"
                                            +"Heiken Ashi 4HC: " + string(C4HH)         + "\n"
                                            +"Heiken Ashi 4HO: " + string(O4HH)         + "\n"
                                            +"Heiken Ashi 1HC: " + string(C1HH)         + "\n"
                                            +"Heiken Ashi 1HO: " + string(O1HH)         + "\n"
                                            );
     
 
     LastSignal=Buy;
                                
  
                             }
else if (Rsi1<50 && Rsi4<50 && RsiD<50 && RsiW<50 && CWHH<OWHH && CDHH<ODHH && C4HH<O4HH && C1HH<O1HH && LastSignal!=Sell){

 //MT4 SendMail function
           
      bool res = SendMail("MT4: OrderSent", +"Instrument: " + Symbol()                  + "\n"
                                            +"SELL" + Symbol()                           + "\n"
                                            +"RSI H1: " + string(Rsi1)                  + "\n"
                                            +"RSI H4: " + string(Rsi4)                  + "\n"
                                            +"RSI D1: " + string(RsiD)                  + "\n"
                                            +"RSI W1: " + string(RsiW)                  + "\n"
                                            +"Heiken Ashi W1C: " + string(CWHH)         + "\n"
                                            +"Heiken Ashi W1O: " + string(OWHH)         + "\n"
                                            +"Heiken Ashi D1C: " + string(CDHH)         + "\n"
                                            +"Heiken Ashi D1O: " + string(ODHH)         + "\n"
                                            +"Heiken Ashi 4HC: " + string(C4HH)         + "\n"
                                            +"Heiken Ashi 4HO: " + string(O4HH)         + "\n"
                                            +"Heiken Ashi 1HC: " + string(C1HH)         + "\n"
                                            +"Heiken Ashi 1HO: " + string(O1HH)         + "\n"
                                            );
    LastSignal=Sell;

}
        }
           
return(0);
                
        }

bool IsNewBar()
{
datetime curbar= Time[0];

if(lastbar!=curbar)
{
lastbar=curbar;
return(true);
}
return(false);
}

These are the errors... anyone knows why? except the last one... 

'=' - '{' beginning bracket expected AlertRsiEA.mq4 6 14

'signals' - declaration without type AlertRsiEA.mq4 7 8

'void' function returns a value AlertRsiEA.mq4 16 1

'LastSignal' - undeclared identifier AlertRsiEA.mq4 41 101

'Buy' - undeclared identifier AlertRsiEA.mq4 41 113

'Sell' - undeclared identifier AlertRsiEA.mq4 65 118

'res' - variable already defined AlertRsiEA.mq4 69 12

 
enum signals ={Buy, Sell, NA};

 to

enum signals {Buy, Sell, NA};
 

Many thanks to everyone guys. I compiled successfully and next week i'll test it, 

 

Hope that works.  

 

If anyone wanna help more, i can't make this ea open in backtest any order. It is the indicator built previously trying to open positions on its own. Is that normal?

 

#define SIGNAL_NONE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4

#property copyright "Expert Advisor Builder"
#property link      "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"

extern int MagicNumber = 0;
extern bool SignalMail = False;
extern bool EachTickMode = True;
extern double Lots = 0.01;
extern int Slippage = 3;
extern bool UseStopLoss = True;
extern int StopLoss = 25;
extern bool UseTakeProfit = False;
extern int TakeProfit = 60;
extern bool UseTrailingStop = False;
extern int TrailingStop = 30;

int BarCount;
int Current;
bool TickCheck = False;
static datetime lastbar;
bool SignAlreadySent=False;


double var3=iRSI(Symbol(), PERIOD_H1, 10, PRICE_CLOSE,0 );
double var4=iRSI(Symbol(), PERIOD_H4, 10, PRICE_CLOSE,0 );
double var5=iRSI(Symbol(), PERIOD_D1, 10, PRICE_CLOSE,0 );
double var6=iRSI(Symbol(), PERIOD_W1, 10, PRICE_CLOSE,0 );

double OWHH = iCustom(Symbol(),PERIOD_D1,"Heiken Ashi",Red,White,Red,White,2,1); //Open WEEKLY
double CWHH = iCustom(Symbol(),PERIOD_D1,"Heiken Ashi",Red,White,Red,White,3,1); //Close WEEKLY
double ODHH = iCustom(Symbol(),PERIOD_D1,"Heiken Ashi",Red,White,Red,White,2,1); //Open daily
double CDHH = iCustom(Symbol(),PERIOD_D1,"Heiken Ashi",Red,White,Red,White,3,1); //Close daily
double O4HH = iCustom(Symbol(),PERIOD_H4,"Heiken Ashi",Red,White,Red,White,2,1); //Open4h
double C4HH = iCustom(Symbol(),PERIOD_H4,"Heiken Ashi",Red,White,Red,White,3,1); //Close 4h
double O1HH = iCustom(Symbol(),PERIOD_H1,"Heiken Ashi",Red,White,Red,White,2,1); //Open1H
double C1HH = iCustom(Symbol(),PERIOD_H1,"Heiken Ashi",Red,White,Red,White,3,1); //Close 1H


// Long
bool buy_condition_3 = iRSI(Symbol(), PERIOD_H1, 10, PRICE_CLOSE,0 )  >  50  ;
bool buy_condition_4 = iRSI(Symbol(), PERIOD_H4, 10, PRICE_CLOSE, 0)  >  50  ;
bool buy_condition_5 = iRSI(Symbol(), PERIOD_D1, 10, PRICE_CLOSE, 0)  >  50  ;
bool buy_condition_6 = iRSI(Symbol(), PERIOD_W1, 10, PRICE_CLOSE, 0)  >  50  ;


bool sell_condition_3 = iRSI(Symbol(), PERIOD_H1, 10, PRICE_CLOSE,0 )  <  50  ;
bool sell_condition_4 = iRSI(Symbol(), PERIOD_H4, 10, PRICE_CLOSE, 0)  <  50  ;
bool sell_condition_5 = iRSI(Symbol(), PERIOD_D1, 10, PRICE_CLOSE, 0)  <  50  ;
bool sell_condition_6 = iRSI(Symbol(), PERIOD_W1, 10, PRICE_CLOSE, 0)  <  50  ;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init() {
   BarCount = Bars;
   lastbar=Time[1];
   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                                                   |
   //+------------------------------------------------------------------+






   
   //+------------------------------------------------------------------+
   //| Variable End                                                     |
   //+------------------------------------------------------------------+

   //Check position
  

   for (int i = 0; i < Total; i ++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
         
         if(OrderType() == OP_BUY) {
            //Close

            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Buy)                                           |
            //+------------------------------------------------------------------+

            

            //+------------------------------------------------------------------+
            //| Signal End(Exit Buy)                                             |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
               if (!EachTickMode) BarCount = Bars;
               
               continue;
            }
            //Trailing stop
            if(UseTrailingStop && 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)                                          |
            //+------------------------------------------------------------------+

            

            //+------------------------------------------------------------------+
            //| Signal End(Exit Sell)                                            |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
               if (!EachTickMode) BarCount = Bars;
               
               continue;
            }
            //Trailing stop
            if(UseTrailingStop && 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 (IsNewBar() && SignAlreadySent==False){
   if (buy_condition_3  &&  buy_condition_4  &&  buy_condition_5  &&  buy_condition_6 && CWHH>OWHH && CDHH>ODHH && C4HH>O4HH && C1HH>O1HH) {
   Order = SIGNAL_BUY;
   SignAlreadySent=True;}

   if (sell_condition_3 && sell_condition_4 && sell_condition_5 && sell_condition_6 && CWHH<OWHH && CDHH<ODHH && C4HH<O4HH && C1HH<O1HH) {
   Order = SIGNAL_SELL;
   SignAlreadySent=True;}
   SignAlreadySent=False;
   }


   //+------------------------------------------------------------------+
   //| Signal End                                                       |
   //+------------------------------------------------------------------+

   //Buy
   if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      
         //Check free margin
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }

         if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) 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)))) {
     
         //Check free margin
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }

         if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) 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);

}
//+------------------------------------------------------------------+
bool IsNewBar()
{
datetime curbar= Time[0];

if(lastbar!=curbar)
{
lastbar=curbar;
return(true);
}
return(false);
}
 
  1. double OWHH = iCustom(Symbol(),PERIOD_D1,"Heiken Ashi",Red,White,Red,White,2,1); //Open WEEKLY
    double CWHH = iCustom(Symbol(),PERIOD_D1,"Heiken Ashi",Red,White,Red,White,3,1); //Close WEEKLY
    

  2.       OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
    
    Check your return codes (OrderSelect, OrderSend and OrderModify) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  3.   for (int i = 0; i < Total; i ++) {
    
    You must count down when closing/deleting in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum
  4. double var6=iRSI(Symbol(), PERIOD_W1, 10, PRICE_CLOSE,0 );
    
    double OWHH = iCustom(Symbol(),PERIOD_D1,"Heiken Ashi",Red,White,Red,White,2,1); //Open WEEKLY
    :
    double C1HH = iCustom(Symbol(),PERIOD_H1,"Heiken Ashi",Red,White,Red,White,3,1); //Close 1H
    
    
    bool buy_condition_3 = iRSI(Symbol(), PERIOD_H1, 10, PRICE_CLOSE,0 )  >  50  ;
    :
    bool buy_condition_6 = iRSI(Symbol(), PERIOD_W1, 10, PRICE_CLOSE, 0)  >  50  ;
    
    
    bool sell_condition_3 = iRSI(Symbol(), PERIOD_H1, 10, PRICE_CLOSE,0 )  <  50  ;
    :
    These globals are constant. If you want them to update you must assign values to them in start().
 

WHRoeder:

 

These globals are constant. If you want them to update you must assign values to them in start().
Lemming has been told this twice already, yet continues to make the same mistake
 

Thanks again... 

Wonderful. Ok Gum i got it now:)  

Reason: