Announcement

Collapse
No announcement yet.

looking for text parsing / trade plotting example

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

  • looking for text parsing / trade plotting example

    Before I start banging my head against this problem I thought i'd ask if something like this existed (or if someone could point me to an efs that solved a similar problem)

    I'd like an EFS that would read in trades from a text file and plot them on a chart.

    Data would be formatted thusly:

    2003-06-18 14:48:35 1 1006.7500 1009.4000


    The columns are date, time, action, buy, sell, and are space delineated. (Action is positive for bought, negative for sold. )

    I have ideas for the bells and whistles of such an efs, but to start a simple skeleton that parses a text file and plots the trades would suffice.

    Thanks for any help! In the mean time, i'll be thinking about and working on this, and will post the results if anyone is interested.

  • #2
    Please post more...

    Please post a more detailed example of your text file so I can try to create something for you.

    Brad
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Wow, thanks Brad. Not being a programmer I don't think i'd get very far on my own so your help is appreciated.

      I'm not sure how much (or what) details you want so i'll just ramble a bit and recap the purpose: what I have in mind is a tool that will plot an arbitrary number of trades on a candle chart. At the moment, i'm trading futures (symbol ES #F) and only planning to plot backwards a week at most, and use time intervals of 1, 3, and 5 minutes.

      The source of the trades will be a text file formatted similarly to the Interactive Brokers statement, which includes a string of entries like this:

      (apologies for the attrocious formatting)

      Date Time Description Exch Qty T. Price S. Price Gain/Loss Comm Curr Code
      2003-06-18, 14:25:31 ES SEP03 GLOBEX -1 1,008.0000 1,008.2000 -10.00 -2.40 USD C
      2003-06-18, 15:09:59 ES SEP03 GLOBEX 1 1,006.2500 1,008.2000 97.50 -2.40 USD O


      Not all of these columns are necessary, so I thought the entries could be streamlined down to :

      Date Time Qty T. Price
      2003-06-18, 14:25:31 -1 1,008.0000
      2003-06-18, 15:09:59 1 1,006.2500

      where Qty determines the action (ie, positive for bought, negative for sold)

      It is trivial to hand build and format these text files from IB statements (simply deleting the unwanted columns in, say, excel and saving the output as a text file). I am personally optimizing for simplicity by creating the text file manually -- given that you are a capable programmer you could probably just as easily parse the entire statement as Interactive Brokers presents it and pull out what you need. (My vote is still for simplicity!)

      As far as what the display looks like, what I imagined was a candle chart where all the bars were black except where positions were held. Long positions would be colored lime, and short positions would be colored red. The point gain/loss would be printed somewhere near the colored bars (perhaps beneath the last bar of the trade) as well as the trade data (entry price beneath the first bar, exit beneath the last)

      That's basically it in a nutshell.

      Thinking this through and writing it down I can forsee a few issues, such as how to represent a trade that was entered mid bar. The entire bar will be colored for an entry that might have been at any price point along the bar -- maybe you have some clever ideas on how to work around this (drawing a fancy arrow or dot where the position was entered perhaps).

      Redesign and improve as you see fit -- i'm sure with your programming and design experience you'll come up with a better UI than I have.

      While you're in there, feel free to add a random insult generator that will chastise me for blowing through stops and being on the wrong side of a trade.

      Cheers,

      John
      Last edited by Freeman; 06-19-2003, 09:21 PM.

      Comment


      • #4
        contents of typical text file

        2003-06-19 09:50:22 -1 1006.7500
        2003-06-19 09:56:25 1 1007.2500
        2003-06-19 10:01:48 1 1008.5000
        2003-06-19 10:15:20 -1 1007.2500
        2003-06-19 10:15:29 -1 1006.7500
        2003-06-19 10:43:09 1 1001.5000
        2003-06-19 10:44:15 -1 1001.2500
        2003-06-19 10:48:35 1 1001.7500
        Last edited by Freeman; 06-20-2003, 07:55 AM.

        Comment


        • #5
          I had a few free hours this morning so I wrote a prototype of this concept. Beware, horrid code ahead! (I'm not a programmer, I just play one on TV.)

          PHP Code:
          function preMain()
          {
          setPriceStudy(true);
          setStudyTitle("Trade Plotter");
          setDefaultChartBG(Color.white);
          setDefaultBarFgColor(Color.white);
          }

          function 
          main(){

          //-----------------------------------------------------------------date calculation
          var vTime = new Date();
          vTime getValue("Time"0);
          var 
          vHour;
          var 
          vMin;
          var 
          vSec;
          var 
          vDay;
          var 
          vMonth;
          // Get Time Variables 
          vHour vTime.getHours();
          vMin vTime.getMinutes();
          vSec vTime.getSeconds();
          vDay vTime.getDate();
          vMonth vTime.getMonth() +1;


          BarHr     getHour();
          BarMin    getMinute();
          CurrentTime  =BarHr*100+BarMin*1;


          // --------------------------------------------------------------- Trades to plot


          var tradeMonth 6;
          var 
          tradeDay 19;
          if(
          vMonth==tradeMonth && vDay==tradeDay)
          {
              
          GoShort(650656"1006.75""1007.25")  
              
          GoLong(701715"1008.50""1007.25")
              
              
          GoShort(715743"1006.75""1001.50")
              
          GoShort(744748"1001.25""1001.75")    
          }

          var 
          tradeMonth 6;
          var 
          tradeDay 18;
          if(
          vMonth==tradeMonth && vDay==tradeDay)
          {
              
          GoLong(928929"1009.50""1009.50")    
              
          GoLong(938947"1010.50""1008.75 ")
              
              
          GoShort(947950"1008.75 ""1010.00")
              
          GoLong(9501025"1009.50""1009.75 ")
              
          GoLong(10271039"1010.50""1009.75")
              
              
          GoShort(10391057"1009.75""1010.25")
              
          GoLong(10571105"1010.25""1010.00")
              
          GoLong(11081125"1010.50""1008.00")
              
          GoLong(11481158"1006.75""1006.00 ")
              
              
          GoShort(11581201"1006.00 ""1006.50")
              
          GoLong(12091223"1006.25""1005.00")
          }


          // --------------------------------------------------------------- End Plotting
          return null;
          }



          // ----------------------------------------------------------------FUNCTIONS
          var longOpenTime;
          var 
          longCloseTime;
          var 
          shortOpenTime;
          var 
          shortCloseTime;
          var 
          OpenPrice;
          var 
          ClosePrice;



          function 
          GoShort(shortOpenTimeshortCloseTimeOpenPriceClosePrice)
          {
              if(
          CurrentTime>=shortOpenTime && CurrentTime<shortCloseTime)
              {
                  
          ShortTrade();
                  
              
                  if(
          CurrentTime==shortOpenTime)
                  {
                      
          drawTextRelative(-5,  low()-.2OpenPriceColor.RGB(255,150,50), Color.black
                      
          Text.FRAME Text.ONTOP nullnull 11getValue("rawtime"));
                      
                      
          drawShapeRelative(-1OpenPriceShape.RIGHTARROW""Color.RGB(155,50,0), Shape.ONTOP Shape.LEFT);
                      
                  }
                      if(
          CurrentTime==shortCloseTime-)
                  {
                      
          drawTextRelative(+1,  high()+.5ClosePriceColor.RGB(255,150,50), Color.black
                      
          Text.FRAME Text.ONTOP nullnull 11getValue("rawtime"));
                      
                      
          drawShapeRelative(+1ClosePriceShape.LEFTARROW""Color.RGB(155,50,0), Shape.ONTOP Shape.LEFT);
                     
                  }
              }

          }


          function 
          GoLong(longOpenTimelongCloseTimeOpenPriceClosePrice)
          {
              if(
          CurrentTime>=longOpenTime && CurrentTime<longCloseTime)
              {
                  
          LongTrade();
              }

              if(
          CurrentTime==longOpenTime)
              {
                  
          drawTextRelative(-1,  high() + .5OpenPriceColor.RGB(128,255,87), Color.black
                  
          Text.FRAME Text.ONTOP nullnull 11getValue("rawtime"));
                  
                  
          drawShapeRelative(-1OpenPriceShape.RIGHTARROW""Color.RGB(50,155,0), Shape.ONTOP Shape.LEFT);
                  
                  
              }
                  if(
          CurrentTime==longCloseTime)
              {
                  
          drawTextRelative(-1,  high() - .5ClosePriceColor.RGB(128,255,87), Color.black
                  
          Text.FRAME Text.ONTOP nullnull 11getValue("rawtime"));
                  
                  
          drawShapeRelative(+1ClosePriceShape.LEFTARROW""Color.RGB(50,155,0), Shape.ONTOP Shape.LEFT);

              }
          }



          function 
          ShortTrade()
          {
              
          setBarBgColor(Color.RGB(200,100,100));
          }

          function 
          LongTrade()
          {
              
          setBarBgColor(Color.RGB(100,200,100));

          If this is loaded and viewed on the symbol ES #F it will show trades placed on 6/18 and 6/19.

          In this version, the trades are stored internally in the EFS file, rather than in a separate text file. Since I usually only make 10 or fewer trades a day it is actually manageable to handle it this way.

          I ran into several UI issues writing this:

          -I don't know how to make the entry arrows draw on top of the candles, so they are sometimes obscured
          -Ditto for the text boxes
          -Due to how the logic is written this does not work well on multiple time frames. (I'm not sure how to make it robust enough to work on any interval.)

          And thought of new features:

          -automatically calculating and displaying stops and profit targets, to compare to actual trade results.
          -displaying the point loss/gain on trades and total for the day

          Over all, i'm happy with the concept, and think the idea is still worthy of full implementation.

          comments, feedback, complete and total rewrites apprecated =)
          Last edited by Freeman; 06-21-2003, 02:09 PM.

          Comment

          Working...
          X