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

Toggle on first alert

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

    Toggle on first alert

    Below I have three SMA's. When all of them are rising I get an alert. When all are falling I get an alert. My issue is I would like to only get an alert on the first instance of all rising or all falling. My problem with the code below is that I get an alert every bar in which all are rising or falling.

    For example: The market has peaked and is starting to fall. All three SMA's change to falling and I get an alert. The next bar the market continues to fall but I do not get an alert. The market continues to fall for a while but bottoms out and starts upward.

    All three SMA's change to rising and I get an alert and just like the falling alert I do not get another alert until all are falling again.

    Thanks in advance!!!

    Code:
    if 	(		
    					
    					Rising(SMA(14))
    					&&Rising(SMA(28))
    					&&Rising(SMA(42))
    					
    					)
    					
    					Alert("AlertLineCrossing", Cbi.Priority.High, alertMessage, soundFile, 0, Color.White, Color.Black);
    				
    				if 	(		
    					
    					Falling(SMA(14))
    					&&Falling(SMA(28))
    					&&Falling(SMA(42))
    					
    					)
    					
    					Alert("AlertLineCrossing", Cbi.Priority.High, alertMessage, soundFile, 0, Color.White, Color.Black);

    #2
    Hello,

    To have your rising and falling actions alternate, within your if statements you could check if a bool variable was not equal to true.

    Within the actions however you set that bool variable to true. This variable is set back to false after the opposite condition becomes true.

    You could try the following,

    Code:
    xRisingLast=false;
    xFallingLast=false;
    
    
      if( Rising(SMA(14))    &&Rising(SMA(28))    &&Rising(SMA(42)) && xRisingLast !=true)
    {
      Alert('AlertLineCrossing', Cbi.Priority.High,
    alertMessage, soundFile, 0, Color.White, Color.Black);
    xRisingLast=true;  //prevents this block from running until this is set to false by next blocv
    xFallingLast=false;
    
    }
    
    
    if  (       Falling(SMA(14)) &&Falling(SMA(28)) &&Falling(SMA(42)) && xFallingLast != true  )
    {
       Alert('AlertLineCrossing', Cbi.Priority.High,
    alertMessage, soundFile, 0, Color.White, Color.Black);
    xFallingLast=true;
    xRisingLast=false; //Allows the first if statement to become true.
    }
    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thank you very much!!!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by manitshah915, Today, 12:59 PM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by ursavent, Today, 12:54 PM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by cre8able, Today, 01:01 PM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by Mizzouman1, Today, 07:35 AM
      3 responses
      17 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by RubenCazorla, Today, 09:07 AM
      2 responses
      13 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X