Announcement

Collapse
No announcement yet.

Coding error

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

  • Coding error

    Hi all

    I'm trying to code an early break-out style alert system. This is the code that I have

    Code:
    var vDonchian = new DonchianStudy(7, 0); //change the 13 to the number of bars before 1030
    // this is done by taking the interval in minutes divided into 60, so for a 5 min chart, 60/5 is 13
    function preMain(){
    setPriceStudy(true);
        setStudyTitle("Crystal Ball");
        setCursorLabelName("a", 0);
        setCursorLabelName("b", 1);
        setDefaultBarStyle(PS_SOLID, 0);
        setDefaultBarStyle(PS_SOLID, 1);
        setDefaultBarFgColor(Color.white, 0);
        setDefaultBarFgColor(Color.white, 1);
        setDefaultBarThickness(1, 0);
        setDefaultBarThickness(1, 1);
        setPlotType(PLOTTYPE_LINE, 0);
        setPlotType(PLOTTYPE_LINE, 1);
    
    }
    
    function main(){
    
    BarHr     = getHour();
    BarMin    = getMinute();
    cBarTimeInt  =BarHr*100+BarMin*1;
    
    if(cBarTimeInt<1455){
    hrOne=0;
    return null;
    }
    
    
    if(cBarTimeInt>=1455
    && hrOne==0){
    hrOne=1;
    hrOneHi=vDonchian.getValue(DonchianStudy.UPPER);
    hrOneLo=vDonchian.getValue(DonchianStudy.LOWER);
    return new Array(high(), low());
    }
    
    if(hrOne==1){
    return new Array(hrOneHi, hrOneLo);
    }
    
    return null; 
    
    /**
        *  The main() function is called once per bar on all previous bars, once per
        *  each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
        *  in your preMain(), it is also called on every tick.
        */
    
    //{{EFSWizard_Expressions
        //{{EFSWizard_Expression_1
            if (
                ((close() - hrOneLo) / (hrOneHi - hrOneLo)) > 0.95
                ((close() - hrOneLo) / (hrOneHi - hrOneLo)) < 1
            ) onAction1()
        //}}EFSWizard_Expression_1 5117
        
        //{{EFSWizard_Expression_2
            else if (
                ((close() - hrOneLo) / (hrOneHi - hrOneLo)) < 0.05
                ((close() - hrOneLo) / (hrOneHi - hrOneLo)) > 0
            ) onAction2();
        //}}EFSWizard_Expression_2 7666
        
    //}}EFSWizard_Expressions 33535
    
    
    //{{EFSWizard_Return
        return null;
    //}}EFSWizard_Return 2256
    
    }
    
    function postMain() {
       /**
        *  The postMain() function is called only once, when the EFS is no longer used for
        *  the current symbol (ie, symbol change, chart closing, or application shutdown).
        */
    }
    
    //{{EFSWizard_Actions
        //{{EFSWizard_Action_1
        function onAction1() {
            Alert.addToList(getSymbol(), "", Color.RGB(0,0,0), Color.RGB(195,0,0));
            Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\New.wav");
            vLastAlert = 1;
        }
        //}}EFSWizard_Action_1 23124
        
        //{{EFSWizard_Action_2
        function onAction2() {
            Alert.addToList(getSymbol(), "", Color.RGB(0,0,0), Color.RGB(195,0,0));
            Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\New.wav");
            vLastAlert = 2;
        }
        //}}EFSWizard_Action_2 24494
        
    //}}EFSWizard_Actions 69550
    The top coding has been taken and adjusted from terms.efs which I've downloaded from here. The alerts side has been copied from the formula wizard, so its a bit of a jigsaw puzzle. My questions are:

    Why can't I get an audio alert up?
    As I have the alert.addtolist, where would the alert show?
    Is it possible to have the setDefaultBarFgColor completely invisible. At the moment it's blocking out some of the numbers
    Is it possible to test it out after hours. I tried testing it on the tick replay, but all that happened was it said Crystal ball ....loading data.

    If you could answer these questions it would be much appricated

    Mark
    PS: Just in case you couldn't tell this is my first EFS project

  • #2
    Hello Mark,

    A similar problem was previously discussed in the thread below. Please review the thread and try the test formula, jonti2.efs.

    Sound Alerts Problem
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Hi Jason

      That's brilliant!!

      1 question down
      3 more to go

      Mark

      Comment


      • #4
        Hi Jason and all

        I've figured out most things, there is one problem that I've found

        Using my wizard it doesn't understand the first time only line for a sound. This code is taken from a very basic wizard, but the first line - the one with the ding won't play. I've tried every combination of sounds and reverse orders, and the only thing I can think it can be is the code for the "... while the following will happen only the first time:" section

        Code:
        //{{EFSWizard_Actions
            //{{EFSWizard_Action_1
            function onAction1() {
                if (vLastAlert != 1) Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Ding.wav");
                Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Bullet.wav");
                vLastAlert = 1;
            }
            //}}EFSWizard_Action_1 27542
            
        //}}EFSWizard_Actions 36527
        Thanks
        Mark

        Comment


        • #5
          Hello Mark,


          The Alert.addToList() alerts will automatically appear in the Alert List Window. To open it manually to see the alerts go to Tools --> EFS --> Alert List.

          Is it possible to have the setDefaultBarFgColor completely invisible. At the moment it's blocking out some of the numbers
          There isn't a choice for invisibility with that function. However, I'm not sure exactly what you are referring to. Can you post a chart image that displays the problem?

          You can test after hours with bar replay or tick replay. If you use tick replay with a short interval (1T), you may experience some problems. Try using a longer-term interval.

          In regards to your code snippet, you can't call two sounds back to back during one execution of the formula. The formula will only play the second, or last one called. Try reming out the Bullet.wav line and see if the Ding.wav fires. To rem out the line, place to forward slashes in front of it ( //Alert....... ).
          Jason K.
          Project Manager
          eSignal - an Interactive Data company

          EFS KnowledgeBase
          JavaScript for EFS Video Series
          EFS Beginner Tutorial Series
          EFS Glossary
          Custom EFS Development Policy

          New User Orientation

          Comment


          • #6
            Hi Jason

            I've changed the code to this

            Code:
            //{{EFSWizard_Actions
                //{{EFSWizard_Action_1
                function onAction1() {
                    if (vLastAlert != 1) Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Ding.wav");
                    vLastAlert = 1;
                }
                //}}EFSWizard_Action_1 17494
                
            //}}EFSWizard_Actions 26113
            ....and no sound at all now

            I can now get the tick replay working, but it still said Loading..... until I jumped forward 1 minute. Not sure why but it works

            Attached is the error that I have found with the numbers down the right-hand side. As you can see there is no number 89.25. It seems as though the values I'm returning in the original coding are blanking out everything

            Thank you again for your help
            Mark.
            Attached Files

            Comment


            • #7
              Hello Mark,

              I noticed you have a logic problem in your code that is preventing your onAction functions from being called. Around line 42 you have a "return null;" that is stopping main() from getting down to the conditions that trigger onAction1(). Remove the return null and test your formula. You may also want to use the debugPrintln() function to make sure your various code blocks are being executed as you are expecting them to. Simply place debugPrintln("hello") in a particular code block and you'll see "hello" printed out in the formula output window, which you can open from Tools --> EFS --> Formula Output Window. You could also replace "hello" with your variable names to check the values they are being set to.

              In regards to the missing y-axis label, I think your formula output label is just covering it. In preMain() you are specifying white for the return colors and you have a white background. You won't be able to see anything in this case. Change the preMain() colors to something other than white or change your chart's background color and see what happens.
              Jason K.
              Project Manager
              eSignal - an Interactive Data company

              EFS KnowledgeBase
              JavaScript for EFS Video Series
              EFS Beginner Tutorial Series
              EFS Glossary
              Custom EFS Development Policy

              New User Orientation

              Comment

              Working...
              X