• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 NT-Roland, Today, 04:36 PM
      0 responses
      2 views
      0 likes
      Last Post NT-Roland  
      Started by Newtrader101, Today, 03:40 PM
      2 responses
      10 views
      0 likes
      Last Post Newtrader101  
      Started by Branpo, Today, 02:58 PM
      2 responses
      7 views
      0 likes
      Last Post Branpo
      by Branpo
       
      Started by sdauteuil, Today, 02:09 PM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by AMATX, Today, 02:19 PM
      2 responses
      11 views
      0 likes
      Last Post AMATX
      by AMATX
       
      Working...
      X