Announcement

Collapse
No announcement yet.

This alert doesn't work

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

  • This alert doesn't work

    Trying to add a drop down menu for an indicator to select from multiple wav files for the alert. "AlertOn" is the variable for whatever .wav name is selected from the menu. Why dosen't this work ? The code for the trigger works but the .wav played for the alert is the Windows warning "donk" sound that plays when you have a pop up open and try to click on something in windows before you close the pop up.

    [PHP]
    var fp8 =
    new FunctionParameter("AlertOn", FunctionParameter.STRING);
    fp8.setName("Alert");
    fp8.addOption("ding");
    fp8.addOption("buzz");

    function main(Length, Source, Upper, Lower, Params, AlertOn) {

    if(getBarState()==BARSTATE_NEWBAR){

    if(vCCI.getValue(CCIStudy.CCI,-2)<Upper && vCCI.getValue(CCIStudy.CCI,-1)>Upper){
    Alert.playSound("AlertOn.wav");
    }[PHP]

  • #2
    Re: This alert doesn't work

    huntergatherer
    The error is in the following line of code
    Alert.playSound("AlertOn.wav");
    which should instead be
    Alert.playSound(AlertOn+".wav");
    Once you make this change the formula should work
    You may also want to add a default sound to the FunctionParameter AlertOn
    Alex


    Originally posted by huntergatherer
    Trying to add a drop down menu for an indicator to select from multiple wav files for the alert. "AlertOn" is the variable for whatever .wav name is selected from the menu. Why dosen't this work ? The code for the trigger works but the .wav played for the alert is the Windows warning "donk" sound that plays when you have a pop up open and try to click on something in windows before you close the pop up.

    [PHP]
    var fp8 =
    new FunctionParameter("AlertOn", FunctionParameter.STRING);
    fp8.setName("Alert");
    fp8.addOption("ding");
    fp8.addOption("buzz");

    function main(Length, Source, Upper, Lower, Params, AlertOn) {

    if(getBarState()==BARSTATE_NEWBAR){

    if(vCCI.getValue(CCIStudy.CCI,-2)<Upper && vCCI.getValue(CCIStudy.CCI,-1)>Upper){
    Alert.playSound("AlertOn.wav");
    }[PHP]

    Comment


    • #3
      Thanks Alex,

      Wouldn't of figured that one out. I'm going to add the default
      .wav as you suggest and also an option to turn alerts on/off.

      Comment


      • #4
        huntergatherer
        You are welcome.
        FWIW the reason it was not working is because you were instructing the alert function to play a sound called ”AlertOn.wav” which did not exist [hence the dull sound]
        When you instead write the parameter as AlertOn+”.wav” you are instructing the formula engine to use the value set for the AlertOn parameter [ie “buzz” or “ding” etc] and concatenate that to the string “.wav”.
        As to adding an option to disable the alerts just add an “OFF” option to the one where you select the sound then modify your condition as follows
        PHP Code:
        if(AlertOn!=”OFF”){//if the AlertOn parameter is not equal to “OFF” then evaluate the condition
            
        if(vCCI.getValue(CCIStudy.CCI,-2)<Upper && vCCI.getValue(CCIStudy.CCI,-1)>Upper){ 
                
        Alert.playSound(AlertOn+.wav");//and play the selected sound
            }

        This way the conditional statement will be evaluated only if the parameter is set to a value other than OFF
        Alex


        Originally posted by huntergatherer
        Thanks Alex,

        Wouldn't of figured that one out. I'm going to add the default
        .wav as you suggest and also an option to turn alerts on/off.

        Comment

        Working...
        X