Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need to set a stop loss equal to indicator value...

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

    Need to set a stop loss equal to indicator value...

    Hello,

    Is it possible to set a stop loss or a trail stop equal to the output of an indicator. I'm trying to do this and in backtest, it does not work correctly.

    I'm trying to set the a Variable's value equal to the indicator and then set the stop loss equal to the Variable.

    This does not work as it always sets the trail stop equal to 1 tick.

    Does anyone know what method I would use in the Strategy builder or what code I may try?

    Thanks in advance,

    dendy.

    Code below:

    #region Variables
    // Wizard generated variables
    private int sMAFast = 6; // Default setting for SMAFast
    private int sMASlow = 12; // Default setting for SMASlow
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    SetTrailStop("", CalculationMode.Ticks, Variable1, false);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (SMA(SMAFast)[0] > SMA(SMAFast)[1]
    && SMA(SMASlow)[0] > SMA(SMASlow)[1]
    && VOLMA(12)[0] > VOLMA(12)[1]
    && ToTime(Time[0]) >= ToTime(13, 0, 0)
    && ToTime(Time[0]) <= ToTime(16, 10, 0))
    {
    EnterLong(DefaultQuantity, "");
    Variable1 = ATRStop(12)[0];

    #2
    How about:
    Code:
    SetTrailStop("", CalculationMode.Ticks, ATRStop(12)[0], false);
    in the OnBarUpdate method?

    Comment


      #3
      I'll try this...

      Thanks.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      67 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      36 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      60 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      62 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      53 views
      0 likes
      Last Post CarlTrading  
      Working...
      X