Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Initializing Long and Short Price Threshold

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

    Initializing Long and Short Price Threshold

    Is there a way for NinjaScript to recognize the current High[0] and Low[0] values within the Initialize function so that when a Strategy is selected via Right Click - Strategy ... the properties dialog is populated with initial values? I've tried the following but the High and Low values aren't recognized when I pull up the Strategy.

    protectedoverridevoid Initialize()
    {
    CalculateOnBarClose =
    true;
    TimeInForce = Cbi.TimeInForce.Day;
    LongThreshold = High[
    0] + 5*TickSize;
    ShortThreshold = Low[
    0] - 5*TickSize;
    }

    Where LongThreshold and ShortThreshold are as follows:

    privatedouble m_LongThreshold = 0.0;
    privatedouble m_ShortThreshold = 0.0;

    [Description("Buy Long Price")]
    [Category(
    "Parameters")]
    publicdouble LongThreshold
    {
    get { return m_LongThreshold; }
    set { m_LongThreshold = Math.Max(1, value); }
    }

    [Description(
    "Sell Short Price")]
    [Category(
    "Parameters")]
    publicdouble ShortThreshold
    {
    get { return m_ShortThreshold; }
    set { m_ShortThreshold = Math.Max(1, value); }
    }


    #2
    doug_p,

    No, you should not place any such logic in Initialize(). If you just want to set it once you can do it in OnBarUpdate().

    Code:
    if (CurrentBar == 0 && FirstTickOfBar)
         // Do something
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thank You

      Ok great thank for your advice I will use your approach.

      Comment


        #4
        Also, if you are in a strategy you may not be able to check for CurrentBar = 0. You would instead want to check for CurrentBar = BarsRequired.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        633 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        567 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X