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

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.
    Kate W.NinjaTrader Customer Service

    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.
          Kate W.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by jaybedreamin, Today, 05:56 PM
          0 responses
          2 views
          0 likes
          Last Post jaybedreamin  
          Started by DJ888, 04-16-2024, 06:09 PM
          6 responses
          18 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by Jon17, Today, 04:33 PM
          0 responses
          1 view
          0 likes
          Last Post Jon17
          by Jon17
           
          Started by Javierw.ok, Today, 04:12 PM
          0 responses
          6 views
          0 likes
          Last Post Javierw.ok  
          Started by timmbbo, Today, 08:59 AM
          2 responses
          10 views
          0 likes
          Last Post bltdavid  
          Working...
          X