• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 rickyblah12, Today, 08:17 PM
        0 responses
        4 views
        0 likes
        Last Post rickyblah12  
        Started by mrlucky1x, Today, 08:07 PM
        0 responses
        2 views
        0 likes
        Last Post mrlucky1x  
        Started by uday12, Today, 07:21 PM
        0 responses
        3 views
        0 likes
        Last Post uday12
        by uday12
         
        Started by voltlon, Today, 05:18 PM
        0 responses
        6 views
        0 likes
        Last Post voltlon
        by voltlon
         
        Started by Bobisam, Today, 04:57 PM
        0 responses
        8 views
        0 likes
        Last Post Bobisam
        by Bobisam
         
        Working...
        X