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 NullPointStrategies, Today, 05:17 AM
    0 responses
    52 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
    43 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    47 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X