Announcement

Collapse
No announcement yet.

Midpoint EFS

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

  • Midpoint EFS

    Hi,

    I am looking for a formula that will draw a line on my advanced chart that is the midpoint from the previous day. i.e. high + low / 2 This would need to work in intraday timeframe on a 1, 3, 5, 15 min chart..

    I have no clue about EFS, actually I don’t know where to start.


    Thanks

  • #2
    Hello tgrant,

    The following code will work for you with any chart interval. I also set it up so that you can go to "Edit Studies" from the advanced chart's right-click menu and change the number of bars for your line. The default is set to one, but if you want to see the simple moving average of the line over the past 5 bars, for example, you can change nLength to 5.

    If you want to begin learning more about how to write EFS formulas, please visit our Advanced Charting Resource Center .

    Code:
    function preMain() {
        setPriceStudy(true);
        setStudyTitle(" High Low Midpoint ");
        setCursorLabelName("Midpoint ");
        setDefaultBarFgColor(Color.blue);
    }
    
    function main(nLength) {
        if (nLength == null) {
            nLength = 1;
        }
        
        var vHigh = high(-nLength, nLength);
        if (vHigh == null) {
            return;
        }
        var vLow = low(-nLength, nLength);
        if (vLow == null) {
            return;
        }
        var dSum = 0;
        for (i = 0; i < nLength; ++i) {
            dSum += ((vHigh[i] + vLow[i]) / 2);
        }
        dSum /= nLength;
        
        return dSum;
    }
    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
      Jason

      Could that code have been written using the Formula Wizard?

      Comment


      • #4
        Thanks,

        What I am looking for or trying to do is make a horizontal line that would show the midpoint from the previous day high i.e. prev day hi + prev day low / 2 and would draw a horizontal line accross the chart. Much like how the Prev high and prev low works that are included in esignal, I have attempted to use the efs from that to write this, along with what the formula you provided. Since I am not a programmer that is my main problem. I do appreciate the help.

        Comment


        • #5
          Hello tgrant,

          Here is the modification to "Prev High.efs" that will draw your midpoint line. Keep in mind it will also work like "Prev High.efs." If you are not using an intraday interval, there will not be any lines drawn.

          Code:
          function preMain() {
          	setPriceStudy(true);
          	setStudyTitle("Prev Midpoint");
          	setCursorLabelName("PMid");
          
          	setDefaultBarStyle(PS_SOLID);
          	setDefaultBarFgColor(Color.black);
          	setDefaultBarThickness(2);
              setPlotType(PLOTTYPE_FLATLINES);
          }
          
          function main() {
              var pHigh = call("getPrevOHLC.efs", "High");
              var pLow = call("getPrevOHLC.efs", "Low");	
          	var vValue = ((pHigh + pLow) / 2);
          	return vValue;
          }
          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
            Thanks Jason,

            exactly what I was looking for...

            Comment

            Working...
            X