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

How to get indicator's last val in the prev. sesh on the 1st bar of today's sesh?

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

  • nothingbutprofits
    replied
    Thanks for the updated info. I posted the similar issue..but with more depth detail today.

    Leave a comment:


  • NinjaTrader_BrandonH
    replied
    Hello nothingbutprofits,

    Thanks for your note.

    MySMA is set up as a plot using a public Series<double> variable in this script instead of setting up MySMA as a private variable by calling private SMA MySMA. This is seen in the Properties section of the previously attached script.

    Since MySMA is a public Series<double> variable, we must specify the barsAgo value for MySMA (MySMA[0]) when assigning a value to it.

    You could also set this up as you described by creating a class-level variable using private SMA MySMA, then assigning a value to the variable with MySMA = SMA(20). See the attached script which is a modified version of the previous script demonstrating this.

    Let us know if we may assist further.

    Attached Files
    Last edited by NinjaTrader_BrandonH; 10-26-2021, 07:38 AM.

    Leave a comment:


  • nothingbutprofits
    replied
    Originally posted by NinjaTrader_BrandonH View Post
    Hello focus333,

    Thanks for your post.

    You could use Bars.IsFirstBarOfSession to determine if the current bar processing is the first bar updated in a trading session. Then, you would print out the SMA indicator with a barsAgo value of 1 (SMA(20)[1]) to get the SMA value 1 bar previous to the current session.

    See the attached example script demonstrating this.

    Also, see the help guide page below for more information about IsFirstBarOfSession.

    IsFirstBarOfSession: https://ninjatrader.com/support/help...rofsession.htm

    Let us know if we may assist further.
    I'm diving in this one..as I'm figuring out on how to read the 3rd party indicator values inside the indicator.

    From your sample file:

    MySMA[0] = SMA(20)[0];

    if (Bars.IsFirstBarOfSession)
    {
    Print("First bar of current session: " + CurrentBar);
    Print("SMA last bar of prev session: " + MySMA[1] + " Bar of prev session: " + (CurrentBar-1));
    }

    I'm trying to understand about that [0] part there.

    I thought it would be private SMA MySMA first, then go from there.

    There are other indicators such as MACD that need to be read inside the custom indicator.

    Maybe you can clarify on this one, please?

    Thanks!

    Leave a comment:


  • NinjaTrader_BrandonH
    replied
    Hello focus333,

    Thanks for your post.

    You could use Bars.IsFirstBarOfSession to determine if the current bar processing is the first bar updated in a trading session. Then, you would print out the SMA indicator with a barsAgo value of 1 (SMA(20)[1]) to get the SMA value 1 bar previous to the current session.

    See the attached example script demonstrating this.

    Also, see the help guide page below for more information about IsFirstBarOfSession.

    IsFirstBarOfSession: https://ninjatrader.com/support/help...rofsession.htm

    Let us know if we may assist further.
    Attached Files

    Leave a comment:


  • How to get indicator's last val in the prev. sesh on the 1st bar of today's sesh?

    Example scenario:
    Indicator plots an SMA over several days - added via ninjascript.

    How to, when the 1st bar of "today" prints (only once) get the value of the SMA at yesterday's last bar?

    I am trying to use code similar to this but it is not working as expected, it seems top print more than once and the values don't quite match. Any tips on getting this right?

    if ( CurrentBar == Bars.BarsSinceNewTradingDay) {
    double val = SMA(20)[Bars.BarsSinceNewTradingDay + 1]; // get the value of "last" bar before the new session
    Print(val);
    }

    Why does CurrentBar == Bars.BarsSinceNewTradingDay evaluate to true so many times? I'd expect this to eval true once a day.

    Thank you kindly!
    Last edited by focus333; 10-19-2021, 11:45 PM.

Latest Posts

Collapse

Topics Statistics Last Post
Started by AveryFlynn, Today, 04:57 AM
1 response
10 views
0 likes
Last Post NinjaTrader_Erick  
Started by Max238, Today, 01:28 AM
4 responses
37 views
0 likes
Last Post Max238
by Max238
 
Started by r68cervera, Today, 05:29 AM
1 response
8 views
0 likes
Last Post NinjaTrader_ChelseaB  
Started by geddyisodin, Today, 05:20 AM
1 response
11 views
0 likes
Last Post NinjaTrader_Gaby  
Started by timko, Today, 06:45 AM
2 responses
14 views
0 likes
Last Post NinjaTrader_ChristopherJ  
Working...
X