NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 10-16-2007, 06:06 PM   #1
ClydeMacLeod
Junior Member
 
Join Date: Oct 2007
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
Default Help with my first script (3 bar reversal)

Hi Guys,

I’m hoping you can help me. I originally wrote this in VB for another trading platform and have converted it to C#. (I’m brand new to C#, but think I have done this properly). When I compile I get a whole load of error messages that do not refer to any lines in my code. I really don’t have any easy way of debugging this.

I had thought about compiling the base template before I started adding code and then at each major step. However, if I try and compile the brand new template, as is, I get errors as well.

I’d really appreciate any help you can give me on this. My intention is to turn this into a system that will automatically move my profit stops on Forex trades at night.

Thanks,
Clyde



Code logic -- 3 bar reversal stop A three bar reversal stop looks three valid bars back and finds either the lowest low (for longs) or highest high (for shorts) of the prior 3 bars. [/font]

A valid bar is defined as being a bar that is not an inside bar (a bar completely within the trading range of the prior bar).[/font]

<snippet - bbs would not premit me to post the whole thing>

protectedoverridevoid Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
CalculateOnBarClose = true;
Overlay = true;
PriceTypeSupported = false;
}

///<summary>
/// Called on each bar update event (incoming tick)
///</summary>

protectedoverridevoid OnBarUpdate()
{
int constOneBarAgo = 1;
int CurrentBarToReview = 1; // Trade bar we are evaluating
int OneBarPriorToCurrentBar = 2;
double RangeLL = Low[0]; // the cumulative Lowest Low of the back test range (start with current bar)
double RangeHH = High[0]; // the cumulative Highest High of the back test range
int ValidBarCount = 0; // We need 3 valid look back bars

while (ValidBarCount < 3)
{
// Loop for three valid bars back
// is this a valid bar for testing?
// A valid bar must be either higher or lower (or both) than the prior bar (not an inside day)

if (High[CurrentBarToReview] > High[OneBarPriorToCurrentBar] | Low[CurrentBarToReview] < Low[OneBarPriorToCurrentBar])
{
if (High[CurrentBarToReview] > RangeHH) RangeHH = High[CurrentBarToReview];
if (Low[CurrentBarToReview] < RangeLL) RangeLL = Low[CurrentBarToReview];
ValidBarCount ++;
}
//Increment loop and index pointer variables
CurrentBarToReview ++;
OneBarPriorToCurrentBar ++;
}

if (longDirection == true)
Plot0.Set(RangeHH);
else
Plot0.Set(RangeLL);
}

#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove

public DataSeries Plot0
{
get { return Values[0]; }
}

[Description("")]
[Category("Parameters")]

publicbool LongDirection
{
get { return longDirection; }
set { longDirection = value; }
}
#endregion
}
}
ClydeMacLeod is offline  
Reply With Quote
Old 10-17-2007, 12:23 AM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Hi ClydeMacLeod,

If you could describe some of the errors or even upload the .cs file we could provide you with some more assistance.

A quick thing I noticed so far is this:
if (High[CurrentBarToReview] > High[OneBarPriorToCurrentBar] | Low[CurrentBarToReview] < Low[OneBarPriorToCurrentBar])

The OR operator is done with two horizontal bars '||'.

See if it allows you to compile after that change.
if (High[CurrentBarToReview] > High[OneBarPriorToCurrentBar] || Low[CurrentBarToReview] < Low[OneBarPriorToCurrentBar])
NinjaTrader_Josh is offline  
Reply With Quote
Old 10-18-2007, 12:41 PM   #3
ClydeMacLeod
Junior Member
 
Join Date: Oct 2007
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
Default It compiles...but

Hi Josh,

Thanks for your reply. I changed the "or" to the correct symbol as you suggested and the code compiles.

However, no indicator results (no line) is displayed when I put this on my chart and I'm not sure why?

Thanks for your help.
Clyde
Last edited by ClydeMacLeod; 10-18-2007 at 01:18 PM. Reason: Correction
ClydeMacLeod is offline  
Reply With Quote
Old 10-18-2007, 02:28 PM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Hi Clyde,

Please check your logs for errors. I suspect you are running into the issue outlined here: http://www.ninjatrader-support.com/v...ead.php?t=3170

Also please check out this tip for debugging:
http://www.ninjatrader-support.com/v...ead.php?t=3418

Good luck.
NinjaTrader_Josh is offline  
Reply With Quote
Old 10-21-2007, 05:58 AM   #5
KBJ
Senior Member
 
Join Date: Mar 2007
Location: , Florida, USA
Posts: 663
Thanks: 36
Thanked 7 times in 6 posts
Default

Clyde,

You might also want to take a look at the MAX and MIN functions in the NinjaTrader help, as they are a much easier way to do what the while loop in your code is attempting.

KBJ
KBJ is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Add API instruction in the script. khawaja Automated Trading 10 10-31-2007 01:46 PM
Unwanted Position Reversal on Exit with Market Order (IB Papertrading) EvolveK Automated Trading 3 09-27-2007 01:36 PM
Help with a Basic Script crazytiger Strategy Development 1 06-20-2007 02:55 AM
NTMarketPosition in EFS script Oli Automated Trading 3 02-27-2007 04:47 AM
Reversal at stop Chicago Miscellaneous Support 1 11-02-2005 11:24 AM


All times are GMT -6. The time now is 10:22 PM.