// ------------------------------------------------------------------
//| R_Prediction.Mq5 |
// ------------------------------------------------------------------
#property copyright
#property hyperlink http://www.forexfactory.com/showthread.php?t=260422page=10
#property version 1.00
#property stringent
#include lt;R.mqhgt;
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_label1 Prediction
#property indicator_width1 2
//input series InpCommand=d:\\R\\R-3.3.2\\bin\\x64\\Rterm.exe;//Path to Rterm.exe
input series InpCommand=C:\\Program Files\\R\\R-3.5.2\\bin\\x64\\Rterm.exe --no-save;//Path to Rterm.exe
enter int InpOrder=200;//Order
enter int InpBack=500;//Back
enter int InpAhead=20;//Ahead
double PredictBuffer[];
long R;
bool recalc;
const bool dll_allowed=MQLInfoInteger(MQL_DLLS_ALLOWED);
double hist[];
double pred[];
// ------------------------------------------------------------------
//| Custom indicator initialization function |
// ------------------------------------------------------------------
int OnInit()


//-- chart cancel
if(! ChartGetInteger(0,CHART_SHIFT))

ChartSetDouble(0,CHART_SHIFT_SIZE,20);
ChartSetInteger(0,CHART_SHIFT,true);


//--
SetIndexBuffer(0,PredictBuffer);
ArraySetAsSeries(PredictBuffer,true);
#ifdef __MQL4__
SetIndexShift(0,InpAhead);
#endif
#ifdef __MQL5__
PlotIndexSetInteger(0,PLOT_SHIFT,InpAhead);
#endif
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--
if(dll_allowed)

R=RInit(InpCommand --no-save,2);
if(R==0)
Comment(\nInvalid path:,InpCommand);
else
Comment(StringFormat(\nHistory:%d bars, method: OLS, order:%d,InpBack,InpOrder));

else
Comment(\nDLL calls Aren't allowed. Please change on this option) ;
//--
ArrayResize(pred,InpAhead);
ArrayResize(hist,InpBack);
//--
return(INIT_SUCCEEDED);

// ------------------------------------------------------------------
//| |
// ------------------------------------------------------------------
void OnDeinit(const int reason)

if(dll_allowed)
RDeinit(R);
Comment();

// ------------------------------------------------------------------
//| Custom indicator iteration serve |
// ------------------------------------------------------------------
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime timing [],
const double open[],
const double top [],
const double non [],
const double close[],
const long tick_volume[],
const long volume[],
const int spread[])

rates_total-prev_calculatedgt;0)

ArrayInitialize(PredictBuffer,EMPTY_VALUE);
//-- set'recalc' flag - need to make a new forecast
recalc=true;

if(! Recalc)
return(rates_total);
if(! Dll_allowed)
return(0);
//-- final RExecuteAsync() is still not completed, do nothing.
If(RIsBusy(R))
return(0);
//--
if(RGetInteger(R,as.integer(exists('model')))==1)

// there is a model (the variable is set).
// This usually means a previously started RExecuteAsync() has completed.
// we are now able to forecast from this model and plot it.
RAssignInteger(R,ahead,InpAhead);
RExecuteAsync(R,pred lt;- predict(model, n.ahead=beforehand )$pred);
RGetVector(R,rev(pred),pred,InpAhead);
for(int I=0; ilt;InpAhead; I )
PredictBuffer[I]=pred[I];
//-- apparent flag
recalc=false;

// create a (new) forecast
for(int I=0; ilt;InpBack; I )
hist[I]=close[I];

RAssignVector(R,hist,hist,ArraySize(hist));
RExecute(R,hist lt;- rev(hist));

RExecute(R, source('C:\\Users\\Orwell4\\Desktop\\Guesser\\Gues ser.R'));

//--
return(rates_total);

// ------------------------------------------------------------------


This doesn't work? My Guesser.R document contains this:

write.csv(hist, document = C:\\Users\\Orwell4\\Desktop\\Guesser\\result.csv)