Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Hoping for alert on first bar only when conditions met

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

    Hoping for alert on first bar only when conditions met

    I have a strategy that sets off an alert whenever two EMAs are falling or rising:

    if (Falling(EMA(Typical, 8)) == true
    && Falling(EMA(Typical, 16)) == true

    {
    PlaySound…etc.

    However, the alert is triggered (and if I altered this to work with trades, the trades would be entered) on every bar the conditions are met.

    My goal is to have the alert sound on - and only on – the very first bar these conditions are met and not on the subsequent ones (until, of course, the reverse conditions are met).

    I’d be very grateful to receive advice as to how to implement this. Is it possible to achieve this with the Strategy Wizard only? Or would some extra coding be necessary, and if so, what would this entail?

    Much obliged in advance for any help.

    #2
    Hello arbuthnot,

    Thank you for posting and welcome to the NinjaTrader forums! You can do this in the wizard. Instead of PlaySound, choose Alert, also under Misc. Alert has a sound playback component as well and you can leave at Rearm seconds = 0 to have it never rearm.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks very much for your advice, Ryan.

      I implemented what you suggested in the Wizard:

      a) this is the resulting code: Alert("MyAlert2", Priority.High, "", @"C:\Program Files\NinjaTrader 7\sounds\Alert4.wav", 0, Color.White, Color.Black);

      b) Also, I have “Rearm seconds = 0”.

      What happened is that the alert was triggered the very first time the conditions were met – but never once since! I’ve tried it with minute bars and range bars, seeing many turns, but unfortunately I’ve heard nothing.

      (I’ve always made sure the strategy was ‘Enabled’.)

      Obviously, I’d like the alert to be triggered on the first bar of every ‘rise’ and then the next ‘fall’, and so on.

      Is there maybe something I need to do to the ‘Rearm’ function?

      Many thanks for your further advice.

      Comment


        #4
        Yes, it's designed to Alert() only once. I thought this is what you were looking for. If you want it to trigger again, you would need to define the conditions for allowing it and then call ResetAlert() or ResetAlerts(). These are unfortunately only available with custom programming.


        I see the idea you're going for. You could do it with two alerts (rising and falling) and then reset one while you're calling the other.

        Code:
        if (risingConditions)
        {
        Alert("Rising", Priority.High, "Rising Alert", "Alert1.wav", 0, Color.White, Color.Black);
        ResetAlert("Falling");
        }
        
        
        if (fallingConditions)
        {
        Alert("Falling", Priority.High, "Falling Alert", "Alert1.wav", 0, Color.White, Color.Black);
        ResetAlert("Rising");	
        }
        Last edited by NinjaTrader_RyanM1; 02-14-2012, 01:41 PM.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          That works brilliantly, Ryan. Without your help, I couldn't have got anywhere near it!

          Much obliged.

          Comment


            #6
            I'm glad that did the trick. Thanks for following up with us.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              When I started this thread, I was working on a strategy that would trigger alerts. With Ryan’s brilliant help, I found a way of having the alerts trigger again (as opposed to once only which was originally happening) using ‘ResetAlert("Falling/Rising")’.

              Now I wish to redo the same strategy (i.e. the same technical ideas behind it) but this time, I wish to automate it by having it place trades, rather than sound alerts.

              Is there an equivalent of ‘ResetAlert’ for the entering of trades so a trade would be ‘triggered again’, so to speak, as the alerts were previously?

              I hope I’ve made my point clearly! I look forward to finding out what I need to do with NinjaScript in this respect.

              Many thanks in advance.

              Comment


                #8
                Hello arbuthnot,
                Thanks for writing in and I am replying for Ryan

                With Managed order approach NinjaTrader will make sure that the same order is not submitted twice. http://www.ninjatrader.com/support/h...d_approach.htm

                You can also check for the current position status and submit order only when your position is flat.

                Code:
                if (Position.MarketPosition == MarketPosition.Flat && (other conditions))
                {
                	EnterLong();
                }
                The above code will go long only if you are flat.

                Please let me know if I can assist you any further.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  Thanks very much for the reply.

                  I obviously didn’t make what I want to say completely clear. My fault entirely.

                  In your reply, you talked about the same order not being submitted twice. The issue I’m trying to address is not one of having too many orders, but on of not having too few!

                  I’ll try to restate the situation:

                  When I originally wrote my strategy to set off an audio alert (dependant purely rising and falling indicators), what happened is that the alerts were triggered once and once only.

                  Ryan said “If you want it to trigger again, you would need to define the conditions for allowing it and then call ResetAlert() or ResetAlerts(). These are unfortunately only available with custom programming. I see the idea you're going for. You could do it with two alerts (rising and falling) and then reset one while you're calling the other.

                  On Ryan’s advice, I added the code ‘ResetAlert("Falling")’ and ‘ResetAlert("Rising")’.

                  (Please see Ryan’s post of 02-14-2012 below.)

                  What I don’t know about is how NinjaScript handles trades compares with how it handles alerts.

                  So this is my point: if you need special code [such as ‘‘ResetAlert("Falling"] when dealing with alerts so they will trigger again in falling/rising indicator situations, is there anything special by way of code that needs to be added when dealing with trades?

                  Or is this not an issue as trades are handled in a completely different way?

                  Am I making myself any clearer this time? If so, I hope you’ll be able to let me know the situation.

                  Many thanks in advance and I look forward to hearing from you.

                  Comment


                    #10
                    Hello arbuthnot,
                    If you use managed approach to submit the orders then you dont have to append any custom codes like what you are using while triggering an Alert.

                    Once you are out of the trade, NinjaTrader will automatically rearm itself for the next entry signal.

                    Please refer to the SampleMACrossover strategy that comes with NinjaTrader to get an idea.
                    • In Control Center menu bar goto Tools>Edit NinjaScript>Strategies...
                    • In the Strategies dialog select SampleMACrossover
                    • Click Ok.


                    Please let me know if I can assist you any further.
                    JoydeepNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    650 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    370 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    109 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    574 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    577 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X