Announcement

Collapse
No announcement yet.

edit studies Alert playSound

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

  • edit studies Alert playSound

    I have a study that alerts (playSound) and I'd like to be able to change the wave file in edit studies. i.e. So that I can have different sounds for different securities.

    I'd be very appreciative if anyone could point me in the right direction or if you have an example study that does simillar.

    Kind Regards, James

  • #2
    Re: edit studies Alert playSound

    James
    You can do that using a STRING type FunctionParameter in which you add all the sounds you want as options eg
    PHP Code:
    var fpx = new FunctionParameter("function_parameter_name"FunctionParameter.STRING);
    fpx.addOption("chimes.wav");
    fpx.addOption("ding.wav");
    fpx.setDefault("ding.wav"); 
    Then add to the list of arguments of the main() function the name you have assigned to the FunctionParameter and use that name as the parameter of the Alert.playSound() function.
    Notice that this logic is virtually the same as the one I provided you in this post.
    You may also want to review the Tutorial 3: Introduction to preMain() and main() which is available in the EFS KnowledgeBase in the Help Guides and Tutorials-> Beginner Tutorials folder as it explains the FunctionParameter Object in detail
    Alex


    Originally posted by James 88
    I have a study that alerts (playSound) and I'd like to be able to change the wave file in edit studies. i.e. So that I can have different sounds for different securities.

    I'd be very appreciative if anyone could point me in the right direction or if you have an example study that does simillar.

    Kind Regards, James

    Comment


    • #3
      Happy New Year all

      I've written/modified these two efs (inc. Alert.playSound and other FunctionParameters) and been studing the tutorials on efs over xmas. There are a few things I've taken from the tutorials and added in (eg. var bEdit/bInit, and var aStopL = new Array(21);???) which I'm not absolutely sure about yet. If any exprienced eye would care to comment on these and the quality of the studies... any development improvements I could make...I'd be very grateful.

      Both are long trailing stops based off ATR; the former off the highest close and latter off a low-8ema. Please try them; seem to work ok.

      James

      PHP Code:
      function preMain() {
          
      setPriceStudy(true);
          
      setStudyTitle("ProfitStop(Long)");
          
      setShowTitleParameters(false);
          
      setComputeOnClose();
          
          
      // Formula Parameters
          
      var fp1 = new FunctionParameter("nATRlen"FunctionParameter.NUMBER);
              
      fp1.setName("ATR Periods");
              
      fp1.setLowerLimit(1);
              
      fp1.setDefault(13);
          var 
      fp2 = new FunctionParameter("nStoplen"FunctionParameter.NUMBER);
              
      fp2.setName("Stop Periods");
              
      fp2.setLowerLimit(1);
              
      fp2.setUpperLimit(21);
              
      fp2.setDefault(13);
          var 
      fp3 = new FunctionParameter("nThick"FunctionParameter.NUMBER);
              
      fp3.setName("Thickness");
              
      fp3.setDefault(1);
          var 
      fp4 = new FunctionParameter("cColor"FunctionParameter.COLOR);
              
      fp4.setName("Color");
              
      fp4.setDefault(Color.red);
          var 
      fp5 = new FunctionParameter("bAlert"FunctionParameter.BOOLEAN);
              
      fp5.setName("Alert");
              
      fp5.setDefault("true");
      }

      var 
      bEdit true;
      var 
      vATR null;
      var 
      aStopL = new Array(21);
      var 
      bInit false;


      function 
      main(nATRlennStoplennThickcColorbAlert) {
          if (
      bEdit == true) {
              
      vATR = new ATRStudy(nATRlen);
              
      setDefaultBarThickness(nThick);
              
      bEdit false;
          }
          
          if (
      bInit == false) {
              
      setDefaultBarFgColor(cColor);
              
      bInit true;
          }
          
          var 
      nState getBarState();
          if (
      nState == BARSTATE_NEWBAR) {
              
      aStopL.pop();
              
      aStopL.unshift(0);
          }
          
          var 
      ATR vATR.getValue(ATRStudy.ATR);
          if (
      ATR == null) return;
          
          var 
      close();
          var 
      vStopL = (- (2*ATR));
          
      aStopL[0] = vStopL;
          
          
          var 
      vStopxL vStopL;
          for (var 
      0nStopleni++) {
              
      vStopxL Math.max(aStopL[i], vStopxL);
          }
          
          var 
      nState getBarState();
          if (
      close(0) < vStopxL&&bAlert==true) {
              
      Alert.playSound("warning.wav");
          }
          
          return 
      vStopxL
      PHP Code:
      function preMain() {
          
      setPriceStudy(true);
          
      setStudyTitle("MAStop(Long)");
          
      //setDefaultBarThickness(1, 0);
          //setDefaultBarFgColor(Color.yellow, 0);
          
          
      setShowTitleParameters(false);
          
      setComputeOnClose();
          
          
      // Formula Parameters
          
      var fp1 = new FunctionParameter("nATRlen"FunctionParameter.NUMBER);
              
      fp1.setName("ATR Periods");
              
      fp1.setLowerLimit(1);
              
      fp1.setDefault(13);
          var 
      fp2 = new FunctionParameter("nMovlen"FunctionParameter.NUMBER);
              
      fp2.setName("MA Periods");
              
      fp2.setLowerLimit(1);
              
      fp2.setDefault(8);
          var 
      fp2 = new FunctionParameter("nStoplen"FunctionParameter.NUMBER);
              
      fp2.setName("Stop Periods");
              
      fp2.setLowerLimit(1);
              
      fp2.setUpperLimit(21);
              
      fp2.setDefault(13);
          
      // Study Parameters
          
      var sp1 = new FunctionParameter("nThick"FunctionParameter.NUMBER);
              
      sp1.setName("Thickness");
              
      sp1.setDefault(1);
          var 
      sp2 = new FunctionParameter("cColor"FunctionParameter.COLOR);
              
      sp2.setName("Color");
              
      sp2.setDefault(Color.yellow);
      }

      var 
      bEdit true;
      var 
      vATR null;
      var 
      vMAL null;
      var 
      aStopL = new Array(21);
      var 
      bInit false;


      function 
      main(nATRlennMovlennStoplennThickcColor) {
          if (
      bEdit == true) {
              
      vATR = new ATRStudy(nATRlen);
              
      vMAL = new MAStudy(nMovlen0"Low"MAStudy.EXPONENTIAL);   
              
      setDefaultBarThickness(nThick);
              
      bEdit false;
          }
          
          if (
      bInit == false) {
              
      setDefaultBarFgColor(cColor);
              
      bInit true;
          }
          
          var 
      nState getBarState();
          if (
      nState == BARSTATE_NEWBAR) {
              
      aStopL.pop();
              
      aStopL.unshift(0);
          }
          
          var 
      ATR vATR.getValue(ATRStudy.ATR);
          var 
      MAL vMAL.getValue(MAStudy.MA);
          if (
      ATR == null || MAL == null) return;
          
          var 
      vStopL = (MAL - (2*ATR));
          
      aStopL[0] = vStopL;
          
          var 
      vStopxL vStopL;
          for (var 
      0nStopleni++) {
              
      vStopxL Math.max(aStopL[i], vStopxL);
          }
          
          return 
      vStopxL

      Comment

      Working...
      X