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

Signal bar

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

    Signal bar

    Hello!
    I am trying to compare two bars.
    I have the following code:
    HTML Code:
    if(Close[0] > EMA(5)[0])
       { double val1 = High[0]}.
    At this level, I have save the value of interest in val1, because I want the next bar that will close above the Bar[0] to be my signal bar. This signal bar can meet the requirements either just after my Bar[0] or couple of bars later. When a bar is mature and a new bar is forming, the mature bar is Bar[1] and the new bar forming Bar[0]. In this case, val1 will not be the value of Bar[0] anymore if the new bar is forming. Right?
    So I have the following code:
    HTML Code:
    if(Close[0] > EMA(5)[0])
    { double val1 = High[0]
       if(Close[0] > val1)
         {DrawArrow();}}.
    And here I am not seeing any arrow printed on the chart.
    To summarize:
    1) A bar has to cross above the EMA. This bar should be the bar of interest. Its value is saved.
    2) The first next bar closing above the bar of interest will be the signal bar. My problem is when the signal bar is not the bar closing directly after the bar of interest, but later.
    How to locate this signal bar? I would appreciate any help.

    Many thanks in advance.

    #2
    hi Stanfillirenfro,

    "In this case, val1 will not be the value of Bar[0] anymore if the new bar is forming. Right?"
    from what I can understand, this is right : val1 stays val1 until the codes assigns it a new value. (edit) wich is every bar where Close[0] > EMA(5)[0]. Also, maybe should we call the close of the previous bar (Close[1]) since Close[0] is not yet ended : Close[0] is just the price right now, unless you're ok with a still working bar.

    DrawArrow() ???
    are you sure about the right syntax for this one ? Should we assume that you have your own method using one of the Draw.Something methods ...?
    https://ninjatrader.com/fr/support/h...8/?drawing.htm

    "How to locate this signal bar?"
    I personally would create a list, to which CurrentBar is added every cross above. Then we would call list.Last() to have the number of the bar crossing val1. Like below
    Code:
    if (CrossAbove(Close[1], EMA(5)[1], 1) == true){myList.Add(CurrentBar[1]); };
    // if like me you do not like to have too unnecessarily huge lists :
    if (myList.Count > someIntValue) { myList.Remove(myList.First()); };
    Last edited by Amedeus; 04-27-2022, 10:43 AM.

    Comment


      #3
      Hello Stanfillirenfro,


      1) A bar has to cross above the EMA. This bar should be the bar of interest. Its value is saved.
      I believe this is the problem based on your description, you saved a local variable. That will be saved for the current bar only. I think you instead meant:

      Code:
      private double valueOfInterest;
      protected override void OnBarUpdate()
      {
          if(Close[0] > EMA(5)[0])
              valueOfInterest = High[0]; 
      
          if(valueOfInterest > 0 && Close[0] > valueOfInterest)
          {
              DrawArrow();
              valueOfInterest = 0; 
          }
      }
      That would keep a value until you clear it and work for multiple bars until the condition is true.

      JesseNinjaTrader Customer Service

      Comment


        #4
        Amedeus and Jesse,

        many thanks for your reply and help. I am implementing based on your advices and I will revert to you in the coming hours.
        Amedeus, the syntax of drawing arrow is not correct., It was not my issue. Thanks for pointing it out. I have it corrected in the code.

        Many thanks again!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        158 views
        0 likes
        Last Post loganjarosz123  
        Started by Belfortbucks, Today, 09:29 PM
        0 responses
        6 views
        0 likes
        Last Post Belfortbucks  
        Started by zstheorist, Today, 07:52 PM
        0 responses
        7 views
        0 likes
        Last Post zstheorist  
        Started by pmachiraju, 11-01-2023, 04:46 AM
        8 responses
        151 views
        0 likes
        Last Post rehmans
        by rehmans
         
        Started by mattbsea, Today, 05:44 PM
        0 responses
        6 views
        0 likes
        Last Post mattbsea  
        Working...
        X