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 SalmaTrader, 07-07-2026, 10:26 PM
      0 responses
      47 views
      0 likes
      Last Post SalmaTrader  
      Started by CarlTrading, 07-05-2026, 01:16 PM
      0 responses
      22 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 06-17-2026, 10:32 AM
      0 responses
      15 views
      0 likes
      Last Post CaptainJack  
      Started by kinfxhk, 06-17-2026, 04:15 AM
      0 responses
      21 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 06-17-2026, 04:06 AM
      0 responses
      23 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Working...
      X