• 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

Moving stop losses question.

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

    Moving stop losses question.

    E.G.
    if(Close[0] > Position.AvgPrice + 50 * TickSize)

    I know that this will test to see if price is above +50 ticks THEN will do whatever code is underneath...in the thread I got it from, it essentially set a stop loss with about 30 ticks at that point.


    However, I have a couple questions.

    1) Can I use something more immediate than Close[0]? Can I use "Bid[0]" or something similar?

    2) What if I have 2 or 3 of the if statements above...what keeps the condition from actually moving the stop loss backwards as the condition changes?

    IE
    the example above moves to 30 ticks...but what if during that time...Close[0] moves back below 50 ticks...if I put one at Close{0} > 30 (put stop loss at +15)...NOW this one is true...will it reset my stop loss now that the +50 is no longer true?

    How should I work around that? Let's say at entry I set a stop loss at 15 ticks back. At +10 I set my stop loss 5 ticks back from entry. At 20 ticks I set my stop loss at 5 ticks from entry...etc. It's not always the same amount, nor is it necessarily that consistent to use the SetTrailStop().

    #2
    Hello Darth_Trader,
    Thank you for writing in.
    1. If you would like to use the bid or ask prices you can use the OnMarketData() method. It might look something like this:
    Code:
    protected override void OnMarketData(MarketDataEventArgs e)
    {
        if(e.MarketDataType == MarketDataType.Bid && e.Price > Position.AvgPrice + 50 * TickSize)
        {
            //Do Something
        }
    }
    The OnMarketData() method has access to intrabar data even when CalculateOnBarClose is set to true. For more information on the OnMarketData() method, please see our help guide here: http://ninjatrader.com/support/helpG...b=onmarketdata

    If you simply want to use the last traded price, you can set CalculateOnBarClose=false; in your Initialize() method and continue using OnBarUpdate(). For example:
    Code:
    protected override void Initialize()
    {
        CalculateOnBarClose = false;
    }
    protected override void OnBarUpdate()
    {
        if(Close[0] > Position.AvgPrice + 50 * TickSize)
        {
            //Do Something
        }
    }
    2. Yes it will continue moving your stop loss anytime that condition is true.
    At +10 I set my stop loss 5 ticks back from entry. At 20 ticks I set my stop loss at 5 ticks from entry
    This part of what you are saying would not require any additional code because the stop loss is adjusted to the same value in relation to the entry price. So it could be +5 ticks or +100 ticks but the stop loss would always be 5 ticks below the entry price.

    Here is an example for OnBarUpdate() based on what you were saying:
    Code:
    protected override void Initialize()
    {
    SetStopLoss(CalculationMode.Ticks, 15); //Set initial stop loss
    }
    protected override void OnBarUpdate()
    {
        if(Close[0] > Position.AvgPrice + 10 * TickSize && Close[0] <= Position.AvgPrice + 20 * TickSize )
        {
            SetStopLoss(Position.AvgPrice - 5 * TickSize);
        }
        else if(Close[0] > Position.AvgPrice + 20 * TickSize)
        {
            SetStopLoss(Position.AvgPrice - 5 * TickSize); 
        }
    }
    NOTE (when dynamically modifying the stop loss): You should always reset the stop loss price/offset value when your strategy is flat, otherwise the last price/offset value set will be used to generate your stop loss order on your next open position.
    Please see our help guide for more information on the SetStopLoss() method: http://ninjatrader.com/support/helpG...ub=setstoploss

    Please let us know if we may be of further assistance.
    Michael M.NinjaTrader Quality Assurance

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by tonynt, Today, 01:42 AM
    0 responses
    6 views
    0 likes
    Last Post tonynt
    by tonynt
     
    Started by NT-Roland, Yesterday, 04:36 PM
    0 responses
    3 views
    0 likes
    Last Post NT-Roland  
    Started by Newtrader101, Yesterday, 03:40 PM
    2 responses
    11 views
    0 likes
    Last Post Newtrader101  
    Started by Branpo, Yesterday, 02:58 PM
    2 responses
    12 views
    0 likes
    Last Post Branpo
    by Branpo
     
    Started by sdauteuil, Yesterday, 02:09 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X