Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to spot a strategy when I got the daily goal

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

    How to spot a strategy when I got the daily goal

    Hi ninjas,

    A simple situation. I got an algo and I'd like to add it this simple condition:

    IF I got the daily profit goal THEN Stop the Algo for the rest of the day

    I searched in help and I think this procedure could accomplish my objective:

    protected override void OnBarUpdate()
    {


    if (GetAccountValue(AccountItem.RealizedProfitLoss) > 25000)
    Return;
    }

    Will this stop the algo totally ?
    Is there any other simpler way to accomplish what I want ?

    Thanks
    Last edited by pstrusi; 09-03-2013, 12:56 AM.

    #2
    pstrusi, that would not stop the algo in terms of disabling it, however you would return out of the OnBarUpdate() method and not process further logic. Also, this would be using the realized Pnl only, so a trade has to close to update and trigger your condition.

    A programmatic disable would be possible as well - http://www.ninjatrader.com/support/h...t7/disable.htm

    More ideas and sample code on halting a strategy could be reviewed here - http://www.ninjatrader.com/support/f...ead.php?t=4804

    Comment


      #3
      Thanks for your suggestions, sound great for my goal.

      Regards

      Comment


        #4
        In order to build a solid method with no basic errors, may I get answers for these ? :

        - Performance.AllTrades.TradesPerformance.Currency.C umProfit MEANS that includes Pnl and realized?
        - Performance.AllTrades.TradesPerformance.Currency.C umProfit is Equal to Position.GetProfitLoss ?

        - Is there any general command or method to cancel all Stops/Profits submitted by the system through these typical lines? :
        SetProfitTarget("", CalculationMode.Ticks, S);
        SetStopLoss("", CalculationMode.Ticks, S, false);

        Thanks

        Comment


          #5
          Performance.AllTrades.TradesPerformance.Currency.C umProfit is the cumulative profit over all historical and realtime trades (AllTrades collection) including the last closed trade.

          Set's could not be cancelled, but would be cancelled by NT automatically if the managed position is exited / not existing anymore.

          Comment


            #6
            That's all what I need to know.

            Thanks for your great assistance

            Comment


              #7
              Bertrand, a little doubt:

              Imagine my Algo is in day 1, working, then eventually achieves its goal, detected through:
              Performance.AllTrades.TradesPerformance.Currency.C umProfit > 1000
              Then I exit all positions with the general:
              ExitLong(); ExitShort ()

              1. If I add after ExitShort() the command Disable(); will it give time to the system to cancel Set's orders?

              2. When I active my Algo again, the value got from : Performance.AllTrades.TradesPerformance.Currency.C umProfit will be just and only for that actual day, right? not historical results included

              Comment


                #8
                Pier, the set's would get cancelled as their managed positions are closed by your Exit market order calls - you could for example detect via the IOrder objects when those are reporting .Filled and only then call .Disable - but I don't more finetuning would be needed.

                Performance.AllTrades would be for everything including historical, in contrast .Realtime would be only for the live taken trades. If you only want to consider pnl for one session, please check into the reference sample it shows how to store the value needed.

                Comment


                  #9
                  Thanks for your suggestion. Seeing that example, I prefer to use GetAccountValue and GetProfitLoss, which carries automatically the Pnl and realized for the day.

                  If I had need further help I'll let u know, but I think it'll be ok

                  Comment


                    #10
                    Does this Loop seem to achieve my daily goal ? // If I profit more than 300 stops

                    while ((GetAccountValue(AccountItem.RealizedProfitLoss)+ Position.GetProfitLoss(Close[0], PerformanceUnit.Currency))< 300);
                    {
                    // Algo Working
                    }
                    ExitLong();
                    ExitShort();
                    Disable();

                    // Algo is disable till new manual activation

                    Comment


                      #11
                      I don't see the need to use a loop, since hitting that condition and stopping should be a one time occurrence for the instance of the script. Also you want to work on CalculateOnBarClose = false if intrabar profit should be considered for GetProfitLoss.

                      Comment


                        #12
                        Thanks for the suggestions, notes taken.

                        Everytime than I start the Algo manually, the variable GetAccountValue(AccountItem.RealizedProfitLoss) reset to Zero, right ?

                        Thanks

                        Comment


                          #13
                          Pier, no it would not reset - the account value it not tied to your strategy instance. The account pnl itself would be only reset on a new day / session.

                          Comment


                            #14
                            so, the GetAccountValue(AccountItem.RealizedProfitLoss) doesn't give the RealizedProfitLoss for the day ?
                            According to the help, it seems that historical data is not included, as you can see here

                            Definition
                            Returns information about the account the strategy is running on.


                            Method Return Value

                            A double value that represents the specified account item. A value of 0 will be returned on historical bars.

                            Comment


                              #15
                              Correct it would give you access to the account pnl, just like the figure in the Control Center > Accounts tab. And you could not access historical values. However the reset is not tied to your starting / stopping a strategy instance, that would only occurs as the account itself rolls into the new session / trading day.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              648 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              369 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              108 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              572 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              573 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X