Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with placing a bracket order in strategy builder

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

    Help with placing a bracket order in strategy builder

    I am not good at coding and hoping to find a way to accomplish this using strategy builder.

    Entry Criteria : Close [0] > Open[0]

    When this criteria is met i,e, bar must close, I want to enter long at say Limit price of Close[0] and also want to record the value High[0] - Low[0] to define my stoploss and take profit price variables. Eg. If the bars range (High[0]-Low[0] was $5 and Close[0]=100. My take profit will be 105 and Stoploss will be 95.

    I am able to establish the position and even capture the take profit and stoploss value. However i want the bracket order submitted as soon as the position is established. Its easy enough to exit position if closing price was higher or lower than my take profit and stoploss order but that is not what i want.

    Can anyone help me with the steps? If this isnt possible to configure via Strategy builder, can someone plz help me with a code? I tried referencing the OCO and ATM syntax but couldnt really code myself.

    #2
    Hello percy3687,

    Thank you for your inquiry.

    In the Strategy Builder, the 'Stops and Targets' screen will allow you to set stop loss and profit target orders that are automatically submitted and managed once your strategy opens a position.

    You can set the value of your stop loss and profit target to your recorded stop loss and take profit variables as well.

    https://ninjatrader.com/support/helpGuides/nt8/index.html?builder_screens.htm#UnderstandingTheSto psAndTargetsScreen

    Please let us know if this doesn't guide you in the right direction.
    Last edited by NinjaTrader_Gaby; 05-17-2024, 09:14 AM.

    Comment


      #3
      Its quite helpful. However it seems to have some problem. I am
      1. Storing a variable called SL that calculates 4*(Close[0] - Low[0]). Multiplying by 4 so i can use Calculation Mode Ticks.
      2. Using Stoploss and ProfitTarget (Calculation Mode Ticks) as guided by you.

      However during execution, NT is submitting an OCO Profit and Stop order at 5 ticks from entry price. 5 happens to be the default value of this double variable. Any idea why the correct value of SL is not being used?



      Code:
      namespace NinjaTrader.NinjaScript.Strategies
      {
          public class slpt1 : Strategy
          {
              private double SL;
      
      
              protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      Description                                    = @"Enter the description for your new custom Strategy here.";
                      Name                                        = "slpt1";
                      Calculate                                    = Calculate.OnBarClose;
                      EntriesPerDirection                            = 1;
                      EntryHandling                                = EntryHandling.AllEntries;
                      IsExitOnSessionCloseStrategy                = true;
                      ExitOnSessionCloseSeconds                    = 30;
                      IsFillLimitOnTouch                            = false;
                      MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                      OrderFillResolution                            = OrderFillResolution.Standard;
                      Slippage                                    = 0;
                      StartBehavior                                = StartBehavior.WaitUntilFlat;
                      TimeInForce                                    = TimeInForce.Gtc;
                      TraceOrders                                    = false;
                      RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                      StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                      BarsRequiredToTrade                            = 20;
                      // Disable this property for performance gains in Strategy Analyzer optimizations
                      // See the Help Guide for additional information
                      IsInstantiatedOnEachOptimizationIteration    = true;
                      SL                    = 5;
                  }
                  else if (State == State.Configure)
                  {
                      SetStopLoss("", CalculationMode.Ticks, SL, false);
                      SetProfitTarget("", CalculationMode.Ticks, SL);
                  }
              }
      
              protected override void OnBarUpdate()
              {
                  if (BarsInProgress != 0)
                      return;
      
                  if (CurrentBars[0] < 1)
                      return;
      
                   // Set 1
                  if ((Close[0] > Open[0])
                       && (Position.MarketPosition == MarketPosition.Flat))
                  {
                      EnterLongLimit(Convert.ToInt32(DefaultQuantity), Close[0], "");
                      SL = 4 *(Close[0] - Low[0]) ;
                  }
                  
              }
          }
      }
      ​
      Last edited by percy3687; 05-18-2024, 01:06 AM.

      Comment


        #4
        I resolved my problem. Just had to move below lines of code under OnBarUpdate()

        SetStopLoss("", CalculationMode.Ticks, SL, false);
        SetProfitTarget("", CalculationMode.Ticks, SL);​

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        52 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        70 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        48 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X