Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How would I go about the following?

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

    How would I go about the following?

    How would I go about the following;

    I want to reference three numbers to find out which one is the closest out of the three below the current market price? Obviously if the number is above the current price then I want to ignore it?

    Regards,
    suprsnipes

    #2
    Hi suprsnipes,

    First off, you can reference the current price (with CalculateOnBarClose = false) with Close[0].

    I'll refer to your three numbers as the following...
    double num1;
    double num2;
    double num3;

    then you could calculate....
    double diff1 = Close[0] - num1;
    double diff2 = Close[0] - num2;
    double diff3 = Close[0] - num3;

    find the minimum distance between....
    double min1 = Math.Min(diff1, diff2);
    double min2 = Math.Min(diff2, diff3);

    find the minimum of those (since Math.Min only accepts 2 inputs)
    double min3 = Math.Min(min1, min2);

    to ignore a value, you can use something like....
    if (Close[0] > num1)
    return;

    With that information, that should get you on the right track to figure out the logic for your code.
    TimNinjaTrader Customer Service

    Comment


      #3
      What if the values are held within another indicator?

      Comment


        #4
        Hi suprsnipes,

        You can reference the other indicator...for example...

        double num1 = SMA(14)[0];
        TimNinjaTrader Customer Service

        Comment


          #5
          Ok that's great.

          What is the best way to store values for use at a later date, most likely in the way you have just suggested? I don't want the values to be reset either.

          Any suggestions?

          Comment


            #6
            Hi suprsnipes,

            Yes, you can declare a variable and store a value to use later in the code as I did with double num1, for example. It will store that unique variable until it is updated, or the indicator is reloaded.
            TimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

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