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 sinpeople, Today, 07:20 AM
    0 responses
    1 view
    0 likes
    Last Post sinpeople  
    Started by Frank1000, Today, 03:05 AM
    0 responses
    4 views
    0 likes
    Last Post Frank1000  
    Started by ntdev, Today, 01:14 AM
    4 responses
    16 views
    0 likes
    Last Post ntdev
    by ntdev
     
    Started by ct, Today, 02:22 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Jason  
    Started by yodaler, Yesterday, 06:12 PM
    4 responses
    13 views
    0 likes
    Last Post NinjaTrader_Jason  
    Working...
    X