Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Get information from indicator into strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Get information from indicator into strategy

    Hello,

    I hope my question will be comprehensible to you, because obviously it is hard to explain here what exactly I am trying to do with my strategy.
    I have a custom indicator which calculates the number of days the bar is above or below an EMA and adds them up. I then calculate the average time and I draw a standard deviation line. I am trying to use this indicator information in my strategy and say: I want to stop my long or short orders which are generated from my strategy rules, when the cumulative number of days above or below the EMA, cross above or below the standard deviation line.

    I don't understand how could I use part of the information from the custom indicator, to manage orders to my strategy. Do I do this in my strategy code or in the indicator code? If I do this in my strategy, my variables from the indicator code are obviously not recognized.

    Please help in case you understand the problem.

    Thanks!

    #2
    You'll do the logic to manage orders (or exit positions) from your
    strategy, using standard deviation data collected by the indicator.

    Your indicator has all the data, already stored in a Series, right?
    You want your strategy to access this standard deviation data, right?

    Make sure the Series is "public" in the indicator. This is usually
    done via public properties.

    Let's use @Darvas.cs as an example.
    Open this indicator in notepad and follow along.

    Suppose the 'Series<double>' variable known as "boxTopSeries"
    was your standard deviations series, and you needed to make this
    available to your strategy.

    Note how "boxTopSeries" is a private variable, but your strategy
    cannot access that -- so we need to spawn a relative to this private
    variable and make it public -- so we use a public property and make
    an identical twin but with a new name "BoxTopSeries" -- note the
    case of the first letter, the change from 'b' to 'B' is critical.

    Scroll down to "Properties" in @Darvas.cs.
    Do you see "BoxTopSeries" in there?
    (No, you don't)

    So, just like in your case, you'll create a public property,

    Code:
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> BoxTopSeries
    {
        get { return boxTopSeries; }
    }
    Wa-laah! Now in your strategy you have access to "BoxTopSeries",
    because it is a public property exposed by the indicator.

    Apply this example to your own situation.
    Does that help?
    Last edited by bltdavid; 04-03-2021, 11:34 AM.

    Comment


      #3
      Originally posted by yannistsoupakis View Post
      I have a custom indicator which calculates the number of days the bar is above or below an EMA and adds them up. I then calculate the average time and I draw a standard deviation line. I am trying to use this indicator information in my strategy and say: I want to stop my long or short orders which are generated from my strategy rules, when the cumulative number of days above or below the EMA, cross above or below the standard deviation line.
      It sounds like your indicator already has two series.
      Series #1 has "the cumulative number of days above or below the EMA".
      Series #2 has "the standard deviation line".
      Both series must be type "Series<double>".
      Is this all correct?

      Are both series publicly exposed by the indicator?
      If not, see my previous post.

      You can use CrossAbove and CrossBelow to achieve what you want.

      Suppose Series #1 was called "MyEmaData".
      Suppose Series #2 was called "MyStdDevData".

      In your strategy, you could check for a CrossAbove, like this,

      Code:
      if (CrossAbove(MyIndy(args).MyEmaData, MyIndy(args).MyStdDevData, 1))
      {
          .... the EMA cumm days has crossed above the StdDev line ....
          .... take action to exit position ....
      }
      The code for CrossBelow is very similar.

      Make sense?

      Last edited by bltdavid; 04-03-2021, 11:58 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Barry Milan, Today, 10:35 PM
      2 responses
      8 views
      0 likes
      Last Post Barry Milan  
      Started by WeyldFalcon, 12-10-2020, 06:48 PM
      14 responses
      1,428 views
      0 likes
      Last Post Handclap0241  
      Started by DJ888, Yesterday, 06:09 PM
      2 responses
      9 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      41 views
      0 likes
      Last Post jeronymite  
      Started by bill2023, Today, 08:51 AM
      2 responses
      16 views
      0 likes
      Last Post bill2023  
      Working...
      X