Announcement

Collapse
No announcement yet.

Cumulative Profit / Loss

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

  • Cumulative Profit / Loss

    Attached is a partial screenshot which shows individual gains/losses per trade (not using backtest mode). I've placed them using drawText...RELATIVETOTOP and would like to know if there's a manner to have them add together to another drawTextRelative location with cumulative totals. I wasn't able to find any help through "search" using "cumulative".
    Partial code for this computation is:

    PHP Code:
    drawTextRelative(0,60,Math.round(vTargetPrice.toFixed(2)*10 vEntryPrice.toFixed(2)*10)/10,Color.white,Color.navy,Text.RELATIVETOTOP Text.VCENTER 
    I'm sure I'd have to learn more about bar counters but I only need this for the current day or so.

    Any help is greatly appreciated!
    Thanks in Advance.
    kz
    Attached Files

  • #2
    Hello Kirk,

    To track cumulative values you need to use global variables. Outside of main() declare a global variable such as,

    PHP Code:
    var nCumPL 0;

    function 
    main() {

    ... 

    In your drawText example you'll need to pull the PL expression out of the function's parameters and assign it to a local variable. Pass the variable to the drawText function. Then you can use the local variable and add its value to the nCumPL global variable.

    PHP Code:

    var nTradePL Math.round(vTargetPrice.toFixed(2)*10 vEntryPrice.toFixed(2)*10)/10;

    nCumPL += nTradePL;

    drawTextRelative(0,60nTradePL ,Color.white,... 
    You could also pass the new global var to another drawText call to display both the trade PL and cumulative values on the chart. Hope this helps.
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Jason,

      Thanks very much, that works great.

      Also found what I need for the current day only...

      Thanks again...

      Kirk
      Last edited by zeller4; 09-12-2007, 02:24 PM.

      Comment


      • #4
        You're most welcome.
        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment

        Working...
        X