Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 Stanfillirenfro, Today, 07:23 AM
      9 responses
      23 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by George21, Today, 10:07 AM
      0 responses
      6 views
      0 likes
      Last Post George21  
      Started by DayTradingDEMON, Today, 09:28 AM
      2 responses
      16 views
      0 likes
      Last Post DayTradingDEMON  
      Started by navyguy06, Today, 09:28 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by cmtjoancolmenero, Yesterday, 03:58 PM
      8 responses
      32 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X