Announcement

Collapse
No announcement yet.

fix a segment by time not relative to current bar

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

  • fix a segment by time not relative to current bar

    Hi

    I would like to draw a segment (or line) where the x co-ordinate is based on a time rather than bars back from the current bar.

    My code below gives me a line from price 830-835 (which is what I want) but it paints at the current bar when i want it to paint from 13:10 to 16:10

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("drawtrade1");

    }

    function main () {
    addLineTool(LineTool.SEGMENT, (hour(1300)+minute(10)), 830, (hour(1600)+minute(10)), 835, 10, Color.brown, "l1");

    return;

  • #2
    you need to address BARS not TIME. The way to accomplish this is to create a lookup feature for the times you want to find, like this..

    PHP Code:
    // Global Variables
    var nBarCounter 0;


    function 
    preMain() {
      
    setPriceStudy(true);
      
    setStudyTitle("drawtrade1");

    }

    function 
    main () {

    //====  New Bar ==============================
      
    var nState getBarState();
      if (
    nState == BARSTATE_NEWBAR) {
       
    //  Bar counter is needed for error checking.
        
    nBarCounter += 1;
      }


       var 
    StartTradeBar fFindTimeOnChart(1310);
       var 
    EndTradeBar fFindTimeOnChart(1610);

       if ((
    StartTradeBar <= 0) && (EndTradeBar <= 0)) {
    //    If the lookup function could find the times, then draw the line
             
    drawLineRelative(StartTradeBar ,830,EndTradeBar ,835PS_SOLID10Color.brown"l1"+nBarCounter);
       }


      return;
    }

    function 
    fFindTimeOnChart(vTime) {
      var 
    0;
      var 
    FoundTimeBar 1;  //  1 = not found.  Found would be negative

      
    while ( (< (nBarCounter-10)) && (FoundTimeBar 0) ) {
        if ( ( ((
    getHour(-x)*100)+getMinute(-x)) >= vTime) &&
             ( (((
    getHour(-x)*100)+getMinute(-x))+getInterval()) < vTime) ) {
          
    //  Found the time in a bar.
           
    FoundTimeBar = -x;
        }
        
    x++;
      }
      return 
    FoundTimeBar;

    Last edited by Doji3333; 04-06-2009, 02:20 PM.
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Thank you very much for this.

      I have put the code into an efs and loaded it onto my chart, but the lines have not drawn. however I am sure i can work it out using the efs knowledge base.

      Thanks again, this is a big help - its always much easier to work from something than to operate from a blank page.

      One question, is the date not important, or does it look for the most recent times i put into?
      var StartTradeBar = fFindTimeOnChart(0220);
      var EndTradeBar = fFindTimeOnChart(0300);

      is it something to do with the line?
      while ( (x < (nBarCounter-10)) && (FoundTimeBar > 0) ) {
      This is the line I really don't understand yet - no worries I'll do some figuring out.
      Last edited by missionyam; 04-07-2009, 03:20 AM.

      Comment


      • #4
        You can also match by date, but you'll have to create a date structure that is uniform for all trades (for example mmddyy). The process is the same. In your lookup feature/function, you would also have to compare the dates and time to make sure you have a match.

        It's pretty much that simple.

        B
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment


        • #5
          Originally posted by missionyam
          Thank you very much for this.

          I have put the code into an efs and loaded it onto my chart, but the lines have not drawn. however I am sure i can work it out using the efs knowledge base.

          Thanks again, this is a big help - its always much easier to work from something than to operate from a blank page.

          One question, is the date not important, or does it look for the most recent times i put into?
          var StartTradeBar = fFindTimeOnChart(0220);
          var EndTradeBar = fFindTimeOnChart(0300);

          is it something to do with the line?
          while ( (x < (nBarCounter-10)) && (FoundTimeBar > 0) ) {
          This is the line I really don't understand yet - no worries I'll do some figuring out.
          The line in question is a WHILE loop. It is used to look up the times that are passed to this function.. It is designed to allow the lookup function to loop thru the most recent bars to try and find the times you are looking for.

          PHP Code:
          function fFindTimeOnChart(vTime) {
            var 
          0;
            var 
          FoundTimeBar 1;  //  1 = not found.  Found would be negative

            
          while ( (< (nBarCounter-10)) && (FoundTimeBar 0) ) {
              if ( ( ((
          getHour(-x)*100)+getMinute(-x)) >= vTime) &&
                   ( (((
          getHour(-x)*100)+getMinute(-x))+getInterval()) < vTime) ) {
                
          //  Found the time in a bar.
                 
          FoundTimeBar = -x;
              }
              
          x++;
            }
            return 
          FoundTimeBar;

          Brad Matheny
          eSignal Solution Provider since 2000

          Comment

          Working...
          X