Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
OnStartUp error
Updated September 17, 2013
Top Posters
looks_one
Ragdoll
with 7 posts (1 thanks)
looks_two
cory
with 2 posts (0 thanks)
looks_3
Big Mike
with 2 posts (0 thanks)
looks_4
Tasker_182
with 2 posts (0 thanks)
trending_up
5,102 views
thumb_up
1 thanks given
group
4 followers
forum
15 posts
attach_file
0 attachments
OnStartUp error
September 17th, 2013, 01:26 PM
virginia
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090
Ragdoll
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];
}
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
September 17th, 2013, 01:43 PM
Cedar Rapids, iowa
Legendary Market Wizard
Experience: Intermediate
Platform: Ninjatrader
Broker: Ninjatrader - Continuum
Posts: 716 since Aug 2009
Thanks Given: 476
Thanks Received: 1,402
cory
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
September 17th, 2013, 02:07 PM
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
}
}
September 17th, 2013, 03:41 PM
virginia
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090
Tasker_182
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.
September 17th, 2013, 03:51 PM
Cedar Rapids, iowa
Legendary Market Wizard
Experience: Intermediate
Platform: Ninjatrader
Broker: Ninjatrader - Continuum
Posts: 716 since Aug 2009
Thanks Given: 476
Thanks Received: 1,402
cory
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
September 17th, 2013, 04:17 PM
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
Last Updated on September 17, 2013