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

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.
    Gaby V.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by cre8able, Yesterday, 01:16 PM
    3 responses
    11 views
    0 likes
    Last Post cre8able  
    Started by Harry, 05-02-2018, 01:54 PM
    10 responses
    3,203 views
    0 likes
    Last Post tharton3  
    Started by ChartTourist, Today, 08:22 AM
    0 responses
    6 views
    0 likes
    Last Post ChartTourist  
    Started by LiamTwine, Today, 08:10 AM
    0 responses
    2 views
    0 likes
    Last Post LiamTwine  
    Started by Balage0922, Today, 07:38 AM
    0 responses
    5 views
    0 likes
    Last Post Balage0922  
    Working...
    X