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

Draw Arrows not working

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

    Draw Arrows not working

    Hello,

    OK, so I am kind of new to c#, but have enough 'coding' background to be able to grasp things pretty well.

    I tried creating a simple indicator that draws arrows above and below bars that are overbought and oversold. However without the second and statements, the arrows would plot on every bar that was ob or os.

    // Condition set 1
    if (RSI(5, 1)[0] >= 80 &&
    RSI(5, 1)[1] < 80)
    {
    DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[0] + 2 * TickSize, Color.Red);
    }


    // Condition set 2
    if (RSI(5, 1)[0] <= 20 &&
    RSI(5, 1)[1] > 20)
    {

    DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0] + -2 * TickSize, Color.Lime);
    }
    When I remove just the second condition for Condition Set 2 (the oversold case) and leaving Condition Set 1 as above, the indicator works fine, but with all conditions laid out, nothing is drawn on the chart.

    // Condition set 2
    if (RSI(5, 1)[0] <= 20)
    {

    DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0] + -2 * TickSize, Color.Lime);
    }
    Would really appreciate some help on this

    Asim

    #2
    The second condition of each condition set is a must. So why do you want to remove it?

    Thanks
    Pi
    ninZa
    NinjaTrader Ecosystem Vendor - ninZa.co

    Comment


      #3
      I don't want to remove it. That's the point. It doesn't work with my full condition set at all But only works when I behin to remove the second condition on the second set.

      Comment


        #4
        Have you checked this:

        if (CurrentBar == 0) return;

        Please put it at the very first line in OnBarUpdate.

        Thanks,
        Pi
        Last edited by ninZa; 12-14-2014, 05:26 AM.
        ninZa
        NinjaTrader Ecosystem Vendor - ninZa.co

        Comment


          #5
          Ah, thanks it works now.

          Didn't realise I needed such a line, as I was calculating/updating on bar close.

          Asim

          Comment


            #6
            Do you realize that you refer to the RSI value of 1 bar ago: RSI(5, 1)[1]
            However, obviously at CurrentBar = 0 you have no bars before it to get the RSI value, which caused the error.

            You should regularly monitor the Log tab (from the Control Center) to look for errors and hints

            Cheers,
            Pi
            ninZa
            NinjaTrader Ecosystem Vendor - ninZa.co

            Comment


              #7
              lol my bad I thought the currentBar was the right most bar i.e. the latest bar, rather than the left most bar. (Different platforms allocate numbers differently, so got mixed up).

              Comment


                #8
                Ya, that is the point.
                ninZa
                NinjaTrader Ecosystem Vendor - ninZa.co

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by fx.practic, 10-15-2013, 12:53 AM
                5 responses
                5,406 views
                0 likes
                Last Post Bidder
                by Bidder
                 
                Started by Shai Samuel, 07-02-2022, 02:46 PM
                4 responses
                98 views
                0 likes
                Last Post Bidder
                by Bidder
                 
                Started by DJ888, Yesterday, 10:57 PM
                0 responses
                8 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by MacDad, 02-25-2024, 11:48 PM
                7 responses
                160 views
                0 likes
                Last Post loganjarosz123  
                Started by Belfortbucks, Yesterday, 09:29 PM
                0 responses
                9 views
                0 likes
                Last Post Belfortbucks  
                Working...
                X