NexusFi: Find Your Edge


Home Menu

 





OnStartUp error


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Ragdoll with 7 posts (1 thanks)
    2. looks_two Big Mike with 2 posts (0 thanks)
    3. looks_3 Tasker_182 with 2 posts (0 thanks)
    4. looks_4 Fat Tails with 2 posts (0 thanks)
    1. trending_up 4,840 views
    2. thumb_up 1 thanks given
    3. group 4 followers
    1. forum 15 posts
    2. attach_file 0 attachments




 
Search this Thread

OnStartUp error

  #11 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090


Ragdoll View Post
OK,

I've had my RTFM moment and have solved the object problem with a little help from Bertrand. I added an if statement to check for a null on GetDayBar(1). The problem now is it is always null.

you can add;
if (Bars.LastBarOfSession)
{
priordayOpen = Open[0];
priordayHigh = High[0];
priordayLow = Low[0];
priordayClose = Close[0];
}

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Deepmoney LLM
Elite Quantitative GenAI/LLM
ZombieSqueeze
Platforms and Indicators
Are there any eval firms that allow you to sink to your …
Traders Hideout
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
The Program
18 thanks
Battlestations: Show us your trading desks!
18 thanks
  #12 (permalink)
 
Tasker_182's Avatar
 Tasker_182 
Cedar Rapids, iowa
Legendary Market Wizard
 
Experience: Intermediate
Platform: Ninjatrader
Broker: Ninjatrader - Continuum
Posts: 716 since Aug 2009
Thanks Given: 476
Thanks Received: 1,401


cory View Post
you can add;
if (Bars.LastBarOfSession)
{
priordayOpen = Open[0];
priordayHigh = High[0];
priordayLow = Low[0];
priordayClose = Close[0];
}

Is the prior day close the settlement price?

Be yourself; everyone else is already taken. Oscar Wilde
Reply With Quote
  #13 (permalink)
 Ragdoll 
Walterboro, South Carolina
 
Experience: Intermediate
Platform: ninjatrader, amibroker, thinkorswim
Trading: futures
Posts: 13 since Aug 2013
Thanks Given: 1
Thanks Received: 6


Finally got it to work!

here is the working code:

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// this is a strategythat uses pivot points and support / resistance levels to set exit and entry points
    /// </summary>
    [Description("this is a strategythat uses pivot points and support / resistance levels to set exit and entry points")]
    public class PivotPlay : Strategy
    {
        #region Variables
        // Wizard generated variables
        private double pct = 0.005; // Default setting for Pct
        // User defined variables (add any user defined variables below
		private bool firstTime;
		private bool islong;
		
		private double pvtu;
		private double pvtl;
		private double rl1u;
		private double rl1l;
		private double rl2u;
		private double rl2l;
		private double rl3u;
		private double rl3l;
		private double sl1u;
		private double sl1l;
		private double sl2u;
		private double sl2l;
		private double sl3u;
		private double sl3l;
		
		private double pvt;
		private double rl1;
        private double rl2;
		private double rl3;
		private double sl1;
		private double sl2;
		private double sl3;
		private double prevDayClose;
		private double prevDayHigh;
		private double prevDayLow;
		
		
        #endregion

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
			firstTime = false;
			islong = false;
			CalculateOnBarClose = true;
			
					
		
        }
		protected override void OnStartUp()
		{
		}
		/// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
		if(Bars.FirstBarOfSession && FirstTickOfBar)
		{
		if (Bars.GetDayBar(1) != null)
			{
			prevDayClose = Bars.GetDayBar(1).Close; 
			prevDayHigh	 = Bars.GetDayBar(1).High; 
			prevDayLow = Bars.GetDayBar(1).Low;
			}
			pvt = (prevDayClose + prevDayHigh + prevDayLow) / 3;
			
			 pvtu = pvt + (pvt * pct);
			 pvtl = pvt - (pvt * pct);
			 rl1u = rl1 + (rl1 * pct);
			 rl1l = rl1 - (rl1 * pct);
			 rl2u = rl2 + (rl2 * pct);
			 rl2l = rl2 - (rl2 * pct);
			 rl3u = rl3 + (rl3 * pct);
			 rl3l = rl3 - (rl3 * pct);
			 sl1u = sl1 + (sl1 * pct);
			 sl1l = sl1 - (sl1 * pct);
			 sl2u = sl2 + (sl2 * pct);
			 sl2l = sl2 - (sl2 * pct);
			 sl3u = sl3 + (sl3 * pct);
			 sl3l = sl3 - (sl3 * pct);
			
			Print(pvt);
			Print(pvtu);
	
			
		
		
	    
		}
		
			
			/// Rule 1;  enter long if close above first bar high...;
			if (Bars.FirstBarOfSession)
			{ return;
			}
			else
			{ int barOne = Bars.BarsSinceSession;
				if (Close[0] > High[barOne])
				{
				

					
				  islong = true;
				  firstTime = true;
				EnterLong("Entry");
				}
			}
		/// rule 2; 
			
			
			
		
			
			
			
		
		
			
        }

        #region Properties
        [Description("")]
        [GridCategory("Parameters")]
        public double Pct
        {
            get { return pct; }
            set { pct = Math.Max(0.001, value); }
        }
        #endregion
    }
}

Started this thread Reply With Quote
  #14 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090


Tasker_182 View Post
Is the prior day close the settlement price?

I copy it from ninja indicator, if you think settlement price is different from this price then you have to enter it manually.

Reply With Quote
  #15 (permalink)
 
Tasker_182's Avatar
 Tasker_182 
Cedar Rapids, iowa
Legendary Market Wizard
 
Experience: Intermediate
Platform: Ninjatrader
Broker: Ninjatrader - Continuum
Posts: 716 since Aug 2009
Thanks Given: 476
Thanks Received: 1,401


cory View Post
I copy it from ninja indicator, if you think settlement price is different from this price then you have to enter it manually.

That's kind of why i asked the question as the thread OP is using yesterdays close for his pivots but if he is calculating futures pivots then he would need the settlement price to have correct pivots.

Be yourself; everyone else is already taken. Oscar Wilde
Reply With Quote
  #16 (permalink)
 Ragdoll 
Walterboro, South Carolina
 
Experience: Intermediate
Platform: ninjatrader, amibroker, thinkorswim
Trading: futures
Posts: 13 since Aug 2013
Thanks Given: 1
Thanks Received: 6

right now I'm testing against stocks to see if the concept tests out. I'll figure out the futures after testing. You are right though, futures require the settlement price to be accurate.

Cheers

Ragdoll

Started this thread Reply With Quote
Thanked by:




Last Updated on September 17, 2013


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts