Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Coding questions

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

    Coding questions

    Hi

    I was wondering if there are any best practices to use during the creation of strategies. For example

    1. I want to use multiple entries with multiple stoploss and profit targets. Is it best to use lists or create an individual instance of each order type
    eg Order stoploss1, Order stoploss2 OR List<Order> stopLossOrders;

    I understand if there is more than 2 SL's then LISTs would be better but for just 2 SLs / PTs is it easier to control as a list or instance?

    I ask because I see examples both ways.

    2. With reference to the above, in samples I have seen just OnOrderUpdate used and in others both OnOrderUpdate and OnExecutionUpdate
    Is it best to use one or the other or both or does it depend on the complexity of the code. Again I ask for clarity sake so that I go down the correct route, your help seems to favour using both.

    3. Can you code new classes and access them from within ninjascript if the file is stored in the correct directory. For example if I created a generic manage order class that could be used by many scripts, could I then place this in a directory and reference it by creating an instance of that class.

    If anyone can provide any pointers it would be appreciated, thanks

    #2
    Hello fishbed,

    Thanks for opening the thread.

    1. I want to use multiple entries with multiple stoploss and profit targets. Is it best to use lists or create an individual instance of each order type
    eg Order stoploss1, Order stoploss2 OR List<Order> stopLossOrders;
    This subjective, really. Creating a List can be a good way to save lines of code when you want to group items together, but it does take the extra step to create the container. It really depends if the instance in which you wish to use a List would benefit from the time spent to create it.

    2. With reference to the above, in samples I have seen just OnOrderUpdate used and in others both OnOrderUpdate and OnExecutionUpdate
    Is it best to use one or the other or both or does it depend on the complexity of the code. Again I ask for clarity sake so that I go down the correct route, your help seems to favour using both.
    OnExecutionUpdate() would be the best place to place logic based on order fills. OnOrderUpdate() would be a good place to tell you if an order has been accepted and working, for example.

    From the help guide:
    Critical: If you want to drive your strategy logic based on order fills you must use OnExecutionUpdate() instead of OnOrderUpdate(). OnExecutionUpdate() is always triggered after OnOrderUpdate(). There is internal strategy logic that is triggered after OnOrderUpdate() is called but before OnExecutionUpdate() that can adversely affect your strategy if you are relying on tracking fills within OnOrderUpdate().
    OnOrderUpdate() - https://ninjatrader.com/support/help...rderupdate.htm
    OnExecutionUpdate() - https://ninjatrader.com/support/help...tionupdate.htm

    3. Can you code new classes and access them from within ninjascript if the file is stored in the correct directory. For example if I created a generic manage order class that could be used by many scripts, could I then place this in a directory and reference it by creating an instance of that class.
    It is possible to create an Add-On that can keep track of information that can be shared between strategies. Our colleague Chelsea has a sample script that demonstrates how sharing information with an Add-On can be done.

    Here is the forum post: http://ninjatrader.com/support/forum...04&postcount=2

    Various other best practices for NinjaScript can be found here - https://ninjatrader.com/support/help..._practices.htm

    Please let me know if I may be of further help.
    JimNinjaTrader Customer Service

    Comment


      #3
      Help with strategy

      Hi, very good, I need a little help to create a strategy, I want to give you the order of: lowest price of today that is greater or equal to the minimum price of the last 6 bars, someone can help me how to put that oden in the strategy.

      Thank you

      Comment


        #4
        Hello killo,

        Welcome to our forums!

        To accomplish this, you could do so by writing your own strategy to utilize the MIN() indicator to tell you the lowest period over an interval of time.

        You would also have to be able to tell your strategy when a new day has occurred to count bars to satisfy the period of MIN() so you can look at the minimum for the bars that have based for that day.

        I do not think this condition could be created solely in the Strategy Builder. Since the Strategy Builder does not support very many mathematical operations, you would not be able to create an indicator that uses a dynamic period.

        Within code, you could create this condition similar to the following:

        Code:
        if(MIN(Low, DailyLowPeriod) >= MIN(Low, 6))
        However, you will need to calculate DailyLowPeriod on each bar update with the difference between the CurrentBar and the first bar of the day.

        You could use IsFirstBarOfSession to identify when the current bar is the first bar of the session.

        Here is the help guide documentation on the components to be used:

        IsFirstBarOfSession - https://ninjatrader.com/support/help...rofsession.htm

        CurrentBar - https://ninjatrader.com/support/help...currentbar.htm

        MIN() Indicator - https://ninjatrader.com/support/help...inimum_min.htm

        Additionally, you may also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. If you would like, I can have our business development follow up with you with a list of professional NinjaScript Consultants who would be happy to create this script or any others at your request. If that is the case, please write in to platformsupport[at]ninjatrader[dot]com with the thread URL and the text "Attention Jim."

        Please let me know if I may be of further help.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by martin70, 03-24-2023, 04:58 AM
        15 responses
        114 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by The_Sec, Today, 02:29 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by jeronymite, 04-12-2024, 04:26 PM
        2 responses
        30 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by Mindset, 05-06-2023, 09:03 PM
        10 responses
        265 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by michi08, 10-05-2018, 09:31 AM
        5 responses
        743 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X