Announcement

Collapse
No announcement yet.

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 BraisedInBlue, Today, 06:43 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post BraisedInBlue  
                    Started by AaronKoRn, Today, 06:28 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post AaronKoRn  
                    Started by pjsmith, Today, 01:00 AM
                    1 response
                    12 views
                    0 likes
                    Last Post NT-Roland  
                    Started by alejandro888, Yesterday, 08:41 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post alejandro888  
                    Started by UltraNIX, Today, 02:14 AM
                    0 responses
                    9 views
                    0 likes
                    Last Post UltraNIX  
                    Working...
                    X