Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

static bars ago stop price

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

    static bars ago stop price

    Hi,
    How do I prevent a price variable set to a BarsAgo value from updating?

    if (
    entry conditions
    )

    {
    StopPrice = Low[myValue];
    EnterLong();
    ExitLongStopmarket(StopPrice)
    StopPrice = 0;
    }

    I know this doesn't work. The StopPrice keeps updating/trailing to myValue ago so how do I do it?

    #2
    Hello trader3000a,

    Thank you for your post.

    Ultimately, you can use print statements to understand how often your StopPrice is being changed. For example:
    Code:
    if (entry conditions / conditions that set/update StopPrice)
    {
    StopPrice = Low[myValue];
    Print(Time[0] + " StopPrice updated!  StopPrice: " + StopPrice);
    // additional actions
    }
    ​Then, you can check the NinjaScript Output window to see when StopPrice is being updated and what value it is set to. Is it possible that your "entry conditions" are being met several times even after the initial entry is submitted? You could consider using a bool to ensure the StopPrice is only set once, such as the following:

    Code:
    if (entry conditions)
    {
    if (doOnce == false)
    {
    StopPrice = Low[myValue];
    doOnce = true;
    }
    // entry method
    }
    
    // reset doOnce to false when flat so it can be used for the next entry
    if (Position.MarketPosition == MarketPosition.Flat)
    doOnce = false;
    Please let us know if we may be of further assistance.

    Comment


      #3
      thanks Emily!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      89 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      135 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      119 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      69 views
      0 likes
      Last Post PaulMohn  
      Working...
      X