Announcement

Collapse
No announcement yet.

Problem displaying contents of variable using Drawtext on Chart

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem displaying contents of variable using Drawtext on Chart

    For an unrealted post http://forum.esignalcentral.com/show...=forex+symbols concerning the composition of FOREX price bars I tried to use the Drawtext to simply display the contents of several variables on the chart.

    I wrote this simple efs to display on the chart next to each bar, the values returned by several Time and Sales functions when the bar was loaded.

    I'm only seeing the values displayed on the last bar and wondering if anyone knows what I'm doing wrong.

    Thanks very much.

    Glen

    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Show Bid-ASK-LAST");
        
    setShowCursorLabel(false);
    }

    function 
    main() {
        var 
    nState getBarState();
        var 
    vBid   = (getMostRecentBid()*1).toFixed(4)*1;
        var 
    vAsk   = (getMostRecentAsk()*1).toFixed(4)*1;
        var 
    vLast  = (getMostRecentTrade()*1).toFixed(4)*1;
        
        
        if (
    nState == BARSTATE_CURRENTBAR) {
            
    debugPrintln("Bid = " +getMostRecentBid() + " Ask = " +getMostRecentAsk() + " Last = " +getMostRecentTrade());
            
            
    drawText ("B="+vBidBelowBar4Color.red,Text.BOLD,"Bid");
            
    drawText ("A="+vAskAboveBar4,  Color.green,Text.BOLD,"Ask");
            
    drawText ("L="+vLastBelowBar3Color.blueText.BOLD,"Last");
        }

     
        
        return;

    Last edited by demarcog; 07-17-2007, 03:24 PM.
    Glen Demarco
    [email protected]

  • #2
    Glen
    That is happening because the tagID parameter you are using in each drawText() command is the same for all the graphic objects being drawn by that command so only the last one is drawn on the chart. You need to use a tagID that will be unique to each graphic object. That can be done using either a counter or a function that returns a value that is unique to each bar such as for example rawtime(0) or getCurrentBarCount() eg
    drawText ("B="+vBid, BelowBar4, Color.red,Text.BOLD,"Bid"+rawtime(0));
    Replace rawtime(0) with getCurrentBarCount() if you prefer to have a bar counter as the tagID
    Alex

    Comment


    • #3
      Originally posted by Alexis C. Montenegro
      Glen
      That is happening because the tagID parameter you are using in each drawText() command is the same for all the graphic objects being drawn by that command so only the last one is drawn on the chart. You need to use a tagID that will be unique to each graphic object. That can be done using either a counter or a function that returns a value that is unique to each bar such as for example rawtime(0) or getCurrentBarCount() eg
      drawText ("B="+vBid, BelowBar4, Color.red,Text.BOLD,"Bid"+rawtime(0));
      Alex
      Alexis,

      Beleive it or not I knew that at one time, but haven't used those functions in awhile and completely forgot about uniqie tagid's.

      Thank you very much for all your help, it is greatly appreciated.

      Glen
      Glen Demarco
      [email protected]

      Comment


      • #4
        Glen
        You are most welcome
        Alex

        Comment


        • #5
          the way I solve this..

          I solve this problem with a simple set of code for all my projects.

          PHP Code:
          var nLastRawTime null;
          var 
          BarCounter 0;
          var 
          newDayBar 0;

          function 
          main() {


            if (
          getValue("rawtime",0) != nLastRawTime) {
            
          //  New Bar
              
          nLastRawTime getValue("rawtime",0);
              
          BarCounter += 1;

              if (
          getDay(0) != getDay(-1)) {
                
          //--  New Day
                
          newDayBar BarCounter;
              }
            }




          }  
          // end of main 
          Using code like this, you can use any graphics/text display you want and simply pass (Barcounter+"UniqueID") in the TAG field.

          It also provides you with an ability to "mark" bars so you can reference them later in your code.. Lets say you found a major bottom on bar 223 (however you decide to identify it), then wanted to reference it when you're at bar 4325...

          All you have to do is SUBTRACT the current bar number from the marked bar (223-4325) = -4102. The major bottom can be identified with "low(-4102)" or low(Bottom_bar-BarCounter).

          Using the NEWDAY bar, I can identify if the market has moved up, down or the currently daily range is more/less than n%% of the opening bar.

          Anyway, just a hint.
          Brad Matheny
          eSignal Solution Provider since 2000

          Comment


          • #6
            Hello Brad,

            Haven't heard from you in sometime, glad to see you are still plugging away. Thanks very much for the tip and insight, I appreciate it very much.

            Glen
            Glen Demarco
            [email protected]

            Comment


            • #7
              hello

              yeah. still plugging away. Mostly focus on automated trading systems now and keeping my clients happy.

              You're very welcome for the insight. Sometimes I forget to keep an eye on this forum when I'm swamped with work - sorry.

              Alex is great and is very knowlegable about EFS. I'm really glad he is here to help out.

              Let me know if you need any more help.
              Last edited by Doji3333; 07-19-2007, 08:37 AM.
              Brad Matheny
              eSignal Solution Provider since 2000

              Comment


              • #8
                Re: hello

                Originally posted by Doji3333
                yeah. still plugging away. Mostly focus on automated trading systems now and keeping my clients happy.

                You're very welcome for the insight. Sometimes I forget to keep an eye on this forum when I'm swamped with work - sorry.

                Alex is great and is very knowlegable about EFS. I'm really glad he is here to help out.

                Let me know if you need any more help.
                Please don't apologize, appreciate the help and glad to hear from you. I too like most of us on the road to abundance, go around in circles expending way too much time and energy "worrying".

                I'm also trying to finish up some automation and would like to have you involved. It's a bit of a catch-22, I can get the resources to bring you aboard once I get a few systems up and autotrading, but might night be able to do that without you involved.....

                I'm very close I though, focusing on FOREX, obviously there are better instruments to trade in terms of profitability (aka volatility) but nothing scales better then currencies in terms of liquidity. I've been trying to avoid another layer of "code" between EFS and IB, but as you know there are real issues there.

                Anyway I'll send you an email with more details as may be too esoteric for the forum.

                Thanks Again,

                Glen
                Glen Demarco
                [email protected]

                Comment


                • #9
                  autotrading

                  Glen,

                  I'll be happy to discuss anything you like. I have systems that are autotrading currently and I have a number of clients that are autotrading with esignal.

                  Of course, I've had to build a few of my own tools to accomplish all of this, but it's worth it in the long run when it all works properly and profitably.

                  I've done quite a bit of work in the forex markets for clients. I've even developed a system for forex trading that I released about a year ago on this forum. It may not have been the best system for forex trading, but it appeared to do moderately well.

                  Right now, I'm autotrading the e-minis (with some success). I'm also still trading my stocks (I love long-term trading stocks - it's so easy).

                  Anyway, let me know how I can help. I've had email problems this week - so if you need to, simply call and we'll chat.

                  B
                  Brad Matheny
                  eSignal Solution Provider since 2000

                  Comment

                  Working...
                  X