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

Alert programming - stumped

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

    Alert programming - stumped

    Hi all, hope someone can point me in the right direction. I am trying to write an alert that will tell me when 3 MA's are within 3 ticks of each other for 5 of the last 10 bars.

    Sounds simple enough but I am having trouble developing the "within" part. I have defined my MA's and I understand the "counts" command to give me the condition is true for 5 from 10. Just having trouble developing the within 3 ticks.

    Example:

    I would like to be alerted on bar close, when a 10 period ema is within 3 ticks of the 20 period ema and within 3 ticks of the 30 period ema AND the 20 period ema must also be within 3 ticks of the 30 period ema for 5 of the last 10 bars.

    OR

    Condition "A" is defined as True :
    At close of bar if
    ValueEMA10 = ValueEMA20(+/- 3ticks) AND
    ValueEMA10 = ValueEMA30(+/- 3ticks) AND
    ValueEMA20 = ValueEMA30(+/- 3ticks)

    If "A" = True for 5 bars out of 10 alert (play tubular bells) or (Draw Mona-Lisa) etc

    I can find <, >, <=, >=, = etc etc etc but I want a +/- 3 (ticks); percent etc is no good otherwise you will have to redefine this for each instrument.

    Can anyone help please.

    In case your wondering, this will define a flattening of price in a trend and alert to a possible breakout opportunity; either continuation or reversal. I trade with range bars and this alert would be the equivalent of a "doji" on a c'stick chart.

    Saves me watching 10+ instruments for a signal condition as I can then use this indicator / strategy in the "Market Analyser" window which will monitor any number of instruments without taking up any screen real estate. (I hope) !! Monitoring MA's has proved to be far more effective than price as they lag and thus filter out "fake outs".

    If you're excited enough and want to help out - I will then be developing this to have configurable time periods so it is only active when you want to trade. Say between 9.30am and 11.30am and 1.30pm to 3.00pm. (No point alerting you at midnight when the condition is almost certainly true because price is range bound due to low volume)

    Any constructive help gratefully appreciated, I'll get there eventually but am hoping to speed things up.

    Sincerely;

    Ben.

    #2
    Hello Ben,

    I read "within" to mean the distance between them. One way may be to nest multiple Math.Max() to take the highest of 3 values, and Math.Min to take lowest of the 3. Subtract these and you have the biggest difference among the 3 values.

    double a = EMA(10)[0];
    double b = EMA(20)[0];
    double c = EMA(30)[0];

    double maxDiff = Math.Max(Math.Max(a, b), c) - Math.Min(Math.Min(a, b), c);

    For the alerting, you can set a plot value as 1 when true, and 0 when false. Then can set alerts when the value of your indicator == 1.

    if (maxDiff <= TickSize * 3)
    Value.Set(1);

    else
    Value.Set(0);
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Yep
      I have used "within" as in:

      at the close of the bar the value of each ema must be "within" 3 ticks of each other. So if the value of the 10 ema is 1.3232 then the value of the 20 and the 30 must be <= 1.3235 and >= 1.3229. This "condition must be met for at least 5 0f 10 bars to give you an alert.

      Hope this clarifies

      Comment


        #4
        Just working through your answer now but its nearly 11pm here. Will write script tomorrow. Sleeping on it always helps but I think that you have hit the nail on the head so to speak. Couldn't see the wood for the trees but as always the simple solution is the best, thanks again.

        Comment


          #5
          Yep, going to stay up for 1 more Guinness and work through this but I can't see any problems; brilliant, neat solution and I now feel a little dumb !!!

          Thanks again.

          Comment


            #6
            You're welcome. I'm happy to hear that worked out for you.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Hi Ryan, this is my first time on the forum and not to sure how it all works yet.

              I am trying to write an alert for when the MACD line closes up/down in relation to its previouse bar.

              Anyones help would be appreciated.

              Thanks.

              Comment


                #8
                Hello eroscoe,

                Welcome to the NinjaTrader forums! If you're just getting started with programming, would recommend the strategy wizard is the best starting point. You can setup conditions like this in a point and click interface, and then view and edit code as needed.

                If you want to compare a value to it's previous value to test if it's higher or lower, this could be done with rising and falling. There is a sample here that can help show you how rising and falling is setup in the strategy wizard:


                See here for the strategy wizard section of our help guide:
                Ryan M.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by BarzTrading, Today, 07:25 AM
                2 responses
                19 views
                1 like
                Last Post BarzTrading  
                Started by devatechnologies, 04-14-2024, 02:58 PM
                3 responses
                20 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by tkaboris, Today, 08:01 AM
                0 responses
                4 views
                0 likes
                Last Post tkaboris  
                Started by EB Worx, 04-04-2023, 02:34 AM
                7 responses
                163 views
                0 likes
                Last Post VFI26
                by VFI26
                 
                Started by Mizzouman1, Today, 07:35 AM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X