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

Keeping First Buy/Sell Signal

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

    Keeping First Buy/Sell Signal

    Dear Support,

    A simple indicator draws many buy and sell arrows when price is above and below RSI 50 line.

    I am looking for a sample script that will keep only the first instance of a buy signal and will not draw another buy signal until after a sell signal, and so on.

    I know we can use a crossover method for the case of RSI, however, I am looking for a method in general to keep only the first instance of a signal until after an opposing signal is generated.

    Many thanks.
    Last edited by aligator; 03-11-2019, 12:18 PM.

    #2
    Hello aligator,

    Thanks for your post.

    We do not have a helper method available for this task, but you could use bools to control the logic so it only occurs once until the some other logic resets the bool. For example:

    Code:
    private bool SingalActive = false;
    protected override void OnBarUpdate()
    {
        // Our signal which should only be fired once.
        if (Close[0] < Open[0] && !SignalActive)
        {
            //Do Something once here. It will happen only the first time this condition becomes true.
    
            SignalActive = true;
        }
    
        // Opposing signal, when the bool should be reset.
        if (Close[0] > Open[0] && SignalActive)
        {
            //Do Something once here
    
            SignalActive = false;
        }
    }
    Please let us know if we can be of further assistance
    JimNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jim View Post
      Hello aligator,

      Please let us know if we can be of further assistance
      Thanks so much Jim, perfect.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Barry Milan, Yesterday, 10:35 PM
      7 responses
      19 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by AttiM, 02-14-2024, 05:20 PM
      10 responses
      179 views
      0 likes
      Last Post jeronymite  
      Started by ghoul, Today, 06:02 PM
      0 responses
      9 views
      0 likes
      Last Post ghoul
      by ghoul
       
      Started by DanielSanMartin, Yesterday, 02:37 PM
      2 responses
      13 views
      0 likes
      Last Post DanielSanMartin  
      Started by DJ888, 04-16-2024, 06:09 PM
      4 responses
      13 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Working...
      X