Announcement

Collapse
No announcement yet.

getMostRecentTrade

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

  • getMostRecentTrade

    I was testing a very simple script;

    if (getMostRecentTrade() == getMostRecentAsk()){
    drawTextPixel(200, 200, " "+getMostRecentTrade()+" ", Color.green, Color.white,Text.BOLD|Text.FRAME| Text.RELATIVETOTOP|Text.RIGHT, "Arial", 15, "Trade");
    drawTextPixel(300, 200, " "+getMostRecentTradeSize()+" ", Color.green, Color.white,Text.BOLD|Text.FRAME| Text.RELATIVETOTOP|Text.RIGHT, "Arial", 15, "TradeS");
    }
    else if (getMostRecentTrade() == getMostRecentBid()){
    drawTextPixel(200, 200, " "+getMostRecentTrade()+" ", Color.red, Color.white,Text.BOLD|Text.FRAME| Text.RELATIVETOTOP|Text.RIGHT, "Arial", 15, "Trade");
    drawTextPixel(300, 200, " "+getMostRecentTradeSize()+" ", Color.red, Color.white,Text.BOLD|Text.FRAME| Text.RELATIVETOTOP|Text.RIGHT, "Arial", 15, "TradeS");

    I tried the script on various timescales, and Tick chart seemed the best for responsiveness. The problem appears occasionally when the values are correctly rendered when compared with Time & Sales, but the color is inverted.

    For example an ASK comes through T&S and the values are correctly updated, but the colour represents a BID. I've attached an image example.

    Any ideas why this might be?
    Attached Files

  • #2
    Hello Kardinal,

    The difference you're seeing may be related to the logic of the conditional statements. I changed the conditions slightly to the following to mimic the logic of the time and sales window. After testing this code for a while today, it seems to be spot on with the time and sales window. Give this a try and let me know if you still see any problems.

    PHP Code:
    function main() {
        if (
    getMostRecentTrade() >= getMostRecentAsk()){
            
    drawTextPixel(200200" "+getMostRecentTrade()+" "Color.greenColor.white,Text.BOLD|Text.FRAMEText.RELATIVETOTOP|Text.RIGHT"Arial"15"Trade"); 
            
    drawTextPixel(300200" "+getMostRecentTradeSize()+" "Color.greenColor.white,Text.BOLD|Text.FRAMEText.RELATIVETOTOP|Text.RIGHT"Arial"15"TradeS"); 
        }
        else if (
    getMostRecentTrade() <= getMostRecentBid()){
            
    drawTextPixel(200200" "+getMostRecentTrade()+" "Color.redColor.white,Text.BOLD|Text.FRAMEText.RELATIVETOTOP|Text.RIGHT"Arial"15"Trade"); 
            
    drawTextPixel(300200" "+getMostRecentTradeSize()+" "Color.redColor.white,Text.BOLD|Text.FRAMEText.RELATIVETOTOP|Text.RIGHT"Arial"15"TradeS");     
        } else {
            
    drawTextPixel(200200" "+getMostRecentTrade()+" "Color.blackColor.white,Text.BOLD|Text.FRAMEText.RELATIVETOTOP|Text.RIGHT"Arial"15"Trade"); 
            
    drawTextPixel(300200" "+getMostRecentTradeSize()+" "Color.blackColor.white,Text.BOLD|Text.FRAMEText.RELATIVETOTOP|Text.RIGHT"Arial"15"TradeS");     
        }

        return;

    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
      So far, so good... thanks.

      Don't understand why the logic tweak of >= / <= versus == makes the difference... but I'm not going to lose sleep about it!

      Comment


      • #4
        Next challenge...

        When I reload the EFS (due to some tweaks) on a Tick chart, the winsig.exe process grabs 95% CPU for a while and eSignal locks up. Then the process finishes it calculations and eSignal comes alive again.

        I presume the reason for this is that the reloading of the EFS is being processed through all the tick data currently in the chart.

        My question is this - what is the best technique to ensure that when the EFS is loaded / reloaded, that the chart (& eSignal in general) does not try to calculate against all the old data?

        Comment


        • #5
          Kardinal
          Add the following statement at the beginning of the main function
          Alex

          PHP Code:
          if(getCurrentBarIndex()<0) return; 

          Comment


          • #6
            Thanks... I had tried that, but it didn't appear to make any noticable difference in the length of time it took to load the script. (Approximately 5 minutes running at 98% CPU).

            I am running the script on the EF#f Tick chart with Time template of 1 day.

            The intention is to build a grid of T&S calculated values.

            PHP Code:

            function preMain() {
                
            setPriceStudy(true);
                
            setCursorLabelName("Pulse");
                
            setStudyTitle("Pulse");
                
            setShowCursorLabel(false);
            }     

            function 
            main() {

            if (
            getCurrentBarIndex()<0) return;        

            if (
            getMostRecentTrade() >= getMostRecentAsk()){
                
            drawTextPixel(200200" "+getMostRecentTrade()+" "Color.greenColor.white,Text.BOLD|Text.FRAMEText.RELATIVETOTOP|Text.RIGHT"Arial"15"Trade"); 
                
            drawTextPixel(300200" "+getMostRecentTradeSize()+" "Color.greenColor.white,Text.BOLD|Text.FRAMEText.RELATIVETOTOP|Text.RIGHT"Arial"15"TradeS"); 
            }
            else if (
            getMostRecentTrade() <= getMostRecentBid()){
                
            drawTextPixel(200200" "+getMostRecentTrade()+" "Color.redColor.white,Text.BOLD|Text.FRAMEText.RELATIVETOTOP|Text.RIGHT"Arial"15"Trade"); 
                
            drawTextPixel(300200" "+getMostRecentTradeSize()+" "Color.redColor.white,Text.BOLD|Text.FRAMEText.RELATIVETOTOP|Text.RIGHT"Arial"15"TradeS"); 
            }
            else
            {
                
            drawTextPixel(200200" "+getMostRecentTrade()+" "Color.navyColor.white,Text.BOLD|Text.FRAMEText.RELATIVETOTOP|Text.RIGHT"Arial"15"Trade"); 
                
            drawTextPixel(300200" "+getMostRecentTradeSize()+" "Color.navyColor.white,Text.BOLD|Text.FRAMEText.RELATIVETOTOP|Text.RIGHT"Arial"15"TradeS"); 
            }
                return ;


            One other aside question... There is Text.RELATIVETOTOP, RELATIVETOBOTTOM, RELATIVETOLEFT... but there doesn't seem to be a RELATIVETORIGHT. I ask as I noticed that when I resize the chart, the cells defined to be x hundred units from the RelativeToLeft can either disappear or move towards the middle. What I need is the ability to fix some of the cells relative to the left of the chart, and other cells to the right of the chart. I accept that if the chart is made too small, then there is a risk of text overlap.

            Comment


            • #7
              The script didn't take very long to load this morning, so I suspect it does have something to do with amount of existing Tick data in the system.

              The other odd thing is that the Color Sync problem is back again - not as noticably as it was yesterday, but there are still odd cases of Bid & Ask quantities being represented in the wrong color.

              Comment


              • #8
                Hello Kardinal,

                Originally posted by Kardinal
                ...

                One other aside question... There is Text.RELATIVETOTOP, RELATIVETOBOTTOM, RELATIVETOLEFT... but there doesn't seem to be a RELATIVETORIGHT. I ask as I noticed that when I resize the chart, the cells defined to be x hundred units from the RelativeToLeft can either disappear or move towards the middle. What I need is the ability to fix some of the cells relative to the left of the chart, and other cells to the right of the chart. I accept that if the chart is made too small, then there is a risk of text overlap.
                There isn't a RELATIVETORIGHT flag at this time. Please feel free to submit a request for this flag to [email protected].

                Originally posted by Kardinal
                The script didn't take very long to load this morning, so I suspect it does have something to do with amount of existing Tick data in the system.
                Yes it does. Processing historical tick data is a heavy process due to the large amount of data that can be present as opposed to interval data.

                The other odd thing is that the Color Sync problem is back again - not as noticably as it was yesterday, but there are still odd cases of Bid & Ask quantities being represented in the wrong color.
                I did not see this behavior with the code example I gave you. Can you post some images? The only other thing I can think of that may be the cause of what you are seeing could be related to the refresh rate of the graphics on your machine. Another way to test your code for accuracy would be to output the data to the formula output window with the time stamp of each trade so that you can compare the data historically to the data in the time and sales window.
                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

                Working...
                X