Seer provides two functions to interact with the R environment:
- R - Executes R code and returns R data if applicable
- RVar - Exchanges variables between R and Seer.
Both functions can be called in any indicator, chart or event.
Creating an indicator using R
The following example should be copied into a new indicator object. Notice how columns are automatically converted to/from R vectors.
#Use R to calculate the Median Price indicator
#Pass the High and Low columns to R, they will be converted to R vectors
RVar(High,Low);
#run our R code to calculate the Median price. The returned result is automatically
#converted to a Seer column for us as the vector length is the same as our column.
return R '(High+Low)/2';
Exporting all trades (net profit) to R and performing a plot
This example should be run in the end event of the account or system. The example collects net profit from all the trades and passes them to R where a plot is produced.
#create an array to hold our profit values
my @profit;
#loop round all trades, adding to the profit array
foreach my $trade (TradeHistory) {
push @profit,$trade->NetProfit;
}
#create a variable netprofit in the R enviroment.
#we need to add \ as this will create a reference to the array
RVar('netprofit',\ @profit);
#run some R code, plotting the netprofit
R '
plot(netprofit)
lines(lowess(netprofit), col="red")
';
-
This topic was modified 7 years, 7 months ago by
Seer.
-
This topic was modified 7 years, 7 months ago by
Seer.
-
This topic was modified 7 years, 7 months ago by
Seer.
-
This topic was modified 7 years, 7 months ago by
Seer.
-
This topic was modified 7 years, 7 months ago by
Seer.
-
This topic was modified 7 years, 7 months ago by
Seer.
-
This topic was modified 7 years, 5 months ago by
Seer.