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

Trying to set up a crossover strategy with a single execution per crossover

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

    Trying to set up a crossover strategy with a single execution per crossover

    When creating a cross-over, the system processes the first trade when the condition is met, but then continues to process further trades as long as the condition is met. What i'd like to do is
    allow ONLY one trade, and that trade being the trade immediately following the crossover. Per the instruction of NinjaTrader, I added code as follows:

    This however results in an error code "The name savedBar does not exist in the current context" Can anyone help with this .

    // Set 1
    if (CrossAbove(HMA1, HMA2, 1)&& CurrentBar!=savedBar)
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");

    savedBar = CurrentBar; //save the entry bar number
    }

    // Set 2
    if (CrossBelow(HMA1, HMA2, 1)&& CurrentBar!=savedBar)
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), "");

    savedBar=CurrentBar; //save the entry bar number

    #2
    Hello sjbeaman,

    Thanks for your post and welcome to the NinjaTrader forums!

    You would need to declare savedBar as an int variable type. You can do this above OnStateChange() like: private int savedBar;
    If you are using the strategy builder, you would need to create the variable in the inputs and variables screen, please see "Understanding the Inputs and Variables screen" https://ninjatrader.com/support/help...er_screens.htm

    CurrentBar is a system variable that provided the bar number that the system is strategy is currently processing its code on. Reference: https://ninjatrader.com/support/help...currentbar.htm
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by judysamnt7, 03-13-2023, 09:11 AM
    4 responses
    59 views
    0 likes
    Last Post DynamicTest  
    Started by ScottWalsh, Today, 06:52 PM
    4 responses
    36 views
    0 likes
    Last Post ScottWalsh  
    Started by olisav57, Today, 07:39 PM
    0 responses
    7 views
    0 likes
    Last Post olisav57  
    Started by trilliantrader, Today, 03:01 PM
    2 responses
    21 views
    0 likes
    Last Post helpwanted  
    Started by cre8able, Today, 07:24 PM
    0 responses
    10 views
    0 likes
    Last Post cre8able  
    Working...
    X