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

filter to turn off a strategy after its up/down by a specified $ amount/%

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

    filter to turn off a strategy after its up/down by a specified $ amount/%

    How do I access the current PnL from a specified time window only. For example, let's say I have strategy A taking trades only from 6am to 8am and from 12pm to 1pm and I want to create a filter that will stop it during either of those time slots if it is up or down x dollars/% during but I don't want this to affect the trading for the next time slot.

    #2
    Hello gordongekko,

    You can include a time filter with your condition that checks the PnL.

    Below is a public link to a reference sample that demonstrates.


    As well as a public link to a video.
    Understand the fundamentals of basic strategy creation by developing an actual strategy using the NinjaTrader Strategy Builder.2:45 Opening a Strategy Builde...
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I have time filters currently. However, if I gate access to the trade collection data using a time filter that will only prevent it from starting the check during that time period but it will still include PnL from other time periods in the calculation. If use a time filter to access something like:

      currentPnL += SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitCurrency;

      How far is the look back period on this by default? What I need to do is have it only check trade data from a specified time window that will be known at startup. For example, let's say I want it to check PnL starting at 9:30 am est and stop at 11 am est and I only want it to reference trades that occurred at a time that was >= 9:30 am est for the current 24 hour period (calendar day in my time zone). At 11am est it will stop checking. I understand how to restrict the start and stop time of the PnL check but not how to limit it's reference range.
      Last edited by gordongekko; 03-12-2018, 11:38 AM.

      Comment


        #4
        Hello gordongekko,

        The line of code gets the performance of the most recent trade.

        When is this code being run?

        Are you allowing this to run outside of the time filter?

        I'm not quite sure what you mean by lookback period. Are you referring to the orders ago index?

        Are you wanting to loop through the performance collection and filter by the order objects time?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I'm currently using time filters only for entries but I want to add an additional filter to disable new entries if the strategy hits a predetermined drawdown value. The strategy will be allowed to trade during several time windows that will only allow orders to go out during those times. If at any point during those time windows the strategy loses a specified amount I disable new orders either using a bool or drawdown <= a maxDrawdown value. What I need is the syntax for checking PnL during a specific time slot only. I don't want it to check PnL outside of that time slot. For example:

          time window 1: 12am to 2am
          time window 2: 5am to 8 am
          time window 3: 12pm to 1pm

          When its monitoring PnL during time window 2 I don't want it to count trades that occurred during time window 1 and when its checking PnL for time window 3 I don't want it being able to access trade PnL from time windows 1 and 2. I'm assuming the default value is the PnL for the time template that the instrument trades on and this resets every time a new daily bar starts.
          Last edited by gordongekko; 03-12-2018, 03:05 PM.

          Comment


            #6
            I should be able to achieve this by keeping a cumulative PnL assigned to a double and then resetting that double in between trading time windows or just making a separate var for each time window.

            The only other potential issue is if a trade is opened in one time window but closed in another.
            Last edited by gordongekko; 03-12-2018, 03:44 PM.

            Comment


              #7
              Hello gordongekko,

              I'm not quite following how this could not be achieved with a time filter.

              If the time is between these two times, accumulate the last trade to the pnl variable..

              Are you saying you have a condition that only triggers between certain times and the condition is triggering outside of those times?
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by PaulMohn, Today, 12:36 PM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by yertle, Yesterday, 08:38 AM
              8 responses
              36 views
              0 likes
              Last Post ryjoga
              by ryjoga
               
              Started by rdtdale, Today, 01:02 PM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by alifarahani, Today, 09:40 AM
              3 responses
              16 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by RookieTrader, Today, 09:37 AM
              4 responses
              19 views
              0 likes
              Last Post RookieTrader  
              Working...
              X