Help Please!

 

Please I need help on this for my EA:

double RSI_Prev = iRSI(NULL,0,6,PRICE_CLOSE,2);

double RSI_Curr = iRSI(NULL,0,6,PRICE_CLOSE,1);

double MA_RSI2 = iMAOnArray(RSI_Prev,0,6,MODE_LWMA,RSI_Prev,2);

double MA_RSI1 = iMAOnArray(RSI_Curr,0,6,MODE_LWMA,RSI_Curr,1);

the comments on tester says: 2013.01.18 00:20 MA+RSI EURUSD,Daily: first parameter for iMAOnArray indicator must be an array

I want the MA to read the value of RSI as its own price.

help appreciated.

Thanks.

 
oladapolaleye:

Please I need help on this for my EA:

double RSI_Prev = iRSI(NULL,0,6,PRICE_CLOSE,2);

double RSI_Curr = iRSI(NULL,0,6,PRICE_CLOSE,1);

double MA_RSI2 = iMAOnArray(RSI_Prev,0,6,MODE_LWMA,RSI_Prev,2);

double MA_RSI1 = iMAOnArray(RSI_Curr,0,6,MODE_LWMA,RSI_Curr,1);

the comments on tester says: 2013.01.18 00:20 MA+RSI EURUSD,Daily: first parameter for iMAOnArray indicator must be an array

I want the MA to read the value of RSI as its own price.

So save the RSI values for the bars into an Array and use the Array in the iMAOnArray() call . . . you can't have a MA when you only have one RSI value can you ?

This thread may help . . . https://www.mql5.com/en/forum/143479

 

RaptorUK, thanks for your help. I read through the thread, its an indicator.

Please check the attached code if am on the way.

Thanks.

Files:
mairsi.mq4  6 kb
 
oladapolaleye:

RaptorUK, thanks for your help. I read through the thread, its an indicator.

Please check the attached code if am on the way.

Thanks.

I've had a very quick look, you seem to be in the right ballpark.


I don't use technical Indicators so I don't do much Indicator coding but I would have coded an indicator to do the MA on the RSI and then used iCustom() in the EA to get the Indicator buffer data. This has an advantage that the Indicator can be tested visually and confirmed to be doing what you want, that is not so easy when it is built into an EA.

 


RaptorUK:

I've had a very quick look, you seem to be in the right ballpark.


I don't use technical Indicators so I don't do much Indicator coding but I would have coded an indicator to do the MA on the RSI and then used iCustom() in the EA to get the Indicator buffer data. This has an advantage that the Indicator can be tested visually and confirmed to be doing what you want, that is not so easy when it is built into an EA.

Thanks but please I need to go forward from here. What else?

Thanks.

 
oladapolaleye:

Thanks but please I need to go forward from here. What else?

Test your code, find out where it is wrong . . . coding the RSI + MA part as an Indicator would make that easier but you can still do it with what you have so far, you need to debug by adding Print() statements, find out what is wrong and fix it.

Please edit your post above to use the SRC button. I have deleted the code you posted as you have refused to edit it using the SRC button.

 
RaptorUK:

Test your code, find out where it is wrong . . . coding the RSI + MA part as an Indicator would make that easier but you can still do it with what you have so far, you need to debug by adding Print() statements, find out what is wrong and fix it.

Please edit your post above to use the SRC button. I have deleted the code you posted as you have refused to edit it using the SRC button.


I searched the code base and I got this indicator to use:

//+------------------------------------------------------------------+
//|                                                 RSI+MA+LABEL.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//|                                           Modified LHC 28.01.2009|
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_separate_window

#property indicator_buffers 2
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_style2 STYLE_SOLID
#property indicator_level1 30
#property indicator_level2 50
#property indicator_level3 70
#property indicator_levelcolor DimGray



//--- input parameters
extern int RSIPeriod = 6;
extern int MAofRSI   = 6; 
extern int MA_method = 3; //Mode LWMA

//--- buffers
double RSIBuffer[];
double MAofRSIBuffer[];


color tColor;
color tColor1;
color tColor3;
color tColor4;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   
//--- 2 buffers used for counting.
   IndicatorBuffers(2);
   SetIndexBuffer(0,RSIBuffer);
   SetIndexBuffer(1,MAofRSIBuffer);
  
//--- indicator line
   SetIndexDrawBegin(0,RSIPeriod);
   SetIndexDrawBegin(1,RSIPeriod);
  
//--- name for DataWindow and indicator subwindow label
   IndicatorShortName("RSI("+RSIPeriod+")");
   SetIndexLabel(0,"RSI("+RSIPeriod+")");
   SetIndexLabel(1,"MA("+MAofRSI+")");
   return(0);
  }
  
//+------------------------------------------------------------------+
//| Relative Strength Index                                          |
//+------------------------------------------------------------------+
int start()
  {
   int i;
   int limit;
   int counted_bars=IndicatorCounted();
   
   //---- check for possible errors
   if(counted_bars<0) return(-1);
   
   //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   //--- main loops 1 and 2
   for(i=0; i < limit; i++)
      {
        RSIBuffer[i]=iRSI(Symbol(),0,RSIPeriod,PRICE_CLOSE,i);
      }
  
   for(i=0; i < limit; i++)
      {
        MAofRSIBuffer[i]=iMAOnArray(RSIBuffer,0,MAofRSI,0,MA_method,i);
        Print("MA value ",MAofRSIBuffer[i]);
      }
 
 
 
  //--- Set Object label (_____)
  ObjectCreate("RSI_line", OBJ_LABEL, WindowFind("RSI("+RSIPeriod+")"), 0, 0);
     ObjectSet("RSI_line", OBJPROP_CORNER,1);
     ObjectSet("RSI_line", OBJPROP_XDISTANCE, 66);
     ObjectSet("RSI_line", OBJPROP_YDISTANCE, 0);
     ObjectSetText("RSI_line","_____", 12, "Calibri", Blue);
  ObjectCreate("MA_rsi_line", OBJ_LABEL, WindowFind("RSI("+RSIPeriod+")"), 0, 0);
     ObjectSet("MA_rsi_line", OBJPROP_CORNER,1);
     ObjectSet("MA_rsi_line", OBJPROP_XDISTANCE, 66);
     ObjectSet("MA_rsi_line", OBJPROP_YDISTANCE, 15);
     ObjectSetText("MA_rsi_line","_____", 12, "Calibri", Red);      
     
     
   //--- Set Label RSI value
   ObjectCreate("RSI_value", OBJ_LABEL, WindowFind("RSI("+RSIPeriod+")"), 0, 0);
     ObjectSet("RSI_value", OBJPROP_CORNER,1);
     ObjectSet("RSI_value", OBJPROP_XDISTANCE, 26);
     ObjectSet("RSI_value", OBJPROP_YDISTANCE, 7);
   ObjectCreate("MArsi_value", OBJ_LABEL, WindowFind("RSI("+RSIPeriod+")"), 0, 0);
     ObjectSet("MArsi_value", OBJPROP_CORNER,1);
     ObjectSet("MArsi_value", OBJPROP_XDISTANCE, 26);
     ObjectSet("MArsi_value", OBJPROP_YDISTANCE, 23);
   ObjectCreate("RSI_phase", OBJ_LABEL,  WindowFind("RSI("+RSIPeriod+")"), 0, 0);
     ObjectSet("RSI_phase", OBJPROP_CORNER, 1);
     ObjectSet("RSI_phase", OBJPROP_XDISTANCE, 8);
     ObjectSet("RSI_phase", OBJPROP_YDISTANCE,9);
   ObjectCreate("MArsi_phase", OBJ_LABEL,  WindowFind("RSI("+RSIPeriod+")"), 0, 0);
     ObjectSet("MArsi_phase", OBJPROP_CORNER, 1);
     ObjectSet("MArsi_phase", OBJPROP_XDISTANCE, 8);
     ObjectSet("MArsi_phase", OBJPROP_YDISTANCE,25);
     
     
     //--- Set Label RSI phase
    if(RSIBuffer[0] > 50 )tColor=Green;
         else tColor=Red;
         ObjectSetText("RSI_value",DoubleToStr(RSIBuffer[0],2), 11, "Calibri", tColor);
         
      //--- 
    if(MAofRSIBuffer[0] > 50 )tColor1=Green;
         else tColor1=Red;
         ObjectSetText("MArsi_value",DoubleToStr(MAofRSIBuffer[0],2), 11, "Calibri", tColor1);
         
      //---   
    if(RSIBuffer[0] > RSIBuffer[1])
           {
            tColor3=Green;
            ObjectSetText("RSI_phase","p",10,"Wingdings 3", tColor3);
           }
    else
           { 
            tColor3=Red; 
            ObjectSetText("RSI_phase","q",10,"Wingdings 3", tColor3);
           }
           
    //---     
    if(MAofRSIBuffer[0] > MAofRSIBuffer[1])
           {
            tColor4=Green;
            ObjectSetText("MArsi_phase","p",10,"Wingdings 3", tColor4);
           }
    else
           { 
            tColor4=Red; 
            ObjectSetText("MArsi_phase","q",10,"Wingdings 3", tColor4);
           }
           
           
    return(0);
  }
//+------------------------------------------------------------------+

 
oladapolaleye:

I searched the code base and I got this indicator to use:

And I used it in my EA as thus, but printed 0 values:

//+------------------------------------------------------------------+
//|                                                  MA+RSI.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+

extern double TakeProfit = 3000;
extern double Lots = 0.1;
extern double TrailingStop = 1500;
extern double StopLoss = 1000;
extern double Gap = 2000;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   double RSIPeriod,MAofRSI;
   int cnt, ticket, total;
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external 
// variables (Lots, StopLoss, TakeProfit, 
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
   if(Bars<100)
     {
      Print("bars less than 100");
      return(0);  
     }
   if(TakeProfit<10)
     {
      Print("TakeProfit less than 10");
      return(0);  // check TakeProfit
     }
// to simplify the coding and speed up access
// data are put into internal variables
      
   double MA_RSI2 = iCustom(NULL,0,"RSI+MA+LABEL",RSIPeriod,MAofRSI,1,2);
   Print("MA value ",MA_RSI2);
   double MA_RSI1 = iCustom(NULL,0,"RSI+MA+LABEL",RSIPeriod,MAofRSI,1,1);
   Print("MA value ",MA_RSI1);
   double MaTr = iMA(NULL,0,50,0,MODE_SMA,PRICE_OPEN,0);

   total=OrdersTotal();
   if(total<1) 
     {
      // no opened orders identified
      if(AccountFreeMargin()<(1000*Lots))
        {
         Print("We have no money. Free Margin = ", AccountFreeMargin());
         return(0);  
        }
      // check for long position (BUY) possibility
      if(MaTr>Bid-Gap*Point && MA_RSI1>MA_RSI2<30)
        {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"MA+RSI",4006,0,Green);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
         else Print("Error opening BUY order : ",GetLastError()); 
         return(0); 
        }
      // check for short position (SELL) possibility
      if(MaTr<Ask+Gap*Point && MA_RSI1<MA_RSI2>70)
        {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"MA+RSI",4006,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
           }
         else Print("Error opening SELL order : ",GetLastError()); 
         return(0); 
        }
      return(0);
     }
   // it is important to enter the market correctly, 
   // but it is more important to exit it correctly...   
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         if(OrderType()==OP_BUY)   // long position is opened
           {
            // should it be closed?
            if(MA_RSI2>50 && MA_RSI1>50)
                {
                 OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
                 return(0); // exit
                }
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else // go to short position
           {
            // should it be closed?
            if(MA_RSI2<50 && MA_RSI1<50)
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
               return(0); // exit
              }
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
   return(0);
  }
// the end.
 
oladapolaleye:

And I used it in my EA as thus, but printed 0 values:


Your Indicator has 3 externs . . .

extern int RSIPeriod = 6;
extern int MAofRSI   = 6; 
extern int MA_method = 3; //Mode LWMA

. . . you must use them all or none in your iCustom() calls. If you use none then the defaults will be used.

 
//+------------------------------------------------------------------+
//|                                                  MA+RSI.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+

extern double TakeProfit = 3000;
extern double Lots = 0.1;
extern double TrailingStop = 1500;
extern double StopLoss = 1000;
extern double Gap = 2000;
extern int RSIPeriod = 6;
extern int MAofRSI   = 6; 
extern int MA_method = 3;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   double RSIPeriod,MAofRSI;
   int cnt, ticket, total;
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external 
// variables (Lots, StopLoss, TakeProfit, 
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
   if(Bars<100)
     {
      Print("bars less than 100");
      return(0);  
     }
   if(TakeProfit<10)
     {
      Print("TakeProfit less than 10");
      return(0);  // check TakeProfit
     }
// to simplify the coding and speed up access
// data are put into internal variables
      
   double MA_RSI2 = iCustom(NULL,0,"RSI+MA+LABEL",6,6,3,1,2);
   Print("MA value ",MA_RSI2);
   double MA_RSI1 = iCustom(NULL,0,"RSI+MA+LABEL",6,6,3,1,1);
   Print("MA value ",MA_RSI1);
   double MaTr = iMA(NULL,0,50,0,MODE_SMA,PRICE_OPEN,0);

   total=OrdersTotal();
   if(total<1) 
     {
      // no opened orders identified
      if(AccountFreeMargin()<(1000*Lots))
        {
         Print("We have no money. Free Margin = ", AccountFreeMargin());
         return(0);  
        }
      // check for long position (BUY) possibility
      if(MaTr>Bid-Gap*Point && MA_RSI1>MA_RSI2<30)
        {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"MA+RSI",4006,0,Green);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
         else Print("Error opening BUY order : ",GetLastError()); 
         return(0); 
        }
      // check for short position (SELL) possibility
      if(MaTr<Ask+Gap*Point && MA_RSI1<MA_RSI2>70)
        {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"MA+RSI",4006,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
           }
         else Print("Error opening SELL order : ",GetLastError()); 
         return(0); 
        }
      return(0);
     }
   // it is important to enter the market correctly, 
   // but it is more important to exit it correctly...   
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         if(OrderType()==OP_BUY)   // long position is opened
           {
            // should it be closed?
            if(MA_RSI2>50 && MA_RSI1>50)
                {
                 OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
                 return(0); // exit
                }
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else // go to short position
           {
            // should it be closed?
            if(MA_RSI2<50 && MA_RSI1<50)
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
               return(0); // exit
              }
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
   return(0);
  }
// the end.
Finally, it returned MA values. You are 2Good! Thank you million times. Look at the edition:
 
oladapolaleye:
Finally, it returned MA values. You are 2Good! Thank you million times.Look at the edition:
Reason: