• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 gtheaded, Today, 03:47 PM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Tyler  
    Started by TAJTrades, Today, 03:25 PM
    0 responses
    5 views
    0 likes
    Last Post TAJTrades  
    Started by DTSSTS, Today, 01:26 PM
    0 responses
    6 views
    0 likes
    Last Post DTSSTS
    by DTSSTS
     
    Started by RFrosty, Today, 01:20 PM
    0 responses
    17 views
    0 likes
    Last Post RFrosty
    by RFrosty
     
    Started by Newtrader101, Today, 12:59 PM
    4 responses
    13 views
    0 likes
    Last Post Newtrader101  
    Working...
    X