• 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

Creating a trailing stop based on indicator value

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

    Creating a trailing stop based on indicator value

    I am trying to write a strategy where I am using a trailing stop. And I'd like to use an indicator called ATRTrailing to act as the stop. Basically it plots itself above or below the price and acts as a stoploss and changes from bar to bar.

    Though I am able to compile the code, when I look at the chart the strategy is not placing any stop loss orders. Can someone please help me to write the correct syntax or help to understand what is wrong here?

    SetStopLoss(CalculationMode.Price,ATRTrailing(4, 10, 0.005)[1]);

    I also tried the other syntax but that did not work either.
    SetTrailStop(CalculationMode.Price,ATRTrailing(4, 10, 0.005)[1]);

    Very much appreciate your help in advance.

    #2
    pandyav, you want to be working with SetStopLoss here in OnBarUpdate() and supply the changing ATR trail price based value on each bar as it updates. A SetTrailStop in mode .Price would not be meaningful, as you would not trail by a price amount but ticks, points or percent offsets for example.

    Where (in which method) were you working with the SetStopLoss call?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      I am entering the StopLoss call under OnBarUpdate method. Here is the full code. It compiles well but when I look at the strategy execution on the chart, I do not see the StopLoss statement being executed where it should be. I simply want the StopLoss to trend based on SuperTrend indicator.

      Much appreciate your help in advance.

      if (CurrentBar < 21)
      return;
      if (anaSuperTrendU11(3, 2.5, 15, false, anaSuperTrendU11BaseType.Median, anaSuperTrendU11OffsetType.Default, anaSuperTrendU11VolaType.True_Range).StopDot[1] <= Low[1]
      && (ToTime(Time[0]) >= 60000 && ToTime(Time[0]) <= 160000)
      && CrossAbove(SlopeSimple(ZeroLagTEMA(10).ZeroTEMA, false, false, 10, SlopeType.SMA).Slope, 0, 1)
      && Rising(VisualEMA(11, false, true, VisualEMACalcMode.Visual, VisualEMAPeriodType.Minute, 120, VisualEMAPriceType.Close).MTF_EMA) == Rising(DefaultInput))
      {
      EnterLong(1,"Long");
      }
      SetStopLoss(CalculationMode.Ticks,anaSuperTrendU11 (3, 2.5, 15, false, anaSuperTrendU11BaseType.Median, anaSuperTrendU11OffsetType.Default, anaSuperTrendU11VolaType.True_Range).StopDot[0]);
      BackColorAll = (ToTime(Time[0]) >= 60000 && ToTime(Time[0]) <= 160000) ? Color.Empty : Color.LightGray;

      Comment


        #4
        pandyav, thanks. The issue is likely your use of the CalculationMode of .Ticks - while your trend calculated value would be price based, so not represent an offset to apply in regards to your entry like the .Ticks mode would demand. To see at which level the stop loss with this call would be exactly placed at, please run the script with TraceOrders enabled -

        http://www.ninjatrader.com/support/f...ead.php?t=3627
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by daya123, Today, 09:16 PM
        0 responses
        5 views
        0 likes
        Last Post daya123
        by daya123
         
        Started by Wingo, Today, 04:52 PM
        1 response
        9 views
        0 likes
        Last Post bltdavid  
        Started by Bionian, Today, 10:10 AM
        3 responses
        20 views
        0 likes
        Last Post Bionian
        by Bionian
         
        Started by D Trader, Today, 01:41 PM
        0 responses
        13 views
        0 likes
        Last Post D Trader  
        Started by rexmie888, Today, 04:00 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_ShawnB  
        Working...
        X