Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

An issue with using a higher time frame on a lower time frame.

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

    An issue with using a higher time frame on a lower time frame.

    I have an alert indicator that uses both HTF(higher time frame) and TTF(trading time frame). The way the indicator is written, the HTF conditions are met, it looks for similar conditions on the TTF. If they conditions are met on both, I coded an alert. HOWEVER, sometimes the conditions are met on the TTF 'first', and then on the HTF. I coded this situation as well. So, when this is the case, the alert will continue to go off after each candle close on the TTF(Which is annoying). I've tried everything I could think of to make it alert me once. I put in a Boolean variable that I have to manually turn on and off. Is there any other way of coding this so that it isn't so physically demanding(i.e. the indicator works on its own). Here is a sample piece of code:



    bool HTFOn = true;


    if(Close[0] > SMA(20)[0])
    {
    //if prev. bar HTF 20 SMA is greater than/equal to TTF 20 SMA, and Curr. bar HTF 20 SMA is less than TTF 20 SMA, and bool HTFOn is equal to true

    if(SMA(BarsArray[1],20)[1] >= SMA(20)[1] && SMA(BarsArray[1],20)[0] < SMA(20)[0] && HTFOn == true)
    {
    PlaySound(NinjaTrader.Core.Globals.InstallDir + @"\sounds\Alert1.wav");
    }
    }

    In this scenario, the alert will keep beeping for every TTF candle close until there's a new HTF candle close.
    I would have to manually go into the indicator parameters and set the boolean varible to false.
    Is there another way of coding this where it will only alert me once in this scenario?

    #2
    Hello jamestrader21x,

    Thanks for your post.

    You could add a condition that limits you to one sound per HTF bar.

    Create an int variable perhaps called soundBar and use it like this:

    if (your conditions to playsound && savedBar != CurrentBars[1]) // savedBar is NOT equal to the current bar of the HTF
    {
    Playsound(...);
    savedBar = CurrentBars[1]; // make them equal
    }

    The first time through the sound will be played, further triggers would be ignored until the next HTF bar.

    Comment


      #3
      I tried that and different variations. I couldn't get it work right. I changed the code from playsound() to BarBrush to make it easier to find an example. I'm either getting no painted bars or many painted bars.

      Comment


        #4
        I figured it out. I used Closes. Since I'm dealing with 1 close for HTF and multiple closes for TTF.

        if(Closes[0][0] == Closes[1][0])
        {
        PlaySound(NinjaTrader.Core.Globals.InstallDir + @"\sounds\Alert1.wav");
        BarBrush = Brushes.Blue;
        }

        Thanks for the help.

        Comment


          #5
          Hi NinjaTrader_PaulH,
          Can you show us how to limit the sound until the condition is false, regardless of how many HTF bars that takes? I am trying to sound an alert only once per condition being true no matter how many bars on all barsarrays go by. So independent of bars...
          Thank You very much!

          -whiterhino

          Comment


            #6
            Hello whiterhino,

            Thanks for your post.

            If the condition to play sound is true, playsound:

            if (Condition == true)
            {
            PlaySound(....);
            }

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            636 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            366 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            107 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            568 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            571 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X