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 SalmaTrader, 07-07-2026, 10:26 PM
        0 responses
        50 views
        0 likes
        Last Post SalmaTrader  
        Started by CarlTrading, 07-05-2026, 01:16 PM
        0 responses
        22 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 06-17-2026, 10:32 AM
        0 responses
        16 views
        0 likes
        Last Post CaptainJack  
        Started by kinfxhk, 06-17-2026, 04:15 AM
        0 responses
        22 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Started by kinfxhk, 06-17-2026, 04:06 AM
        0 responses
        23 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Working...
        X