R/Empty4 indicator

Place your new trading idea here to see if someone can automate it.
Hercules
Trader
Posts: 11
Joined: Wed Apr 15, 2015 11:11 pm

R/Empty4 indicator

Post by Hercules »

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);
}
//:::::::::::::::::::::::::::::::::::::::::::::
dokopy
Trader
Posts: 35
Joined: Thu Mar 19, 2015 7:22 am

R/Empty4 indicator

Post by dokopy »

Nepojmenovaný 1.jpg
You do not have the required permissions to view the files attached to this post.
Hercules
Trader
Posts: 11
Joined: Wed Apr 15, 2015 11:11 pm

R/Empty4 indicator

Post by Hercules »

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.
Last edited by Hercules on Fri Jan 22, 2016 3:24 pm, edited 1 time in total.
dokopy
Trader
Posts: 35
Joined: Thu Mar 19, 2015 7:22 am

R/Empty4 indicator

Post by dokopy »

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.
Hercules
Trader
Posts: 11
Joined: Wed Apr 15, 2015 11:11 pm

R/Empty4 indicator

Post by Hercules »

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.
You do not have the required permissions to view the files attached to this post.
dokopy
Trader
Posts: 35
Joined: Thu Mar 19, 2015 7:22 am

R/Empty4 indicator

Post by dokopy »

Thank you! :good:
User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

R/Empty4 indicator

Post by milanese »

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
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
jrodriguez97
Posts: 1
Joined: Thu Jun 09, 2016 1:53 am

Re: R/Empty4 indicator

Post by jrodriguez97 »

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
Post Reply

Return to “Ideas for Possible Automation”