Profile Picture

StochasticOscillator

Posted By isaacvictorbabani 2 Years Ago
Message
Posted Thursday February 26 2015
Hi.  
I would like to understand if the StochasticOscillator in RE is the same as what most platforms refer to as "Stochastics Fast"?  It would appear to be the same as it takes the same 2 parameters, but some confirmation would be helpful.

Further, I had some other questions regarding the oscillator:

1. How can I programmatically retrieve the value of K and D at any given time?  The StochasticOscillator class methods/properties do not seem to include anything that would return the the value of K or D at any given time (at least not from the API reference: http://www.rightedgesystems.com/documentation/developerguide/index.aspx)

2. When I add the oscillator to a chart, I only see 1 line, whereas I would expect to see both the K-line and the D-line.  Can someone please advise?

3. Provided I am receiving ticks from IB, will the value of the indicator get updated with each incoming tick?  Or will it only update at the close of a bar (i.e. 1-minute or 5 minute)?  

Thank you.  
Posted Friday February 27 2015
We use the formula from the book Technical Analysis from A to Z.

Indicators in RightEdge only generate one series.  So we have two indicators for this.  The "Stochastic Oscillator" indicator gives the %K value, and the "Stochastic Oscillator %D" indicator gives the %D value.

Indicators don't update on ticks, just at the end of each bar.

Thanks,
Daniel
Posted Friday February 27 2015
Thank you.

So if we assume I am using 5-minute bars within my strategy and declare:  StochasticOscillator stochasticK = new StochasticOscillator(10, 3); 

If I then try to retrieve the most recent value of the indicator using stochasticK.Current while in the middle of a 5-minute bar, is this value calculated using the last 10 completed bars?  

Is there no way to have it calculate from the latest 9 completed bars AND the current, partially-formed bar?  

To make the example concrete, say it is 11:03.  Would the indicator use the 10 bars ending with the last completed bar (ending at 11:00) or would it attempt to also use the partially-formed current bar (11:00-11:03)?  
Posted Friday February 27 2015
I think technically a Stochastic Oscillator with parameters 10 and 3 will be computed using the last 12 completed bars, due to the 3-period slowing.

In any case, no, indicators aren't calculated based on partial bars.  Some day I'll probably re-do how indicators are written and (among other things) add support for this.

For now, you can't use the built-in RightEdge indicators for this.  If you need it, you can write your own code to do the calculations you need, and you can have it calculate a new partial value whenever you get a NewTick event.

Thanks,
Daniel
Posted Friday February 27 2015
Thank you.  

Is there sample code of an indicator that performs calculations on fully-formed bars while also using the current partially-formed bar to update?  Any such indicator will be fine as I just want to get a general understanding of how this is done in RE.  
Posted Monday March 02 2015
Here's a sample of doing this with a simple moving average.  Note that you end up writing almost the same calculation twice, once in NewBar and once in NewTick, but that the bounds of the values you are computing it on change.  For more complicated indicators I would probably find a way to avoid this duplication.


public class MySymbolScript : MySymbolScriptBase
{
  UserSeries MySMA = new UserSeries();
  const int SMA_PERIODS = 10;

  double PartialSMA = 0.0;

  public override void Startup()
  {
   MySMA.ChartSettings.ShowInChart = true;
  }

  public override void NewBar()
  {
   if (Bars.Count >= SMA_PERIODS)
   {
    double sum = 0;
    for (int i=0; i<SMA_PERIODS;i++)
    {
      sum += Bars.LookBack(i).Close;
    }
    MySMA.Current = sum / SMA_PERIODS;
   }
  }

  public override void NewTick(BarData partialBar, TickData tick)
  {
   if (Bars.Count >= SMA_PERIODS - 1)
   {
    double sum = partialBar.Close;
    for (int i=0; i<SMA_PERIODS - 1; i++)
    {
      sum += Bars.LookBack(i).Close;
    }
    PartialSMA = sum / SMA_PERIODS;
   }  
  }
}


Thanks,
Daniel
Posted Monday March 02 2015
Thank you.  The SMA is actually a perfect example since it underlies the default calculation of the Stochastic D.  The Stochastic K is a very simple calculation.  

Just one question:  when "sum += Bars.LookBack(i).Close;" is called from within NewTick, are the Bars still whatever bar size are used within the strategy (i.e. 5M bars) with the last bar just representing the current (partially-formed) bar?  
Posted Monday March 02 2015
isaacvictorbabani (3/2/2015)
Just one question:  when "sum += Bars.LookBack(i).Close;" is called from within NewTick, are the Bars still whatever bar size are used within the strategy (i.e. 5M bars) with the last bar just representing the current (partially-formed) bar?  


Yes.  It's possible to set up different frequencies, but those are accessed differently.  The Bars property and partialBar passed to NewTick will always be in the primary system frequency.

Thanks,
Daniel
Posted Monday March 02 2015
Perfect.  Exactly what I needed to understand.  
Thanks.  


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems