Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Daily loss limit examples

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

  • NinjaTrader_Jim
    replied
    Welcome to the forums TheTradingNetwork!


    There would not be a parameter to add, the logic will have to be created in the Strategy Builder. Please see post 1 for the DailyLossLimitMultiTradeExample_NT8 example to see how this logic can be set up.

    We look forward to assisting.

    Leave a comment:


  • TheTradingNetwork
    replied
    Hey everyone, I'm curious if it's possible to do something like this directly inside the strategy builder without manually coding it? For instance if I have a strategy working properly from the Strategy Builder, is there a way to allow for the ability of a daily loss limit or profit limit with a combination of the strategy builder parameters?

    TIA

    Leave a comment:


  • NinjaTrader_Jim
    replied
    Hello jpatri,

    There is no ETA and feature requests are tracked internally as the requests often contain internal discussion which we would not want to have public facing.

    Feature Request Disclaimer.

    We receive many requests and cannot reasonably implement all requested features or changes. Interest is tracked internally and if enough interest is tracked, it would be weighed against how feasible it would be to make those changes to consider implementing.

    When new features are implemented, they will be listed in the Release Notes page of the Help Guide. The ID number will be different than the internal feature request tracking ID, but the description of the feature will let you know if that feature has been implemented.

    Release Notes -
    https://ninjatrader.com/support/help...ease_notes.htm

    Let us know if you have any questions.

    Leave a comment:


  • jleira
    replied
    Originally posted by JonTansey View Post
    Rookie question here. How do I view the DailyLossLimitExample_NT8.zip (1.6 KB, 1 view) once I import it?
    After Import it you have to enable the strategy on your chart or you can try to understand the logic of the script with the ninjascript editor and copy it on your own strategy

    Leave a comment:


  • jpatri
    replied
    Hello,
    Does anyone know the status of the "loss limit tool for NinjaScript Strategies" ID# SFT-2936 and a link to track its progress or release? An indicator that stops my trades if I gain or loose set mounts would be a major improvement to my stratagies!
    Thank you!

    Leave a comment:


  • NinjaTrader_Jim
    replied
    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.

    Leave a comment:


  • Trader17
    replied
    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.

    Leave a comment:


  • Trader17
    replied
    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.

    Leave a comment:


  • NinjaTrader_Jim
    replied
    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.

    Leave a comment:


  • Trader17
    replied
    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.

    Leave a comment:


  • Trader17
    replied
    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.

    Leave a comment:


  • NinjaTrader_Jim
    replied
    Hello Trader17,

    Thanks for your patience.

    So in the Script by Chelsea I basically change it ti calculate on each tick or price change and both use the common term IsFirstTickOfBar? And while doing so now the bar currently forming will take "0" as its index and the bar that just closed will take "1' off which I need to calculate the strategy. Correct? As when we use Calculate on bar close then "0" is the one that just closed.
    Changing the script to Calculate.OnEachTick or Calculate.OnPriceChange will have the script's OnBarUpdate method iterate with each new tick or price change. BarsAgo 0 values for Price Series and plots (Close[0]) will update with each new iteration instead of having OnBarUpdate iterate once when the bar closes (Calculate.OnBarClose.) If you would like to have some code calculate on bar closes when using Calculate.OnEachTick or Calculate.OnPriceChange, you will want to use BarsAgo 1 references on the first tick of a new bar. See IsFirstTickOfBar linked in post #16.


    And in this code the first line that uses the Close[0] technically is not a close of the bar forming as I will use OnTickUpdate but just the term "close" is used, correct? How do you get the code in a block in the post? Am I supposed to copy and paste it and put it between Code and /Code?
    Close[0] represents the data point for the close of the bar. When calculating on each tick or on price changes, this value is updated with each new tick or price change. Once the bar closes, then the index will shift (I.E. Close[0] becomes Close[1].) There is no OnTickUpdate method. You can use [CODE] blocks similar to [QUOTE] blocks to post formatted code.


    Also using the same code I guess I can also put a limit on Daily Profit as GetUnrealizedProfitLoss returns a positive number for profit and negative number for loss. So I can add another input like ProfitLimit similar to LossLimit if I need to stop trading after achieving a set amount of profit for the day, correct?

    How do I make a duplicate of this strategy to play around with?
    Yes, you will have full control over the strategy logic and could model similar behavior for a daily profit behavior. You can open your strategy in the NinjaScript Editor, right click and select Save As to create a duplicate strategy.

    We look forward to being of further assistance.

    Leave a comment:


  • NinjaTrader_Jim
    replied
    Hello Trader17,

    I have seen your messages.

    I am approaching the end of my shift and I will be replying tomorrow during our regular office hours.

    Thanks for your patience.

    Leave a comment:


  • Trader17
    replied
    Also using the same code I guess I can also put a limit on Daily Profit as GetUnrealizedProfitLoss returns a positive number for profit and negative number for loss. So I can add another input like ProfitLimit similar to LossLimit if I need to stop trading after achieving a set amount of profit for the day, correct?

    How do I make a duplicate of this strategy to play around with?

    Thanks a lot.
    Last edited by Trader17; 04-15-2019, 01:33 PM.

    Leave a comment:


  • Trader17
    replied
    Originally posted by NinjaTrader_Jim View Post
    Hello Trader17,

    You can then set Calculate.OnEachTick or OnPriceChange and then place your trading logic in a check for IsFirstTickOfBar. BarsAgo 0 indexes should then be BarsAgo 1 indexes since you are referencing the bar that had just closed within that logic.

    The block of code checking daily PnL would not have to be inside any logic for IsFirstTickOfBar and can still use BarsAgo 0 references because it is calculating on each tick or price change.

    Code:
    // if in a position and the realized day's PnL plus the position PnL is greater than the loss limit then exit the order
    if (Position.MarketPosition == MarketPosition.Long
    && (currentPnL + Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0])) <= -LossLimit)
    {
    //Print((currentPnL+Position.GetProfitLoss(Close[0], PerformanceUnit.Currency)) + " - " + -LossLimit);
    // print to the output window if the daily limit is hit in the middle of a trade
    Print("daily limit hit, exiting order " + Time[0].ToString());
    ExitLong("Daily Limit Exit", "long1");
    }
    We look forward to being of further assistance.
    And in this code the first line that uses the Close[0] technically is not a close of the bar forming as I will use OnTickUpdate but just the term "close" is used, correct? How do you get the code in a block in the post? Am I supposed to copy and paste it and put it between Code and /Code?

    Thanks.
    Last edited by Trader17; 04-15-2019, 01:32 PM.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by averoos, Today, 03:51 PM
0 responses
8 views
0 likes
Last Post averoos
by averoos
 
Started by crazyhorse2393, Today, 03:31 PM
2 responses
11 views
0 likes
Last Post crazyhorse2393  
Started by wooofad, Today, 02:56 PM
1 response
11 views
0 likes
Last Post NinjaTrader_Kate  
Started by jalley, Today, 02:29 PM
1 response
5 views
0 likes
Last Post NinjaTrader_Kate  
Started by dtl-saw, Today, 02:53 PM
1 response
9 views
0 likes
Last Post NinjaTrader_ChrisL  
Working...
X