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 Print the CurrentPrice and the Stop Price everytime the price or stop moves

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

    How to Print the CurrentPrice and the Stop Price everytime the price or stop moves

    If we set a Trailing Stop, how do we:

    Print(string.Format("Price={0} StopPrice={1}", Close[0], StopPrice))

    What function gets called everytime the stop moves (ie. the trailing stop moves) or the price moves? I.e where do I put the above line of code so that I can see every determination/update of the value of the stop price?

    This would be extremely useful for debugging what is going on with my stops as they do not appear to be doing what I think they should be.

    The thing I am trying to determine is what happens if I use SetTrailStop(stopPips) in OnBarUpdate every single bar?

    Say we are long and that the price has moved down and therefore the stop price has stayed where it is. Does the next call to SetTrailStop(stopPips) move the stop down, or does it leave it alone?
    Last edited by AlgoJason; 02-07-2018, 04:50 PM.

    #2
    Hello AlgoJason,

    I'm not understanding your inquiry.

    When you say how do we and then you have a print that prints the close price and a variable named StopPrice, what are you looking to do with these?

    Anytime an order is update, such as a price change or state change, this will trigger OnOrderUpdate().

    Below is a publicly available link to the help guide on OnOrderUpdate().


    You could print the <order>.StopPrice to print the price of the stop order object.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the fast reply.

      I have tried to do that in the attached example TraceStopPrice.cs. The stop is getting set, and it is getting hit, as the attached screen capture of the chart shows. But the OnOrderUpdate code is not outputting what the stop price is.

      How do I trace the stop price? (it should be 944.00).

      The NT output is:

      lastClose=945.75 stop=0 AFP=0
      lastClose=945.75 stop=0 AFP=0
      lastClose=945.75 stop=0 AFP=0
      lastClose=945.75 stop=0 AFP=945.75
      What I want/expected the out put to be was something like...

      lastClose=945.75 stop=944.00 AFP=0
      lastClose=945.75 stop=944.00 AFP=0
      lastClose=945.75 stop=944.00 AFP=0
      lastClose=945.75 stop=944.00 AFP=945.75
      lastClose=xxx stop=944.00 AFP=945.75
      lastClose=yyy stop=944.00 AFP=945.75
      ...
      ...
      lastClose=944.00 stop=944.00 AFP=945.75
      Attached Files
      Last edited by AlgoJason; 02-07-2018, 05:37 PM.

      Comment


        #4
        Solution here:

        I found the solution to the problem here:
        Support for the development of custom automated trading strategies using NinjaScript.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Belfortbucks, Today, 09:29 PM
        0 responses
        6 views
        0 likes
        Last Post Belfortbucks  
        Started by zstheorist, Today, 07:52 PM
        0 responses
        7 views
        0 likes
        Last Post zstheorist  
        Started by pmachiraju, 11-01-2023, 04:46 AM
        8 responses
        151 views
        0 likes
        Last Post rehmans
        by rehmans
         
        Started by mattbsea, Today, 05:44 PM
        0 responses
        6 views
        0 likes
        Last Post mattbsea  
        Started by RideMe, 04-07-2024, 04:54 PM
        6 responses
        33 views
        0 likes
        Last Post RideMe
        by RideMe
         
        Working...
        X