Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Money management issue: why doesn't this routine work?

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

    Money management issue: why doesn't this routine work?

    Hi Ninjas,

    For money management purposes, I consider important to have a simple tool that stops and disables an Algo whenever a daily limit is reached. The following sub-routine was to do this job:

    if (l==true) // L is a variable where this limit is actived ON ( True) or OFF ( False )
    {
    if((GetAccountValue(AccountItem.RealizedProfitLoss )+Position.GetProfitLoss(Close[0],PerformanceUnit.Currency)> g || (GetAccountValue(AccountItem.RealizedProfitLoss)+ Position.GetProfitLoss(Close[0],PerformanceUnit.Currency))< -g);
    {
    ExitLong();
    ExitShort();
    SendMail ("Email1", "Email2", "DAILY LIMIT REACHED", "P&L RLZD " + GetAccountValue(AccountItem.RealizedProfitLoss).To String() + " "+ "P&L UNRLZD " + Position.GetProfitLoss(Close[0], PerformanceUnit.Currency).ToString());
    Disable();
    }
    }

    The problem is that whenever I attempt to put it ON when the Algo was going to be activated, this one appears to stay OFF, as it never the Algo was put to work.
    I think that maybe is the method CalculateOnBarClose=true that has sort kind of "interference", preventing the Algo correctly to work.

    Any ideas, suggestions or reasons to address this issue ?

    Thanks
    Last edited by NinjaTrader_Bertrand; 09-10-2013, 02:55 AM. Reason: replaced emails with placeholders

    #2
    I've tried another way, but with the same result, The Algo seems to be paralyzed, doesn't work:

    if ((GetAccountValue(AccountItem.RealizedProfitLoss)+ Position.GetProfitLoss(Close[0], PerformanceUnit.Currency))> g && l==true )
    {
    ExitLong();
    ExitShort();
    SendMail ("EMAIL1", "EMAIL2", "MAXIMUM DAILY PROFIT REACHED", "P&L RLZD " + GetAccountValue(AccountItem.RealizedProfitLoss).To String() + " "+ "P&L UNRLZD " + Position.GetProfitLoss(Close[0], PerformanceUnit.Currency).ToString());
    Disable();
    }
    if ((GetAccountValue(AccountItem.RealizedProfitLoss)+ Position.GetProfitLoss(Close[0], PerformanceUnit.Currency))< -2*g && l==true )
    {
    ExitLong();
    ExitShort();
    SendMail ("EMAIL1", "EMAIL2", "MAXIMUM DAILY LOSS REACHED", "P&L RLZD " + GetAccountValue(AccountItem.RealizedProfitLoss).To String() + " "+ "P&L UNRLZD " + Position.GetProfitLoss(Close[0], PerformanceUnit.Currency).ToString());
    Disable();
    }

    Why and can I put this to work properly ?
    Last edited by pstrusi; 09-10-2013, 03:09 AM.

    Comment


      #3
      I've just solved the issue with the last way to put it, the reason why it still didn't work was cause the old sim101 account had a limit already reached.

      So, thanks anyway

      Comment


        #4
        That would make sense Pier, thanks for the update. I've also edited your first post to blank out the emails posted...

        Comment


          #5
          Bertrand, I've tried now to put it at work with my real account, which has all sums in Zero ( PnL rlzd and unRlzd ) but the Algo doesn't work, Why? It's important to me have this daily limit measure activated

          Comment


            #6
            Pier, you mean then it's immediately disabled by your snippet posted?

            That can only be due to either those conditions evaluating to 'true' - I would suggest to print the variables used as debug -

            GetAccountValue(AccountItem.RealizedProfitLoss)+ Position.GetProfitLoss(Close[0], PerformanceUnit.Currency))> g

            (GetAccountValue(AccountItem.RealizedProfitLoss)+ Position.GetProfitLoss(Close[0], PerformanceUnit.Currency))< -2*g

            Comment


              #7
              Thanks for your suggestion Bertrand, I'll try it when market closes. I can't interrupt the Algo now. I'll let u know what I find.

              Regards

              Comment


                #8
                Hi Bertrand,

                I've done the test with the Output windows, and effectively the variable Position.GetProfitLoss(Close[0], PerformanceUnit.Currency), which if you don't have any position, it's supposed to be zero, in fact gave me 412,09. I don't have idea where does it take this from.

                So, please if any ideas, let me know

                Comment


                  #9
                  Pier, 'which if you don't have any position' > what position do you refer to here in this statement?

                  Position.GetProfitLoss would be your strategy position and not the account one, so if you script is starting up managing a historical position > this would be sure giving you a non zero value.

                  Comment


                    #10
                    Thanks for your response Bertrand.

                    The position I'm referring to is exactly the "Active opened Position", it's the actual position that is opened and changing with any price tick.
                    The function definition for Position.GetProfitLoss is: "Calculates the unrealized PnL for the position". That's why I use it as supposed Unrealized PnL for an opened position .
                    So I don't understand why if it's supposed to carry a non-zero values when you don't have any opened position.
                    In case that this function works like that, then either the definition would be changed ( Inluding the historical data ) or it should be created an "only unrealized PnL for active positions"

                    Still I need a variable which could give me the actual unrealized PnL.

                    I hope you can understand what I'm looking for

                    Comment


                      #11
                      Pier,

                      'So I don't understand why if it's supposed to carry a non-zero values when you don't have any opened position.'

                      Position does not equal position, meaning you have two position parts working together - the strategy and the account position. If you enable a strategy and it carries a (strategy) position from historical data, then you would need see the Position.GetProfitLoss prrint for that, disregarding whatever is actually happening at the account level.

                      Comment


                        #12
                        I understand the concepts of strategy and account positions, so having in mind that I wonder:

                        if you activate a strategy from Flat, which has synced the Strategy and Account position, don't you think that it's logical to have an actual and opened unrealized position variable in Zero? That's what I look for to have in my calculation, so my question is:

                        If you wanted a clear and "only unrealized PnL for your actual position, which is synced in all accounts" what would you use?

                        Thanks for your patience

                        Comment


                          #13
                          No, as the strategy would still trade it's strategy position - when you have a sync operation to your account that freshly opend account position would be starting from the point of execution to track PNL. However for accessing this you would need to use GetAccountValue Realized Pnl counterpart.

                          Comment


                            #14
                            So, If I understand well this, it means that if I'd like to calculate the fresh new PnL for a new opened position, I'd have just to calculate the difference between GetAccountValue Realized Pnl Minus GetProfitLoss?

                            Comment


                              #15
                              Pier, sorry but I don't see how this would help you, since none of those properties would update for the synch execution - the account is realized pnl only and Position.GetProfitLoss is the strategy position Pnl. The synch execution is also submitted outside the OnExecution so you could not grab the execution.Price here for compares.

                              For an undocumented way to attempt working directly with the account further, you can check into - http://www.ninjatrader.com/support/f...2&postcount=33

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              113 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              60 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              40 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              43 views
                              0 likes
                              Last Post TheRealMorford  
                              Started by Mindset, 02-28-2026, 06:16 AM
                              0 responses
                              82 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Working...
                              X