![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Oct 2007
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
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 } } |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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])
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Oct 2007
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
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
|
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Mar 2007
Location: , Florida, USA
Posts: 663
Thanks: 36
Thanked 7 times in 6 posts
|
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |