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

swing indicator & output window

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

    swing indicator & output window

    Dear Traders,

    I should say I am a beginner with ninjaScript.
    I am trying to make use of swing indicator. My code is very simple:

    protected override void OnBarUpdate()
    {

    // Prints the high price of the most recent swing high
    Print("The high of the swing bar is " + High[Math.Max(0, Swing(5).SwingHighBar(0, 1, 5))]);

    }

    And my problem(s) are simple I guess but I couldn't solve them. So

    1. How do I stop this code from populating the whole output window.? I want just a few values.
    2. If there are roughly 120 bars on the chart, I would like this indicator to return lets say 3-4 highs which happened within a range of last 80 bars. How would I do this?
    3. What is the most efficient way of printing the output of the code into the output window. I currently do this: a) compile the indicator b) clear the output window c) go to chart window d) press F5 to populate the output window. I there a smarter way?

    Regards,

    Ionaz

    #2
    ionaz,

    I am happy to assist you.

    Why don't you try using DrawText or DrawTextFixed? This will output directly to the chart and won't clutter the output window.

    For more information, please see the following links.

    DrawText : http://www.ninjatrader.com/support/h...l?drawtext.htm

    DrawTextFixed : http://www.ninjatrader.com/support/h...wtextfixed.htm

    What sort of chart are you running this on?

    As far as your second question. I am not sure what you mean. Do you want to display 3-4 highs in order of them occurring as some sort of resistance level?

    Please let me know if I may assist further.
    Last edited by NinjaTrader_AdamP; 11-09-2011, 08:11 AM.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Dear AdamP

      Thank you. I will certainly use those methods as they seem to be a great shortcut for the debugging.

      I am using this on the hourly chart since I am currently using a free version of Ninja.

      Adam, I am not concerned about the resistance level, I am interested in the swing indicator, because I want to find the prices of those 3-4 peaks, and then check if they form a HH (higher highs) and HL (higher lows).

      Another condition that I want to test is if those HHs and HLs are above the SMA(89) line.

      I would be very grateful if you could direct me to the right way and show which methods I need to use.

      Thanks again very much!

      Regards

      ionaz

      Comment


        #4
        Sorry, my mistake, I actually meant the daily chart

        Comment


          #5
          Hi ionaz,

          If you have Print() in every OnBarUpdate() then it prints for every bar. You would have to conditionally print, maybe by creating a data series and comparing its value to it previous and only printing on the changes. Something like:

          if (myCustomDataSeries[0] != myCustomDataSeries[1])
          Print("This value is new");

          Please see here for help working with custom data series objects in NinjaScript.


          It's good to be aware of challenges with accessing swing programatically. Swing is mainly used as a visual to show market structure. As new values come in, prior swing values are changed, and this can make getting meaningful programmatic values difficult.
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            I was able to create this which may work for you. It's designed to run on the last bar of the chart, and then prints the swing values for the last so many instances of swing highs.

            Code:
            if (Count - 2 == CurrentBar) //True on last bar when CalculateOnBarClose = true
            {				
            for (int x = 1; x < 11;  x++) //Prints the last 10 instances of swing. runs on last bar. 
            Print("The high of instance " + x + " swing bar is " + High[Math.Max(0, Swing(5).SwingHighBar(0, x, CurrentBar))]);					
            }
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Ryan,

              Thank you very much! Very much appreciated.
              That
              "for (int x = 1; x < 11; x++)"

              was a great relief for my battle.

              ionaz

              Comment


                #8
                easier said than done

                Ok, I have to admit my first steps with NinjaScript are really tough. I I think it's silly to spend more time on this cosidering that it's a peace of cake for this forum.

                What I'm trying to do is plotting dots that mark swing highs/lows on the chart (in this case last 10 instances of swing high). I failed to understand the mechanics of plotting when I looked at the code of original swing indicator. So I am building it myself, with your support.

                And I know that to plot a dot I need the X and Y values roughly speaking. I've already got Y values already (Thank you and this thread). Now when it comes to x values, from all the methods I've checked the quickest I believe is to use the same swing syntax. This is what I don't understand. The swing description in the help guide says: "You can access methods within this indicator to determine the number of bars ago a swing point occured or the current swing value." Ok, great, I am interested in the number of bars ago a swing point occured, because this will work as an x-axis value when it comes to DrawDot() method.

                So I don't understand how can I dig this <bars ago> value via Swing syntax:

                Swing(int strength).SwingHighBar(int barsAgo, int instance, int
                lookBackPeriod)
                Swing(IDataSeries input, int strength).SwingHighBar(int barsAgo,
                int instance, int lookBackPeriod)


                In my view it is asking me to indicate the barsAgo value, but I am looking for it!

                Sorry for such a long text around such an easy thing, I guess I just spent too much time on it.

                Looking forward to your reply

                ionaz

                Comment


                  #9
                  Hi ionaz,
                  if this can help. An indicator already done by a member.
                  Here you have an example + a trace on the chart.
                  You can change it if you like.
                  good luck
                  Attached Files

                  Comment


                    #10
                    Hi mate41,

                    Thank you for the indicator. It looks pretty much what I might need.
                    However for the sake of brevity and out of curiosity now I must know how to extract a "bars ago" from the swing indicator.

                    If I go to the description of the swing ind, I see that I should be able to do that. It says it returns value representing the number of bars ago. What I don't get is that according to the syntax it looks to me that I will be asked to indicate this number myself.

                    I might be wrong. I should be wrong if I got it right.

                    I would really appreciate if you could teach me how to extract # of bars ago via the swing indicator.

                    BTW, are there any drawbacks in doing that through the swing indicator?

                    Thank you

                    ionaz

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by CortexZenUSA, Today, 12:53 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post CortexZenUSA  
                    Started by CortexZenUSA, Today, 12:46 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post CortexZenUSA  
                    Started by usazencortex, Today, 12:43 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post usazencortex  
                    Started by sidlercom80, 10-28-2023, 08:49 AM
                    168 responses
                    2,264 views
                    0 likes
                    Last Post sidlercom80  
                    Started by Barry Milan, Yesterday, 10:35 PM
                    3 responses
                    11 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Working...
                    X