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

Plotting arrows on indicator problems

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

    Plotting arrows on indicator problems

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

    #2
    Hello Chris,

    Unless RemoveDrawObject() is being called with the tag name of the object it shouldn't be removed.

    Meaning, if on one tick the condition is true and the object is drawn, then on the same bar the next tick the condition is false, the drawing object should remain as it was removed with RemoveDrawObject().

    Are you calling RemoveDrawObject()?

    May I see the print and output from the print showing the bar where the condition is evaluating as true?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      This was at 9:24AM PST on the 1 min chart on ES.

      1/25/2018 9:24:00 AM PriceLow[0]: 2844 < BollingerLower3[0]: 2844.04062701613 & StochasticK[0]: 16.6666666666641 < 20
      1/25/2018 9:24:00 AM Arrow Up Printed
      I do not have RemoveDrawObject referenced anywhere in my logic.

      Thanks,
      Chris

      Comment


        #4
        Hello Chris,

        Which condition is this for? (You have not included the print as requested)

        What is the value of NumberLow?

        What is the value of the Low on the previous bar? Is this greater than the bollinger1.Lower on the previous bar?
        What is the value of the Low on the current bar? Is this less than the bollinger1.Lower on the current bar?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Sorry Chelsea,

          I will add those to my print. On the print though, you can see that the NumberLow value is 20. As for the previous bar, would the previous bar(s) matter if 0 of 2 or 1 of 2 of the conditions are false? On the current bar that does not plot, I have noticed that the previous bar has crossed the band and is < Bollinger.Lower1, but the value of Stochastic is > NumberLow, resulting in 1 of 2 conditions to be true. This is an issue I can't seem to resolve as I would like the current bar arrow to be placed regardless of the conditions on the previous bar, just as long as the current bars conditions are true. Any explanations would be helpful.

          Thanks,
          Chris

          Comment


            #6
            So as you can see, the print shows that the previous bar did cross the band, but stochastic is greater than 20, only making conditions 1 of 2 true. On the current bar, price is less than the band and stochastic is less than 20, making both conditions 2 of 2 true. However, due to the previous bar, an arrow did not print. I don't have any logic in my script stating that the previous bars conditions must be false, which is why I am confused. I have attached a pic to show the two bars conditions.

            1/25/2018 7:15:00 AM PriceLow[1]: 2833.75 >= BollingerLower3[1]: 2837.53699129244 & StochasticK[1]: 24.8847517730492 > 20 & PriceLow[0]: 2834 < BollingerLower3[0]: 2834.9258158175 & StochasticK[0]: 16.9680851063826 < 20
            Attached Files

            Comment


              #7
              Hello Chris,

              You need to print what is in the condition.

              Your print does not match the condition so I cannot tell you why the condition is false or true.

              Condition
              Code:
              if ((Stochastics1.K[0] < NumberLow)
              && (Bollinger1.Lower[0] <= priorValueLow3 && (CrossBelow(Low, Bollinger1.Lower, 1))))
              Print
              Code:
              Print(string.Format("{0} | Stochastics1.K[0]: {1} < NumberLow: {2} && Bollinger1.Lower[0]: {3} <= priorValueLow3: {4} && Low[1]: {5} > Bollinger1.Lower[1]: {6} && Low[0]: {7} < Bollinger1.Lower[0]: {3}", Time[0], Stochastics1.K[0], NumberLow, Bollinger1.Lower[0], priorValueLow3, Low[1], Bollinger1.Lower[1], Low[0]));
              What output do you get for this?
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Chelsea,

                Here is what I got:

                1/25/2018 7:15:00 AM | Stochastics1.K[0]: 16.9680851063826 < NumberLow: 20 && Bollinger1.Lower[0]: 2834.9258158175 <= priorValueLow3: 2837.53699129244 && Low[1]: 2833.75 > Bollinger1.Lower[1]: 2837.53699129244 && Low[0]: 2834 < Bollinger1.Lower[0]: 2834.9258158175
                The only issue I see from this print is that the Low[1]: 2833.75 > Bollinger1.Lower[1]: 2837.53699129244. Would this be causing the issue, even though I have no logic regarding the cross of the previous price cross in my script?

                Chris

                Comment


                  #9
                  Hello Chris,

                  A CrossBelow is between two bars. If Series A is above Series B on the previous bar, and Series A is below Series B on the current bar, it has crossed below.

                  If you do not want any reference to the previous bar, do not use CrossBelow or CrossAbove.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Ok,

                    So what could be used to generate an arrow the instant price (Low[0]) crosses below the bollinger band without using cross below? I have tried Low[0] < Bollinger1.Lower[0], but I feel like when using this, the arrow isn't generated at the point of intersection, and is generated closer to the time of bar close.

                    Thanks,
                    Chris

                    Comment


                      #11
                      Hello Chris,

                      If you want to detect when a value crosses below you would need to compare with the previous bars close.

                      Meaning your condition would have to reference the previous bar.

                      Also, if your script is running with Calculate set to .OnBarClose, then the condition is only checked with the bar closes and thus can only perform the action when the bar closes. If you have Calculate set to .OnPriceChange then this would check each time the price changes and the object would be drawn the moment the price changes (in real-time or historically with TickReplay enabled).
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Well I am currently using Calculate.OnEachTick. So what you're saying is that there is no way to have an arrow posted on a current bar if the previous bar has crosses the band? I feel like there should be a way to plot an arrow if the previous bar has crossed the band as well. If the cross doesn't work, is there a way to have an arrow plotted once the low is detected below the band instead of detecting a cross?

                        Thanks,
                        Chris

                        Comment


                          #13
                          Hello Chris,

                          The CrossAbove / CrossBelow detects when SeriesA crosses SeriesB on the current bar by comparing the price of the previous bar.

                          There is no offset on this to detect when the previous bar has crossed.

                          You would need to explictly write this as a condition.

                          However, I am not quite understanding. Did you want to detect if the previous bar has crossed the bar previous to it?

                          As in: SeriesA from 2 bars ago is greater than SeriesB from 2 bars ago and SeriesA from 1 bar ago is less than SeriesB from 1 bar ago?

                          if (SeriesA[2] > SeriesB[2] && SeriesA[1] < SeriesB[1])
                          {
                          // execute code
                          }

                          (From what you've said so far, I don't think this is what you want)


                          In historical data, Calculate is always OnBarClose unless TickReplay is on. May I confirm that you are viewing this with real-time data only?
                          Or may I confirm you have TickReplay enabled?


                          Below is a publicly available link to the help guide on Calculate.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Chelsea,

                            Thanks for the example. What I am wanting out of this is to stop a previous bar from allowing an arrow placed at the current bar when the the conditions are true. I don't care what the previous bar does. All I care about is that the current bar is able to generate an arrow when it's conditions are true, regardless of what the previous bar does. I have been running it on live SIM and with my account, as well as replay with tick replay active. I hope this explanation is making sense. To put it simply, I have noticed that a few candles were not placing arrows when they should have, and the problem had to do with the previous candle. I'm just curious to know if there's a way around this issue so I can get the candle to plot the arrow. If reviewing the script will help, I'd be happy to send it your way.

                            Thank you,
                            Chris

                            Comment


                              #15
                              Hello Chrisca,

                              I'm replying on behalf of Chelsea who is out of the office today.

                              All I care about is that the current bar is able to generate an arrow when it's conditions are true
                              Focusing on this as your goal we should consider the following notes:
                              • Calculate.OnEachTick will allow for actions that happen mid bar that do not happen when looking just at the close of a bar
                              • Tick Replay will allow historical bars to be reproduced with Tick Data and allow NinjaScripts to run on Calculate.OneachTick for historical data
                              • CrossAbove() and CrossBelow() have a lookback period. Logic using greater than and less than operators could be used for mid bar comparisons


                              With these notes in mind, I think you can accomplish your goal using greater than and less than operators in your logic with Calculate set to OnEachTick to get arrows at any mark where the tick goes above or below a desired level. If you want to see the same thing for historical bars, you would want to use Tick Replay.

                              Any other instances where there looks like there is a crossover, I would recommend taking debugging steps to print the prices going into your logic to see if the condition did or did not become true. There may be instances on the chart where you see a line cross through some points but since indicator plots are broken down to the data series used, you may see interpolated crossovers when the tick did not actually hit that level.

                              Please let us know if we can be of further help.
                              JimNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by tkaboris, Today, 05:13 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post tkaboris  
                              Started by GussJ, 03-04-2020, 03:11 PM
                              16 responses
                              3,281 views
                              0 likes
                              Last Post Leafcutter  
                              Started by WHICKED, Today, 12:45 PM
                              2 responses
                              19 views
                              0 likes
                              Last Post WHICKED
                              by WHICKED
                               
                              Started by Tim-c, Today, 02:10 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Taddypole, Today, 02:47 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post Taddypole  
                              Working...
                              X