Announcement

Collapse
No announcement yet.

Question on how to stop updating during Regular Trading Hour for trades plot

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

  • Question on how to stop updating during Regular Trading Hour for trades plot

    Hi,

    I have an efs to plot trades on the charts.
    I apply this study on a ES 2min charts with RTH time template ( 9:30am - 16:15pm )

    If I view the plot outside RTH it work fine. But during RTH it shift the line everytime a new 2 min bar close.

    What do I need to add/change to the code to stop shifting the line.

    Thank you

    Tony

    PHP Code:
    /*

    Tony Hariman  August 2nd 2009

    The goal for this program is to load csv file from my trading platform and plot the entry exit on the charts.

    This is what the csv file look like:
    "Entry Time","Exit Time","Symbol","Side","Quantity","Entry Price","Exit Price","P/L","Gross Profit","Net Profit","Time in Trade","MAE","MFE","Strategy","Live/Simulation","Trade #"
    "7/28/2009 9:49:58 AM","7/28/2009 9:53:10 AM","ES","Long",1,978.25,977,-1.25,-62.5,-67.3,"03:11",-1,.25,"Default Strategy","Live",1
    "7/28/2009 10:03:29 AM","7/28/2009 10:16:06 AM","ES","Short",1,974.5,970.5,4,200,195.2,"12:37",-1,3.75,"Default Strategy","Live",2
    "7/28/2009 10:37:55 AM","7/28/2009 10:39:30 AM","ES","Short",1,971.5,972.5,-1,-50,-54.8,"01:35",-1,0,"Default Strategy","Live",3

    So far I'm concentrating on plotting the trade in the charts

    I use perl to convert the csv file to GoLong and GoShort and copy paste to this efs
    This perl will also round down to the nearest 2 min bar chart for the entry and exit time.

    I get the logic for this efs from one of the users in the forum.

    */

    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Trades Plot");
    }


    var 
    Index null;
    var 
    BeginIndex null;
    var 
    cntr 0;
    var 
    cntr2 0;
    var 
    vDay null;
    var 
    vMonth null;

    function 
    main() {
     
        var 
    vTime = new Date();
        
    vTime getValue("Time"0);
        
    vDay vTime.getDate();
        
    vMonth vTime.getMonth() + 1;

        
    Index getCurrentBarIndex();

        
    BarHr getHour();
        
    BarMin getMinute();
        
    BarSec getSecond();
        
    CurrentTime BarHr 10000 BarMin 100 BarSec 1;

        
    GoLong(7239540095600956.00957.00); // 95537 95609 1
        
    GoLong(723110000110200968.50969.50); // 110121 110342 1
        
    GoLong(723111000111400970.50972.00); // 111113 111419 1.5
        
    GoShort(727101200101400974.50972.25); // 101204 101429 2.25
        
    GoShort(727103000104800971.25970.25); // 103002 104832 1
        
    GoLong(727110000111000971.25971.75); // 110111 111102 .5
        
    GoShort(728100200101600974.50970.50); // 100329 101606 4
        
    GoShort(7299500095600969.75969.00); // 95147 95609 .75
        
    GoLong(7309520095400984.25987.25); // 95204 95512 3
        
    GoLong(730103800103800993.00993.50); // 103800 103815 .5
     
        
    return null;
    }

    function 
    GoLong(LongMonthLongDayLongEntryTimeLongExitTimeLongEntryPriceLongExitPrice) {
        if (
    vMonth == LongMonth && vDay == LongDay) {

            if (
    CurrentTime == LongEntryTime) {
                
    BeginIndex Index;
                
    cntr2 += 1;
                
    drawShapeAbsolute(Index 1LongEntryPriceShape.RIGHTARROWnullColor.blueShape.LEFT Shape.ONTOPcntr2);
            }
            if (
    CurrentTime == LongExitTime) {
                
    cntr += 1;
                if (
    LongEntryTime == LongExitTime) {  // draw line if trade happen in the same bar
                    //drawShapeAbsolute( Index-1 , LongEntryPrice, Shape.RIGHTARROW, null, Color.yellow, Shape.LEFT | Shape.ONTOP, null );
                    
    drawLineAbsolute(BeginIndex 1LongEntryPriceIndex 1LongEntryPricePS_SOLID2Color.black"Line" cntr);
                    
    cntr += 1;
                    
    drawLineAbsolute(BeginIndex 1LongExitPriceIndex 1LongExitPricePS_SOLID2Color.black"Line" cntr);
                } else {
                    
    drawLineAbsolute(BeginIndexLongEntryPriceIndexLongExitPricePS_SOLID2Color.blue"Line" cntr);
                }
                
    cntr2 += 1;
                
    drawShapeAbsolute(Index 1LongExitPriceShape.LEFTARROWnullColor.blueShape.LEFT Shape.ONTOPcntr2);
            }

        }
        return 
    null;
    }

    function 
    GoShort(ShortMonthShortDayShortEntryTimeShortExitTimeShortEntryPriceShortExitPrice) {
        if (
    vMonth == ShortMonth && vDay == ShortDay) {

            
    //debugPrintln( "  CurrentTime:" + CurrentTime + " Entry:" + ShortEntryTime + " Exit:" + ShortExitTime);
            
    if (CurrentTime == ShortEntryTime) {
                
    BeginIndex Index;
                
    cntr2 += 1;
                
    drawShapeAbsolute(Index 1ShortEntryPriceShape.RIGHTARROWnullColor.yellowShape.LEFT Shape.ONTOPcntr2);
            }
            if (
    CurrentTime == ShortExitTime) {
                
    cntr += 1;

                if (
    ShortEntryTime == ShortExitTime) { // draw line if trade happen in the same bar
                    //drawShapeAbsolute( Index-1 , ShortEntryPrice, Shape.RIGHTARROW, null, Color.yellow, Shape.LEFT | Shape.ONTOP, null );
                    
    drawLineAbsolute(BeginIndex 1ShortEntryPriceIndex 1ShortEntryPricePS_SOLID2Color.black"Line" cntr);
                    
    cntr += 1;
                    
    drawLineAbsolute(BeginIndex 1ShortExitPriceIndex 1ShortExitPricePS_SOLID2Color.black"Line" cntr);
                } else {
                    
    drawLineAbsolute(BeginIndexShortEntryPriceIndexShortExitPricePS_SOLID2Color.yellow"Line" cntr);
                }
                
    cntr2 += 1;
                
    drawShapeAbsolute(Index 1ShortExitPriceShape.LEFTARROWnullColor.yellowShape.LEFT Shape.ONTOPcntr2);
            }

        }
        return 
    null;


  • #2
    Try changing your Draw functions to DrawLineRelative or DrawShapeRelative functions.

    I'm not sure if the problem is within your code or something related to the new esignal release. There have been reports of "shifting graphics" with the RTS indicator. So maybe this is something internal.

    My advice would be to change the ABSOLUTE to RELATIVE functions and see if this helps.
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Originally posted by Doji3333
      Try changing your Draw functions to DrawLineRelative or DrawShapeRelative functions.

      I'm not sure if the problem is within your code or something related to the new esignal release. There have been reports of "shifting graphics" with the RTS indicator. So maybe this is something internal.

      My advice would be to change the ABSOLUTE to RELATIVE functions and see if this helps.
      Thank you for you help. I think it is more of logic that need to be change. I tried the Relative but with that it look like that I also need to change the logic.

      Tony

      Comment


      • #4
        You might choose to enclose your main code functions within a statement that determines if the current BAR TIME is within the times you want being drawn.

        You already have the following variables in your code.

        BarHr = getHour();
        BarMin = getMinute();

        Using these, you can easily create a time value I like to use for simple time functions - like this..

        var nBarTime = (BarHr*100)+BarMin;

        This will return values like 800, 1115, 1315 based on the current bar on the chart.

        Using this new "nBarTime" variable, you can create a simple routine to check if code function is allowed or not... like this...

        var Allowed2Operate = ((nBarTime >= 630) && (nBarTime <= 1315));

        This will check to see if the current bar time is between 6:30AM and 13:15PM. If so, then it will return TRUE.

        So all you have to do is then use this "conditional" value in the MAIN portion of your code... like this...

        if (Allowed2Operate) {
        // do whatever in here
        }

        Hope this helps.
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment


        • #5
          Originally posted by Doji3333
          You might choose to enclose your main code functions within a statement that determines if the current BAR TIME is within the times you want being drawn.

          You already have the following variables in your code.

          BarHr = getHour();
          BarMin = getMinute();

          Using these, you can easily create a time value I like to use for simple time functions - like this..

          var nBarTime = (BarHr*100)+BarMin;

          This will return values like 800, 1115, 1315 based on the current bar on the chart.

          Using this new "nBarTime" variable, you can create a simple routine to check if code function is allowed or not... like this...

          var Allowed2Operate = ((nBarTime >= 630) && (nBarTime <= 1315));

          This will check to see if the current bar time is between 6:30AM and 13:15PM. If so, then it will return TRUE.

          So all you have to do is then use this "conditional" value in the MAIN portion of your code... like this...

          if (Allowed2Operate) {
          // do whatever in here
          }

          Hope this helps.
          Probably the idea is ok. Maybe I need to do the same logic but more on day, month not time.
          Since with time it will still keep updating the line if I'm looking at it during market hours. Which will be within the time range.

          Thank you going to give it a try.

          Comment


          • #6
            Tony
            You would need to make changes in the logic regardless of whether you use the drawXxxAbsolute() or drawXxxRelative() functions.
            Using the drawXxxRelative() is probably simpler to implement but it can be done just the same using the drawXxxAbsolute() functions
            Enclosed below is my revision of your script which should be working correctly ie the graphic objects should not shift as new bars are being added in real time [and without the need to prevent the script from running within the RTH session]. Comments indicate which lines of code I modified
            Alex


            PHP Code:
            function preMain() {
                
            setPriceStudy(true);
                
            setStudyTitle("Trades Plot");
            }


            var 
            Index null;
            var 
            BeginIndex null;
            var 
            cntr 0;
            var 
            cntr2 0;
            var 
            vDay null;
            var 
            vMonth null;

            function 
            main() {
             
                var 
            vTime = new Date();
                
            vTime getValue("Time"0);
                
            vDay vTime.getDate();
                
            vMonth vTime.getMonth() + 1;

                
            Index getCurrentBarCount();//modified by ACM

                
            BarHr getHour();
                
            BarMin getMinute();
                
            BarSec getSecond();
                
            CurrentTime BarHr 10000 BarMin 100 BarSec 1;

                
            GoLong(7239540095600956.00957.00); // 95537 95609 1
                
            GoLong(723110000110200968.50969.50); // 110121 110342 1
                
            GoLong(723111000111400970.50972.00); // 111113 111419 1.5
                
            GoShort(727101200101400974.50972.25); // 101204 101429 2.25
                
            GoShort(727103000104800971.25970.25); // 103002 104832 1
                
            GoLong(727110000111000971.25971.75); // 110111 111102 .5
                
            GoShort(728100200101600974.50970.50); // 100329 101606 4
                
            GoShort(7299500095600969.75969.00); // 95147 95609 .75
                
            GoLong(7309520095400984.25987.25); // 95204 95512 3
                
            GoLong(730103800103800993.00993.50); // 103800 103815 .5
             
                
            return null;
            }

            function 
            GoLong(LongMonthLongDayLongEntryTimeLongExitTimeLongEntryPriceLongExitPrice) {
                if (
            vMonth == LongMonth && vDay == LongDay) {

                    if (
            CurrentTime == LongEntryTime) {
                        
            BeginIndex Index;
                        
            cntr2 += 1;
                        
            drawShapeRelative(-1LongEntryPriceShape.RIGHTARROWnullColor.blueShape.LEFT Shape.ONTOP"ShapeA"+cntr2);//modified by ACM
                    
            }
                    if (
            CurrentTime == LongExitTime) {
                        
            cntr += 1;
                        if (
            LongEntryTime == LongExitTime) {  // draw line if trade happen in the same bar
                            
            drawLineRelative(-1LongEntryPrice1LongEntryPricePS_SOLID2Color.black"LineA" cntr);//modified by ACM
                            
            cntr += 1;
                            
            drawLineRelative(-1LongExitPrice1LongExitPricePS_SOLID2Color.black"LineB" cntr);//modified by ACM
                        
            } else {
                            
            drawLineRelative(BeginIndex-IndexLongEntryPrice0LongExitPricePS_SOLID2Color.blue"LineC" cntr);//modified by ACM
                        
            }
                        
            cntr2 += 1;
                        
            drawShapeRelative(1LongExitPriceShape.LEFTARROWnullColor.blueShape.LEFT Shape.ONTOP"ShapeB"+cntr2);//modified by ACM
                    
            }

                }
                return 
            null;
            }

            function 
            GoShort(ShortMonthShortDayShortEntryTimeShortExitTimeShortEntryPriceShortExitPrice) {
                if (
            vMonth == ShortMonth && vDay == ShortDay) {

                    if (
            CurrentTime == ShortEntryTime) {
                        
            BeginIndex Index;
                        
            cntr2 += 1;
                        
            drawShapeRelative(-1ShortEntryPriceShape.RIGHTARROWnullColor.yellowShape.LEFT Shape.ONTOP"ShapeC"+cntr2);//modified by ACM
                    
            }
                    if (
            CurrentTime == ShortExitTime) {
                        
            cntr += 1;

                        if (
            ShortEntryTime == ShortExitTime) { 
                            
            drawLineRelative(-1ShortEntryPrice1ShortEntryPricePS_SOLID2Color.black"LineD" cntr);//modified by ACM
                            
            cntr += 1;
                            
            drawLineRelative(-1ShortExitPrice1ShortExitPricePS_SOLID2Color.black"LineE" cntr);//modified by ACM
                        
            } else {
                            
            drawLineRelative(BeginIndex-IndexShortEntryPrice0ShortExitPricePS_SOLID2Color.yellow"LineF" cntr);//modified by ACM
                        
            }
                        
            cntr2 += 1;
                        
            drawShapeRelative(1ShortExitPriceShape.LEFTARROWnullColor.yellowShape.LEFT Shape.ONTOP"ShapeD"+cntr2);//modified by ACM
                    
            }

                }
                return 
            null;

            Comment


            • #7
              Great it work ACM. Don't know exactly how the logic is. But time to move on, to reading the file and convert it to the GoLong and GoShort.

              Thank you again ACM and Doji3333

              Tony

              Comment


              • #8
                Tony
                You are welcome and I am glad to hear it is working now
                Alex


                Originally posted by tonhar
                Great it work ACM. Don't know exactly how the logic is. But time to move on, to reading the file and convert it to the GoLong and GoShort.

                Thank you again ACM and Doji3333

                Tony

                Comment

                Working...
                X