Announcement

Collapse
No announcement yet.

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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      46 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      22 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      33 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      50 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Working...
      X