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

Arrows on indicator not plotting on each (true condition) bar

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

    Arrows on indicator not plotting on each (true condition) bar

    Hello,

    I have an indicator that draws an arrow up/down when price crosses a BB and stochastic is above/below a certain number. For the most part, it works great. I have noticed however, that an arrow is not plotted on the current bar if the previous bar crosses a band, but the stochastic is not above/below a certain number. I understand that the previous bar does not meet all of my conditions, be the next bar (current bar) does. Is there a way to correct this problem do I can get an arrow EACH time the conditions are met? Here is my current logic:

    // Set 1
    if (IsFirstTickOfBar)

    priorValueLow3 = Bollinger1.Lower[0];

    if ((Stochastics1.K[0] < NumberLow)
    && (Bollinger1.Lower[0] <= priorValueLow3 && (CrossBelow(Low, Bollinger1.Lower, 1))))
    {
    Draw.ArrowUp(this, @"GreenArrowUp"+CurrentBar, false, 0, (Low[0] + (-2 * TickSize)) , Brushes.Lime);
    }

    if (Bollinger1.Lower[0] <= priorValueLow3)
    {
    priorValueLow3 = Bollinger1.Lower[0];
    }
    Thank you very much for the help.
    Chris

    #2
    Hello Chris,

    Thank you for the post.

    With the sample provided, the condition will only evaluate the current bar. If you wanted to check two bars ago for the cross above, expand the lookback period to 2. You would also need to check for the Bollinger1.Lower[0] <= priorValueLow3 for the previous bar as well.

    Example:

    Code:
    if ( ((Stochastics1.K[0] < NumberLow)
    && (Bollinger1.Lower[0] <= priorValueLow3 && (CrossBelow(Low, Bollinger1.Lower, 1)))) || 
    ((Stochastics1.K[1] < NumberLow)
    && (Bollinger1.Lower[1] <= priorValueLow3 && (CrossBelow(Low, Bollinger1.Lower, 2)))) )
    or:

    Code:
    if ( ((Stochastics1.K[0] < NumberLow)
    && (Bollinger1.Lower[0] <= priorValueLow3 && (CrossBelow(Low, Bollinger1.Lower, 2))))
    To check the current value of Stockastics.K and Bollinger.Lower and evaluate the CrossBelow with a 2 bar look back.


    Please let us know if this does not resolve your inquiry.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chris,

      The problem I am having is two things:

      1) Even though the conditions are true, an arrow is not being drawn for each 'true' bar.

      2) Of the 2 conditions I am looking for, if the previous bar has 1 of 2 conditions true and the current bar has 2 of 2 conditions true, an arrow will not be drawn for the bar where both conditions are met.

      Hope that makes sense.
      Chris

      Comment


        #4
        Chris,


        it seems to me like your problem can be solved rather easily.


        commands like isrising, isfalling and particularly crossbelow and crossabove are quite quirky (this is also true of all oscillating indicators like rsi, stochastics and such).

        crossbelow is only true for the single bar when close[1] was above the lower bollinger band and now close[0] is below it. for the following periods, it won't be true anymore as it was close[2] that was above the indicated level but now both close[1] and close[0] have been below, and so on.

        i would recommend you changed crossbelow for close[0] < lower bollinger band, this way for every bar in which close is below the lower bollinger band and the other conditions that have been defined are true the indicator should draw an arrow as intended.


        very well, regards.

        Comment


          #5
          Thank you for the responses.

          So what I am trying to do is catch a a pullback from an extreme move. I would like an arrow drawn the instant price crosses a band so I can place an order at point of intersection and catch the pullback on the current bar. The issue I have though is that an arrow is not being plotted on each bar that does this. I have noticed that if the current bar crosses and an arrow is drawn, an arrow will not be plotted on the following candle that crosses the band as well. It seems to have a problem plotting if more than one candle in a row crosses the band. I have used (CrossBelow(Low, (CrossBelow(Close, (Low[0] < Bollinger1.Lower[0]), and so on. Does anyone have any idea that could help plot arrows on each bar that has conditions listed as true?

          Thank you,
          Chris

          Comment


            #6
            Hello Chris,

            Thanks for the reply.

            I do not see how you could have two cross below subsequently and the lookback period is 1, the plot would have to reverse the condition in the bar after a cross below so the condition would be false on the current bar. I do not have the full code so I can only guess, but this might be the reason you are not getting the results you want.

            Have you added Print statements to debug this? You can Print out your conditions to see why they are not becoming true when you want them to. These prints can be viewed from the Ninjascript output window.

            https://ninjatrader.com/support/help...-us/?print.htm - Print
            https://ninjatrader.com/support/help...us/?output.htm - Output window.

            Please let us know if you have any questions.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              ChrisL,

              It seems to be working better now after using this logic provided:

              // Set 1
              if (IsFirstTickOfBar)

              priorValueLow3 = Bollinger1.Lower[0];

              if ((Stochastics1.K[0] < NumberLow)
              && (Bollinger1.Lower[0] <= priorValueLow3 && (Low[0] < Bollinger1.Lower[0] )))
              {
              Print(Times[0][0].ToString() + @"Conditions True. Arrow Should Be Placed");
              Draw.ArrowUp(this, @"GreenArrowUp"+CurrentBar, false, 0, (Low[0] + (-2 * TickSize)) , Brushes.Lime);
              }

              if (Bollinger1.Lower[0] <= priorValueLow3)
              {
              priorValueLow3 = Bollinger1.Lower[0];
              }
              One strange issue I am having though is that if I switch to another chart and switch back, the arrows will occasionally disappear. Is there a solution to this that will keep the arrows permanently plotted?

              Thanks,
              Chris

              Comment


                #8
                Hello Chris,

                Thank you for the reply.

                Are you switching the instruments on the same chart or switching to a new tab/window? You can set the IsSuspendedWhileInactive property to false in State.SetDefualts to keep the indicator calculating even if not visible.



                You can always reload the script on your chart with F5. Using print statements will help you debug most things. Have you already tried printing the values that your condition is evaluating? The best place to start would be to add a print within the IF statement, and if it does not print anything during runtime, then print out the values used in that condition to see why those values are not evaluating to true, then adjust your script accordingly.

                If we may be of any further assistance, please let us know.
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks ChrisL,

                  I have changed the IsSuspendedWhileEnactive = false, so we will see what that does. As for the arrows not plotting, I have used prints for price and indicator values to see if the conditions are true and should plot, and it seems like when stochastic value is false and the cross below is true on the previous bar, and both conditions are true on current bar, an arrow won't print due to the previous bars values. Very confusing to say the least. I'll keep working on it.

                  If sending you the script will give you a better idea on what is happening and what I am trying to explain, I will be happy to send it to you.

                  Thanks again,
                  Chris

                  Comment


                    #10
                    Hello Chris,

                    Thank you for the reply.

                    This could be caused by your conditions becoming false after some amount of data has loaded.
                    Or, if nothing prints on the chart, then it could be that no historical data was processed at all. I would like to test this script on my computer to see what could be going wrong.

                    First, make sure the script compiles then follow these steps to export the script.


                    After this, send me your code file to*platformsupport[at]ninjatrader[dot]com.*
                    You can do this by going to the Control Center-> Help-> Mail to Platform Support.
                    Please reference the following in the email body:"ATTN ChrisL <paste this forum thread link here>"

                    You will find the exported .zip file in ..\Documents\NinjaTrader 8\bin\Custom\ExportNinjaScript

                    I look forward to your reply.
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      Thank Chris,

                      I'll send it your way right now. So I noticed today that I also can't get an arrow to show up until I click on another chart and then click back, or by reloading ninjascript.

                      Let me know what you find, and thanks again,
                      Chris

                      Comment


                        #12
                        I am having issues with the arrows on my indicator not plotting when the conditions are true if the prior bar(s) are true as well. They will also disappear and reappear on a tick by tick basis if the conditions change between true and false. I think it may have to do with my IsFirstTickOfBar and priorValue logic. Is there way to set those so if the conditions becomes true, the arrow will plot on each bar that has true conditions and not allow them to change back to false, thus removing the arrows?

                        Here is mu logic:
                        // Set 1
                        if (IsFirstTickOfBar)

                        priorValueLow3 = Bollinger1.Lower[0];

                        if ((Stochastics1.K[0] < NumberLow)
                        && (Bollinger1.Lower[0] <= priorValueLow3 && (CrossBelow(Low, Bollinger1.Lower, 1))))
                        {
                        Draw.ArrowUp(this, @"GreenArrowUp"+CurrentBar, false, 0, (Low[0] + (-2 * TickSize)) , Brushes.Lime);
                        }

                        if (Bollinger1.Lower[0] <= priorValueLow3)
                        {
                        priorValueLow3 = Bollinger1.Lower[0];
                        }
                        Thank you all for the much needed support and help,
                        Chris

                        PS: Here are some picks (examples of what is happening

                        Pic(1)(Time 42:02) shows that an arrow should be drawn, but is not because of the previous candles crossing the band, even though conditions on the previous bars are not all true, but they are true on the current bar.

                        Pic(2)(Time 37:03) shows that an arrow up was plotted because stochastic was below blue line(20), and price low crossed the band.

                        Pic(3)(Time 32:41)shows the arrow had disappeared after being plotted 5 minutes ago, due to price moving up, causing stochastic to be pulled above the blue line.
                        Attached Files
                        Last edited by chrisca; 01-24-2018, 12:49 PM.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by rtwave, 04-12-2024, 09:30 AM
                        4 responses
                        31 views
                        0 likes
                        Last Post rtwave
                        by rtwave
                         
                        Started by yertle, Yesterday, 08:38 AM
                        7 responses
                        29 views
                        0 likes
                        Last Post yertle
                        by yertle
                         
                        Started by bmartz, 03-12-2024, 06:12 AM
                        2 responses
                        22 views
                        0 likes
                        Last Post bmartz
                        by bmartz
                         
                        Started by funk10101, Today, 12:02 AM
                        0 responses
                        7 views
                        0 likes
                        Last Post funk10101  
                        Started by gravdigaz6, Yesterday, 11:40 PM
                        1 response
                        9 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Working...
                        X