Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using Built-In Variables

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

    Using Built-In Variables

    I am trying to create a dynamic stop condition so that my strategy will be more responsive to market volatility. At the time of an order (I'm entering with a limit order set at the current ask for longs and bid for shorts) I set Variable0 to either a lower band value for a long, or an upper band value for a short. I am using the strategy wizard so that the trailingstop value gets set to variable0 in the initialize portion of the code. My expectation is that for each entry a new value for variable0 is set, and that is good until the next trade is entered. However, when I test the strategy the stop never executs. The only way I can get out of a position is through a profit target exit, or the close of the session. What am I doing wrong?
    DaveN

    #2
    Hello,

    Thanks for your note.

    A Dynamic stop would actually take editing the code manually and cannot be done through the strategy wizard, please let me know if you are confiterable in doing this as once unlocked you will not be able to use the strategy wizard with this strategy again.

    The only way to do it in the strategy wizard is to not to ue the stops and targets page, but to use the Conditions and exit page and add a Do The Following of Exit Long position by a stop order You must call this on every onBarUpdate that you are in the position.

    Let me know if I can be of further assistance.
    BrettNinjaTrader Product Management

    Comment


      #3
      Using Variable0 for Dynamic Stops

      I am comfortable programming in NTScript, though I have never been able to get stops using variable0 to work. Do you have some reference code that shows how to do this? For instance say in the code you are running an average of the highs and a separate average of the lows. When a long executes I would like to set the stop to 2 ticks below that average low value, and then udpate it as the price moves up. What would that look like in code, (if you have some example similar to that)?
      Thanks
      DaveN
      Last edited by daven; 01-14-2011, 02:05 PM. Reason: Misspellings

      Comment


        #4
        Hello,

        Sure here is the sample code on how to do this.

        Essentially you have to move it out of Initialize() so it update on each OnBarUpdate().



        Let me know if I can be of further assistance.
        BrettNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        58 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