Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Moving target

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

    Moving target

    Who can help me?

    I programmed the following strategy into the wizard
    ParobolicSar:CrossBelow(ParabolicSAR(0.02,0.2,0.02), Low,1))
    EnterLong(DefaultQuantity,"");

    CrossAbove(ParabolicSAR(0.02,0.2,0.02), High,1))
    EnterShort(DefaultQuantity,"");

    SetStopLoss("", CalculationMode.Ticks,15,true);


    But I would like to add a target as follows:

    Target 1: 25 points: if these 25 points are not reached, the position should close at target 2.
    Target 2: 20 points: if these 20 points are not reached, the position should close at target 3.
    Target 3: 15 points: if these 15 points are not reached, the position should close at target 4.
    Target 4: 10 points: if these 10 points are not reached, the position should close at target 5.
    Target 5: 5 points: if these5 points are not reached, the position should close at target 6.
    Target 6: 2 points if these 2 points are not reached, close at change of SAR.

    Anather possibility, a tralingstop, but that may only start as my position has reached 7 points in de good direction.

    Could someone explain how to add this target and at what location in the strategy.

    Harry Hintzen

    #regionVariables
    // Wizard generated variables
    privateintmyInput0 = 1; // Default setting for MyInput0
    // 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>
    protectedoverridevoidInitialize()
    {
    Add(ParabolicSAR(0.02, 0.2, 0.02));
    Add(ParabolicSAR(0.02, 0.2, 0.02));
    SetStopLoss("", CalculationMode.Ticks, 15, true);

    CalculateOnBarClose = true;
    }

    ///<summary>
    ///Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoidOnBarUpdate()
    {
    // Condition set 1
    if(CrossBelow(ParabolicSAR(0.02, 0.2, 0.02), Low, 1))
    {
    EnterLong(DefaultQuantity, "");
    }

    // Condition set 2
    if(CrossAbove(ParabolicSAR(0.02, 0.2, 0.02), High, 1))
    {
    EnterShort(DefaultQuantity, "");
    }
    }

    #2
    Hello HHintzen,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    I would not use a Profit Target for this idea, as the limit orders will likely be rejected if submitted above the market when short or below when long. Instead use SetStopLoss in the following manner:
    Code:
    			if(Position.MarketPosition != MarketPosition.Flat)
    			{
    				if(Close[0]< Position.AvgPrice + 2*Instrument.MasterInstrument.PointValue)
    					SetStopLoss(CalculationMode.Ticks, ParabolicSAR(0.02,0.2,0.02)[0]);
    				else if(Close[0]< Position.AvgPrice + 5*Instrument.MasterInstrument.PointValue)
    					SetStopLoss(Position.AvgPrice + 2*Instrument.MasterInstrument.PointValue);
    				else if(Close[0]< Position.AvgPrice + 10*Instrument.MasterInstrument.PointValue)
    					SetStopLoss(Position.AvgPrice + 5*Instrument.MasterInstrument.PointValue);
    				else if(Close[0]< Position.AvgPrice + 15*Instrument.MasterInstrument.PointValue)
    					SetStopLoss(Position.AvgPrice + 20*Instrument.MasterInstrument.PointValue);
    				else if(Close[0]< Position.AvgPrice + 20*Instrument.MasterInstrument.PointValue)
    					SetStopLoss(Position.AvgPrice + 15*Instrument.MasterInstrument.PointValue);
    				else if(Close[0]< Position.AvgPrice + 25*Instrument.MasterInstrument.PointValue)
    					SetStopLoss(Position.AvgPrice + 20*Instrument.MasterInstrument.PointValue);
    				else
    					SetStopLoss(Position.AvgPrice + 25*Instrument.MasterInstrument.PointValue);
    			}
    I would also recommend reviewing the reference sample at the following link: http://www.ninjatrader.com/support/f...ead.php?t=3222

    Please let me know if I may be of further assistance.

    Comment


      #3
      Moving target.

      Hello Patrick,

      Thanks four your reaction.

      Can you also tel my where I have to put this in my starategy ?

      if(Position.MarketPosition != MarketPosition.Flat)
      {
      if(Close[0]< Position.AvgPrice + 2*Instrument.MasterInstrument.PointValue)
      SetStopLoss(CalculationMode.Ticks, ParabolicSAR(0.02,0.2,0.02)[0]);
      else if(Close[0]< Position.AvgPrice + 5*Instrument.MasterInstrument.PointValue)
      SetStopLoss(Position.AvgPrice + 2*Instrument.MasterInstrument.PointValue);
      else if(Close[0]< Position.AvgPrice + 10*Instrument.MasterInstrument.PointValue)
      SetStopLoss(Position.AvgPrice + 5*Instrument.MasterInstrument.PointValue);
      else if(Close[0]< Position.AvgPrice + 15*Instrument.MasterInstrument.PointValue)
      SetStopLoss(Position.AvgPrice + 20*Instrument.MasterInstrument.PointValue);
      else if(Close[0]< Position.AvgPrice + 20*Instrument.MasterInstrument.PointValue)
      SetStopLoss(Position.AvgPrice + 15*Instrument.MasterInstrument.PointValue);
      else if(Close[0]< Position.AvgPrice + 25*Instrument.MasterInstrument.PointValue)
      SetStopLoss(Position.AvgPrice + 20*Instrument.MasterInstrument.PointValue);
      else

      Comment


        #4
        Hello HHintzen,

        Thank you for your response.

        You can place this in the OnBarUpdate() method at any place, usually this would be placed after the entry conditions.

        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