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 pechtri, 06-22-2023, 02:31 AM
        10 responses
        124 views
        0 likes
        Last Post Leeroy_Jenkins  
        Started by judysamnt7, 03-13-2023, 09:11 AM
        4 responses
        59 views
        0 likes
        Last Post DynamicTest  
        Started by ScottWalsh, Yesterday, 06:52 PM
        4 responses
        36 views
        0 likes
        Last Post ScottWalsh  
        Started by olisav57, Yesterday, 07:39 PM
        0 responses
        7 views
        0 likes
        Last Post olisav57  
        Started by trilliantrader, Yesterday, 03:01 PM
        2 responses
        22 views
        0 likes
        Last Post helpwanted  
        Working...
        X