SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sat Sep 23, 2017 1:35 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Jul 11, 2012 4:27 pm 
Offline

Joined: Wed Aug 08, 2007 6:32 pm
Posts: 200
Hi,

How do I code for the bar.close to cross above or below and indicator. I get how to do indicators crossing indicators but cant figure out how to bar.close unless i need to create a timeseries with it and then perform the cross. Is there a simpler way?


Top
 Profile  
 
PostPosted: Wed Jul 11, 2012 5:25 pm 
Offline

Joined: Wed Oct 08, 2003 1:06 pm
Posts: 833
Hi,

Please use
CrossesAbove(BarSeries series, Bar bar, BarData barData)
and
CrossesBelow(BarSeries series, Bar bar, BarData barData)
methods of the indicator class.

Regards,
Sergey.


Top
 Profile  
 
PostPosted: Wed Jul 11, 2012 5:52 pm 
Offline

Joined: Wed Aug 08, 2007 6:32 pm
Posts: 200
Can you give me an example of this? I think I am getting the implementation wrong for some reason


Top
 Profile  
 
PostPosted: Thu Jul 12, 2012 3:59 pm 
Offline

Joined: Wed Oct 08, 2003 1:06 pm
Posts: 833
here it is:
Code:
public class MyStrategy : Strategy
{
   SMA sma;
   public override void OnStrategyStart()
   {
      sma = new SMA(Bars, 14);
      Draw(sma);
   }

   public override void OnBar(Bar bar)
   {
      if (sma.CrossesAbove(Bars, bar, BarData.Close))
         Buy(1);
      
      if (sma.CrossesBelow(Bars, bar, BarData.Close))
         Sell(1);      
   }
}


Regards,
Sergey.


Top
 Profile  
 
PostPosted: Mon Jul 23, 2012 1:55 pm 
Offline

Joined: Wed Aug 08, 2007 6:32 pm
Posts: 200
thanks that helps alot


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

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 2 guests


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:  
cron
Powered by phpBB® Forum Software © phpBB Group