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

Passing any data between indicators and managing indicator from another indicator.

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

    Passing any data between indicators and managing indicator from another indicator.

    My initial aim was to create a mechanism that allows to perform certain actions on certain indicators contained in any forms , when certain condition occurs for a specific indicator in a specific form.


    Let's look at my example:
    In the files included, an indicator MyTest looks whether Close price is higher than the upper Bollinger band or is lower than the lower Bollinger band. It paints my form accordingly using BackColorAll (green or red).
    But in addition I wanted to cause other indicators (2 instances of MyBackColorAll in my example) to paint BackColorAll in their forms.
    Look at attached screen2.jpg – it shows the results. The 2 min and 3min series were painted, when Bollinger conditions on 1min series occured.


    Now let's call the indicator MyTest a master indicator and instances of MyBackColorAll slave indicators.


    Look at the the code in SpecialAction.cs file. It implements a singleton class SpecialAction. The singleton object contains a dictionary :
    Code:
    private Dictionary<string,object> actionDict ;
    accesed by a property ActionDict.
    This dictionary is global and accessible by any indicator/strategy everywhere. You may pass any data in it, boxing the object in a master indicator and unboxing it in slave indicators instances. Every slave instance would look for its matching key.


    When a condition occurs in a master indication, the dictionary item is either added or updated accordingly. When a condition does not appear anymore, the item is removed.


    In my particular example I passed an integer value, expressing a condition which occurred in MyTest indicator.
    MyBackColorAll indicator unboxed this value and painted BackColorAll accordingly.


    Look at a key of the item in the master indicator. In this particular code it consists of a name of the slave indicator and its instrument name. the key is “MyBackColorAll|$EURUSD” .
    The slave indicator looks for a matching key, gets a value and performs painting if the key is found.

    Of course the master can add more than one item and direct them to more than one slave indicator type.
    I can be more restrictive. For example, if I would be interested to do my painting only on 5min data series, I would build my key as “MyBackColorAll|$EURUSD|5min”


    Current example checks for conditions in the master indicator once for a bar. The slave indicator checks for them only at the first tick on bar. It may delay an action performed by a slave. An alternative is to use OnMarketData, but I'm afraid it may be too heavy CPU load in case of a lot of slave instances. Of course it could work well in my example of 2 slave instances.


    Last, but not least – for Ninja people. Please pass this post to developers. I'm sure they can implement such mechanism in more elegant and optimal way than me. I have no access to Ninja intenals.
    Attached Files

    #2
    xTrader1, thanks much for sharing your work here with our community, I'm sure it will be highly appreciated.

    I will also let development know and note your request for such a feature set on our product enhancement lists.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks xTrader1, this was just what I was looking for

      Ducman

      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
      7 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by jeronymite, 04-12-2024, 04:26 PM
      2 responses
      31 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