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

Close[0] not picking up the proper value

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

    Close[0] not picking up the proper value

    I have the lifetime license and I'm creating a little addon to charttrader. It is a strategy and the strategy (for now) is supposed to print the Close[0] when clicking a button. When the mybutton3 is pressed it prints Close[0].

    However I am noticing that the value printed is actually the 1st bar (all the way back) loaded in the chart. Why is it not properly picking up the current Close? Code is attached

    Please see LINE 671 stopInput.Text = (Close[0]).ToString();

    Button 4 is supposed to also pick up the Close[0] when clicked and it always pick up the same value and use it in a certain way but no matter when it is clicked it always brings back the same value of 42.65 instead of the "current" Close[0] -> Please look at lines 63 and 64 and 68.


    Thank you.

    Last edited by focus333; 12-21-2020, 04:36 PM.

    #2
    Hello focus333,

    Thanks for the post.

    You would need to use a TriggerCustomEvent in the button handler to be able to access NinjaScript properties with BarsAgo in that context.



    Code:
    [U]protected [/U]void Button4Click(object sender, RoutedEventArgs e)
    {
        TriggerCustomEvent(o =>
        {
            //your code here
        }, null);
    }
    As a side note, you don't need to add protected modifier to any of your custom void methods you can make those private or public depending on the use case. The protected modifier is used on the overrides in the scripts base class and that's really the only time you need to use that modifier.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      NinjaTrader_Jesse Jesse, thank you for the excellent reply! It worked! So under what circumstances do I need to use the TriggerCustomEvent? Is it only in the case of buttons?

      Comment


        #4
        Hello focus333,

        That would be any time you are outside of the NinjaScript data event driven context. For example a button event, a WPF event, OnRender. You wouldn't use a TriggerCustomEvent in all cases like from OnRender, that would would be a situation where you just access the bar data by specific indexes from the series instead. The trigger custom event is more of a one shot trigger to get everything up to date in the current context like a button event. It would not be good to run this a high frequency like from OnRender. The analogue to using TriggerCustomEvent would be GetValueAt where you get a value by its index: https://ninjatrader.com/support/help...tsub=getvaluea

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        26 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 02-22-2024, 01:11 AM
        5 responses
        32 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, Yesterday, 09:53 PM
        2 responses
        49 views
        0 likes
        Last Post wzgy0920  
        Started by Kensonprib, 04-28-2021, 10:11 AM
        5 responses
        192 views
        0 likes
        Last Post Hasadafa  
        Started by GussJ, 03-04-2020, 03:11 PM
        11 responses
        3,234 views
        0 likes
        Last Post xiinteractive  
        Working...
        X