stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

R/Empty4 indicator
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=2069
Page 5 of 5
Author:  Hercules [ Fri Jan 22, 2016 12:00 pm ]
Post subject:  R/Empty4 indicator

This line is misspelled R = Rinit. It should be R = RInit. Probably this worked on an older mt4R inculde file but NOT now.

Code: Select all

//:::::::::::::::::::::::::::::::::::::::::::::
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Black
#property indicator_minimum -1
#property indicator_maximum 1
#property indicator_separate_window 
#include <mt4R.mqh> 
extern int GdvPeriod = 20;
extern int GdvLookBack = 500;
extern double GdvAlpha = 1000;
extern string Rpath = "C:/Program Files/R/R-3.2.3/bin/x64/Rterm.exe --no-save";
extern int RDebugLevel = 1;// 0,1,2
extern string RTempDir = "";//

//:::::::::::::::::::::::::::::::::::::::::::::
//:::::::::::::::::::::::::::::::::::::::::::::
string IndName= "GradientVolatility0";
string IndVer= "0.1.0";
double ExtMapBuffer1[];
double ExtMapBuffer2[];
int nextBarTime;
int R;
int init()
{
  IndicatorBuffers(2);
  IndicatorDigits(Digits+10);
  IndicatorShortName(StringConcatenate(IndName," ",IndVer));
  SetIndexStyle( 0 , DRAW_LINE );
  SetIndexStyle( 1 , DRAW_NONE );
  SetIndexDrawBegin( 0 , GdvPeriod );
  SetIndexDrawBegin( 1 , GdvPeriod );
  SetIndexBuffer( 0 , ExtMapBuffer1 );
  SetIndexBuffer( 1 , ExtMapBuffer2 );
  //string Rterm = StringConcatenate(Rpath, " --no-save" );
  R = RInit(Rpath,RDebugLevel);
  
  // R check
   RExecute(R, "ret <- TRUE");
   bool ret = RGetBool(R,"ret");
   if(!ret){
      Alert("Rterm.exe path maybe wrong..");
      Comment("Rterm.exe path maybe wrong..");
      return(0);
      }
  RExecute(R, "histNum <- numeric(0)" );
  RExecute(R, "library(zoo)" );
  return(0);
}
//:::::::::::::::::::::::::::::::::::::::::::::
int start()
{
  int i;
  double hist[] ;
  double ret[] ;
  int unused_bars;
  int used_bars=IndicatorCounted();

  if (used_bars<0) return(-1);
  if (used_bars>0) used_bars--;
  unused_bars=Bars-used_bars;

  if(RIsBusy(R)) return(0);
  ArrayResize(ret,GdvLookBack);
  int len= RGetInteger(R, "length(histNum)" );
  if( RGetInteger(R, "as.integer(exists('model'))" ) ==1)
  {
    RGetVector(R, StringConcatenate( "rev(model)[1:" ,GdvLookBack, "]" ),ret,GdvLookBack);
    for(i=0;i<GdvLookBack;i++)
    {
      ExtMapBuffer1[i] = ret[i];
    }
  }
  if( isNewBar()==true )
  {
    ArrayResize(hist, GdvLookBack );
    for(i= GdvLookBack -1;i>=0;i--)
    {
      hist[i] = Close[i];
    }
    RAssignVector(R, "hNum" ,hist,ArraySize(hist) );
    RExecute(R, "hNum <- rev(hNum)" );
    RExecute(R, "histNum <- c(hNum)" );
    RExecuteAsync(R, "model <- rollapply(histNum,"+GdvPeriod+",function(x) as.numeric(lm(x ~ seq_along(x))$coeff[2]))*"+GdvAlpha+" " );
  }
  return(0);
}
int isNewBar()
{
  if( nextBarTime == Time[0] )
    return(false);
  else
    nextBarTime = Time[0];
  return(true);
}
//:::::::::::::::::::::::::::::::::::::::::::::
//:::::::::::::::::::::::::::::::::::::::::::::
int deinit()
{
  RDeinit(R);
  return(0);
}
//:::::::::::::::::::::::::::::::::::::::::::::
Author:  dokopy [ Fri Jan 22, 2016 12:36 pm ]
Post subject:  R/Empty4 indicator

Nepojmenovaný 1.jpg
Author:  Hercules [ Fri Jan 22, 2016 1:11 pm ]
Post subject:  R/Empty4 indicator

If you read the error, it say it doesn't find the mt4R.mqh file. You have to install it in the specified folder according to the error message.
Author:  dokopy [ Fri Jan 22, 2016 2:02 pm ]
Post subject:  R/Empty4 indicator

Hercules » Fri Jan 22, 2016 1:11 pm wrote:If you read the error, it say it doesn't find the mt4R.mql file. You have to install it in the specified folder according to the error message.
Please attach corrected indicator.
Author:  Hercules [ Fri Jan 22, 2016 3:29 pm ]
Post subject:  R/Empty4 indicator

You need the mt4R.mqh file in the MQL4/Include folder. You fixed the source file and it won't help if I upload it because that IS NOT THE ERROR.
Author:  dokopy [ Fri Jan 22, 2016 6:42 pm ]
Post subject:  R/Empty4 indicator

Thank you! :good:
Author:  milanese [ Tue Jan 26, 2016 1:46 pm ]
Post subject:  R/Empty4 indicator

stijn » Tue Jan 26, 2016 11:59 am wrote:Hey guys,
I am new on this forum but have been experimenting with the R interop. I am an R programmer.

My Empty4 is from FXCM, but the script won't work. It says:

2016.01.26 12:34:01.790 'GradientVolatility0' is not script and cannot be executed

The error disappears when I delete the properties at the top:

//#property indicator_color2 Black
//#property indicator_minimum -1
//#property indicator_maximum 1
//#property indicator_separate_window

Then it doesn't work functionally anymore of course.

It seems like, only string properties work. How do you advise please?
this is an indicator, you must place it in your indicators folder....

Cheers :)

Tommaso
Author:  jrodriguez97 [ Thu Jun 09, 2016 3:35 am ]
Post subject:  Re: R/Empty4 indicator

6y588 » Fri May 24, 2013 8:17 am wrote:
Follow steps in post #3 above. If that has been done, and it still does not work.

Then, change the "Rinit" to "RInit".
Hi,
I have the same error, and I have changed Rinit to RInit. It works, but know
'matrix' - invalid array access mt4R.mqh 334 27

thanks for your help
All times are UTC Page 5 of 5