Announcement

Collapse
No announcement yet.

Alert when approaching High

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

  • Alert when approaching High

    I am attempting to put together an EFS that will color the chart background when a stock is within .05 (or any other # desirded) of its day high. I would also like to have a sound play say every 5 seconds as long as it is within that range of the high. I would then do the same for the low side as well.

    I have the following code as a start...i'm getting an error about calling the High:

    var vLastAlert = -1;

    function preMain(){
    setPriceStudy(true);
    setStudyTitle("High");

    }

    function main(){

    var nearhigh = callFunction("gettodayOHLC.efs","High");

    if (close() <=nearhigh -0.05)
    onAction1()

    return null;
    }

    function onAction1(){
    setChartBG(Color.lime);

    vLastAlert = 1;
    }





    If anyone has any ideas on how to complete this I would greatly appreciate it. I'm still searching the msg boards for answers as well.

    Thanks,

    cas

  • #2
    cas
    The enclosed code should do what you want

    PHP Code:
    vLastAlert=-1;

    function 
    preMain(){
    setPriceStudy(true);
    setStudyTitle("High");
    }

    function 
    main(){

    var 
    nearhigh callFunction("/OHLC/getTodayOHLC.efs","main","High"); 
     
    if (
    close() >=nearhigh -0.05){
    onAction1();
    }else{
    setChartBG(Color.white);
    }

    return 
    null;
    }

    function 
    onAction1(){
    setChartBG(Color.lime);
    vLastAlert 1;

    Also you may want to look at the Background.efs which is available here which may provide you with some further ideas.
    Alex

    Comment


    • #3
      Alex,

      Thank you very much! that works great....then I got to thinking/cut/pasting..and realized that it would be good to have both the high/low side in a single EFS. The one I came up with below only colors the chart on the low side..not the high side....can you quickly see where my error is?

      vLastAlert=-1;

      function preMain(){
      setPriceStudy(true);
      setStudyTitle("NearHigh_low");
      }

      function main(){

      var nearhigh = callFunction("/OHLC/getTodayOHLC_cas.efs","main","High");
      var nearlow = callFunction ("/OHLC/getTodayOHLC_cas.efs","main","Low");

      if (close() >=nearhigh -0.05)
      onAction1();

      if (close() <=nearlow +.05)
      onAction2();


      else{
      setChartBG(Color.lightgrey);
      }

      return null;
      }

      function onAction1(){
      setChartBG(Color.green);
      vLastAlert = 1;
      }
      function onAction2(){
      setChartBG(Color.red);
      vLastAlert = 2;
      }



      Thank you again for all of the help!

      cas

      Comment


      • #4
        cas
        The main reason the efs will not work is because you are using two callFunction() with getTodayOHLC.efs which is not set up for that.
        Download and save to the OHLC folder the attached getTodayOHLC1.efs and substitute the efs name in your formula.
        Once the above changes are implemented it should work (barring any syntax errors which I have not checked for)
        Alex
        Attached Files

        Comment


        • #5
          Alex,

          Thanks for the quick reply's.....I think i'm confused....since I am trying to get both the high and low of the day, I thought I needed to assign to a variable...hence my attempt at calling both...this is below is wher ei'm at....I get no errors....but no chart color either:

          vLastAlert=-1;

          function preMain(){
          setPriceStudy(true);
          setStudyTitle("NearHigh_low");
          }

          function main(){

          var nearhigh = callFunction("/OHLC/gettodayohlc1.efs","main","High");
          var nearlow = callFunction ("/OHLC/gettodayohlc1.efs","main","Low");

          if (close() >=nearhigh -0.05)
          onAction1();

          if (close() <=nearlow +.05)
          onAction2();


          else{
          setChartBG(Color.lightgrey);
          }

          return null;
          }

          function onAction1(){
          setChartBG(Color.green);
          vLastAlert = 1;
          }
          function onAction2(){
          setChartBG(Color.red);
          vLastAlert = 2;
          }

          Comment


          • #6
            cas
            As to making the two calls that was correct. It is the efs you were calling that cannot be used in that instance which is why I provided one that was modified to be used with multiple calls.
            With regards to the efs it seems to be working (I just modified the nearlow value to +10 to trigger it with $INDU).
            Alex



            Comment


            • #7
              hmmm....yes, it does color on new lows...but in putting in charts at highs, I don't get results. I'm playing around with it still.....must be something very simple.

              Thanks,

              cas

              Comment


              • #8
                cas
                Change the conditions to the following
                Alex

                PHP Code:
                if (close() >=nearhigh -0.05){
                onAction1();
                }
                else if (
                close() <=nearlow +0.05){
                onAction2();
                }
                else{
                setChartBG(Color.lightgrey);

                Comment


                • #9
                  Bingo! Thank you very much!


                  cas

                  Comment


                  • #10
                    Alert - Near the High

                    Alex:
                    Is it possible to create an alert for this .efs instead of coloring the background or bar?

                    Harndog

                    Comment


                    • #11
                      Harndog
                      The enclosed efs should do the following.
                      When the High (or Low) first crosses the pre-set threshold it should sound one ding and trigger an alert list. The alerts should reset once the High (or Low) of a bar crosses back under (or over) the threshold.
                      Alex

                      PHP Code:
                      var nLastRawTime

                      function 
                      preMain(){
                      setPriceStudy(true);
                      setStudyTitle("NearHigh_low");

                      }

                      function 
                      main(){

                      var 
                      nearhigh callFunction("/OHLC/gettodayohlc1.efs","main","High"); 
                      var 
                      nearlow callFunction ("/OHLC/gettodayohlc1.efs","main","Low");

                          if (
                      getValue("rawtime",0) != nLastRawTime) { 
                          
                              if (
                      high() >= nearhigh-0.05 && high(-1) < nearhigh-0.05){
                                  
                      Alert.playSound("ding.wav");
                                  
                      Alert.addToList(getSymbol(),"Near High",Color.black,Color.lime);
                                  
                      nLastRawTime getValue("rawtime",0);
                              }
                              if (
                      low() <= nearlow+0.05 && low(-1) > nearlow+0.05){
                                  
                      Alert.playSound("ding.wav");
                                  
                      Alert.addToList(getSymbol(),"Near Low",Color.black,Color.red);
                                  
                      nLastRawTime getValue("rawtime",0);
                              }
                          }
                          
                      return 
                      null;

                      Comment


                      • #12
                        Hello All,

                        Has anyone managed to get the script below to work? Each time I run it I get the following message even the file is located in the directory in which it is being called?


                        "Error Calling Function (main) in OHLC/gettodayohlc1.efs

                        Any assistance would be greatly appreciated.


                        Cheers

                        Carlton

                        Comment


                        • #13
                          Carlton
                          Try using the attached version of getTodayOHLC1.efs and see if it returns the same error.
                          Alex
                          Attached Files

                          Comment


                          • #14
                            Alex,

                            Thanks for getting back to me. The attached efs no longer gives me an syntax errors, however its not showing any data on the chart at all.


                            Cheers

                            Carlton

                            Comment


                            • #15
                              Alex,

                              What I meant to say was, "there are no syntax errors, however, its not alerting when a new high is approaching."

                              Cheers

                              Carlton

                              Comment

                              Working...
                              X