Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Variable0 Not working as a stop

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

    Variable0 Not working as a stop

    I have a very simple strategy which enters a trade and sets a stop loss value at the same time the trade is entered. It appears that setting the variable as I am, isn't resulting in stopped trades.

    I set the stop loss in the Initialize section to Variable0 for longs and Variable1 for short:

    Code:
     protected override void Initialize()
            {
                SetProfitTarget("", CalculationMode.Ticks, Profit1);
                SetStopLoss("BCMT3_L", CalculationMode.Price, Variable0, false);
                SetStopLoss("BCMT3_S", CalculationMode.Price, Variable1, false);
                CalculateOnBarClose = true;
            }
    Then when I enter a trade I set either Variable0 (Long) or Variable1 (Short) to the low or high of the trigger bar, plus or minus an offset which is set in the Variables section:

    Code:
            private int profit1 = 9; // Default setting for Profit1
            private int plus_Offset = 3; // Default setting for Plus_Offset
            private double min_Offset = -3.0; // Default setting for Min_Offset
    Code:
                	{
                    EnterLong(DefaultQuantity, "BCMT3_L");
    	Variable0 = Low[0] + Min_Offset * TickSize;
                	}
    I'm also trying to move the stop up or down, if the low of the current bar is higher than the relevant Variable for the market position:

    Code:
    	if (Position.MarketPosition == MarketPosition.Long
    	&& Low[0] > Variable0)
    	{
    	Variable0 = Low[0] + Min_Offset * TickSize;
    	}
    Am I using Variables 0 and 1 incorrectly, because when I test the strategy the stops never execute?
    Thanks
    DaveN

    #2
    daven,

    When you set :
    SetStopLoss("BCMT3_L", CalculationMode.Price, Variable0, false);
    SetStopLoss("BCMT3_S", CalculationMode.Price, Variable1, false);
    It permanently sets the stop loss to whatever Variable0 and Variable1 are initialized to.

    You need to set your stop loss again after you change variable0 or variable1.

    Here is a reference sample that covers how to do this : http://www.ninjatrader.com/support/f...ead.php?t=3222

    Please let us know if you require additional assistance.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Variable0 not working continued

      That fixed it. I add a setstoploss statement each time I set the Value of Variable0 or 1 and it is working great now.
      Thanks for your help, have a great weekend.
      DaveN

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      61 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      40 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      21 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      23 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      51 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X