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

Green/Red arrow indicator for use in a strategy?

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

    Green/Red arrow indicator for use in a strategy?

    Hello,

    I have developed a straight forward indicator that works well on the chart. It paints/draws a green/red arrow if certain conditions occur. It does the calculation on the First Tick of Bar and draws the appropriate arrow on the previous bar if the criteria are met.

    I would like to use this indicator in a strategy, so I don't have reprogram the logic into the strategy.

    In the indicator, I have tried a dozen approaches.

    I have tried using the Value series but I get errors. I think that makes sense since there's plot happening every tick/price change/first tick of bar.

    So, I added a public Signal property that returns 1 for long/green arrow, -1 for short/red arrow and 0 for no signal. This property should retain its value for the duration of the bar after the criteria is met. That is, the bar of the First Tick of Bar when the code is run to determine whether Signal is set to 1, -1, or 0.

    This section of the code is run properly when debugging but I think it is from an instance of the indicator on the chart (not done in the strategy).

    But, for some reason, the strategy is always getting 0 for the Signal, never 1 or -1. I even added a public method to the strategy to ensure the OnBarUpdate is being called on the indicator.

    public void Calc() {
    this.OnBarUpdate();
    }


    In the strategy, I'm calling Calc in OnBarUpdate. Still just getting 0's.

    Thanks,
    Matt



    #2
    Hello,

    I was able to figure this out. Not sure if this is the correct/best solution but it is working nicely. I needed to add a Plot to the indicator and set it to update on each tick. On each tick, I check to see if the CurrentBar is greater than the previous. If so, then I do the logic of the indicator. Also, by adding a plot, I can use Value[0] in the strategy instead of the signal property (which has now been completely removed).

    Thanks!
    Matt

    Comment


      #3
      Hello StealthM93,

      That would be a correct way to check for a new bar. Other indicators like BuySellVolume use that approach so that sounds like it should work.

      As a side note you should not call this.OnBarUpdate(); in your logic, there are situation which strategies need to have the indicator update but there is a specific method for that. You can see an example of using Update() in this example: https://ninjatrader.com/support/help...alues_that.htm
      JesseNinjaTrader Customer Service

      Comment


        #4
        Thank you, NinjaTrader_Jesse, that is very helpful!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by lightsun47, Today, 03:51 PM
        0 responses
        4 views
        0 likes
        Last Post lightsun47  
        Started by 00nevest, Today, 02:27 PM
        1 response
        8 views
        0 likes
        Last Post 00nevest  
        Started by futtrader, 04-21-2024, 01:50 AM
        4 responses
        44 views
        0 likes
        Last Post futtrader  
        Started by Option Whisperer, Today, 09:55 AM
        1 response
        13 views
        0 likes
        Last Post bltdavid  
        Started by port119, Today, 02:43 PM
        0 responses
        9 views
        0 likes
        Last Post port119
        by port119
         
        Working...
        X