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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    93 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    138 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    123 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    73 views
    0 likes
    Last Post PaulMohn  
    Working...
    X