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 pmachiraju, 11-01-2023, 04:46 AM
      8 responses
      149 views
      0 likes
      Last Post rehmans
      by rehmans
       
      Started by mattbsea, Today, 05:44 PM
      0 responses
      5 views
      0 likes
      Last Post mattbsea  
      Started by RideMe, 04-07-2024, 04:54 PM
      6 responses
      33 views
      0 likes
      Last Post RideMe
      by RideMe
       
      Started by tkaboris, Today, 05:13 PM
      0 responses
      5 views
      0 likes
      Last Post tkaboris  
      Started by GussJ, 03-04-2020, 03:11 PM
      16 responses
      3,283 views
      0 likes
      Last Post Leafcutter  
      Working...
      X