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

Price Crossover

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

    Price Crossover

    Hi all,

    By way of a minimal working example, say I wanted to enter when current price > previous high using the following,

    Code:
     protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;
    
    if (CurrentBars[0] < 1)
    return;
    
    // Set 1
    if (CrossAbove(Close, High, 1))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }
    
    }
    and calculations set to OnPriceChange.

    Click image for larger version

Name:	2.jpg
Views:	127
Size:	162.2 KB
ID:	1209645

    Unfortunately the strategy is not executing any trades. I verified potential entries using Print. I've also experimented with OnTickReplay and Playback with no luck.

    I assume I'm overlooking something quite simple?

    Any thoughts/recommendations would be greatly appreciated!

    #2
    Hello gravityflyer,

    Thank you for your post.

    The issue is this line:

    if (CrossAbove(Close, High, 1))

    I'm guessing this was set up in the Strategy Builder. If you were coding manually, the correct syntax would be:

    if(CrossAbove(Close, High[1], 1)

    The problem is that in the Builder you can't actually specify the high of the prior bar by selecting the High series as the bars ago will be ignored. What you can do is save the prior high to a variable in a set before this set, then use that variable as the second part of the comparison in your set. Your other option would be to unlock the code and correct that line manually.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Ah yes, makes sense! Thank you Kate!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by ageeholdings, Today, 07:43 AM
      0 responses
      7 views
      0 likes
      Last Post ageeholdings  
      Started by pibrew, Today, 06:37 AM
      0 responses
      4 views
      0 likes
      Last Post pibrew
      by pibrew
       
      Started by rbeckmann05, Yesterday, 06:48 PM
      1 response
      14 views
      0 likes
      Last Post bltdavid  
      Started by llanqui, Today, 03:53 AM
      0 responses
      6 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by burtoninlondon, Today, 12:38 AM
      0 responses
      12 views
      0 likes
      Last Post burtoninlondon  
      Working...
      X