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

Short/Long strategy only taking long positions

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

    Short/Long strategy only taking long positions

    Hi, I created a strategy in the strategy builder and basically what I want to occur is I want to take the high and low of the range from a specified time period, and then take a long if it crosses above the high or take a short if it crosses below the low. It takes a long as per the parameters, but for whatever reason it never takes a short position despite meeting the criteria... Would someone be able to help me figure out what I'm doing wrong?

    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, 1);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if (
    // Opening Range Time
    ((Times[0][0].TimeOfDay >= new TimeSpan(6, 29, 0))
    && (Times[0][0].TimeOfDay <= new TimeSpan(6, 30, 0)))
    // RangeHigh
    && ((Close[0] > RangeHigh)
    || (RangeHigh == 0)))
    {
    RangeHigh = Close[0];
    }

    // Set 2
    if (
    // Opening Range Time
    ((Times[0][0].TimeOfDay >= new TimeSpan(6, 29, 0))
    && (Times[0][0].TimeOfDay <= new TimeSpan(6, 30, 0)))
    // RangeLow
    && ((Close[0] < RangeLow)
    || (RangeLow == 0)))
    {
    RangeLow = Close[0];
    }

    // Set 3
    if ((Times[0][0].TimeOfDay > new TimeSpan(6, 30, 0))
    && (CrossAbove(Close, RangeHigh, 1)))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }

    // Set 4
    if ((Times[0][0].TimeOfDay > new TimeSpan(6, 30, 0))
    && (CrossBelow(Close, RangeLow, 1)))
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), "");
    }

    }
    }
    }​

    #2
    Hello RDTrader16,

    Just looking at the code I don't specifically see what may be wrong, for this type of question I would suggest using a Print action to see what the value are for the variables you are setting. That would provide insight on what may be happening.

    To do that you can add a Set 5 with just the action Misc -> Print. In the print action you can add different variables or prices to the output so you can see what the values are on each bar. The best way to print this would be to print the Time series and also the RangeHigh and RangeLow variables you used. That information will be sent to the control center -> new -> NinjaScript output window.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by RosaRichardow, Today, 12:21 AM
    1 response
    3 views
    0 likes
    Last Post marcus2300  
    Started by ETFVoyageur, Today, 12:45 AM
    1 response
    6 views
    0 likes
    Last Post ETFVoyageur  
    Started by TradeSaber, Yesterday, 10:33 PM
    1 response
    11 views
    0 likes
    Last Post TradeSaber  
    Started by percy3687, Yesterday, 12:28 AM
    2 responses
    25 views
    0 likes
    Last Post percy3687  
    Started by AnnBarnes, 04-24-2024, 12:17 PM
    2 responses
    22 views
    0 likes
    Last Post tradingfxvps  
    Working...
    X