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 NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      56 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      133 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      73 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X