Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using an Integer for [BarsAgo]

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

    Using an Integer for [BarsAgo]

    Hello,
    I'm totally new at this and I got some basic code that logs swing highs and lows that I created from the Strategy Builder.
    I am looking to use the code in a custom indicator.
    My question is how to use the "SwingStrength" Integer in the [BarsAgo]. (there is no way to set this in the Strategy Builder)
    I have an Integer (user input) called "SwingStrength" and want to have that as the [BarsAgo] when plotting the chart markers and getting the time stamp.
    I made the BarsAgo in the code below Bold Red.
    Please see attached code.

    Thank you for any help with this.

    RMIperiod = 14;
    RMIsmooth = 3;
    SwingStrength = 5;
    HiddenDivergence = true;
    StandardDivergence = false;
    H1 = 0;
    H2 = 0;
    H3 = 0;
    L1p = 0;
    L2p = 0;
    L3p = 0;
    H1i = 0;
    H2i = 0;
    H3i = 0;
    L1i = 0;
    L2i = 0;
    L3i = 0;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    Swing1 = Swing(Close, Convert.ToInt32(SwingStrength));
    TOTrimi1 = TOTrimi(Close, Convert.ToInt32(RMIperiod), Convert.ToInt32(RMIsmooth));
    }
    }

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

    if (CurrentBars[0] < 3)
    return;

    // Set 1
    if (Swing1.SwingHigh[0] != H1)
    {
    H3 = H2;
    H2 = H1;
    H1 = Swing1.SwingHigh[0];
    Log(Convert.ToString(H1) + @"-H1p-" + Convert.ToString(Times[0][3].TimeOfDay), Cbi.LogLevel.Information);
    Draw.Diamond(this, @"ppoc Diamond_1 " + Convert.ToString(CurrentBars[0]), false, 3, (High[3] + (10 * TickSize)) , Brushes.Blue);
    H3i = H2i;
    H2i = H1i;
    H1i = TOTrimi1[3];
    Log(Convert.ToString(H1i) + @"-H1i-" + Convert.ToString(Times[0][3].TimeOfDay), Cbi.LogLevel.Information);
    }

    // Set 2
    if (Swing1.SwingLow[0] != L1p)
    {
    L3p = L2p;
    L2p = L1p;
    L1p = Swing1.SwingLow[0];
    Log(Convert.ToString(L1p) + @"-L1p-" + Convert.ToString(Times[0][3].TimeOfDay), Cbi.LogLevel.Information);
    Draw.Diamond(this, @"ppoc Diamond_2 " + Convert.ToString(CurrentBars[0]), false, 3, (Low[3] + (-10 * TickSize)) , Brushes.Red);
    L3i = L2i;
    L2i = L1i;
    L1i = TOTrimi1[3];
    Log(Convert.ToString(L1i) + @"-L1i-" + Convert.ToString(Times[0][3].TimeOfDay), Cbi.LogLevel.Information);
    }

    #2
    Hi laoshr, thanks for writing in. It looks like you already have the variable SwingStrength, you can use that value to index any array since it's an integer.

    if (CurrentBars[0] < SwingStrength)
    return;

    TOTrimi1[SwingStrength], Times[0][SwingStrength], etc.


    Comment


      #3
      Thank you NinjaTrader_ChrisL,
      I was thinking along the right track.
      Thank you again for your expertise.
      Regards,
      James

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      574 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      333 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      553 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      551 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X