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:	186
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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      91 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      137 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      121 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      72 views
      0 likes
      Last Post PaulMohn  
      Working...
      X