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:	175
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 NullPointStrategies, Today, 05:17 AM
      0 responses
      52 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      48 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X