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 AaronKoRn, Yesterday, 09:49 PM
      0 responses
      11 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Yesterday, 08:42 PM
      0 responses
      10 views
      0 likes
      Last Post carnitron  
      Started by strategist007, Yesterday, 07:51 PM
      0 responses
      12 views
      0 likes
      Last Post strategist007  
      Started by StockTrader88, 03-06-2021, 08:58 AM
      44 responses
      3,982 views
      3 likes
      Last Post jhudas88  
      Started by rbeckmann05, Yesterday, 06:48 PM
      0 responses
      10 views
      0 likes
      Last Post rbeckmann05  
      Working...
      X