Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Basic coding issue - How to build own Methods for general use?

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

    Basic coding issue - How to build own Methods for general use?

    Hello,

    as mentioned in former posts, i am a coding beginner. It would be useful for me to create own methods, what are saved in an libary.

    For instance i want to call this basic code



    if( Open[InputValue] == Close[InputValue]
    && Open[InputValue] == High[InputValue]
    && Open[InputValue] >= Low[InputValue] + 5 * TickSize
    )

    {
    ItsADoji = true;
    }

    else

    {
    ItsADoji = false;
    }


    Everything i have coded till now was inside the protected override void method, what you get if you unlock an strategy.

    I want to make my code more readable and create often used pieces of code in some kind of public libarys, so i have
    access to often used code pieces. (The same way i use the predefinded Open[] method for instance,)


    It would be great if you can show me the steps how to create a own method with the attached code for having an general template.

    Thanks!

    #2
    Hello debleded,

    Thank you for your post.

    You'd want to use a partial class for that. I've attached an example of doing this for an indicator - we have one script that holds our partial class, and then we can reference it from any indicator script.

    A similar thing could be done for Strategies as well, make a separate Strategy script to hold those partial classes. Basically you'd create a strategy script, and then you could basically do the same as in the indicator example, just use the following instead of the first few lines in the indicator example:

    Code:
    namespace NinjaTrader.NinjaScript.Strategies
    {
    
    // Use case: partial class methods available to all strategies
    // this combines with all strategies; use long unique method names to avoid conflicting with scripts from other developers
    public partial class Strategy
    {
    // put your partial classes in here
    }
    }
    Please let us know if we may be of further assistance to you.
    Attached Files

    Comment


      #3
      Thank you kate,

      it took me a while but now i´m able to create own partial classes. I created some public partial bools what works fine.

      What would be the best way, if i have the requirement to get multiple values of the partial class back?

      So for instance i want to get back
      - if Doji ist true

      and other double or int values like
      - Low/High/Open of Doji
      - Bar index of Doji or anything else


      Should create a new public partial double / int with basically the same code of your example for every additional value(

      if(DojiPartialClassExample == true)
      {return Low/High/...}

      (I know i just could insert this code in my main method, but it´s an example, representative vor more laborious calculations)


      Or is there a easier way to accomplish the task?

      Comment


        #4
        Hello debleded,

        Thank you for your note.

        You would need to create separate methods that return the specific values you wish to retrieve for each one.

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

        Comment


          #5
          Ok, thanks

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          44 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          124 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          65 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X