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 in the next bar [-1]

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

    Draw in the next bar [-1]

    Hi.
    I have a query, I have an indicator that is working.
    And mark the points in the table.
    What I need is that when you start the next bar, also place the point at the same price level.
    Since "Sells[-1]" can not be placed.
    I do not know how to do it.

    Thanks.





    protected override void OnBarUpdate()
    {

    if (CurrentBar <3)
    return;


    {
    if ((Close[1] > Open[1])&&(Close[0] < Open[0]))
    {
    Sells[0] = Close[0]-(2*TickSize);
    }

    else if ((Close[1] < Open[1])&&(Close[0] > Open[0]))
    {
    Buys[0] = Close[0]+(2*TickSize);
    }
    }
    }









    #2
    Hello iradielt,

    Thanks for your post.

    Prior to your conditions that conditionally set the current bar of sells and buys, you can copy the previous bar values.

    protected override void OnBarUpdate()
    {

    if (CurrentBar <3)
    return;

    Sells[0] = Sells[1]; // copy previous bar to current bar
    Buys[0] = Buys[1]; // copy previous bar to current bar

    {
    if ((Close[1] > Open[1])&&(Close[0] < Open[0]))
    {
    Sells[0] = Close[0]-(2*TickSize); // if conditions are true write new value into the current bar of Sells
    }

    else if ((Close[1] < Open[1])&&(Close[0] > Open[0]))
    {
    Buys[0] = Close[0]+(2*TickSize); // if conditions are true write new value into the current bar of Buys
    }
    }
    }


    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply.
      And this how can I do it?
      He has some example of that.
      I do not understand what I should add to it.

      Comment


        #4
        Hello iradielt,

        Thanks for your reply.

        The code I added to your code example would keep the last used sells or buys until your conditions write a new sells or buys value.

        This is the code lines I added:
        Sells[0] = Sells[1]; // copy previous bar to current bar
        Buys[0] = Buys[1]; // copy previous bar to current bar
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        3 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        1 view
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        9 views
        0 likes
        Last Post Javierw.ok  
        Started by timmbbo, Today, 08:59 AM
        2 responses
        10 views
        0 likes
        Last Post bltdavid  
        Working...
        X