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

Price crossing VWAP help

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

    Price crossing VWAP help

    I am trying to get a simple strategy to go long anytime the following conditions are met:

    Price is below Ninjacators VWAP indicator
    MACD crosses above average

    Go Long

    Code:
    namespace NinjaTrader.NinjaScript.Strategies
    {
    	public class Crossover : Strategy
    	{
    		private MACD MACD1;
    		private ncatSmartVWAP ncatSmartVWAP1;
    
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description								= @"";
    				Name									= "Crossover";
    				Calculate									= Calculate.OnBarClose;
    				EntriesPerDirection							= 5;
    				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)
    			{
    				SetStopLoss("", CalculationMode.Ticks, StopLossTicks, false);
    			}
    		
    			
    			else if (State == State.DataLoaded)
    			{				
    				MACD1							= MACD(12, 26, 9);
    			    ncatSmartVWAP1					= ncatSmartVWAP(Close);
    			}
    		}
    		
    		protected override void OnBarUpdate()
    		{
    			if (BarsInProgress != 0) 
    				return;
    
    			if (CurrentBars[0] < 1)
    			return;
    			
    			 // Set 1
    			if (Close[0] < ncatSmartVWAP1[0])
    			{
    				if ((CrossAbove(MACD1.Default, MACD1.Avg, 1)))
    				{
    					EnterLong(Convert.ToInt32(OrderQuantity), "");
    				}
    This code compiles fine but will not run on the strategy analyzer nor will it enable on a chart. The log outputs this error:

    "Indicator 'ncatSmartVWAP': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.

    Does anyone see what may be causing this?

    #2
    Hello Rogue_Two,
    Thanks for your post.

    I suspect that the line
    Code:
    ncatSmartVWAP1 = ncatSmartVWAP(Close);
    in State.DataLoaded is where the issue falls. I am having trouble making sense of the "Close" series you are passing in as an input, so that would be my first guess.

    If changing the input from "Close" to something else does not work, than I suggest reaching out to the vendor and asking them how to properly call this indicator in your strategy and what inputs you should be using.
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      I'll give that a try.

      Thanks Josh

      Comment


        #4
        I can't seem to figure out what it is.

        Ninjacators replied and said they do not offer support pertaining to Ninjascript and their indicators.

        Comment


          #5
          How should the Ninjatrader Orderflow VWAP be stated if I wanted to use that instead?

          Comment


            #6
            Here is our documentation on the OrderFlowVWAP Indicator method.
            Help Guide - Order Flow VWAP

            The sample at the bottom of that page demonstrates how you would implement in your script. Let me know if you have questions.
            Josh G.NinjaTrader Customer Service

            Comment


              #7
              Thanks Josh. I keep getting errors when I am trying to test the example in the link you posted.

              "Unhandled exception: Could not load file or assembly 'NinjaTrader.Vendor' or one of its dependencies. The system cannot find the file specified.

              Aslo, an error occurs if I try and use the strategy builder to get the basics put in when working with OrderFlow VWAP.

              Going back to the ncatSmartVWAP I was originally trying to work with...here is the .cs file

              Code:
              namespace NinjaTrader.NinjaScript.Indicators
              {
              	public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
              	{
              		
              		private ncatSmartVWAP[] cachencatSmartVWAP;
              
              		
              		public ncatSmartVWAP ncatSmartVWAP()
              		{
              			return ncatSmartVWAP(Input);
              		}
              
              
              		
              		public ncatSmartVWAP ncatSmartVWAP(ISeries<double> input)
              		{
              			if (cachencatSmartVWAP != null)
              				for (int idx = 0; idx < cachencatSmartVWAP.Length; idx++)
              					if ( cachencatSmartVWAP[idx].EqualsInput(input))
              						return cachencatSmartVWAP[idx];
              			return CacheIndicator<ncatSmartVWAP>(new ncatSmartVWAP(), input, ref cachencatSmartVWAP);
              		}
              
              	}
              }
              
              namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
              {
              	public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
              	{
              		
              		public Indicators.ncatSmartVWAP ncatSmartVWAP()
              		{
              			return indicator.ncatSmartVWAP(Input);
              		}
              
              
              		
              		public Indicators.ncatSmartVWAP ncatSmartVWAP(ISeries<double> input )
              		{
              			return indicator.ncatSmartVWAP(input);
              		}
              	
              	}
              }
              
              namespace NinjaTrader.NinjaScript.Strategies
              {
              	public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
              	{
              		
              		public Indicators.ncatSmartVWAP ncatSmartVWAP()
              		{
              			return indicator.ncatSmartVWAP(Input);
              		}
              
              
              		
              		public Indicators.ncatSmartVWAP ncatSmartVWAP(ISeries<double> input )
              		{
              			return indicator.ncatSmartVWAP(input);
              		}
              
              	}
              }
              Any chance you can take a look and see why my statement in State == State.DataLoaded is not working correctly? It seems like such a simple task to get closing price tested against where VWAP is yet I can't get it to work.

              Comment


                #8
                I keep getting errors when I am trying to test the example in the link you posted.
                This sounds like an error unrelated to Order Flow has occurred. What version of NT8 are you on?
                Aslo, an error occurs if I try and use the strategy builder to get the basics put in when working with OrderFlow VWAP.
                What is the error message?
                Going back to the ncatSmartVWAP I was originally trying to work with...here is the .cs file
                This snippet of code is protected and you would not be able to edit it.
                Any chance you can take a look and see why my statement in State == State.DataLoaded is not working correctly?
                What is the error message you are getting, and what code do you have inside State,DataLoaded?
                Josh G.NinjaTrader Customer Service

                Comment


                  #9
                  This sounds like an error unrelated to Order Flow has occurred. What version of NT8 are you on?
                  I'm on the latest release of 8.0.13.1

                  What is the error message?
                  When attempting to get conditions set to the Order Flow VWAP in the strategy builder I get the error message of:

                  "Unhandled exception: Could not load file or assembly 'NinjaTrader.Vendor' or one of its dependencies. The system cannot find the file specified."

                  This snippet of code is protected and you would not be able to edit it.
                  Oh, I'm not trying to edit it. I was only posting it to get some insight on how I may be able to get price to compare to this indicator as a condition.

                  What is the error message you are getting, and what code do you have inside State,DataLoaded?
                  "Indicator 'ncatSmartVWAP': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.

                  I've tried to put just about everything inside State.DataLoaded for the ncatSmartVWAP indicator.

                  I started off with

                  ncatSmartVWAP1 = ncatSmartVWAP(Close);

                  and have tried just about everything in place of (Close) as you suspected that might be in error.

                  Comment


                    #10
                    I'd like to take a look at your log and trace files to confirm a few things.
                    Please write in to PlatformSupport(at)NinjaTrader(dot)com
                    Reference this forum post and include ATTN: JOSH in the subject line.
                    1. Open your NinjaTrader folder under My Documents.
                    2. Right click on the 'log' and 'trace' folders and select Send To> Compressed (zipped) Folder.
                    3. Send the 2 compressed folders as attachments to the email address above.
                    4. Once complete, you can delete these compressed folders.
                    Josh G.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by ScottWalsh, 04-16-2024, 04:29 PM
                    6 responses
                    27 views
                    0 likes
                    Last Post ScottWalsh  
                    Started by frankthearm, Today, 09:08 AM
                    10 responses
                    35 views
                    0 likes
                    Last Post frankthearm  
                    Started by GwFutures1988, Today, 02:48 PM
                    0 responses
                    3 views
                    0 likes
                    Last Post GwFutures1988  
                    Started by mmenigma, Today, 02:22 PM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by NRITV, Today, 01:15 PM
                    2 responses
                    9 views
                    0 likes
                    Last Post NRITV
                    by NRITV
                     
                    Working...
                    X