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

no trade if the position was open the previous bar

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

    no trade if the position was open the previous bar

    Hi

    how is it possible to include in the script, "do not open a position if a position was open in the previous bar"

    can you help ?

    Thomas

    #2
    Thomas79,

    You can use BarsSinceEntry(). Please find an example below.

    Code:
    protected override void OnBarUpdate()
    { 
        if (CurrentBar < 20) 
            return; 
     
        // Only enter if at least 10 bars has passed since our last entry
        if (BarsSinceEntry() > 10 && CrossAbove(SMA(10), SMA(20), 1))
             EnterLong();
    }
    For more information, please see the following link.



    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by ETFVoyageur, Today, 10:34 AM
    8 responses
    20 views
    0 likes
    Last Post ETFVoyageur  
    Started by HiddenPhilosopher, 05-22-2020, 01:09 AM
    28 responses
    2,722 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by warpinator, 05-16-2024, 10:44 AM
    11 responses
    60 views
    0 likes
    Last Post ETFVoyageur  
    Started by KNalley, 01-24-2020, 10:33 AM
    10 responses
    965 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by Skifree, Today, 11:47 AM
    3 responses
    13 views
    0 likes
    Last Post Skifree
    by Skifree
     
    Working...
    X