• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Daily loss limit examples

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

    #31
    Originally posted by NinjaTrader_Jim View Post
    Hello Trader17,


    If you change the strategy to Calculate.OnEachTick or OnPriceChange, line 53 if (Bars.IsFirstBarOfSession) will be true for each tick of that bar. I would suggest adding an IsFirstTickOfBar check with that condition to ensure it only happens once on that bar.

    Please let us know if you have any questions.
    Thank you. In this statement for Line 53 I would leave it as is because the PnL is reset each day on the first session bar, correct? And I add IsFirstTickOfBar in the logic itself to prevent calculation more than once for the last closed bar. Correct?

    Thanks a lot.

    Comment


      #32
      Originally posted by NinjaTrader_Jim View Post
      Hello Trader17,

      Bools return a true or false value and checking if (YourBool == true) is equivalent to checking if(YourBool). It can be very helpful and will at times be necessary to test out the concept to observe the behavior. For example, you could create a couple conditions that print a message if the condition becomes true.

      if (IsFirstTickOfBar) Print("Condition 1 This is true"");

      if (IsFirstTickOfBar == true) Print("Condition 2 This is true");

      We look forward to being of further assistance.
      So are both correct for Ninja Script? I know == True is meaningless as it is what is returned upon checking the logic.
      Thank you.

      Comment


        #33
        Hello Trader17,

        There will be countless questions in regards to what is possible with C#/NinjaScript and what is correct syntax. It will be necessary for you as an individual working on the script to test your questions to see if what you think you have written is correct or if it is not. For that reason, I will leave the question presented in #32 as an exercise to you. Please set up test conditions similar to my reply in which you have quoted. Testing this will be a straightforward answer to your question that you can set up on your end.

        Thank you. In this statement for Line 53 I would leave it as is because the PnL is reset each day on the first session bar, correct? And I add IsFirstTickOfBar in the logic itself to prevent calculation more than once for the last closed bar. Correct?
        If you add a check for IsFirstTickOfBar to the condition on line 53 in Chelsea's script and change the script to use Calculate.OnPriceChange or Calculate.OnEachTick, then you will restrict the code to only reset the daily PnL once, and not multiple times per bar.

        Many of these questions will be best answered by testing on your own. Our role is not to provide examples that perform multiple tasks so you can copy and use in your custom works, but to educate you on how each concept works. My recommendation would be to start with simple test scripts so you can get used to working with scripts that calculate OnEachTick or OnPriceChange, and then once you have mastered these concepts, combine the behavior with the Daily Loss example.

        We look forward to being of further assistance.
        JimNinjaTrader Customer Service

        Comment


          #34
          Originally posted by NinjaTrader_Jim View Post
          Hello Trader17,

          If you add a check for IsFirstTickOfBar to the condition on line 53 in Chelsea's script and change the script to use Calculate.OnPriceChange or Calculate.OnEachTick, then you will restrict the code to only reset the daily PnL once, and not multiple times per bar.

          We look forward to being of further assistance.
          Thanks. I was going to leave Line 53 as is with Calculate set to Each Tick and just use Is First Tick of Bar in the condition logic to restrict it from calculating entry logic on each tick. And Script will still recognize the first bar of session with calculate set to calculate on each tick, correct?

          Or to reset the PnL only once while using Calculate on Each Tick if I use Is First Tick of Bar and First Bar of Session keeps it from resetting on every tick in the first session bar as you mentioned. So as long as a tick is traded in the new session it assumes it is the first bar of session without waiting for it to close and we are calculating on each tick it will reset the PnL to zero only once, correct?

          Thank you.
          Last edited by Trader17; 04-17-2019, 01:55 PM.

          Comment


            #35
            Now when this is used in a strategy it calculates the PnL on all trades for the day including historical trades. What if I want to start it for just a couple of hours anytim I wish and have the PnL start from zero at that point? Anything in Script that can prevent calculating historical trades for the day till I start it?
            Thank you.

            Comment


              #36
              Hello Trader17,

              I noticed that you also have a ticket open regarding this item with my colleague, Kate, over email. We ask that you continue working with the current technician assigned to your ticket without opening a new ticket. This helps us to ensure that the same technicians are not working on the same items which improves our ability to serve all of our clients.

              Thanks. I was going to leave Line 53 as is with Calculate set to Each Tick and just use Is First Tick of Bar in the condition logic to restrict it from calculating entry logic on each tick. And Script will still recognize the first bar of session with calculate set to calculate on each tick, correct?
              We should be clear that our role is not to provide recommendation for modifying single lines of code. Our role is to provide educational information on how to use the software. As with learning any new language there will be a necessary level of testing to understand how to work with that language. This sort of hypothetical question would be best answered by testing with prints to see the behavior yourself.

              Or to reset the PnL only once while using Calculate on Each Tick if I use Is First Tick of Bar and First Bar of Session keeps it from resetting on every tick in the first session bar as you mentioned. So as long as a tick is traded in the new session it assumes it is the first bar of session without waiting for it to close and we are calculating on each tick it will reset the PnL to zero only once, correct?
              The first bar of a session is determined by the Trading Hours template. The first tick of that bar will have IsFirstTickOfBar == true and Bars.IsFirstBarOfSession == true. This is another item that would be best answered by testing with prints to observe the behavior.

              Now when this is used in a strategy it calculates the PnL on all trades for the day including historical trades. What if I want to start it for just a couple of hours anytim I wish and have the PnL start from zero at that point? Anything in Script that can prevent calculating historical trades for the day till I start it?
              You can have the strategy return from historical processing in OnBarUpdate with if (State == State.Historical) return;

              Please understand that while we are here to assist you on your journey, our support services are not equipped to handle large numbers of questions that involve confirming a concept, and many such items are best understood through testing. If you have any additional questions, please attach the debug prints you are using and the output received so we can offer further direction to help you test these items to better understand these concepts.

              We look forward to being of further assistance.
              JimNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by afoschini, Today, 02:57 AM
              0 responses
              1 view
              0 likes
              Last Post afoschini  
              Started by jecoyeko, Today, 12:45 AM
              0 responses
              6 views
              0 likes
              Last Post jecoyeko  
              Started by Newtrader101, Yesterday, 06:31 PM
              1 response
              9 views
              0 likes
              Last Post NinjaTrader_EricB  
              Started by Tyler7498, Yesterday, 07:34 PM
              0 responses
              4 views
              0 likes
              Last Post Tyler7498  
              Started by Woomera, Yesterday, 07:24 PM
              2 responses
              10 views
              0 likes
              Last Post Woomera
              by Woomera
               
              Working...
              X