Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnPriceChange and Crossover

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

    OnPriceChange and Crossover

    I have been debugging my code and I am lost. I have set my strategy to OnPriceChange and checking IsFirstTickOfBar to find the crossover. If I say CrossAbove(fast,slow,1), I believe it looks at the current bar. If I set Crossover(fast,slow,2), it returns it for current and previous bar and so the strategy gets executed twice. I want to check if the crossover happened during the last bar.

    When I am on playback, I noticed that the bar closed above on the previous bar, but the first tick of the bar the crossover is false (it went down by 1 tick). I still would like to take the trade based on the previous bar, no matter what the current bar returns.

    How do I make sure that in both scenarios it looks only at the previous bar.
    \
    Thanks!!
    Last edited by Graci117; 01-24-2024, 08:32 PM.

    #2
    Hello Graci117,

    Thank you for your post.

    You will need to create your own condition instead of using CrossAbove or CrossBelow, as these functions cannot exclude the current bar.

    For example,

    Code:
    if (fast[2] < slow[2] && fast[1] > slow[1])
    //do something
    ​
    Please let us know if you have any other questions.

    Comment

    Latest Posts

    Collapse

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