Trading Algorithm R code

Hi
please can you help me
I want to use PSO technical to I know when I will buy or sell the stock in R.
can you give me am example with real finance data
thank you