Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

SMA Stopp Loss with Strategy Builder

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

    SMA Stopp Loss with Strategy Builder

    Trying to implement a stopp loss using an adjusted SMA (7 +5) through Strategy Builder
    Running on a Daily Chart

    Calculate on bar close

    Input:

    SMA_Stopp_Void ( bool, default = false ) to switch the stopp function on and off in the strategy

    Conditions and Actions:

    Tab1

    If all:

    Position.marketPosition = MarketPosition.Long
    SMA_Stopp_Void = true
    GetCurrentAsk(DefaultInput) < (SMA(7)0)+5)

    Do the following:

    ExitLong(Position.Quantity,@"SMA_Stopp","")

    ....Draw....."something" ( not yet defined )

    Tab2

    vice versa for Short Position

    ---------------------

    nothing happens?


    #2
    Hello pmmkm,

    Thanks for your post.

    Are you testing this in the strategy analyzer, playback using market replay data, or live data?

    Using Calculate.OnBarClose with live data means your code would run once at the end of the day. Is that what you want?
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul,

      no, I want to run this first of all with live data, once the price is crossing the SMA, the position should be stopped out.

      I use three types of stopps.

      the profit Stopp with fixed amount
      the Stopp Loss with fixed amount,
      the SMA Stopp

      btw. my first tab is

      If All

      state = state.realtime

      Then

      print (position.market.position to string())
      print (position.quantity to string ())


      the profit and loss is calculated on bar close what is ok, and the bracket order is set for stopp and for loss.

      Do I have to change the calculate on to "each tick" .....to do this?

      EDIT: It should work as a comparison !!!! If the stopp loss is closer then the stopp loss is valid, if the SMA Stopp is closer the stopp loss is becoming the active order and replaces the stopp loss order. .....alternatively also the two stopp orders can be visible and once one of them is released the other should be cancelled.

      EDIT2:

      While I am writing a come to the conclusion whats wrong, the stop order I have to set in the Stops and Targets section !!!!!!!
      :-)
      Last edited by pmmkm; 01-29-2019, 08:46 AM.

      Comment


        #4
        Hello pmmkm,

        Thanks for your reply and clarification.

        To be reactive to price crossing the SMA as it happens then yes you would want to use the Calculate.OnEachTick.

        With a moving stop loss (the SMA), one area of concern is if the SMA value travels close to the fixed stop or profit targets, if they should place an exit order at the same time, you may have an overfill condition which will disable the strategy or you may end up in the opposite position. What you could do is, since you know your fixed stop and profit is to check the value of the SMA to those price levels added to the position Average price which is your entry price and if it is within a couple of ticks to then set a bool to false which would need to be in the conditions of the SMA exit such that the SNMA exit, in that case, would not fire and would allow the profit/stop to execute normally.
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Aviram Y, Today, 05:29 AM
        4 responses
        11 views
        0 likes
        Last Post Aviram Y  
        Started by algospoke, 04-17-2024, 06:40 PM
        3 responses
        27 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by bmartz, 03-12-2024, 06:12 AM
        3 responses
        30 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Started by gentlebenthebear, Today, 01:30 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by cls71, Today, 04:45 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X