SmartQuant Discussion
http://www.smartquant.com/forums/

bar Close crosses an indicator
http://www.smartquant.com/forums/viewtopic.php?f=59&t=10254
Page 1 of 1

Author:  azuric [ Wed Jul 11, 2012 4:27 pm ]
Post subject:  bar Close crosses an indicator

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?

Author:  Baraz Sergey [ Wed Jul 11, 2012 5:25 pm ]
Post subject:  Re: bar Close crosses an indicator

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.

Author:  azuric [ Wed Jul 11, 2012 5:52 pm ]
Post subject:  Re: bar Close crosses an indicator

Can you give me an example of this? I think I am getting the implementation wrong for some reason

Author:  Baraz Sergey [ Thu Jul 12, 2012 3:59 pm ]
Post subject:  Re: bar Close crosses an indicator

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.

Author:  azuric [ Mon Jul 23, 2012 1:55 pm ]
Post subject:  Re: bar Close crosses an indicator

thanks that helps alot

Page 1 of 1 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/