Announcement

Collapse
No announcement yet.

Adanced Chart display

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

  • Adanced Chart display

    Hi,

    I've tried to display a number of variables in my advanced chart. E.g StopLoss Level, Profit Exit etc. They should only however be visible when in a trade and are turned to null when the trade exits.

    For some reason once they have been displayed once, even though they are null in value they still appear on the chart. They do not affect anything however can still be seen.

    Is there any way around this? Or am I simply nit picking?

    Thanks
    Attached Files

  • #2
    Hi thestranger,

    From what I see, you are setting these variables to null in numerous places in your code, subsequently, you are testing them if they are less than or equal to some value.
    I believe the subsequent tests of the null values is why you are having issues.

    I suspect that you are loosing track of the logic in your code and simply missing the reason why this is occuring. My recommendation is that you stop for a day or two, then come back and re-examine your logic. This always helps me when faced with similar logic issues.



    The way you have this structured is tough to troubleshoot, at least for me...



    You may want to examine the way you have the logic structured to determine if this is why you are having a problem.



    As an aside, you are sometimes testing if (high() >= nProfitExitShort), you need to go through and modify your tests to contain the index number like this...

    if (high(0) >= nProfitExitShort)



    I hope this is of some help.

    Comment


    • #3
      Hi thestranger,

      It looks like I may have misunderstood your question, let me try again.

      Once you send a variable to the Cursor window, you cannot remove the placeholder. If you want to send something to the cursor window, you can prevent it from being charted by changing it to a string. Conversion to a string in Javascript is easily accomplished by adding a string to the number.

      For example...

      PHP Code:
      return new Array(nDonch_UppernDonch_LowernStopLevelnProfitExitLong+""nProfitExitShort+""nTradeEntryPrice+""nTradeEntryPrice2+""nTradeEntryPrice3+""nTradeEntryPrice4+""); 
      The strings will appear in the cursor window but will not go to the chart as a plotted variable.

      If you want the chart marked up to reflect these transient values you will have to draw some lines on the chart when the condition is met. Let me know and I will show you how to do this...

      Comment


      • #4
        Thanks for getting back to me Steve.

        I didnt clearly explain what I was attempting to achieve in the previous post. Sorry!

        I'll try again;

        For example when I test my code on the $INDU chart, the ProfitExitShort line (BLUE) continues to be displayed even though between 10/19/05 - 5/17/06 I am not short. The line does not affect my test (as the value = null), it simply makes the chart look untidy. Is there anyway I can make the line disappear when not in a trade? The entryprice lines do not stay on the chart when the trade ends however other lines do.

        Any ideas?

        Comment


        • #5
          Hi thestranger,

          You are most welcome. The way to handle this is to draw the lines using another technique. It will not work by using the return statement.

          This is the command set that you will be using, with the drawLineRelative() being the preferred method in my opinion.


          drawLineRelative()
          drawLineAbsolute()
          clearLines()
          removeLine()

          addLineTool()
          clearLineTool()
          removeLineTool()

          When using the drawLineRelative(), pay close attention to the tagID variable. This is unique to the line. If you draw one line with a tagID,
          then subsequently draw another with the same ID, it will remove the first line.


          Here is one link showing it being used in an efs and here is a second link and a third link to the command in the knowledgebase.

          Let me know if you run into any problems using this, I will help you.

          Comment


          • #6
            Thanks again Steve.

            I'm going to have a play with this and see if I can code something up. One last thing, Is there a command to retrieve the current bar offset? I've had a quick look and can only find ways of retrieving values from bars etc but not the actual bar number e.g. -23.

            Comment


            • #7
              Hi thestranger,

              You ae welcome. The way I manage this is to use the command getCurrentBarCount() .

              For example, if you were to enter a trade at a bar and you wanted to put a line at the stop-loss, you would save the barcount at that bar when you are entering the trade.

              start = getCurrentBarCount();// start is a global variable

              Then, every new bar, you would redraw that line (using the same tagID ) by calculating the offset as follows...

              var x1 = start - getCurrentBarCount(); // x2 would be zero

              Then, continue to redraw until you are out of the trade. For efficiency, I would only draw the line when a new bar has begun, so you would test for a newbar, e.g.
              if (getBarState() == BARSTATE_NEWBAR)

              By only drawing once every new bar, this will improve efficiency in real time. This would have no effect while backtesting or otherwise loading historical bars when starting up the efs.

              Once you no longer need to draw this line and draw another, transition to the next tagID.

              Comment

              Working...
              X