Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need Help for a simple indicator programming

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

    Need Help for a simple indicator programming

    I am a newbie to NT. I used to use TOS to program all my candlestick indicator. Now I want to write the same in NT and find it really difficult. Here is what I want to achieve:

    A Green up arrow indicate to buy when a WICK REVERSAL candlestick appear
    Condition:
    1. The body is used to determine the size of the reversal wick. A wick that is 3.5 times larger than the size of the body.
    2. The bullish reversal wick, the close of the bar fall within the top 25 percent of the overall range
    If these 2 conditions is true, a green up arrow show under that candlestick to indicate buy.

    I use the wizard to create a double called "ShadowFactor" and a double called "Closepercentage" and a Green Arrow plot.

    Here is the code:
    Code:
    namespace NinjaTrader.Indicator
    {
        public class selfWichBullRev : Indicator
        {
            #region Variables
            // Wizard generated variables
                private double shadowFactor = 0.35; // Default setting for ShadowFactor
                private double closepercentage = 0.25; // Default setting for Closepercentage
            // User defined variables (add any user defined variables below)
            #endregion
    
            protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.SteelBlue), PlotStyle.TriangleUp, "PossibleBuy"));
                Overlay                = false;
            }
    
            protected override void OnBarUpdate()
            {
                if (High[0] - Close[0] <= Closepercentage * (High[0] - Low[0]) && Math.Min(Open[0], Close[0]) - Low[0] > 100 * ShadowFactor * Math.Abs(Open[0] - Close[0]) )
                {PossibleBuy.Set(Close[0]);
                }
              
            }
    
            #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 PossibleBuy
            {
                get { return Values[0]; }
            }
    
            [Description("")]
            [GridCategory("Parameters")]
            public double ShadowFactor
            {
                get { return shadowFactor; }
                set { shadowFactor = Math.Max(0.01, value); }
            }
    
            [Description("")]
            [GridCategory("Parameters")]
            public double Closepercentage
            {
                get { return closepercentage; }
                set { closepercentage = Math.Max(0.01, value); }
            }
            #endregion
        }
    }
    When I compile, it keep saying that error:
    Line 62: Cannot implicitly convert type 'double' to 'int'
    Line 62 is the
    public double ShadowFactor
    {
    get { return shadowFactor; }
    set { shadowFactor = Math.Max(0.01, value); }
    }
    Which is the wizard generate section and has nothing to do with me...

    Please help me to find out where go wrong...

    Thank

    #2
    Further investigation, any thing I wrote in Ninja Script return this error : "Cannot implicitly convert type 'double' to 'int?'. An explicit conversion exists (are you missing a cast?)"

    I follow step by step in Help - Beginner - Using Price Variable. When in the step to hit F5, this error show up again!

    Then I copy and paste a indicator copy, the same error show up.

    Is my software have problem? Or am I missing something.

    Comment


      #3
      Originally posted by hughred22 View Post
      Further investigation, any thing I wrote in Ninja Script return this error : "Cannot implicitly convert type 'double' to 'int?'. An explicit conversion exists (are you missing a cast?)"

      I follow step by step in Help - Beginner - Using Price Variable. When in the step to hit F5, this error show up again!

      Then I copy and paste a indicator copy, the same error show up.

      Is my software have problem? Or am I missing something.
      It sounds like your error is in another, different, indicator, as your code, at first blush, does look correct. Look at the error returned to see what file has the problem. You can always paste a picture of what your compilation error is, so that we can take a look.

      Comment


        #4
        You are right on! I am such a noob.
        This problem solved and I have another serious problem.
        So after successfully compiled 4 indicators, 2 is working and 2 is not showing up. Here is the run down:
        I created 4 candlestick indicator to indicate Wick Reversal pattern.

        WickBullRev:
        Code:
                protected override void OnBarUpdate()
                {
        
                    if(High[0] - Close[0] <= 0.20 * (High[0] - Low[0]) && Math.Min(Open[0], Close[0]) - Low[0] > 3.50 * Math.Abs(Open[0]-Close[0]))
                    {
                    // Paints a red down arrow on the current bar 1 tick below the low
                    DrawArrowUp(CurrentBar.ToString(), true, 0, Low[0] - TickSize, Color.SkyBlue);
         
                    }
                }
        WickReversalBullBuySingel
        Code:
        protected override void OnBarUpdate()
                {
                     if(High[1] - Close[1] <= CloseP3 * (High[1] - Low[1]) && Math.Min(Open[1], Close[1]) - Low[1] > ShadowFactor3 * Math.Abs(Open[1]-Close[1]) && Close[0] > High[1])
                    {
                    // Paints a red down arrow on the current bar 1 tick below the low
                    DrawArrowUp(CurrentBar.ToString(), true, 0, Low[0] - TickSize, Color.LightGreen);
         
                    }
                }
        WickReversalBear
        Code:
         protected override void OnBarUpdate()
                {
                if(Close[0]- Low[0] <= CloseP * (High[0] - Low[0]) && High[0] - Math.Max(Open[0], Close[0]) > ShadowFactor * Math.Abs(Open[0]-Close[0]))
                    {
                    // Paints a red down arrow on the current bar 1 tick below the low
                    DrawArrowDown(CurrentBar.ToString(), true, 0, High[0] + TickSize, Color.SkyBlue);
                    }
                }
        WickBearReversalSellSingal:
        Code:
        protected override void OnBarUpdate()
                {
                    if(Close[1]- Low[1] <= CloseP2 * (High[1] - Low[1]) && High[1] - Math.Max(Open[1], Close[1]) > ShadowFactor2 * Math.Abs(Open[1]-Close[1]) && Close[0] < Low[1])
                    {
                    // Paints a red down arrow on the current bar 1 tick below the low
                    DrawArrowDown(CurrentBar.ToString(), true, 0, High[0] + TickSize, Color.LightGreen);
                    }
                }
        The first time after I coded, I loaded all the indicators in my ES chart and all worked beautifully.
        BUT, when I open my YN chart, "WickReversalBullBuySingel" and "WickBearReversalSellSingal" did not show up. Then I close the ES and open the ES again, the red green signal now is gone. I restart my NT and Computer 100 times, and both "WickReversalBullBuySingel" and "WickBearReversalSellSingal" do not show up.

        So it show up once and then do not show up anymore. There is not complied problem. What should I do to trouble shoot this? Thank in advance.

        Comment


          #5
          Hello,

          Please follow the instructions below to see where the errors are coming from after compiling the indicator. This will allow you to debug the indicator/strategy or remove it from your PC. If you are wondering why you receive an error when compiling only one indicator, it is because NinjaTrader compiles all indicators and strategies- not just one.

          Open NinjaTrader
          From the Control Center select the Tools menu--> select the Edit NinjaScript menu item--> select Indicator
          Select an indicator and double click on it.
          A new window will appear and you will need to right click in the window and select Compile to compile the indicators.
          At the bottom of the window a new section will appear were you can find the error locations.
          From there you have the option to remove the indicator or debug it.

          Let me know what errors are listed here or take a screenshot. To send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CRTL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.
          BrettNinjaTrader Product Management

          Comment


            #6
            Hello,


            Do you receive any errors on the Log tab of the Control Center?

            Based on the code you provided, you're likely running into an issue explained in the following forum post from our Tips section:

            http://www.ninjatrader.com/support/f...ead.php?t=3170

            Please try adding the following snippet to the beginning of your code in OnBarUpdate()
            Code:
            if (CurrentBar < 1)
            return;
            This is to account for the DataSeries objects where you have Close[1] instead of Close[0].



            You need to ensure you have enough bars on the chart to calculate correctly.
            MatthewNinjaTrader Product Management

            Comment


              #7
              I actually found the problem by comparing my code to the Candlestickpatterm code. You are spot on and I need to make sure I have enough bars....

              Now I am feeling like an idiot...Haha~~~

              Thanks and you guys are awesome!! Glad I switch to NT
              More programming~~~~ Yeah!

              Comment


                #8
                We are happy to help! Have a great weekend
                MatthewNinjaTrader Product Management

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by pilotfo, Today, 12:50 PM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by DTSSTS, Today, 11:35 AM
                2 responses
                7 views
                0 likes
                Last Post DTSSTS
                by DTSSTS
                 
                Started by sinpeople, Today, 07:20 AM
                2 responses
                5 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by Frank1000, Today, 03:05 AM
                5 responses
                12 views
                0 likes
                Last Post Frank1000  
                Started by fscabrera03, Yesterday, 01:18 PM
                2 responses
                25 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X