Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Help with my first script (3 bar reversal)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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
    }
    }

    #2
    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 P.NinjaTrader Customer Service

    Comment


      #3
      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, 01:18 PM. Reason: Correction

      Comment


        #4
        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:


        Good luck.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          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

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by wzgy0920, 02-22-2024, 01:11 AM
          5 responses
          32 views
          0 likes
          Last Post wzgy0920  
          Started by wzgy0920, Yesterday, 09:53 PM
          2 responses
          49 views
          0 likes
          Last Post wzgy0920  
          Started by Kensonprib, 04-28-2021, 10:11 AM
          5 responses
          191 views
          0 likes
          Last Post Hasadafa  
          Started by GussJ, 03-04-2020, 03:11 PM
          11 responses
          3,230 views
          0 likes
          Last Post xiinteractive  
          Started by andrewtrades, Today, 04:57 PM
          1 response
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X