Announcement

Collapse
No announcement yet.

Cursor Values w/out drawing lines on Price Chart

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cursor Values w/out drawing lines on Price Chart

    I have the following EFS that draws an orange line at the mid-point of every candle on the price chart. I want the value of the midpoint also reported back to the cursor window, so it shows when I put the mouse over the bar (hence the last line is "return (MidPoint)". However, when I do this to get the MidPoint reported back into the Cursor Window, the EFS also draws a blue line connecting the midpoints of each candle. How do I get the EFS to NOT draw that blue connecting line, while still getting my orange MidPoint lines on the chart AND getting the MidPoint value reported back into the cursor window?

    =====================================

    var MidPoint = 0;

    function preMain() {
    setComputeOnClose(true);
    setPriceStudy(true);
    setStudyTitle("MidPoint");
    setCursorLabelName("MidPoint");
    }


    //=========================================
    function main () {

    MidPoint = 0.5*(high() + low()); // Average of High and Low

    drawLineRelative(7, MidPoint, 0, MidPoint, PS_SOLID, 1, Color.RGB(255,155,0), "MPB"+getCurrentBarCount());

    return (MidPoint);
    }

  • #2
    Hi f1sh7,

    To accomplish this, convert the value in the return statement to a string. I marked up your efs with two ways to accomplish this, along with making some other small changes.

    PHP Code:
    //=====================================

    var MidPoint 0;

    function 
    preMain() {
    setComputeOnClose(true); 
    setPriceStudy(true);
    setStudyTitle("MidPoint");
    setCursorLabelName("MidPoint",0);
    setDefaultBarFgColor(Color.RGB(255,155,0), 0);
    }


    //=========================================
    function main () {

    MidPoint 0.5*(high(0) + low(0)); // Average of High and Low

    drawLineRelative(7MidPoint0MidPointPS_SOLID1Color.RGB(255,155,0), "MPB"+getCurrentBarCount());

    //return (MidPoint); // need to convert to text
    //return (MidPoint.toFixed(3));  //method 1
    return (""+MidPoint);  //method 2


    Comment


    • #3
      Thank you

      That is perfect....

      THANK YOU!

      JOHN

      Comment


      • #4
        Want to alert if previous middle is crossed

        I want to be alerted (intrabar) if the current price crosses the previous candle's midpoint.

        How do I do that?

        Thanking You in Advance...

        Avery aka *************

        ************* at gmail dot com

        P.S. I am a little rusty at eSignal coding... been coding on TradeStation



        //=====================================

        var MidPoint = 0;

        function preMain() {
        //setComputeOnClose(true);
        setPriceStudy(true);
        setStudyTitle("MidPoint");
        setCursorLabelName("MidPoint",0);
        setDefaultBarFgColor(Color.blue, 0);
        }


        //=========================================
        function main () {

        MidPoint = 0.5*(high(0) + low(0)); // Average of High and Low

        if( MidPoint == close(0) ) {
        Alert.addToList(getSymbol(), MidPoint +" MidPoint", Color.black, Color.blue);
        Alert.playSound("swoosh.wav");
        }

        drawLineRelative( 0 , MidPoint, 1 , MidPoint, PS_SOLID, 1, Color.blue, "MPB"+getCurrentBarCount());

        //return (MidPoint); // need to convert to text
        //return (MidPoint.toFixed(3)); //method 1
        return (""+MidPoint); //method 2

        }

        Comment


        • #5
          buzzhorton
          In order to calculate the previous bar's midpoint you need to change this
          PHP Code:
          MidPoint 0.5*(high(0) + low(0)); 
          to the following
          PHP Code:
          MidPoint 0.5*(high(-1) + low(-1)); 
          Then to create an alert you need to first declare an external variable that you use to prevent the alerts from going off continuously once an event is triggered. For example
          PHP Code:
          var AlertTriggered false
          Then at the beginning of function main() you need to add the logic to reset that variable to false at every new bar.
          PHP Code:
          if(getBarState() == BARSTATE_NEWBAR){
              
          AlertTriggered false;

          At this point you can add the logic to trigger your alert
          PHP Code:
          if(AlertTriggered == false){
              if(
          high(-1) < Midpoint && close(0) >= Midpoint || low(-1) > Midpoint && close(0) <= Midpoint){
                  
          Alert.playSound("ding.wav");
                  
          AlertTriggered true;
              }
          }
          //replace high(-1) and low(-1) with other price value as required 
          For a complete example of how to create an alert at a specific price see this thread and for an example of how to limit the alert to only once per bar see this thread
          Also if you are not familiar with programming in efs I would suggest that you review the JavaScript for EFS video series. That will provide you with a thorough introduction to programming in JavaScript which is at the foundation of EFS. Then go through the EFS KnowledgeBase and study the Help Guides and Tutorials which will provide you with the specifics of EFS.
          Alex

          Comment


          • #6
            Thank you.

            I think I figured it out...


            PHP Code:

            function preMain() {


                
            setStudyTitle("TRO_60MIN_MIDDLE_FX ");
                
            setPriceStudy(true);
                
            setCursorLabelName("High"0);


                
            setCursorLabelName("Mid"1);

                
            setCursorLabelName("Low"2);

                
            setCursorLabelName("PrevMid"3);

                
            setDefaultBarFgColor(Color.red0);

                
            setDefaultBarFgColor(Color.cyan1);
                
            setDefaultBarFgColor(Color.blue2);

                
            setDefaultBarFgColor(Color.magenta3);
            }

            function 
            main(nNumDays) {

                if (
            nNumDays == null)
                    
            nNumDays 1;
               


            var 
            xHH high(inv("60") ); //this creates the series object of the daily high

            var xLL  low(inv("60") ); //this creates the series object of the daily low

            var  HH  xHH.toFixed(4)*//this creates the series object of the daily high

            var  LL  xLL.toFixed(4)*//this creates the series object of the daily low

            var xMidPoint 0.5*( HH LL  )  ; // Average of High and Low

            Mid xMidPoint.toFixed(4)*1   // Average of High and Low
                    
             
             
            var xPrevMid 0.5*( xHH.getValue(-1) + xLL.getValue(-1) )  ; // Average of High and Low

            PrevMid xPrevMid.toFixed(4)*1   // Average of High and Low

              

                
            if( PrevMid == close(0) ) {
                    
            Alert.addToList(getSymbol(), PrevMid +" PrevMid"Color.blackColor.magenta);
                    
            Alert.playSound("chime.wav");
                    }

                  
                if( 
            Mid == close(0) ) {
                    
            Alert.addToList(getSymbol(), Mid +" Mid"Color.blackColor.cyan);
                    
            Alert.playSound("swoosh.wav");
                    } 
                
             

            drawLineRelativeMidMidPS_SOLID1Color.cyan"Mid"+getCurrentBarCount());

            drawLineRelativeHHHHPS_SOLID1Color.blue"HH"+getCurrentBarCount());

            drawLineRelativeLLLLPS_SOLID1Color.red"LL"+getCurrentBarCount());

            drawLineRelativePrevMidPrevMidPS_SOLID1Color.magenta"PM"+getCurrentBarCount());



            /*
            debugPrintln("Hi "+HH);//this will print the current value of the series

            debugPrintln("Lo "+LL);//this will print the current value of the series

            debugPrintln("Mid "+Mid);//this will print the current value 
            */


            return  new Array(  ""+HH,""+Mid""+LL""+PrevMid ) ;


            That's a version for FOREX.

            Is there anyway to make studies PARAMETER driven instead of having to edit them? Remember, I have been coding in TradeStation EasyLanguage for the past 3 years or so. I am used to creating "soft coded" indicators that are parameter driven.

            In this case, I would want an input variable, iDecimals, so the user could determine how many decimals the study should round to.

            Also, I would want an input variable, iAlert, that could be set to true or false, so the user can turn off the alerts if they so desire.

            Finally, I would want an input variable, iInterval, or auto detection by the study, so the user could specify which interval to use to determine the current and previous middle.

            By the way, since this is using 60 minute bars, I do NOT want the alert to turn off. I want to know each occurence.

            Thanks again for your help.

            P.S. Trading in the direction of the price crossing the previous candle's middle is VERY PROFITABLE. The current middle is used as an exit when the price reverses if you haven't already taken your profit of off the table.

            Daytraders can use the 60 minute interval. Swing Traders use the daily.


            Last edited by buzzhorton; 07-21-2006, 11:47 AM.

            Comment


            • #7
              buzzhorton
              Use the Function Parameter Object to set up all your parameters.
              As to the decimals rather than using .toFixed() which locks you to a specific number of decimals use the formatPriceNumber() function which will adapt the display to the format of the security being charted
              You can use the function getInterval() to retrieve the interval being charted and based on that assign a value to your variable eg
              if(getInterval()==5) myInterval = 60;
              There are also some other functions available such as isIntraday(), isDaily(), etc. I would suggest that you read through the Function Reference in the EFS KnowledgeBase
              Alex

              Comment


              • #8
                Thanks again, Alex.

                One step at a time.

                First, I got formatPriceNumber to work:

                var LL = formatPriceNumber(xLL)*1 ;

                Next, I used:

                var xInterval = getInterval() ;

                Looks like it will take some work to get the parameter code installed.

                I really appreciate your help, Alex.


                PHP Code:




                function preMain() {




                    
                setStudyTitle("$_Scratch ");
                    
                setPriceStudy(true);
                    
                setCursorLabelName("High"0);


                    
                setCursorLabelName("Mid"1);

                    
                setCursorLabelName("Low"2);

                    
                setCursorLabelName("PrevMid"3);

                    
                setDefaultBarFgColor(Color.red0);

                    
                setDefaultBarFgColor(Color.cyan1);
                    
                setDefaultBarFgColor(Color.blue2);

                    
                setDefaultBarFgColor(Color.magenta3);
                }

                function 
                main(nNumDays) {

                    if (
                nNumDays == null)
                        
                nNumDays 1;


                var 
                xInterval getInterval()    ;

                var 
                xHH high(inv(xInterval) ); //this creates the series object of the daily high

                var xLL  low(inv(xInterval) ); //this creates the series object of the daily low

                var  HH  formatPriceNumber(xHH)*//this creates the series object of the daily high

                var  LL  formatPriceNumber(xLL)*//this creates the series object of the daily low

                var xMidPoint 0.5*( HH LL  )  ; // Average of High and Low

                Mid formatPriceNumberxMidPoint) *1   // Average of High and Low
                        
                 
                 
                var xPrevMid 0.5*( xHH.getValue(-1) + xLL.getValue(-1) )  ; // Average of High and Low

                PrevMid formatPriceNumberxPrevMid )*1   // Average of High and Low
                    

                    
                if( PrevMid == close(0) ) {
                        
                Alert.addToList(getSymbol(), PrevMid +" PrevMid"Color.blackColor.magenta);
                        
                Alert.playSound("chime.wav");
                        }

                      
                    if( 
                Mid == close(0) ) {
                        
                Alert.addToList(getSymbol(), Mid +" Mid"Color.blackColor.cyan);
                        
                Alert.playSound("swoosh.wav");
                        } 
                    
                drawLineRelativeMidMidPS_SOLID1Color.cyan"Mid"+getCurrentBarCount());

                drawLineRelativeHHHHPS_SOLID1Color.blue"HH"+getCurrentBarCount());

                drawLineRelativeLLLLPS_SOLID1Color.red"LL"+getCurrentBarCount());

                drawLineRelativePrevMidPrevMidPS_SOLID1Color.magenta"PM"+getCurrentBarCount());



                /*

                debugPrintln("Hi "+HH);//this will print the current value of the series

                debugPrintln("Lo "+LL);//this will print the current value of the series

                debugPrintln("Mid "+Mid);//this will print the current value 

                */

                return  new Array(  ""+HH,""+Mid""+LL""+PrevMid ) ;


                Last edited by buzzhorton; 07-21-2006, 12:41 PM.

                Comment


                • #9
                  I modified PrevDay-OHLC to include the previous day's middle and to alert when the any of the lines are crossed.

                  When prompted, set iAlert to false to turn sound off.

                  MAY ALL YOUR FILLS BE COMPLETE.



                  PHP Code:

                  /**************************************************
                  Alexis C. Montenegro © April 2004                         
                  Use and or modify this code freely. If you redistribute it
                  please include this and or any other comment blocks and a 
                  description of any changes you make. 
                  ***************************************************/

                  debugClear(); 

                  function 
                  preMain() {

                      
                  setPriceStudy(true);
                      
                  setStudyTitle("TRO_PrevDay-OHLC");
                      
                  setCursorLabelName("POpen"0);
                      
                  setCursorLabelName("PHigh"1);
                      
                  setCursorLabelName("PLow"2);
                      
                  setCursorLabelName("PClose"3);
                      
                  setCursorLabelName("PMiddle"4);


                      
                  setDefaultBarFgColor(Color.red,0);
                      
                  setDefaultBarFgColor(Color.black,1);
                      
                  setDefaultBarFgColor(Color.black,2);
                      
                  setDefaultBarFgColor(Color.blue,3);
                      
                  setDefaultBarFgColor(Color.magenta,4);

                      
                  setDefaultBarThickness(2,0);
                      
                  setDefaultBarThickness(3,1);
                      
                  setDefaultBarThickness(3,2);
                      
                  setDefaultBarThickness(2,3);
                      
                  setDefaultBarThickness(3,4);

                      
                  setPlotType(PLOTTYPE_FLATLINES,0); // PLOTTYPE_FLATLINES
                      
                  setPlotType(PLOTTYPE_FLATLINES,1);
                      
                  setPlotType(PLOTTYPE_FLATLINES,2);
                      
                  setPlotType(PLOTTYPE_FLATLINES,3);
                      
                  setPlotType(PLOTTYPE_FLATLINES,4);

                      
                  checkVersion(1,"http://share.esignal.com/ContentRoot/ACM%20Test/Formulas/PrevDay-OHLC.efs");

                  }

                  var 
                  vOpen null;
                  var 
                  vOpen1 null;
                  var 
                  vHigh null;
                  var 
                  vHigh1 null;
                  var 
                  vLow null;
                  var 
                  vLow1 null;
                  var 
                  vClose1 null;

                  var 
                  vMid null;
                  var 
                  vMid1 null;


                   
                  askForInput();


                      var 
                  iAlert = new FunctionParameter("iAlert"FunctionParameter.BOOLEAN);
                      
                  iAlert.setDefaulttrue );


                  function 
                  main(iAlert) {

                      if (
                  close(-1)==null
                          return;
                      
                      if(
                  getBarState()==BARSTATE_NEWBAR&&getDay()!=getDay(-1)) {
                          
                  vHigh1 vHigh;
                          
                  vLow1 vLow;
                          
                  vOpen1 vOpen;
                          
                  vClose1 formatPriceNumberclose(-1) ) * ;//comment out this line if using alternate vClose1 
                          
                  vMid1 formatPriceNumbervMid ) * ;
                          
                  vHigh high();
                          
                  vLow low();
                          
                  vOpen=open();

                      }
                      
                      if (
                  vHigh == null
                          
                  vHigh high();
                      if (
                  vLow == null
                          
                  vLow low();
                      
                      
                  vHigh Math.max(high(), vHigh);
                      
                  vLow Math.min(low(), vLow);
                      
                  vMid =   ( vHigh vLow ) * .50  ;  


                      
                  //alternate vClose1 if one wants to use the daily bar Close. NOTE that this will not work with Tick Replay
                      //vClose1 = call("/OHLC/getPrevOHLC.efs", "Close");    
                      
                      
                      
                  if (vOpen1 == null || vLow1 == null || vHigh1 == null || vClose1 == null) {
                          return;
                      } else {

                  // PREVIOUS MIDDLE ALERT 

                      
                  if(  ( high(-1) < vMid1 || low(0) < vMid1 )        && close(0) >= vMid1 ){
                      
                  Alert.addToList(getSymbol(), vMid1 +" Cross above PrevMiddle"Color.greenColor.black);
                        if( 
                  iAlert == true Alert.playSound("ding.wav");

                        
                  debugPrint("Cross above PrevMiddle: " formatPriceNumbervMid1 ) + " " +  getValue"Time" ) + "\n" ); 
                       }
                   
                      if( ( 
                  low(-1) > vMid1 || high(0) > vMid1   )          && close(0) <= vMid1 ){
                      
                  Alert.addToList(getSymbol(), vMid1 +" Cross below PrevMiddle"Color.redColor.black);
                          if( 
                  iAlert == true Alert.playSound("ding.wav");

                        
                  debugPrint("Cross below PrevMiddle: " formatPriceNumbervMid1 ) + " " +  getValue"Time" ) + "\n" );  
                       }


                  // PREVIOUS High ALERT 

                      
                  if(  ( high(-1) < vHigh1 || low(0) < vHigh1 )        && close(0) >= vHigh1 ){
                      
                  Alert.addToList(getSymbol(), vHigh1 +" Cross above PrevHigh"Color.greenColor.black);
                        if( 
                  iAlert == true Alert.playSound("ding.wav");

                        
                  debugPrint("Cross above PrevHigh: " formatPriceNumbervHigh1 ) + " " +  getValue"Time" ) + "\n" ); 
                       }
                   
                      if( ( 
                  low(-1) > vHigh1 || high(0) > vHigh1   )          && close(0) <= vHigh1 ){
                      
                  Alert.addToList(getSymbol(), vHigh1 +" Cross below PrevHigh"Color.redColor.black);
                          if( 
                  iAlert == true Alert.playSound("ding.wav");

                        
                  debugPrint("Cross below PrevHigh: " formatPriceNumbervHigh1 ) + " " +  getValue"Time" ) + "\n" );  
                       }

                  // PREVIOUS Low ALERT 

                      
                  if(  ( high(-1) < vLow1 || low(0) < vLow1 )        && close(0) >= vLow1 ){
                      
                  Alert.addToList(getSymbol(), vLow1 +" Cross above PrevLow"Color.greenColor.black);
                        if( 
                  iAlert == true Alert.playSound("ding.wav");

                        
                  debugPrint("Cross above PrevLow: " formatPriceNumbervLow1 ) + " " +  getValue"Time" ) + "\n" ); 
                       }
                   
                      if( ( 
                  low(-1) > vLow1 || high(0) > vLow1   )          && close(0) <= vLow1 ){
                      
                  Alert.addToList(getSymbol(), vLow1 +" Cross below PrevLow"Color.redColor.black);
                          if( 
                  iAlert == true Alert.playSound("ding.wav");

                        
                  debugPrint("Cross below PrevLow: " formatPriceNumbervLow1 ) + " " +  getValue"Time" ) + "\n" );  
                       }

                  // PREVIOUS Close ALERT 

                      
                  if(  ( high(-1) < vClose1 || low(0) < vClose1 )        && close(0) >= vClose1 ){
                      
                  Alert.addToList(getSymbol(), vClose1 +" Cross above PrevClose"Color.greenColor.black);
                        if( 
                  iAlert == true Alert.playSound("ding.wav");

                        
                  debugPrint("Cross above PrevClose: " formatPriceNumbervClose1 ) + " " +  getValue"Time" ) + "\n" ); 
                       }
                   
                      if( ( 
                  low(-1) > vClose1 || high(0) > vClose1   )          && close(0) <= vClose1 ){
                      
                  Alert.addToList(getSymbol(), vClose1 +" Cross below PrevClose"Color.redColor.black);
                          if( 
                  iAlert == true Alert.playSound("ding.wav");

                        
                  debugPrint("Cross below PrevClose: " formatPriceNumbervClose1 ) + " " +  getValue"Time" ) + "\n" );  
                       }



                  // PREVIOUS Open ALERT 

                      
                  if(  ( high(-1) < vOpen1 || low(0) < vOpen1 )        && close(0) >= vOpen1 ){
                      
                  Alert.addToList(getSymbol(), vOpen1 +" Cross above PrevOpen"Color.greenColor.black);
                        if( 
                  iAlert == true Alert.playSound("ding.wav");

                        
                  debugPrint("Cross above PrevOpen: " formatPriceNumbervOpen1 ) + " " +  getValue"Time" ) + "\n" ); 
                       }
                   
                      if( ( 
                  low(-1) > vOpen1 || high(0) > vOpen1   )          && close(0) <= vOpen1 ){
                      
                  Alert.addToList(getSymbol(), vOpen1 +" Cross below PrevOpen"Color.redColor.black);
                          if( 
                  iAlert == true Alert.playSound("ding.wav");

                        
                  debugPrint("Cross below PrevOpen: " formatPriceNumbervOpen1 ) + " " +  getValue"Time" ) + "\n" );  
                       }


                   if ( 
                  isLastBarOnChart() == true ) { 
                        
                  //clear the Formula Output Window 
                   
                        //print a line of text to that window 
                        
                  debugPrint"The previous day's midpoint is: " formatPriceNumbervMid1 ) + "\n" ); 
                     } 


                          return new Array(
                  vOpen1,vHigh1,vLow1,vClose1,vMid1);
                      }

                  Last edited by buzzhorton; 07-23-2006, 01:09 PM.

                  Comment

                  Working...
                  X