Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to prevent sound from iterating for each signal when loading a multi-day chart

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

    how to prevent sound from iterating for each signal when loading a multi-day chart

    i've added a PlaySound() to an indicator signal that paints a BackBrush and i've tried multiple techniques but they all play every iteration of PlaySound() for the 12 days of indicator signals when the chart is loaded... yikes...
    how can i prevent this or maybe i'm omitting a key step in the coding strategy
    here's the code i've landed on...
    (for some reason the indenting is being stripped out)

    Code:
    private int   savedBar;
    
    if (ShowCDRMsignals && IsFirstTickOfBar && CurrentBar > SlowestEmaP + SlowHmaP )
    {
    
    if ( (cumulativeDelta.DeltaClose[2] < FastKmedian[2] && cumulativeDelta.DeltaClose[1] > FastKmedian[1] ) && realMotion[1] > rmsmaF[1]
    || ( (realMotion[2] < rmsmaF[2] && realMotion[1] > rmsmaF[1]) && (cumulativeDelta.DeltaClose[1] > FastKmedian[1]) ) )
    {
    if (CDRMsignalsFullChart)
    { BackBrushesAll[1] = CDRMLongBrush; }
    else
    { BackBrushes[1] = CDRMLongBrush; }
    
     if (upSignalSound && CurrentBar != savedBar )
    { PlaySound(UpSound);
    savedBar = CurrentBar;
    }​
    thanks

    #2
    Hello stafe,

    Thank you for your post.

    If you would only like an action to occur in realtime and not during the historical processing of the script, you could add a check for State == State.Realtime nested inside of your condition. For example:
    Code:
    if (upSignalSound && CurrentBar != savedBar )
    {
    if (State == State.Realtime)
    PlaySound(UpSound);
    savedBar = CurrentBar;
    }​​

    Please let us know if we may be of further assistance.

    Comment


      #3
      thank you for the response, i'll give that a whirl later this afternoon. I've got other indicators that play sound when their if(then) is satisfied but don't play every iteration when the chart loads... it's got me a little stumped but your suggestion will definitely take care of this latest issue... thanks again

      Comment


        #4
        that worked perfectly...

        another question along the same vein -- how can i limit signals within an indicator to the current session only if i load 12 days ? i was looking for something like IsCurrentDay or IsCurrentSession but not finding a way through...

        i've got another question about the same indicator but regarding the signal strategy itself --- in the code above a crossover check is done between bar[2] and bar[1] -- i tried multiple possibilities with CrossAbove and CrossBelow to see if i could get them to start the lookback of 1 from bar[1] after bar[0] opens but couldn't find a work-around -- would an offset to the method be in order ? ie CrossAbove(ISeries, ISeries, lookback, offset)

        thanks

        Comment


          #5
          Originally posted by stafe View Post
          that worked perfectly...

          another question along the same vein -- how can i limit signals within an indicator to the current session only if i load 12 days ? i was looking for something like IsCurrentDay or IsCurrentSession but not finding a way through...

          i've got another question about the same indicator but regarding the signal strategy itself --- in the code above a crossover check is done between bar[2] and bar[1] -- i tried multiple possibilities with CrossAbove and CrossBelow to see if i could get them to start the lookback of 1 from bar[1] after bar[0] opens but couldn't find a work-around -- would an offset to the method be in order ? ie CrossAbove(ISeries, ISeries, lookback, offset)

          thanks
          Hello stafe,

          Thank you for your reply.

          To run calculations only for the current session, you could try the suggestions made in the following post:You could use the sessionIterator class and compare it with the system's DateTime.Now information to determine if the bar is within the current session or you could compare the Time[0] with the current DateTime.Now information:For your question about CrossAbove and CrossBelow, what do you mean about starting a lookback from 1 bar ago after the current bar opens? No offset may be applied when using the CrossAbove or CrossBelow methods. You would have to potentially create a custom series and save the desired values from 1 bar ago as the currentBar value for that custom series and use that series in the crossover condition.

          Please let me know if I may be of further assistance.

          Comment


            #6
            thanks for the consideration on the CrossAbove/Below method - an interesting workaround... i may try creating my own method (not likely)

            i'll have to read a bit more on the current session check

            Comment

            Latest Posts

            Collapse

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