Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trend Following Script

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

    Trend Following Script


    Hello Support,

    how to code following TradeStation EasyLanguage Script in NinjaTrader:
    ------------------------------------------------------------------------------------------------
    // Entries and Exits
    Buy next bar at highD(0) stop;
    Sellshort next bar at lowD(0) stop;
    End;

    // Stop loss
    setstopcontract;
    setstoploss(MyStop);
    setprofittarget(myprofittarget);
    setdollartrailing(mytrailingstop);

    ----------------------------------------------------------------------------
    ​The problems I have in implementing the above script is the Stop Loss part.

    When I use managed orders I can implement:

    ...
    EnterLongStopMarket(...);
    EnterShortStopMarket(...);
    ...

    and this is working, but when I add:

    SetStopLoss(...);
    SetProfitTarget(...);
    ​​​​
    Can you help?

    Regards
    Oliver


    #2
    Hello Oliver,

    Thanks for your post.

    Set methods (such as SetStopLoss()/SetProfitTarget()) or Exit methods (such as ExitLongLimit()/ExitLongStopLimit()) could be used to place stop/targets from your strategy.

    Set methods prep NinjaTrader to submit protective order when an entry order is filled. These methods should be called in OnStateChange() when the State == State.Configure.

    See the help guide documentation below for more information about these methods.

    SetStopLoss(): https://ninjatrader.com/support/help...etstoploss.htm
    SetProfitTarget(): https://ninjatrader.com/support/help...ofittarget.htm
    SetTrailStop(): https://ninjatrader.com/support/help...ttrailstop.htm

    Exit methods should be called in OnBarUpdate() if you decide to use them for your stop/target orders. You could consider checking if Position.MarketPosition is equal to MarketPosition.Long or MarketPosition.Short to detect if you are in a Long or Short position and then call your Exit methods within that condition.

    Managed Approach Order Methods: https://ninjatrader.com/support/help...d_approach.htm

    I have attached a simple example script demonstrating how to use Exit methods for stops/targets that you could view.

    And, you could find an example of implementing Trailing Stop using Exit methods in the Strategy Builder here: https://ninjatrader.com/support/foru...der#post806596
    Attached Files
    Last edited by NinjaTrader_BrandonH; 06-26-2023, 10:24 AM.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    134 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X