Announcement

Collapse
No announcement yet.

Thermometer + Bid/Ask

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

  • Thermometer + Bid/Ask

    Would anyone be so kind and suggest how I can display the Bid/Ask values and change the Thermometer bar color to show the spread as indicated in the picture?

    var fpArray = new Array();
    var bInit = false;
    var vInterval = null;
    var xOpen = null;
    var xHigh = null;
    var xLow = null;
    var xClose = null;

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Thermo Bid/Ask");
    setShowCursorLabel(true);
    setPriceStudy(true);
    setColorPriceBars(true);
    setCursorLabelName("Bid:", 0);
    setCursorLabelName("Ask:", 1);
    setDefaultBarFgColor( Color.red, 0 );
    setDefaultBarFgColor( Color.green, 1 );
    //setDefaultPriceBarColor( Color.red, 0 );
    //setDefaultPriceBarColor( Color.green, 1 );
    setShowTitleParameters(false);

    var x=0;
    fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING);
    with(fpArray[x++]){
    setDefault();
    }
    fpArray[x] = new FunctionParameter("Lookback", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(0);
    setDefault(0);
    }
    fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
    with(fpArray[x++]){
    setName("Show Parameters");
    setDefault(false);
    }
    }
    var b = null;
    var b1 = null;
    var a = null;
    var a1 = null;
    var aColor = Color.grey;
    var bColor = Color.grey;
    function main(Interval,Lookback,Params) {
    b1 = b;
    a1 = a;

    b = getMostRecentBid();
    if (b == null) b = b1;
    if (b > b1) {
    bColor = Color.lime;
    } else if (b < b1) {
    bColor = Color.magenta;
    }
    b *= 10000
    b = Math.round(b);
    b /=10000;
    drawShapeRelative(7, b, Shape.CIRCLE, null, bColor, Shape.ONTOP, "bid");
    drawLineRelative(6, b, 9, b, PS_SOLID, 1, bColor, "bid line"); setDefaultBarFgColor(bColor, 0);
    drawTextRelative(4, b1, "B", bColor, null, Text.BOLD | null | Text.VCENTER | Text.ONTOP, null, 8, "bid text");

    a = getMostRecentAsk();
    if (a == null) a = a1;
    if (a > a1) {
    aColor = Color.lime;
    } else if (a < a1) {
    aColor = Color.magenta;
    }
    a *= 10000
    a = Math.round(a);
    a /=10000;
    drawShapeRelative(7, a, Shape.CIRCLE, null, aColor, Shape.ONTOP, "ask");
    drawLineRelative(6, a, 9, a, PS_SOLID, 1, aColor, "ask line"); setDefaultBarFgColor(aColor, 1);
    drawTextRelative(4, a1, "A", aColor, null, Text.BOLD | null | Text.VCENTER | Text.ONTOP, null, 8, "ask text");

    if(bInit == false){
    if(isIntraday() && Interval == null) Interval = "D";
    else if(isDaily() && Interval == null) Interval = "W";
    else if(isWeekly() && Interval == null) Interval = "M";
    else if(Interval == null) Interval = getInterval();
    vInterval = Interval;
    xOpen = open(inv(vInterval));
    xHigh = high(inv(vInterval));
    xLow = low(inv(vInterval));
    xClose = close(inv(vInterval));
    setShowTitleParameters(eval(Params));
    bInit = true;
    }

    drawLineRelative(7,xClose.getValue(-Lookback),7,xHigh.getValue(-Lookback),PS_SOLID,3,Color.red,2);
    drawLineRelative(7,xClose.getValue(-Lookback),7,xLow.getValue(-Lookback),PS_SOLID,3,Color.green,3);
    drawShapeRelative(7,b1, Shape.DIAMOND, null, Color.yellow, null, 4);
    drawShapeRelative(7,a1, Shape.DIAMOND, null, Color.yellow, null, 5);
    return new Array (""+a, ""+b);

    }
    Attached Files
    --FOREX--

  • #2
    RuGO
    To do what you want to accomplish change the corresponding sections of code as shown in the screenshots enclosed below.
    The result of these changes can be seen in the enclosed screenshot of a chart
    Alex







    Comment


    • #3
      Alexis, many thanks for the prompt response and for your help!

      One issue which I failed to clarify is my challenge in determining how to return the Ask/Bid values in the price pane to the right (see image). If I use "return new Array (a, b)" this will plot lines accross the chart, but will also show the values in the price pane (however not in the proper color scheme). Using the "return new Array (""+a, ""+b)" will show the proper color and values in the cursor window, but will not show up in the price pane.

      Seems like an easy fix, but just cannot think of it...

      A great many thanks once again, as I don't think we can express enough gratitude for all the miracles you make happen in this forum!
      Attached Files
      --FOREX--

      Comment


      • #4
        RuGO
        You are most welcome and thank you for the kind words.
        What you are trying to do is not possible. An efs will display the value in the price scale only when it is returning a number. When you use return new Array (""+a,""+b) you are returning strings which the efs engine does not plot or display in the price scale
        Alex

        Comment


        • #5
          Alexis
          I copy and pasted the efs below into the editor and made the changes you suggested including adding line 95. It returned this Reference Error.
          Could you please tell on how to fix this error.

          Downloads\Bid-Ask Thermometer.efs, line 95: Reference Error: PS_Solid is not defined

          Thanks for your help,
          David

          Comment


          • #6
            David
            The error is due to the fact that PS_Solid is not a valid Pen Style. It should be PS_SOLID as shown in the example.
            JavaScript is a case sensitive language
            Alex

            Comment

            Working...
            X