Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need a Hand Setting Stop Loss to Low of Previous Entry Bar and Set Profit Target too

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

    #16
    Hi grimmer01​,

    Another thing you can try that may make things a bit easier.
    Define different doubles for your Stop/Profit/BreakevenTarget as soon as you enter a trade.

    Add "&& (Position.MarketPosition == MarketPosition.Flat)" to your conditions so these numbers don't change once you're already in the trade.


    I modified your code a bit to show what I mean. You might have to mess around with it a bit but should hopefully lead you in the right direction.
    I also added some prints you can reference on your NinjaScript Output so you can make sure you have the correct numbers.

    Hope it helps!
    Attached Files
    TradeSaber Inc.NinjaTrader Ecosystem Vendor - TradeSaber Inc.

    Comment


      #17
      Originally posted by grimmer01 View Post
      Thanks again Emily for your feedback.

      I feel like we're going down a rabbit hole and this is getting a bit far field.

      I am really baffled that writing this code is taking this many replies...haha.

      With an 'unlocked' strategy, why is writing the code this complex? I've contacted 3, third party vendors, none of which have replied to me. I've written 4 or 5 replies to this thread.so far. What am I missing about this part of the strategy that no one can figure out? I am really surprised.

      Emily, please lend some insight that is not extremely vague. I am kind of desperate for any help that I can use in my strategy. TradeSaber gave a decent reply and I can use for manual entries. I am trying to make this a fully automated strategy. It's as simple as Target = AveragePositionPrice + ( close of Signal Bar - Low of Bar prior to Signal Bar).

      thanks in advance.
      Hello grimmer01,

      Thank you for your reply.

      TradeSaber's input is appreciated and part of what makes our forum community great. In the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services or one on one educational support in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our associates.

      That said, through email or on the forum we are happy to answer any questions you may have about NinjaScript if you decide to code this yourself. We are also happy to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.

      You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. I understand you have reached out to third-party vendors already; the NinjaTrader Ecosystem has affiliate contacts who provide educational and consulting services. Please let me know if you would like our NinjaTrader Ecosystem team to follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one-on-one educational services.

      Otherwise, I am still glad to offer some suggestions to help you through the debugging process. What I suggest from here is to add Print() statements throughout your script to understand what is happening and narrow down the cause of any errors or unexpected behavior from your strategy. I mentioned this in post number 5 of the thread - prints are a highly valuable resource for debugging a script and working with it to get it to behave exactly as expected. For example, when your signal is hit I recommend saving the CurrentBar to a variable and print that variable to ensure it is the correct bar index where the signal was hit. When an entry is filled within OnExecutionUpdate() you can print the variable with that saved bar number again to make sure it is still the expected value. Next, subtract that saved bar number from CurrentBar to get the number of barsAgo that the signal was hit, and make sure that the value is greater than 0, etc. Adding in print statements along the way for all values used in your script can help narrow down issues. Here is the link I previously shared regarding using prints to debug, along with a couple of other debugging resources:




      I understand my responses may seem vague; some error messages do not immediately show us what the cause might be or where it is located in your script so I do not have a direct answer for you. I am glad to offer these suggestions to you so that you can add prints as a debugging tool and figure out what the cause might be. If you are getting unexpected values in your prints to the NinjaScript Output window, please feel free to save the output and share it with me as that might help to identify the next debugging step.

      I appreciate your time and patience. Please feel free to reach out with any additional questions or concerns.​

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      57 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      133 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      73 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      50 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X