SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sun Apr 05, 2020 11:30 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sun Feb 07, 2010 8:06 pm 
Offline

Joined: Mon Mar 05, 2007 7:02 am
Posts: 58
I am testing a long only strategy on individual equities, but it appears that the results could be improved if I only trade the system when the S&P 500 is > it's 100 Day SMA.

Any suggestions on how to code this?

I can't seem to figure it out right now so I am reading in a CSV file that sets a bool value to determine if the S&P is above/below its 100 day SMA. I know this is a bad way to do it, so I would like to code this logic in my OnBar() method.

Thanks,
Eric


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 07, 2010 10:13 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6817
Hi,

I am not sure I understand what you want to do. You can access bar or other data series for S&P (if you have such instrument and corresponding data in the database of course) in a strategy instance created for another instrument (similar to spread trading strategy FAQ on this forum). You can create SMA with this series. You can set a flag and make this SMA static if you want to have only one copy of SMA indicator.

Or?

Regards,
Anton


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 07, 2010 10:51 pm 
Offline

Joined: Mon Mar 05, 2007 7:02 am
Posts: 58
Dr. Anton Fokin wrote:
Hi,

I am not sure I understand what you want to do. You can access bar or other data series for S&P (if you have such instrument and corresponding data in the database of course) in a strategy instance created for another instrument (similar to spread trading strategy FAQ on this forum). You can create SMA with this series. You can set a flag and make this SMA static if you want to have only one copy of SMA indicator.

Or?

Regards,
Anton


Anton - Thanks for the reply. After re-reading my original post, it was unclear. I am trying to do something like this:

Code:
BarSeries SPX_Bars;
SMA sma_SPX_1;
SMA sma_SPX_100;
double sma_SPX_1_Last;
double sma_SPX_100_Last;
   public override void OnStrategyStart()
   {
         SPX_Bars = new BarSeries();
         if (SPX_Bars != null)
         {
            sma_SPX_1 = new SMA(SPX_Bars,1, Color.White);
            sma_SPX_100 = new SMA(SPX_Bars,100, Color.Red);
            Draw(sma_SPX_1, 0);
            Draw(sma_SPX_100, 0);
         }
      }
   }
public override void OnBar(Bar bar)
{
    if (sma_SPX_1 > sma_SPX_100)
    {
         // Trade the stock system
    }
    else
    {
         // Go Long Government Bonds
    }
}


I am just trying to access the last value of the SPX Moving Averages that I set up in the strategy from the OnBar() method of another symbol.

Hopefully that clarifies things more.

Thanks,
Eric


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group