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

SamplestreamWriter and 30min indicator help.

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

    SamplestreamWriter and 30min indicator help.

    Hello Ninjatrader Team,

    I have a indicator that I put on the Daily Chart which shows me what the %change for the first 30min . For example looking at SPY-DailyChart instrument on April 28,2017 when I load that indicator it show that for the first 30min on April 28,2017 %chg was -0.15%.
    ----------
    My issues is when I put that indicator into SampleStreamWriter. It will only spit out 256 results for the %chg indicator. How can I tell ninjatrader to # look back bars to load 1000 Daily as well 1000 30min for the indicator. So for every Daily bar I want as well the first 30min for that day.

    Code:
           {
    	    Add(PeriodType.Minute, 30);
                Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                Overlay				= false;
    
            }
            protected override void OnBarUpdate()
            {
    			if(CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired) return;			
    			if (BarsInProgress ==0)
    			{           
                               Plot0.Set(((Closes[1][12] / Opens[1][12])-1)*100) ;
    			}			
            }
    And for SampleStreamWriter I just downloaded the one from ninjatrade website.

    #2
    Hello wallsteetking,

    Thanks for opening the thread.

    When adding a data series with Add() it should have the same look back period as the primary data series. This could be limited by the Minimum bars look back setting of the indicator. Please make sure this setting is set to infinite to allow the indicator and the data series within to use the maximum number of days loaded by the primary data series.

    You can use FirstTickOfBar along with CalculateOnBarClose = false to detect the first tick on a new daily bar to detect a when to reference the first 30 minute bar for that day.

    Here is some code that demonstrates this as an example:

    Code:
    private bool newDay = false;
    protected override void OnBarUpdate()
    {
    	double myDbl;
    	if (BarsInProgress == 0 && FirstTickOfBar == true)
    		newDay = true;
    	if (BarsInProgress == 1 && newDay == true)
    	{
    		// Get the price for the first 30 minute bar of the day.
    		myDbl = Closes[1][0];
    		newDay = false;
    	}
    }
    Here are the help guide articles on FirstTickOfBar and CalculateOnBarClose for reference.

    FirstTickOfBar - http://ninjatrader.com/support/helpG...ttickofbar.htm

    CalculateOnBarClose - http://ninjatrader.com/support/helpG...onbarclose.htm

    Please let me know if I may be of further assistance with this matter.
    Last edited by NinjaTrader_Jim; 05-02-2017, 11:12 AM.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hello Jim,

      I tried what you said if I fallowed your code correctly. However, it does not work, when I put the indicator into SampleStreamWriter it still does the same thing as before. I am wundering If I need to update the samplestreamwriter code to allow exporting daily and minute data into excel?

      Also inside your code
      Code:
      myDbl = Close[1][0];
      I think this should be closes instead of close because we are looking at multitime frame
      Code:
      myDbl = Closes[1][0];
      Can you please advise how I can make samplestreamwriter export daily and minute data at the same time into excel file. Thank you

      Furthermore, some more information.
      I open market analyzer load samplestreamwriter ( with the update code you gave me, then I click input-daily data and then I click #lookback to infinite with load 500 days back.

      Comment


        #4
        Hello wallsteetking,

        Thanks for the reply, and pointing out my typo.

        After performing further tests, I do not think this can be done in a Market Analyzer in NinjaTrader 7. The number of bars to load only gives you enough historical data to satisfy the smallest data series. If we specify 500 bars to load, we will get 500 30 minute bars and not get 500 daily bars.

        We can specify a greater number of bars to load to work around this, we can apply it to a chart, or we can make a separate instance of SampleStreamWriter to record these values to a file.

        Creating a file that can be imported in excel is done much the same way as it is done in the SampleStreamWriter. The idea is to write to a file, but when making a file that you want to import with excel, you will want to create a .csv or Comma Separated Values file.

        Simply rename the extension from .txt to .csv and make sure the values are separated with commas when you are calling sw.WriteLine().

        This can be done with StreamWriter or with System.IO to write to a file. Another sample that writes to .csv files can be found here: http://ninjatrader.com/support/forum...p=15&keyid=614

        Please let me know if I may be of further help.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by gravdigaz6, Today, 11:40 PM
        0 responses
        4 views
        0 likes
        Last Post gravdigaz6  
        Started by MarianApalaghiei, Today, 10:49 PM
        3 responses
        9 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by XXtrader, Today, 11:30 PM
        0 responses
        3 views
        0 likes
        Last Post XXtrader  
        Started by love2code2trade, Yesterday, 01:45 PM
        4 responses
        28 views
        0 likes
        Last Post love2code2trade  
        Started by funk10101, Today, 09:43 PM
        0 responses
        9 views
        0 likes
        Last Post funk10101  
        Working...
        X