Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    BertrandNinjaTrader Customer Service

    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.
          BertrandNinjaTrader Customer Service

          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.

                BertrandNinjaTrader Customer Service

                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.
                      BertrandNinjaTrader Customer Service

                      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.
                          BertrandNinjaTrader Customer Service

                          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.
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by andrewtrades, Today, 04:57 PM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by chbruno, Today, 04:10 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              436 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post FAQtrader  
                              Started by rocketman7, Today, 09:41 AM
                              5 responses
                              19 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X