Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help writing a simple indicator

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

    Help writing a simple indicator

    Hi,

    What I want is for Ninja to:

    Code:
    Bar1 = (High[1] - Low[1]) / TickSize;
    Bar2 = (High[2] - Low[2]) / TickSize;
    Bar3 = (High[3] - Low[3]) / TickSize;​
    MultipleBars1-3 = (Bar1 + Bar2 + Bar3) / 3;
    And

    Code:
    Bar2     =  (High[2] - Low[2]) / TickSize;
    Bar3     =  (High[3] - Low[3]) / TickSize;            
    Bar4     =  (High[4] - Low[4]) / TickSize;
    MultipleBars2-4    =    (Bar2 + Bar3 + Bar4) / 3;


    And display those two average price figures (MultipleBars1-3 & MultipleBars2-4) on the left size on the chart. e.g.
    Average Price:
    19
    25


    And for them to update an recalculate everytime a bar closes.

    Any suggestions/help would be really appreciated,
    thanks!



    #2
    Hello Bob-Habanai,

    Thank you for your post.

    You should be able to achieve this by using variables declared at the class level for the four different bars and the two multiples. You could then use the Draw.TextFixed() method to draw text in a specific location on the chart, such as BottomLeft or TopLeft. Here is the help guide page for Draw.TextFixed():


    If you keep the same tag for the drawing tool, then each time the tag is used the same draw object will be modified. This way, if the values are updated in OnBarUpdate and the indicator is set to calculate OnBarClose, the averages will be re-calculated on each bar close and update the existing fixed text drawing tool.

    Please let us know if we may be of further assistance.

    Comment


      #3
      Thank you Emily for your reply,

      I was able to get a single number to display at the bottom left.

      Code:
      Draw.TextFixed(this, "AveragePrice", Math.Round(MultipleBars, 0).ToString(), TextPosition.BottomLeft, Brushes.AntiqueWhite, EfficiencyFont, Brushes.Blue, Brushes.Black, 0);

      But I don't know how to get the other number to display below or above it?

      Thanks.

      Comment


        #4
        Hello Bob-Habanai,

        Thank you for your reply.

        You may add \n to a string to indicate a new line. For example, if I were to use the following draw method in a script:

        Draw.TextFixed(this, "tag", "test\ntest2\ntest3", TextPosition.BottomLeft, false, "");

        The text would show on the bottom left of the chart like this:

        test
        test2
        test3

        Screenshot: https://www.screencast.com/t/nfbAprqh

        Please let us know if we may be of further assistance.

        Comment


          #5
          Thanks Emily,

          That's helpful, but how do you do that with strings?

          Here's two things I want to do, but am unsure how:

          1:
          Draw.TextFixed(this, "tag", MyNumberString"×".ToString(myDoubleFormat), TextPosition.BottomLeft, false, "");​
          In that one, I want Ninja to calculate a number then add ×​ to it.

          and 2:
          Draw.TextFixed(this, "tag", MyNumberString\nMyOtherString.ToString(myDoubleFor mat), TextPosition.BottomLeft, false, "");​​
          In this one I want to have two strings appear one on top of the other.

          Thanks again for your help!
          Last edited by Bob-Habanai; 12-18-2022, 05:26 PM.

          Comment


            #6
            Hello Bob-Habanai,

            Thank you for your reply.

            You should be able to concatenate strings with the + operator or you could use the String.Format() method to convert the objects into strings and insert them into the string. For more information, please see the following publicly available link from the Microsoft website:
            Converts the value of objects to strings based on the formats specified and inserts them into another string. If you are new to the String.Format method, see Get started with the String.Format method for a quick overview.


            Here are a couple of examples that would print in the same way and add the same line breaks, just with different formatting:

            Code:
            Print(Time[0] + "\n" + myDouble + "\nTest String 1");
            vs.

            Code:
            Print(String.Format("{0}\n{1}\nTest String 2", Time[0], myDouble));
            To apply this to your example, it could look something like this:

            MyNumberString"×".ToString(myDoubleFormat)

            Code:
            MyNumberString + "×​"
            or
            Code:
            String.Format("{0}×", MyNumberString)​
            MyNumberString\nMyOtherString.ToString(myDoubleFor mat)

            Code:
            MyNumberString + "\n" + MyOtherString​
            or
            Code:
            String.Format("{0}\n{1}", MyNumberString, MyOtherString)
            Please let me know if I may be of further assistance.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            576 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            334 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