Announcement

Collapse
No announcement yet.

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.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    81 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    66 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