Announcement

Collapse
No announcement yet.

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.

    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.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        50 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 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