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

RoundToTickSize on Secondary DataSeries

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

    RoundToTickSize on Secondary DataSeries

    Is there an easier way to get RoundToTickSize on an Added Dataseries?

    Instrument.GetInstrument("^VIX"). -- intellisense doesn't show RoundToTickSize as an option, and if I type it in, it doesn't compile ( no definition for RoundToTickSize ).

    Feels odd to call it the MasterInstrument when accessing it.

    I don't want to round to ES .25 tick size, but ^VIX's .01.


    This code does work fine:

    Code:
    namespace NinjaTrader.NinjaScript.Strategies
    {
    	public class RoundtoTickSizeEXA : Strategy
    	{
    		
    		static 	int ES  = 0;
    		static 	int VIX = 1;
    		
    		[B]Instrument Instrument_vix;[/B]
    		
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description									= @"none";
    				Name										= "RoundtoTickSizeEXA";
    				Calculate									= Calculate.OnBarClose;
    				EntriesPerDirection							= 1;
    				EntryHandling								= EntryHandling.AllEntries;
    				IsExitOnSessionCloseStrategy				= true;
    				ExitOnSessionCloseSeconds					= 30;
    				IsFillLimitOnTouch							= false;
    				MaximumBarsLookBack							= MaximumBarsLookBack.TwoHundredFiftySix;
    				OrderFillResolution							= OrderFillResolution.Standard;
    				Slippage									= 0;
    				StartBehavior								= StartBehavior.WaitUntilFlat;
    				TimeInForce									= TimeInForce.Gtc;
    				TraceOrders									= false;
    				RealtimeErrorHandling						= RealtimeErrorHandling.StopCancelClose;
    				StopTargetHandling							= StopTargetHandling.PerEntryExecution;
    				BarsRequiredToTrade							= 20;
    				// Disable this property for performance gains in Strategy Analyzer optimizations
    				// See the Help Guide for additional information
    				IsInstantiatedOnEachOptimizationIteration	= true;
    			}
    			else if (State == State.Configure)
    			{
    				
    				AddDataSeries("^VIX", Data.BarsPeriodType.Minute, 3);
    				[B]Instrument_vix  = Instrument.GetInstrument("^VIX");
    [/B]			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			//Add your custom strategy logic here.
    			
    			if (BarsInProgress != 0)
    				return;
    			
    			if (CurrentBars[ES] < 0 || CurrentBars[VIX] < 20)
    				return;
    			//Add your custom strategy logic here.
    			// only process on real-time data 
       			if (State == State.Historical) 
    				return; 
    			
    
    				
    					Print ( ToTime(Time[0]) +"+VIX SMA(14)="+[B]Instrument_vix.MasterInstrument.RoundToTickSize(SMA(BarsArray[VIX], 14)[0])[/B]
    											+" ES="+Instrument.MasterInstrument.RoundToTickSize(BarsArray[ES][0]) 
    											+"  ES SMA(14)="+Instrument.MasterInstrument.RoundToTickSize(SMA(BarsArray[ES],14)[01]));
    					
    				
    			
     
    		}

    #2
    Hello sledge,

    After adding a series with AddDataSeries() try:
    Code:
    BarsArray[1].Instrument.MasterInstrument.RoundToTickSize(double value)
    Anywhere after State.DataLoaded has been reached.


    Last edited by NinjaTrader_ChelseaB; 02-26-2017, 04:54 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      And that is a valid shortcut. Thanks!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by junkone, Today, 11:37 AM
      2 responses
      14 views
      0 likes
      Last Post junkone
      by junkone
       
      Started by frankthearm, Yesterday, 09:08 AM
      12 responses
      44 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by quantismo, 04-17-2024, 05:13 PM
      5 responses
      35 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by proptrade13, Today, 11:06 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by love2code2trade, 04-17-2024, 01:45 PM
      4 responses
      35 views
      0 likes
      Last Post love2code2trade  
      Working...
      X