Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Set stop Los On High Low day

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

    Set stop Los On High Low day

    Hello everyone

    there was a task in the strategy to set a pending stop loss order at the current high or low of the day

    maximum and minimum I get like this

    Code:
    double valueHigh = CurrentDayOHL().CurrentHigh[0];
    double valueLow = CurrentDayOHL().CurrentLow[0];
    I need a stop instead of this

    Code:
    // Submits a stop loss of $500
    SetStopLoss(CalculationMode.Ticks, 31);
    a stop was set for the current valueHigh / valueLow

    how to try what will be the correct syntax and logic?

    The first one deals with strategy, thanks for your understanding

    #2
    Hello memonolog,

    Thank you for your post.

    You'd want to use a CalculationMode of ticks, and you'd want to make sure you're calling the SetStopLoss() method in OnBarUpdate just prior to the entry so the Stop Loss may be properly updated to use the current value of valueHigh or valueLow. So, something like:

    Code:
    double valueHigh = CurrentDayOHL().CurrentHigh[0];
    double valueLow = CurrentDayOHL().CurrentLow[0];
    
    protected override void OnBarUpdate()
    {
    if([I]your entry conditions for a long order go here)[/I]
    {
    SetStopLoss(CalculationMode.Price, valueLow);
    EnterLong();
    }
    else if ([I]your entry conditions for a short order go here)[/I]
    {
    SetStopLoss(CalculationMode.Price, valueHigh);
    EnterShort();
    }
    }
    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Originally posted by NinjaTrader_Kate View Post
      Hello memonolog,

      Thank you for your post.

      You'd want to use a CalculationMode of ticks, and you'd want to make sure you're calling the SetStopLoss() method in OnBarUpdate just prior to the entry so the Stop Loss may be properly updated to use the current value of valueHigh or valueLow. So, something like:

      Code:
      double valueHigh = CurrentDayOHL().CurrentHigh[0];
      double valueLow = CurrentDayOHL().CurrentLow[0];
      
      protected override void OnBarUpdate()
      {
      if([I]your entry conditions for a long order go here)[/I]
      {
      SetStopLoss(CalculationMode.Price, valueLow);
      EnterLong();
      }
      else if ([I]your entry conditions for a short order go here)[/I]
      {
      SetStopLoss(CalculationMode.Price, valueHigh);
      EnterShort();
      }
      }
      Please let us know if we may be of further assistance to you.
      Thank You!

      Comment


        #4
        Originally posted by NinjaTrader_Kate View Post
        Hello memonolog,

        Thank you for your post.

        You'd want to use a CalculationMode of ticks, and you'd want to make sure you're calling the SetStopLoss() method in OnBarUpdate just prior to the entry so the Stop Loss may be properly updated to use the current value of valueHigh or valueLow. So, something like:

        Code:
        double valueHigh = CurrentDayOHL().CurrentHigh[0];
        double valueLow = CurrentDayOHL().CurrentLow[0];
        
        protected override void OnBarUpdate()
        {
        if([I]your entry conditions for a long order go here)[/I]
        {
        SetStopLoss(CalculationMode.Price, valueLow);
        EnterLong();
        }
        else if ([I]your entry conditions for a short order go here)[/I]
        {
        SetStopLoss(CalculationMode.Price, valueHigh);
        EnterShort();
        }
        }
        Please let us know if we may be of further assistance to you.
        Tell me one more please, I use the input

        Code:
        else if (State == State.Configure)
        
        // Submits a profit target order 10 ticks away from the avg entry price
        SetProfitTarget(CalculationMode.Ticks, 50);
        }
        
        EnterLong();
        how to specify, for example, an entry with 2 contracts with different take profit
        for example the first target (contract 1) 50 ticks the second (contract 2) 100 ticks

        need correct syntaxes / examples

        thank you in advance

        Comment


          #5
          Hello memonolog,

          Thank you for your reply.

          Since you're using Set methods, you'd need to use two separate entries with two separate profit targets, and link them using Signal Names. You'd also want to set your entry handling to Unique Entries, so each is allowed to enter under the order handling rules. Building somewhat off the previous example, though this would just be for long orders:

          Code:
           protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = @"Enter the description for your new custom Strategy here.";
          Name = "ExampleScaleOutProfitTarget";
          // further code removed for brevity
          }
          else if (State == State.Configure)
          {
          
          SetProfitTarget("Entry1", CalculationMode.Ticks, 50);
          SetProfitTarget("Entry2", CalculationMode.Ticks, 100);
          }
          }
          
          protected override void OnBarUpdate()
          {
          if (BarsInProgress != 0)
          return;
          
          if (CurrentBars[0] < 1)
          return;
          
          double valueLow = CurrentDayOHL().CurrentLow[0];
          
          if ([I]your entry conditions are true for a long entry[/I])
          {
          SetStopLoss(CalculationMode.Price, valueLow);
          EnterLong(Convert.ToInt32(DefaultQuantity), @"Entry1");
          EnterLong(Convert.ToInt32(DefaultQuantity), @"Entry2");
          }
          
          }
          For shorts, you'd need another pair of SetProfitTarget() calls and to link those to the associated short orders.

          Please let us know if we may be of further assistance to you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          62 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          134 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          75 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          50 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X