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

CrossAbove/CrossBelow help

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

    CrossAbove/CrossBelow help

    Is it possible to have a CrossAbove or CrossBelow trigger to occur only if an oscillating indicator has not reached a certain point prior?

    Let's say I have an oversold line at 0.80 and a neutral point at 0.50. My strategy just entered a short because a CrossBelow 0.80 occurred and the indicator continues downward but does not reach the neutral point of 0.50. It then turns and now crosses above 0.80, in which I would like the CrossAbove to trigger a long entry since the neutral point of 0.50 was never reached.

    How would I accomplish something like this?

    #2
    Hello Rogue_Two,

    Thanks for your post.

    One way to handle that would be to set a bool to either true or false when you first enter the short. In another condition, you would check if you are in a short position and if your oscillator goes below 50 you set the bool to the other state. In another condition, you would check that the bool is is in the original condition (meaning oscillator had not gone below 50) and that you are in a short position and that you have a cross above 80. For example:

    if (your original conditions to cross below 80)
    {
    EnterShort();
    myBelow50bool = false;
    }

    if (Position.MarketPosition == MarketPosition.Short && youroscillator[0] < 50)
    {
    myBelow50bool = true;
    }

    if (PositionMarketPosition == MarketPosition.Short && myBelow50bool == false && your oscillator crosses above 80)
    {
    EnterLong();
    }


    Note: depending on your actual logic you may need additional code, this is just a quick example of pseudo code based on the information provided and has not been tested.
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by reynoldsn, Today, 07:23 AM
    6 responses
    18 views
    1 like
    Last Post reynoldsn  
    Started by reynoldsn, Today, 07:26 PM
    0 responses
    4 views
    0 likes
    Last Post reynoldsn  
    Started by ETFVoyageur, 05-07-2024, 07:05 PM
    12 responses
    78 views
    0 likes
    Last Post bltdavid  
    Started by Haiasi, 04-25-2024, 06:53 PM
    5 responses
    76 views
    0 likes
    Last Post alancurry  
    Started by ZeroKuhl, Today, 04:31 PM
    0 responses
    16 views
    0 likes
    Last Post ZeroKuhl  
    Working...
    X