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

Outputting static value from indicator

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

    Outputting static value from indicator

    Hi,

    If I wanted to output a static value if a condition in an indicator is true is this possible? e.g. create an indicator and output a static value of 1 when below is true....

    if (EMA(20)[0] > EMA(20)[60])
    output 1

    To add context it is to create signals within market analyzer when certain conditions are true.

    Thanks
    Tim

    #2
    Hello Tim,

    The Market Analyzer uses the Plot to display the number inside of the Column, so you would want to set the Plot value to 1 when your condition is true inside of a Custom Indicator file.

    For example:
    Code:
    protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                Overlay				= false;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // Checks to make sure there is atleast 81 bars worth of data before calculating 
                //  so that there is enough data.
                if(CurrentBar < 81)
                {
                       return;
                }
                // Use this method for calculating your indicator values. Assign a value to each
                if (EMA(20)[0] > EMA(20)[60])
                {
                     Plot0.Set(1);
                }
                else
                {
                     Plot0.Set(0);
                }
            }
    JCNinjaTrader Customer Service

    Comment


      #3
      Many thanks for the quick response - that worked perfectly.

      Tim

      Comment


        #4
        Originally posted by tdouglas View Post
        Hi,

        If I wanted to output a static value if a condition in an indicator is true is this possible? e.g. create an indicator and output a static value of 1 when below is true....

        if (EMA(20)[0] > EMA(20)[60])
        output 1

        To add context it is to create signals within market analyzer when certain conditions are true.

        Thanks
        Tim
        If you do not want to plot that value, but just want to use it as a trendfilter that can be accessed by other indicators or strategies, you can also use an IntSeries() object to hold those values. You can set the output to 1, if the condition is true, to -1 if the opposite is true, and to 0, if both EMAs are equal.

        Comment


          #5
          Thanks Harry - I'll take a look at that too.

          Tim

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by chbruno, Today, 04:10 PM
          0 responses
          1 view
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          6 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          19 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by frslvr, 04-11-2024, 07:26 AM
          9 responses
          127 views
          1 like
          Last Post caryc123  
          Working...
          X