Announcement

Collapse
No announcement yet.

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.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    56 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    133 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    73 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X