Coding help - page 726

 

Hi Mladen,

I'm trying to code this in MT5, but I'm think that I'm not using the correct implementation,

my idea is to use more indicators, please give me a light... ;-) 

 

I need help to make this modular, because I will work with more indicators (6 to 8), 
this is a sample to understand I'm trying to do..

in this sample:
I put only 3 indicadors.

//global variables
bool m_buy = true;
bool m_sell = true;
enum Signal{
   IN_OUT=0,  //in & out
   IN=1,      //in
   OUT=2,     //out
};

I have a EA with indicators that I want to mix and optimize it in BackTest.

//some sample data for signal for In/Out states only for exemplification
iT_InOut = IN_OUT;  //Itrend usage => In & Out
RSI_InOut = IN_;     //RSI usage =>only IN 
MFI_InOut = OUT_;     //MFI usage =>only OUT
//

//this is the complete sequence IF I USE all signals in+out
//only to show the completly sequence (I will not use it)
m_buy=(m_it00[0]>m_it10[0] && m_it00[0]>m_it01[0] && m_rsi0[0]>m_rsi1[0] && m_mfi0[0]>m_mfi1[0]);
// The green is growing and more than red, RSI is growing, MFI is growing
m_sell=(m_it00[0]<m_it10[0] && m_it00[0]<m_it01[0] && m_rsi0[0]<m_rsi1[0] && m_mfi0[0]<m_mfi1[0]);
// The green falls and less than red, RSI falls, MFI falls


//now the skeleton that I'm trying to make work (in future I will use much more indicators)
               
              if(!PositionSelect(Symbol()))   ///No opened it's first entrance
                 {              
                 
                 if (!iT_InOut==OUT_) //Itrend (only options with IN)
                     {
                     m_buy= (m_buy  && m_it00[0]>m_it10[0] && m_it00[0]>m_it01[0]);
                     m_sell=(m_sell && m_it00[0]<m_it10[0] && m_it00[0]<m_it01[0]);
                     }
                  
                 if (!RSI_InOut==OUT_) //RSI (only options with IN)
                     {
                     m_buy =(m_buy  && m_rsi0[0]>m_rsi1[0]);
                     m_sell=(m_sell && m_rsi0[0]<m_rsi1[0]);
                     }                
                
                 if (!MFI_InOut==OUT_) //MFI (only options with IN)
                     {
                     m_buy =(m_buy  && m_mfi0[0]>m_mfi1[0]);
                     m_sell=(m_sell && m_mfi0[0]<m_mfi1[0]);
                     }                 
                  }
                 
                 ///We have opened order it's EXIT
                 else
                 {
                 //Itrend (only options with EXIT)
                 if (!iT_InOut==IN_)
                     {
                     m_buy =(m_buy  && m_it00[0]>m_it10[0] && m_it00[0]>m_it01[0]);
                     m_sell=(m_sell && m_it00[0]<m_it10[0] && m_it00[0]<m_it01[0]);
                     }
                 //RSI (only options with EXIT)
                 if (!RSI_InOut==IN_)
                     {
                     m_buy =(m_buy  && m_rsi0[0]>m_rsi1[0]);
                     m_sell=(m_sell && m_rsi0[0]<m_rsi1[0]);
                     }                     
                 //MFI (only options with EXIT)
                 if (!MFI_InOut==IN_)
                     {
                     m_buy =(m_buy  && m_mfi0[0]>m_mfi1[0]);
                     m_sell=(m_sell && m_mfi0[0]<m_mfi1[0]);
                     }
                 }
 
baraozemo:

Hi Mladen,

I'm trying to code this in MT5, but I'm think that I'm not using the correct implementation,

my idea is to use more indicators, please give me a light... ;-) 

 

I need help to make this modular, because I will work with more indicators (6 to 8), 
this is a sample to understand I'm trying to do..

in this sample:
I put only 3 indicadors.

//global variables
bool m_buy = true;
bool m_sell = true;
enum Signal{
   IN_OUT=0,  //in & out
   IN=1,      //in
   OUT=2,     //out
};

I have a EA with indicators that I want to mix and optimize it in BackTest.

//some sample data for signal for In/Out states only for exemplification
iT_InOut = IN_OUT;  //Itrend usage => In & Out
RSI_InOut = IN_;     //RSI usage =>only IN 
MFI_InOut = OUT_;     //MFI usage =>only OUT
//

//this is the complete sequence IF I USE all signals in+out
//only to show the completly sequence (I will not use it)
m_buy=(m_it00[0]>m_it10[0] && m_it00[0]>m_it01[0] && m_rsi0[0]>m_rsi1[0] && m_mfi0[0]>m_mfi1[0]);
// The green is growing and more than red, RSI is growing, MFI is growing
m_sell=(m_it00[0]<m_it10[0] && m_it00[0]<m_it01[0] && m_rsi0[0]<m_rsi1[0] && m_mfi0[0]<m_mfi1[0]);
// The green falls and less than red, RSI falls, MFI falls


//now the skeleton that I'm trying to make work (in future I will use much more indicators)
               
              if(!PositionSelect(Symbol()))   ///No opened it's first entrance
                 {              
                 
                 if (!iT_InOut==OUT_) //Itrend (only options with IN)
                     {
                     m_buy= (m_buy  && m_it00[0]>m_it10[0] && m_it00[0]>m_it01[0]);
                     m_sell=(m_sell && m_it00[0]<m_it10[0] && m_it00[0]<m_it01[0]);
                     }
                  
                 if (!RSI_InOut==OUT_) //RSI (only options with IN)
                     {
                     m_buy =(m_buy  && m_rsi0[0]>m_rsi1[0]);
                     m_sell=(m_sell && m_rsi0[0]<m_rsi1[0]);
                     }                
                
                 if (!MFI_InOut==OUT_) //MFI (only options with IN)
                     {
                     m_buy =(m_buy  && m_mfi0[0]>m_mfi1[0]);
                     m_sell=(m_sell && m_mfi0[0]<m_mfi1[0]);
                     }                 
                  }
                 
                 ///We have opened order it's EXIT
                 else
                 {
                 //Itrend (only options with EXIT)
                 if (!iT_InOut==IN_)
                     {
                     m_buy =(m_buy  && m_it00[0]>m_it10[0] && m_it00[0]>m_it01[0]);
                     m_sell=(m_sell && m_it00[0]<m_it10[0] && m_it00[0]<m_it01[0]);
                     }
                 //RSI (only options with EXIT)
                 if (!RSI_InOut==IN_)
                     {
                     m_buy =(m_buy  && m_rsi0[0]>m_rsi1[0]);
                     m_sell=(m_sell && m_rsi0[0]<m_rsi1[0]);
                     }                     
                 //MFI (only options with EXIT)
                 if (!MFI_InOut==IN_)
                     {
                     m_buy =(m_buy  && m_mfi0[0]>m_mfi1[0]);
                     m_sell=(m_sell && m_mfi0[0]<m_mfi1[0]);
                     }
                 }
In that code I don't see the indicator usage at all (and how the values are copied to corresponding arrays)
 

Hello guys,

 

I really need help, i'm building an expert with the waddah attar scalping indicator, the logic is working, all is ok.

Except one thing, as you see in the  backtest screenshot, at each green bar the expert opens a buy, same for the red bars. I want only 1 trade per color change.

What i want is :

INDICATOR TURNS GREEN ---> it opens a buy ---> the buy closes ---> INDICATOR TURNS RED ---> it opens a sell ---> the sell closes ---> repeat

I want only 1 trade per color change.

 

Here is my code : (the same for short) 

//Trading decision.
   bool SendLong = false, SendShort = false;
  
    double clnowsell = iCustom(Symbol(),WAScalpingTimeFrame,"Waddah_Attar_Scalping",IPeriod,P1,P2,1,clbar);
    double clpresell = iCustom(Symbol(),WAScalpingTimeFrame,"Waddah_Attar_Scalping",IPeriod,P1,P2,1,clbar+1);
  
    double clnowbuy = iCustom(Symbol(),WAScalpingTimeFrame,"Waddah_Attar_Scalping",IPeriod,P1,P2,0,clbar);
    double clprebuy = iCustom(Symbol(),WAScalpingTimeFrame,"Waddah_Attar_Scalping",IPeriod,P1,P2,0,clbar+1);

   //Long trade
  
   //Specific system filters
   //if (some condition) SendLong = true;
  
   if (clnowbuy > 0) SendLong = true;

 

Can someone please come with a simple solution, look at the line 1265, the logic comes here.

 

Thanks a lot !

 

 
LittleCaro:

Hello guys,

 

I really need help, i'm building an expert with the waddah attar scalping indicator, the logic is working, all is ok.

Except one thing, as you see in the  backtest screenshot, at each green bar the expert opens a buy, same for the red bars. I want only 1 trade per color change.

What i want is :

INDICATOR TURNS GREEN ---> it opens a buy ---> the buy closes ---> INDICATOR TURNS RED ---> it opens a sell ---> the sell closes ---> repeat

I want only 1 trade per color change.

 

Here is my code : (the same for short) 

//Trading decision.
   bool SendLong = false, SendShort = false;
  
    double clnowsell = iCustom(Symbol(),WAScalpingTimeFrame,"Waddah_Attar_Scalping",IPeriod,P1,P2,1,clbar);
    double clpresell = iCustom(Symbol(),WAScalpingTimeFrame,"Waddah_Attar_Scalping",IPeriod,P1,P2,1,clbar+1);
  
    double clnowbuy = iCustom(Symbol(),WAScalpingTimeFrame,"Waddah_Attar_Scalping",IPeriod,P1,P2,0,clbar);
    double clprebuy = iCustom(Symbol(),WAScalpingTimeFrame,"Waddah_Attar_Scalping",IPeriod,P1,P2,0,clbar+1);

   //Long trade
  
   //Specific system filters
   //if (some condition) SendLong = true;
  
   if (clnowbuy > 0) SendLong = true;

 

Can someone please come with a simple solution, look at the line 1265, the logic comes here.

 

Thanks a lot !

 

Change the condition to

  if (clnowbuy > 0 && clprebuy == 0) SendLong = true;

Same for the shorts

 

Thank you Mladen !

 

Sometimes we get stuck, and we need a fresh look on our work.

 

Thanks again ! 

 
LittleCaro:

Thank you Mladen !

 

Sometimes we get stuck, and we need a fresh look on our work.

 

Thanks again ! 

Bonjour,

Ravi de voir une Française, tiens moi au courant des tes résultats avec waddah attar ;)

Green pips

 

Hi guys I'm trying to edit an ema-rsi indicator that can show an up or down arrow when 4 ema cross happens and rsi is > or < 50.

My problem is that theese arrows don't refresh for every tick once they appeared, I need to change timeframe if I want to check if conditions are still good to show arrow. Can you tell me where is the problem ? I post the code.

Thank you 

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red

#property indicator_width1 4
#property indicator_width2 4

double CrossUp[];
double CrossDown[];
extern int FasterEMA1     = 6;
extern int SlowerEMA1     = 12;
extern int FasterEMA2     = 7;
extern int SlowerEMA2     = 14;
extern int RSInowPeriod   = 6;
extern int barsBack       = 2000;
extern bool AlertsMessage = true;
extern bool AlertsSound   = true;
extern bool debug         = false;
extern double K           = 1.0 ;

bool EMACrossedUp = false;
bool RSICrossedUp = false;
bool EMACrossedDown = false;
bool RSICrossedDown = false;
int SignalLabeled = 0// 0: initial state; 1: up; 2: down.
int upalert=false,downalert=false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0DRAW_ARROWEMPTY);
   SetIndexArrow(0241);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1DRAW_ARROWEMPTY);
   SetIndexArrow(1242);
   SetIndexBuffer(1, CrossDown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int limit, i, counter;
   double fasterEMA1now, slowerEMA1now, fasterEMA1previous, slowerEMA1previous, fasterEMA2now, slowerEMA2now, fasterEMA2previous, slowerEMA2previous;
   double RSInow;
   double Range, AvgRange;

   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=MathMin(Bars-counted_bars,barsBack);
   
   for(i = limit; i>=0; i--) {
       
      counter=i;
      Range=0;
      AvgRange=0;
      for (counter=i ;counter<=i+9;counter++)
      {
        AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10;

      fasterEMA1now = iMA(NULL0, FasterEMA1, 0MODE_EMAPRICE_CLOSE, i);
      fasterEMA1previous = iMA(NULL0, FasterEMA1, 0MODE_EMAPRICE_CLOSE, i+1);
      
      fasterEMA2now = iMA(NULL0, FasterEMA2, 0MODE_EMAPRICE_CLOSE, i);
      fasterEMA2previous = iMA(NULL0, FasterEMA2, 0MODE_EMAPRICE_CLOSE, i+1);
      
      slowerEMA1now = iMA(NULL0, SlowerEMA1, 0MODE_EMAPRICE_CLOSE, i);
      slowerEMA1previous = iMA(NULL0, SlowerEMA1, 0MODE_EMAPRICE_CLOSE, i+1);
      
      slowerEMA2now = iMA(NULL0, SlowerEMA2, 0MODE_EMAPRICE_CLOSE, i);
      slowerEMA2previous = iMA(NULL0, SlowerEMA2, 0MODE_EMAPRICE_CLOSE, i+1);
      
      RSInow=iRSI(NULL,0,RSInowPeriod,PRICE_CLOSE,i);
      
      if (RSInow > 50) {
         if (debug)Print(TimeToStr(Time[i],TIME_DATE)+TimeToStr(Time[i],TIME_SECONDS)+" RSI UP ");
         RSICrossedUp = true;
         RSICrossedDown = false;
      }
      
      if (RSInow < 50) {
         if (debug)Print(TimeToStr(Time[i],TIME_DATE)+TimeToStr(Time[i],TIME_SECONDS)+" RSI DOWN ");
         RSICrossedUp = false;
         RSICrossedDown = true;
      }
      
      if ((fasterEMA1now >= slowerEMA1now) && (fasterEMA1previous < slowerEMA1previous) && (fasterEMA2now >= slowerEMA2now) && (fasterEMA2previous < slowerEMA2previous) ) {
         if (debug)Print(TimeToStr(Time[i],TIME_DATE)+TimeToStr(Time[i],TIME_SECONDS)+" EMA UP ");
         EMACrossedUp = true;
         EMACrossedDown = false;
      }

      if ((fasterEMA1now <= slowerEMA1now) && (fasterEMA1previous > slowerEMA1previous) && (fasterEMA2now <= slowerEMA2now) && (fasterEMA2previous > slowerEMA2previous)) {
         if (debug)Print(TimeToStr(Time[i],TIME_DATE)+TimeToStr(Time[i],TIME_SECONDS)+" EMA DOWN ");
         EMACrossedUp = false;
         EMACrossedDown = true;
      }

      if ((EMACrossedUp == true) && (RSICrossedUp == true) && (SignalLabeled != 1)) {
         CrossUp[i] = Low[i] - K*Range;
         if (debug)Print(TimeToStr(Time[i],TIME_DATE)+TimeToStr(Time[i],TIME_SECONDS)+" SIGNAL UP ");
         if(i<=2 && AlertsMessage && !upalert)
           {
            Alert (Symbol()," ",Period(),"M  BUY SIGNAL ");
            //SendMail("EMA Cross Up on "+Symbol(),"");
            upalert=true;
            downalert=false;
           }           
         if(i<=2 && AlertsSound && !upalert)
           {
            PlaySound("alert.wav");
            upalert=true;
            downalert=false;
           }
         SignalLabeled = 1;
      }

      else if ((EMACrossedDown == true) && (RSICrossedDown == true) && (SignalLabeled != 2)) {
         CrossDown[i] = High[i] + K*Range;
         if (debug)Print(TimeToStr(Time[i],TIME_DATE)+TimeToStr(Time[i],TIME_SECONDS)+" SIGNAL DOWN ");
         if(i<=2 && AlertsMessage && !downalert)
           {
            Alert (Symbol()," ",Period(),"M  SELL SIGNAL ");
            //SendMail("EMA Cross Down on "+Symbol(),"");
            downalert=true;
            upalert=false;
           }
         if(i<=2 && AlertsSound && !downalert)
           {
            PlaySound("alert.wav");
            downalert=true;
            upalert=false;
           }
         SignalLabeled = 2;
      }
   }
   return(0);
}
//end
 
mladen:
In that code I don't see the indicator usage at all (and how the values are copied to corresponding arrays)

Hi Mladen,

 

Here is the "sample-ea-modular.mq5" with some code inside... and with the interface that have the Idea that I want.

I'm trying to make it modular , the idea is to optimize separately in/out of each indicator..

If I can make this with the "sample-ea-modular.mq5" I will change the real EA.

the real base is the Ea-sample.mq5. (i'm posting only to you see all the indicators)

Files:
 
oguz:

Dear @mladen,

If you are able to resolve the error mentioned below, please be very pleased.

Thank you... 

 

 "Question : There's a warning when I attched to chart and use auto gmt offset.


Warning as this: Warning, use manual GMToffsets only on backtest.

Automatic GMT offset calculation works only on live/demo trading
and should be set as FALSE for backtests - strategy testing.

Is this normal? Or should I turn auto gmt offset to false? 

Answer : I turned AutoGMTOffset off and set GMT offset manually. No more warning message and seems to be working just fine on demo. Go figure. Maybe it's a bug. Oh yeah, it's definitely a bug. 

I looked at the code and an "else" operation is either omitted or misplaced. The message should only be issued if UseAutoGMTOffset is set to FALSE.

So, ignore this message and be happy. Everything is working as (ahem) designed." 

oguz

As usual (you already know that) I don't comment on decompiled code, but I see that you are on a right track : if it works (the option), use it. If it doesn't then don't. As far as I see that is just a message (not an error) so ...

 

Dear @mladen,

If you are able to resolve the error mentioned below, please be very pleased.

Thank you... 

 

 "Question : There's a warning when I attched to chart and use auto gmt offset.


Warning as this: Warning, use manual GMToffsets only on backtest.

Automatic GMT offset calculation works only on live/demo trading
and should be set as FALSE for backtests - strategy testing.

Is this normal? Or should I turn auto gmt offset to false? 

Answer : I turned AutoGMTOffset off and set GMT offset manually. No more warning message and seems to be working just fine on demo. Go figure. Maybe it's a bug. Oh yeah, it's definitely a bug. 

I looked at the code and an "else" operation is either omitted or misplaced. The message should only be issued if UseAutoGMTOffset is set to FALSE.

So, ignore this message and be happy. Everything is working as (ahem) designed." 
Reason: