Announcement

Collapse
No announcement yet.

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 NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        54 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        70 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X