Using R in Seer

Tagged: 

This topic contains 0 replies, has 1 voice, and was last updated by Seer Seer 6 years, 9 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #533
    Seer
    Seer
    Keymaster

    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 6 years, 5 months ago by Seer Seer.
    • This topic was modified 6 years, 5 months ago by Seer Seer.
    • This topic was modified 6 years, 5 months ago by Seer Seer.
    • This topic was modified 6 years, 5 months ago by Seer Seer.
    • This topic was modified 6 years, 5 months ago by Seer Seer.
    • This topic was modified 6 years, 5 months ago by Seer Seer.
    • This topic was modified 6 years, 3 months ago by Seer Seer.
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.