Announcement

Collapse
No announcement yet.

Alert.addToList problem ...

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

  • Alert.addToList problem ...

    Good afternoon
    I have some "Alert" handling code, which seems only to work when Tools, EFS, Settings,make all formulas compute on close is checked (this is what I want).
    PHP Code:
    function BuyMessage(Buy_Mess){
                
    setBarFgColor(Color.black,0);setBarFgColor(Color.black,1);
                
    setBarThickness(2,0);setBarThickness(2,1);setBarBgColor(Color.green);
                
    debugPrint(Buy_Mess+crlf);
                
    Alert.addToList(getSymbol(),Buy_MessColor.greenColor.black );
               
                
    /*Alert.playSound("cashreg.wav");
                Alert.email(Buy_Mess)*/
    return ; 

    The code is invoked by :
    callFunction("FunctionLib.efs","BuyMessage",Buy_Me ss) from within a Function.

    Do I need to pass the symbol, or is getSymbol(), etc. universally available to all applications?
    I have found that the Alert.addToList never executes (the statements immediately before it do execute).
    Unchecking this setting sets off a flood of Alerts to the Alert List: i.e. it does execute.
    What is going on here, please?
    Thanks
    George

  • #2
    My assumptions...

    George,

    Try passing it the SYMBOL. This is the only thing that could be causing a problem with the call.

    I would think this would be all you need to do to solve the problem...

    Regarding the setComputeOnClose() issue. You can resolve this issue by time-stamping the action taken on a bar...

    Here is an example....

    PHP Code:
    var nLastAlertTime 0;

       if (
    getValue("rawtime"0) != nLastAlertTime) {

        
    Test for new alerts...

         
    nLastAlertTime getValue("rawtime",0);
       } 
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Brad - thanks, but I am afraid that is not it.

      I came across this on another thread:


      "Thanks for responding. ......

      (... 1 hr later ...)

      I finally figured out the problem. The Javascript processor IGNORES all invocations of Alert.addToList() until it has processed all prevous bars and is currently processing bar 0. The attached test.efs proves this. The eSignal developers should include this kind of detail in the online help."

      I tend to agree with this, but cannot grasp why - having now modularized this message handling code by placing it in a Callable Function Library - it no longer executes, except when I setComputeonClose from Tools,EFS, Settings? Is it possible that the setCompute,etc... causes the system to never be processing Bar 0 (but that the current bar is always -1)??

      Thanks
      George

      Comment


      • #4
        Originally posted by wombat953
        Is it possible that the setCompute,etc... causes the system to never be processing Bar 0 (but that the current bar is always -1)??
        I believe this is the case. I'm not completely sure if the bar index is -1, but I don't think that bar 0 will ever be reached if "Make all formulas compute on close" is checked in the Tools -> EFS -> Settings dialog.
        Regards,
        Jay F.
        Product Manager
        _____________________________________
        Have a suggestion to improve our products?
        Click Support --> Request a Feature in eSignal 11

        Comment


        • #5
          Jay -thanks, that was my interpretation.
          Can you assist me with my first inquiry, below?
          Thanks
          George
          Last edited by wombat953; 08-20-2003, 07:22 AM.

          Comment


          • #6
            George,

            You'll need to pass the symbol to BuyMessage() for this to work correctly. I believe this is because getSymbol() will only return a symbol if it is active on a chart. Since you are using callFunction to activate BuyMessage(), it will not be aware of what the symbol is your wanting to use it with.
            Regards,
            Jay F.
            Product Manager
            _____________________________________
            Have a suggestion to improve our products?
            Click Support --> Request a Feature in eSignal 11

            Comment


            • #7
              Jay
              I am currently passing the symbol (via getSymbol()), but this makes no difference. What does make a difference is setting setComputeOnClose() NOT to be checkmarked in Tools, EFS,Settings. Reloading of the calling EFS causes a flood of alerts to be issued. So the code is working both with, and without, passing the symbol. But I do wantComputeonClose checked.
              This is counter-inuitive behaviour, and may be a bug. I don't know. It worked when the function was defined in the calling EFS.

              Is there any formal documentation on Alerts, other than:
              "Adds the specified symbol and description to your Alert list." from Divergence Software, Inc.


              George
              PS. Here is the code:
              Invocation of function:

              PHP Code:
              function Buy() {  
              ticksize=callFunction("FunctionLib.efs","getTicksize",getSymbol());
              var 
              stopIn = (high(0)+ticksize);
              var 
              stopOut =(Math.min(low(0),low(-1))-ticksize);
              ticksize=callFunction("FunctionLib.efs","getTicksize",getSymbol());
              var 
              Buy_Mess "**"+currBarTime+"**BUY_STOP "+getSymbol()+At+formatPriceNumber(stopIn)
                          +
              ", Protective SELL_STOP "+At+formatPriceNumber(stopOut);
              callFunction("FunctionLib.efs","BuyMessage",Buy_Mess,getSymbol());
              return 

              The function itself is as before:
              PHP Code:
              const tab "\t";
              const 
              comma ","
              const 
              slash "/"
              const 
              blank " ";
              const 
              colon ":";
              const 
              crlf "\n";
              const 
              At "@";
              const 
              star "*";
              var 
              ticksize=0;
              function 
              PriceBarColors(vOpen,vClose) {
                          
              /*debugPrintln(getSymbol()+"Bar: "+getCurrentBarIndex()
              +" vOpen: " +vOpen+" vCLose: " +vClose) */  
                 
              if (vClose vOpensetPriceBarColor(Color.lime)
                 else 
                 if (
              vClose vOpen)  setPriceBarColor(Color.red
              return 
              null
              }
              function 
              getTicksize(symbol){/*debugPrintln(symbol);*/
              var ESRegular =    "ES #F=2";
              var 
              ESContinuous "ES #F";
              var 
              NQRegular =    "NQ #F=2";
              var 
              NQContinuous "NQ #F";
              var 
              Russell2000 =  "AB #F";
              var 
              Dow          "YM #F";
              switch (
              symbol) {
                  case 
              ESRegular   :ticksize 0.25;break;
                  case 
              ESContinuous:ticksize 0.25;break;
                  case 
              NQRegular   :ticksize 0.5; break;
                  case 
              NQContinuous:ticksize 0.5; break;
                  case 
              Russell2000 :ticksize 0.1; break;
                  case 
              Dow         :ticksize 1; break;
                  }                   
              //end switch
              return ticksize;
              }                       
              //end function
              function BuyMessage(Buy_Mess,symbol){
                          
              setBarFgColor(Color.black,0);setBarFgColor(Color.black,1);
                          
              setBarThickness(2,0);setBarThickness(2,1);setBarBgColor(Color.green);
                          
              debugPrint(Buy_Mess+crlf);
                          
              Alert.addToList(symbol,Buy_MessColor.greenColor.black );
                         
                          
              /*Alert.playSound("cashreg.wav");
                          Alert.email(Buy_Mess)*/
              return null
              }   
              function 
              SellMessage(Sell_Mess,symbol) {
                          
              setBarFgColor(Color.black,0);setBarFgColor(Color.black,1);
                          
              setBarThickness(2,0); setBarThickness(2,1);  setBarBgColor(Color.red);
                          
              debugPrint(Sell_Mess+crlf);
                          
              Alert.addToList(symbol,Sell_MessColor.redColor.black );
                          
              /*Alert.playSound("cashreg.wav");
                           Alert.email(Sell_Mess)*/
              return null;
              }
              function 
              averageIntervalRange(numIntervals,date,time) {
              var 
              x=0;var rng=0;var period=0;
              var 
              nTot=0;
              if (
              numIntervals==nullnumIntervals=100;
                  for (
              x=-numIntervalsx<0x++) {
                      
              rng Math.abs(high(x)-low(x));
                      
              nTot =nTot+rng;
                  }
                  
              avg = (nTot/numIntervals).toFixed(2);
                  if (!
              isDWM()) period "minutes"
                  
              else period "";
                  
              debugPrint(star+date+star+time+star+getSymbol()+" Bar "+getCurrentBarIndex()+colon
                  
              +" Avg Periodic Range for "+getSymbol()+" for chart interval "+getInterval()+blank+period+" = "+avg+" points\n")
              return 
              avg;

              Last edited by wombat953; 08-20-2003, 10:43 AM.

              Comment


              • #8
                George,

                Instead of using the Compute on Close, I would suggest implementing the tip that Doji3333 referred to. It should clear up that necessity of using Compute on Close.
                Regards,
                Jay F.
                Product Manager
                _____________________________________
                Have a suggestion to improve our products?
                Click Support --> Request a Feature in eSignal 11

                Comment


                • #9
                  Jay - I may have to pursue that suggestion.
                  But what if an EFS does require Compute on CLose?

                  I must say that it is not clear to me why this should impact the functioning of the Alert methods. Certainly, it does not appear to be documented anywhere (in fact, I am not sure there is any documentation regarding the functioning of the Alert methods). I am not sure if this is a problem with core JavaScript, or the implemetation of IDC's EFS extensions to it.
                  Thanks
                  George

                  Comment


                  • #10
                    Jay/Brad - I am unclear about this, esp the initialization.
                    Where does the var nLastAlertTime = 0 go? It cannot be in the called function (else will always be zero), and note that there is no "main" since I am calling callable functions and have no interest in any main.
                    Thanks
                    George

                    Comment


                    • #11
                      Hi,

                      A comment on one thing you said:

                      and note that there is no "main" since I am calling callable functions and have no interest in any main.

                      Just because a function is callable doesn't mean it can't have a main. In fact often having a main and being able to load an EFS function into an chart by itself is the easiest way to debug them.

                      Garth
                      Garth

                      Comment


                      • #12
                        Garth - exactly right, but I don't require one in this case, where I might want to initialize a variable (nLastAlertTime = 0) only once, and not for each iteration of main, let alone each tick.
                        In any case, I am completely stumped, once again, for the time being...
                        Regards
                        George
                        Last edited by wombat953; 08-20-2003, 07:12 PM.

                        Comment


                        • #13
                          So guys, where do I place the AlertInitialization variable?
                          i.e the statement that initializes it to zero, such that this won't happen every time
                          Thks
                          George

                          Comment


                          • #14
                            Hello George,

                            Let's start over with a fresh solution.

                            First, here are a couple of clarifications. You have the correct understanding of the Alert object not working when SetComputeOnClose is true. The Alert object only works on bar index of 0. It has been suggested to our development team to allow the Alert object to operate when SetComputeOnClose is true, but it has not been implemented yet. The other problem you are experiencing has to do with how the advanced chart works with the setBarBgColor() function. When you call that function the background color will be changed. However, on the next iteration of main(), if you do not have a routine that sets the background color, that bar will return to it's default color. You have a couple solutions for this.

                            First of all, don't use setComputeOnClose(), let the formula compute tick-by-tick. Now, if you use setDefaultBarBgColor() vs setBarBgColor(), then the color will remain. If you take this route, then you'll need to check for the instance of a new bar and set the default bar background color back to your neutral color.

                            The other solution is outlined in the code examples below. This example uses setBarBgColor(). The trick here is to set a variable equal to the color in your FunctionLib.efs function, return that variable to your formula and call setBarBgColor() on each tick until the condition becomes false or a new bar arrives. Again, you'll need to check for the instance of the new bar and reset the color variable to null. The other item I've added to this example is a flag that controls the execution of your callFunction() statement. In this example, the flag only allows the callFunction block to execute once per bar. You could use a similar process to simulate the compute on close feature by using a flag or by checking for the instance of a new bar to check conditions that occurred on bar -1, or the bar that just closed. Let me know if this will work for you or if you have any questions.

                            test1.efs:
                            PHP Code:
                            var vFlag false;
                            var 
                            vColor null;

                            function 
                            main() {
                                if (
                            getBarState() == BARSTATE_NEWBAR) {
                                    
                            vColor null
                                    
                            vFlag false;
                                }
                                
                                if (
                            getCurrentBarIndex() == && vFlag == false) {
                                    var 
                            Buy_Mess " Buy it ";
                                    
                            vColor callFunction("FunctionLib.efs","BuyMessage",Buy_Mess);
                                    
                            vFlag true;
                                }
                                
                                if (
                            vColor != nullsetBarBgColor(vColor);

                            FunctionLib.efs
                            PHP Code:
                            function BuyMessage(Buy_Mess){
                                
                            setBarFgColor(Color.black,0);setBarFgColor(Color.black,1);
                                
                            setBarThickness(2,0);setBarThickness(2,1);
                                var 
                            vColor Color.green;
                                
                            debugPrintln(Buy_Mess);
                                
                            Alert.addToList(getSymbol(),Buy_MessColor.greenColor.black );

                                
                            /*Alert.playSound("cashreg.wav");
                                Alert.email(Buy_Mess)*/
                                
                            return vColor

                            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


                            • #15
                              Jason - thanks for the detailed reply. My "coloring" is actually working properly, and is "cut" when the BUY or SELL signal, as appropriate, is true, and the BUY and SELL functions are invoked (which then invoke their respective message handlers). Green background for buy and red for sell (as well as thicker lines for my variables %K and %D). If the signal is not present for the next bar, yes, you are right, the background color reverts to its default (white), which is what I want. If the signal is in in effect for the next bar, it will be green/red, again, as appropriate.

                              Does this change your approach at all?

                              I am monitoring several futures index contracts with this "system", and desperately need the alert to function, so I know when to take a position. This is the only part that is not functioning correctly, and as I mentioned earlier, if I disable setCompute, I am flooded with Alerts (and ditto to the Formula Output window, which I am now using as a "proxy" for the Alert List, since the debugPrint does work as documented).

                              Thanks
                              George

                              Comment

                              Working...
                              X