Announcement

Collapse
No announcement yet.

Code to add prior bars volume to BidAskRatio.efs chart

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

  • Code to add prior bars volume to BidAskRatio.efs chart

    I hope I am asking these questions in the correct thread.

    My questions are what do i need to add to the code below to get my advanced charts to:



    1. Fill in volume for the days prior to the current day, and, also for the time(s) prior to the opening of the chart with the BidAskRatio.efs on it?

    To clarify, the BidAskRatio.efs below will only collect data from the time it is open and onward. It will not collect and display data from the time(s) prior to the opening of the chart.



    2. What code do I need to add to allow the efs to save to the chart? For example, if i am using a 15minute chart or a 1 minute chart, what code do I need to add to the efs so that it will save the information that has been displayed on the chart when I select save chart.



    Here is a copy of the BidAskRatio.efs code.





    /************************************************** ***************
    Provided By : eSignal (c) Copyright 2004
    Description: Bid/Ask Ratio



    Version 2.0



    Notes
    *** 2.0 - 11/26/2004 ***
    - Added Trade Volume Filter. Trade Volume less than the Filter
    number will be excluded when Srouce is set to Volume.
    - 5/27/05 - Fix for Trade Volume Filter. Wasn't properly
    reseting the total at new bar.




    Formula Parameters: Defaults:
    Analysis Cumulative
    [Bar, Cumulative]
    Study Output Ask/Bid
    [Ask/Bid, Ask/Total, Bid/Total, Ask-Bid]
    Source Volume
    [Tick, Volume]
    Trade Volume Filter 0
    Positive Color blue
    Negative Color red
    Thickness 2
    Plot Type Line
    [Line, Histogram]
    ************************************************** ***************/



    function preMain() {
    setStudyTitle("Bid\/Ask Ratio ");
    setCursorLabelName("Ask/Bid", 0);
    setDefaultBarThickness(2, 0);
    setShowTitleParameters(false);

    addBand(1, PS_SOLID, 1, Color.black, "even");

    var fp0 = new FunctionParameter("sType", FunctionParameter.STRING);
    fp0.setName("Analysis");
    fp0.addOption("Bar");
    fp0.addOption("Cumulative");
    fp0.setDefault("Cumulative");
    var fp1 = new FunctionParameter("sOutput", FunctionParameter.STRING);
    fp1.setName("Study Output");
    fp1.addOption("Ask/Bid");
    fp1.addOption("Ask/Total");
    fp1.addOption("Bid/Total");
    fp1.addOption("Ask-Bid");
    fp1.setDefault("Ask/Bid");
    var fp2 = new FunctionParameter("sSource", FunctionParameter.STRING);
    fp2.setName("Source");
    fp2.addOption("Tick");
    fp2.addOption("Volume");
    fp2.setDefault("Volume");
    var fp2a = new FunctionParameter("nFilter", FunctionParameter.NUMBER);
    fp2a.setName("Trade Volume Filter");
    fp2a.setLowerLimit(0);
    fp2a.setDefault(0);
    var fp3 = new FunctionParameter("cPos", FunctionParameter.COLOR);
    fp3.setName("Positive Color");
    fp3.setDefault(Color.blue);
    var fp4 = new FunctionParameter("cNeg", FunctionParameter.COLOR);
    fp4.setName("Negative Color");
    fp4.setDefault(Color.red);
    var fp5 = new FunctionParameter("nThickness", FunctionParameter.NUMBER);
    fp5.setName("Thickness");
    fp5.setDefault(2);
    var fp6 = new FunctionParameter("sPlotType", FunctionParameter.STRING);
    fp6.setName("Plot Type");
    fp6.addOption("Line");
    fp6.addOption("Histogram");
    fp6.setDefault("Line");
    }



    var nAsk = null;
    var nBid = null;
    var nRet = 1;
    var aReturn = new Array(1); // return array;



    // Volume
    var nBidVol = 0;
    //var nInsideVol = 0;
    var nAskVol = 0;
    var nTotalVol = 0;
    var vVol = null;
    var bPrimed = false;



    // Tick
    var nBidTick = 0;
    //var nInsideTick = 0;
    var nAskTick = 0;
    var nTotalTick = 0;



    var bEdit = true;



    function main(sType, sOutput, sSource, nFilter, cPos, cNeg, nThickness, sPlotType) {
    if (bEdit == true) {
    setStudyTitle("BidAskRatio: " + sOutput + ": " + sSource + " (" + sType + ")");
    setDefaultBarThickness(nThickness, 0);
    setCursorLabelName(sOutput, 0);
    if (sPlotType == "Histogram") setPlotType(PLOTTYPE_HISTOGRAM, 0);
    if (sOutput == "Ask-Bid") {
    addBand(0, PS_SOLID, 1, Color.black, "even");
    nRet = 0;
    }
    bEdit = false;
    }



    if (getCurrentBarIndex() < 0) return nRet;

    var nState = getBarState();



    if (sSource == "Volume") {
    if (nState == BARSTATE_NEWBAR) {
    vVol = 0;
    if (sType == "Bar" || getDay(0) != getDay(-1)) {
    nBidVol = 0;
    //nInsideVol = 0;
    nAskVol = 0;
    vVol = 0;
    nTotalVol = 0;
    aReturn[0] = 0;
    }
    }

    var vPrevVol = 0;
    if (vVol != 0 && bPrimed == true) vPrevVol = vVol;

    var nTempAsk = getMostRecentAsk();
    var nTempBid = getMostRecentBid();
    if (nTempAsk != null && nTempAsk != 0) nAsk = nTempAsk;
    if (nTempBid != null && nTempBid != 0) nBid = nTempBid;
    var vClose = close();
    vVol = volume();

    var vTradeVol = vVol - vPrevVol;
    if (vTradeVol < nFilter) return aReturn;

    if (bPrimed == false && vVol != null) {
    bPrimed = true;
    return;
    } else {
    nTotalVol += vTradeVol;
    if (vClose <= nBid) {
    nBidVol += vTradeVol;
    } else if (vClose >= nAsk) {
    nAskVol += vTradeVol;
    } /*else {
    nInsideVol += vTradeVol;
    }*/
    }
    } else if (sSource == "Tick") {
    if (nState == BARSTATE_NEWBAR) {
    if (sType == "Bar" || getDay(0) != getDay(-1)) {
    nBidTick = 0;
    //nInsideTick = 0;
    nAskTick = 0;
    nTotalTick = 0;
    aReturn[0] = 0;
    }
    }

    var nTempAsk = getMostRecentAsk();
    var nTempBid = getMostRecentBid();
    if (nTempAsk != null && nTempAsk != 0) nAsk = nTempAsk;
    if (nTempBid != null && nTempBid != 0) nBid = nTempBid;
    var vClose = close();

    nTotalTick++;
    if (vClose <= nBid) {
    nBidTick++;
    } else if (vClose >= nAsk) {
    nAskTick++;
    } /*else {
    nInsideTick++;
    }*/
    }


    // Return Data
    var nReturn = 1;
    switch (sSource) {
    case "Volume" :
    switch (sOutput) {
    case "Ask/Bid" :
    if (nBidVol == 0) nReturn = 1;
    else nReturn = (nAskVol/nBidVol);
    break;
    case "Ask/Total" :
    if (nTotalVol == 0) nReturn = 1;
    else nReturn = (nAskVol/nTotalVol);
    break;
    case "Bid/Total" :
    if (nTotalVol == 0) nReturn = 1;
    else nReturn = (nBidVol/nTotalVol);
    break;
    case "Ask-Bid" :
    nReturn = (nAskVol-nBidVol);
    break;
    default : nReturn = 1;
    }
    break;
    case "Tick" :
    switch (sOutput) {
    case "Ask/Bid" :
    if (nBidTick == 0) nReturn = 1;
    else nReturn = (nAskTick/nBidTick);
    break;
    case "Ask/Total" :
    if (nTotalTick == 0) nReturn = 1;
    else nReturn = (nAskTick/nTotalTick);
    break;
    case "Bid/Total" :
    if (nTotalTick == 0) nReturn = 1;
    else nReturn = (nBidTick/nTotalTick);
    break;
    case "Ask-Bid" :
    nReturn = (nAskTick-nBidTick);
    break;
    default : nReturn = 1;
    }
    break;
    default: nReturn = 1;
    }

    if (nReturn >= 1) setBarFgColor(cPos, 0);
    else setBarFgColor(cNeg, 0);



    aReturn[0] = nReturn;
    return nReturn;
    }



    Thank you for your help.

  • #2
    Price_9
    1) The Bid/Ask functions used in efs can retrieve those quotes only in real time so it is not possible at this time to fill in the historical data.
    2) To save the data collected in real time you need to use the File Object. There are several threads in this forum (such as for example this one) that discuss how to implement the File Object. I would also suggest that you review the 'ez-2-use' file utitlity developed by Steve Hare and described in this post
    Alex

    Comment


    • #3
      Alexis,

      What function(s) would you recommend I use to change the Bid/Ask functions to so they will collect prior data.

      I am very new at programming.

      Thanks for you help.

      Comment


      • #4
        Price_9,
        There aren't any other functions to do this because the historical Bid/Ask data is not available in EFS.
        As to being new to programming in EFS if you are interested in learning then you may want to start by reviewing the JavaScript for EFS video series and the Core JavaScript Reference Guide. Those 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

        Working...
        X