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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    45 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    31 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X