Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Master and Secondary Strategy files

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

  • bltdavid
    replied
    Understood, thanks!

    Leave a comment:


  • NinjaTrader_Jim
    replied
    Hello bltdavid,

    We are only going to provide support/advise for things that are documented and have been thoroughly tested/used by our support team.

    We don't have educational examples built using abstract classes so we are not going to provide insight for using them with NinjaScript.

    Leave a comment:


  • NinjaTrader_Kate
    replied
    Hello bltdavid,

    Thank you for your reply.

    Jim is out of the office today and I would need to confirm that with him. I will confirm whether or not this would be the case with him when he returns.

    Thanks in advance for your patience.

    Leave a comment:


  • bltdavid
    replied
    Originally posted by NinjaTrader_Jim View Post
    There can be limitations with using more advanced C# concepts like inheritance (and other concepts) where NinjaScript wrappers for indicators cannot be properly applied.

    We have some examples showing how partial classes can be used in NinjaScript, but we do not have examples prepared for abstract classes and methods.

    Since we have not fully navigated those ideas, we would not officially support/suggest using those concepts.
    I would note that since NinjaScript strategies don't have wrappers,
    no such limitation exists when an abstract base class is used
    with a Strategy-- is that correct?

    Leave a comment:


  • NinjaTrader_Jim
    replied
    Hello bltdavid,

    There can be limitations with using more advanced C# concepts like inheritance (and other concepts) where NinjaScript wrappers for indicators cannot be properly applied.

    We have some examples showing how partial classes can be used in NinjaScript, but we do not have examples prepared for abstract classes and methods.

    Since we have not fully navigated those ideas, we would not officially support/suggest using those concepts.

    Leave a comment:


  • bltdavid
    replied
    Originally posted by NinjaTrader_Kate View Post
    There can be limitations using advanced C# concepts in NinjaScript, so your mileage may vary
    Hi Kate,

    With regard to use of an 'abstract base class' ...

    Can you provide any specific examples where its use caused a problem?

    I mean, to what limitations are you referring to?

    Thanks
    Last edited by bltdavid; 11-06-2021, 11:23 PM.

    Leave a comment:


  • bltdavid
    replied
    Excellent!
    Last edited by bltdavid; 08-16-2023, 03:40 PM.

    Leave a comment:


  • UltraNIX
    replied
    Originally posted by bltdavid View Post

    Hmm, you may have a lot of learning ahead of you.
    (But that's ok, there are plenty of paths forward.)

    I just wanted to say,
    You actually asked about an advanced topic common to every professional
    programmer everywhere: and that is how to best organize the code so you
    have as little duplication and overlap as possible.

    You even used a common code word among engineers -- the word "refactor"
    suggested to me that you might know something about the need and benefits
    of such code organization. Perhaps I was wrong -- but that's ok.

    What I want to say is: Welcome to the world of Software Engineering 101.

    I'm not being mean or condescending at all. I'm trying to say, if you are new
    to this, then your wonderful journey of discovery is about to begin. The C#
    language is very elegant and quite beautiful, but learning (more of) it may
    come at a considerable cost -- mostly your time.

    My point is: Don't give up!
    Keep learning, the dividends from mastering the examples in that website link
    will provide you enormous benefits as you move forward with NinjaScript.

    Some very advanced concepts in the C# language were invented precisely
    to help organize code. To do what you are asking, take my example and
    understand how MyStrategyBase fits into the class hierarchy -- technically,
    you would say "MyStrategyBase extends Strategy" -- then keep on reading
    about C# classes and surfing the web for more examples and tutorials.

    Hang in there!

    I used the word "refactor", because I previously purchased and watched courses for NinjaTrading coding by NinjaCoding.net. So I am not a complete beginner, but far from being a serious coder/developer. My skills and knowledge are enough to create an automated algo, but in terms of structure, I am sure, a professional coder could refactor my code for more efficiency.

    You are not mean or codescending, I am familiar with your posts and I found you being helpful in other topics.

    What I consider as difficulty for me - all the resources on web are for pure C# and there are so few courses dedicated to NinjaTrader coding. It is interesting and I follow along, as long as I have resources. But once I am stuck, it gets difficult. I find myself having much more ideas than skills and knowledge that would let me implement those ideas.

    Leave a comment:


  • UltraNIX
    replied
    Originally posted by bltdavid View Post
    Sure.

    Study the attached files.

    The abstract base class "MyStrategyBase" acts like a middle-man.

    You're inserting this class into the inheritance hierarchy, and anything
    in MyStrategyBase has full and complete access to the class it inherits
    from -- in this case, the Strategy class.

    You add your own methods, variables, properties, to MyStrategyBase.

    The reason this is so powerful is that you are extending the 'Strategy'
    class with new 'features' -- sorta like what a partial class does -- but
    you can really fine tune the contents of MyStrategyBase for just one or
    two strategies -- or you can make it a common base that you use for all
    your strategies.

    Inheritance is the heart and soul of OOP, and the C# language supports
    inheritance extremely well.

    There are lots of resources on the web.
    Inheritance is a standard feature of the C# language.

    Good luck!



    For sample strategy attached, it will color the background based upon the
    begin/end times you specify (but stop coloring for the break period, which
    represents known high volatility times, like for an economic report).

    For ex,
    Trade BeginTime = 600
    Trade EndTime = 1100
    Break BeginTime = 900
    Break EndTime = 930

    Restricts trading to the hours 6am to 11am, with a 30min break starting
    at 9am. All times 24hr format, and all times are local.
    That's a start! I downloaded both files and took a first look, trying to understand ins and outs. WIll need to spend more time, but, as I said, it's a start, thank you!

    Leave a comment:


  • bltdavid
    replied
    Originally posted by UltraNIX View Post
    Thank you, even though examples in that website are not that easy for me to implement.
    Hmm, you may have a lot of learning ahead of you.
    (But that's ok, there are plenty of paths forward.)

    I just wanted to say,
    You actually asked about an advanced topic common to every professional
    programmer everywhere: and that is how to best organize the code so you
    have as little duplication and overlap as possible.

    You even used a common code word among engineers -- the word "refactor"
    suggested to me that you might know something about the need and benefits
    of such code organization. Perhaps I was wrong -- but that's ok.

    What I want to say is: Welcome to the world of Software Engineering 101.

    I'm not being mean or condescending at all. I'm trying to say, if you are new
    to this, then your wonderful journey of discovery is about to begin. The C#
    language is very elegant and quite beautiful, but learning (more of) it may
    come at a considerable cost -- mostly your time.

    My point is: Don't give up!
    Keep learning, the dividends from mastering the examples in that website link
    will provide you enormous benefits as you move forward with NinjaScript.

    Some very advanced concepts in the C# language were invented precisely
    to help organize code. To do what you are asking, take my example and
    understand how MyStrategyBase fits into the class hierarchy -- technically,
    you would say "MyStrategyBase extends Strategy" -- then keep on reading
    about C# classes and surfing the web for more examples and tutorials.

    Hang in there!

    Leave a comment:


  • bltdavid
    replied
    Sure.

    Study the attached files.

    The abstract base class "MyStrategyBase" acts like a middle-man.

    You're inserting this class into the inheritance hierarchy, and anything
    in MyStrategyBase has full and complete access to the class it inherits
    from -- in this case, the Strategy class.

    You add your own methods, variables, properties, to MyStrategyBase.

    The reason this is so powerful is that you are extending the 'Strategy'
    class with new 'features' -- sorta like what a partial class does -- but
    you can really fine tune the contents of MyStrategyBase for just one or
    two strategies -- or you can make it a common base that you use for all
    your strategies.

    Inheritance is the heart and soul of OOP, and the C# language supports
    inheritance extremely well.

    There are lots of resources on the web.
    Inheritance is a standard feature of the C# language.

    Good luck!



    For sample strategy attached, it will color the background based upon the
    begin/end times you specify (but stop coloring for the break period, which
    represents known high volatility times, like for an economic report).

    For ex,
    Trade BeginTime = 600
    Trade EndTime = 1100
    Break BeginTime = 900
    Break EndTime = 930

    Restricts trading to the hours 6am to 11am, with a 30min break starting
    at 9am. All times 24hr format, and all times are local.
    Attached Files

    Leave a comment:


  • UltraNIX
    replied
    Originally posted by NinjaTrader_Kate View Post
    Hello UltraNix,

    Thank you for your reply.

    Abstract classes are a C# concept and would be unsupported by NinjaTrader staff. There can be limitations using advanced C# concepts in NinjaScript, so your mileage may vary. As of now, we do not have any examples that can be used to navigate that path.

    A publicly available resource can be found here: https://www.geeksforgeeks.org/c-sharp-abstract-classes/

    Please let us know if we may be of further assistance to you.
    Thank you, even though examples in that website are not that easy for me to implement.

    Leave a comment:


  • NinjaTrader_Kate
    replied
    Hello UltraNix,

    Thank you for your reply.

    Abstract classes are a C# concept and would be unsupported by NinjaTrader staff. There can be limitations using advanced C# concepts in NinjaScript, so your mileage may vary. As of now, we do not have any examples that can be used to navigate that path.

    A publicly available resource can be found here: https://www.geeksforgeeks.org/c-sharp-abstract-classes/

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

    Leave a comment:


  • UltraNIX
    replied
    Originally posted by bltdavid View Post
    Although Kate means well, I would forget the 'partial class' suggestion.

    There is a better way.

    Create your own abstract base class that inherits from Strategy.

    Code:
    abstract public class MyStrategyBase : Strategy
    Then your actual strategy inherits from MyStrategyBase.

    All of your common strategy code goes into MyStrategyBase.
    You attracted my interest. Could you tell me more and provide more resources, as I'm not a full-blown coder, just adapting what I see elsewhere.

    Leave a comment:


  • bltdavid
    replied
    Although Kate means well, I would forget the 'partial class' suggestion.

    There is a better way.

    Create your own abstract base class that inherits from Strategy.

    Code:
    abstract public class MyStrategyBase : Strategy
    Then your actual strategy inherits from MyStrategyBase.

    All of your common strategy code goes into MyStrategyBase.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by jpkulkarni, Today, 09:27 PM
0 responses
4 views
0 likes
Last Post jpkulkarni  
Started by Scalper888, Yesterday, 05:09 PM
5 responses
23 views
0 likes
Last Post Scalper888  
Started by CardozoPeggy, Today, 06:01 PM
0 responses
3 views
0 likes
Last Post CardozoPeggy  
Started by aaaa7389, Today, 05:33 PM
0 responses
4 views
0 likes
Last Post aaaa7389  
Started by aaaa7389, Today, 05:32 PM
0 responses
5 views
0 likes
Last Post aaaa7389  
Working...
X