Announcement

Collapse
No announcement yet.

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:	180
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.

    Comment


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

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      21 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      50 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Working...
      X