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 -

        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        5 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        18 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by frslvr, 04-11-2024, 07:26 AM
        9 responses
        127 views
        1 like
        Last Post caryc123  
        Started by selu72, Today, 02:01 PM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Working...
        X