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

Stop Loss Strategy Builder Current Day OHL

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

    Stop Loss Strategy Builder Current Day OHL

    Hello please i try in the strategy builder set the stop loss with the indicator current day OHL but dont work , I wish set the stop in the low of N bars ago. i need unlock the strategy or i can set it in the strategy builder.

    Regards

    #2
    Hello walter739,

    In the builder the stops and targets page are mainly going to be fixed offsets which are set at startup of the script rather than during processing of data.

    For what you are asking the code would need to be unlocked, this is mainly because in the builder the targets are setup once opposed to in manual coding they can be setup before entering which allows for calculated prices.

    I would suggest using the builder to complete your script overall while using a fixed offset for the stop for testing. Once you are happy with how the overall conditions work you could unlock the code and customize the stop further to use a custom price. Because you would need to unlock the code I would also suggest saving a duplicate of this strategy before doing that. You can go back and re edit your builder code as many times as needed and re save duplicates if you needed to update some of the builder designed logic. In the builder where you select the straetgy you want to edit, in the drop down menu you can hover the mouse over a strategy and "Save As" appears to duplicate it.



    I look forward to being of further assistance.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse, thanks for your help, i look this video



      and help me with the stop and profit in the strategy builder with the current day OHL

      But i unknow how i can set the stop price for short position in the first high price before the average price. If you can help me with these, i attached picture for example with red circles .

      If i can these with the the strategy builder better, if not i can unlock and learn.

      Regards

      Comment


        #4
        Hello walter739,
        But i unknow how i can set the stop price for short position in the first high price before the average price. If you can help me with these, i attached picture for example with red circles .
        I wanted to clarify, do you mean to use the high price for the bar which happened 1 bar before the bar where your entry filled?


        I look forward to being of further assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks for answer Jesse, sorry for my english.

          In this moment my strategy work in short position with exits with indicator current day OHL set in high, green line, attached new picture.

          I need for short position set the exits in the first highest bar before the entry. I attached the picture in red circles the first highest bar before the entry for you see better my need.

          What code need change for set this, it is possible in strategy builder?

          I think these, but i dont know how write:

          if ((MAX1[N bars ago] > Position.AveragePrice)
          && (MAX1[N bars ago+1 bar ago] < MAX1[N bars ago]))
          {
          shortloss = shortloss;
          }

          // Set 2
          if (Position.MarketPosition == MarketPosition.Short)
          {
          ExitShortStopMarket(Convert.ToInt32(QuantityStocks ), shortloss, @"exitshortloss", @"sell");

          }


          Regards
          Last edited by walter739; 12-05-2019, 07:46 AM.

          Comment


            #6
            Hello walter739,

            Thank you for the clarification.

            From the description it sounds like you want to set this before the entry however you wouldn't be able to call the exit before the entry. This would be set before you call the exit, so in this case it looks like it would go in set 2 as the first action before the ExitShortStopMarket.

            In the builder you could add this into your set's action before ExitShortStopMarket.
            • Click Add to add a new action
            • Go to Misc -> Set shortloss
            • Hover the mouse over the value and click Set
            • In the new window that opens, click Indicator -> Max and configure as you wanted.
            As long as your exit is using the shortloss variable like you have shown it should be set prior to calling the exit.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Hello Jesse, thank for your help

              Please i need you see the picture of my need, maybe i not explain well.

              I try with your instructions but not work for my need. I found the swing indicator and go fine for show the price of the exit , But i dont know how set it for use the exit price of the swing before the entry.

              I try this code but not work


              if (BarsInProgress != 0)
              return;

              if (CurrentBars[0] < 2
              || CurrentBars[1] < 0)
              return;

              // Set 1
              if (Swing1.SwingHigh[1] > Position.AveragePrice)
              {
              Shortloss = Shortloss;
              }

              // Set 2
              if ((Times[0][0].TimeOfDay >= TimeOpen.TimeOfDay)
              && (Times[0][0].TimeOfDay <= Timeclose.TimeOfDay)
              && (DaysOk == true)
              && (EMA1[0] < EMA2[0])
              && (CrossBelow(Close, EMA3, 1)))
              {
              EnterShort(Convert.ToInt32(QuantityStocks), @"sell");
              }

              // Set 3
              if (Position.MarketPosition == MarketPosition.Short)
              {
              ExitShortStopMarket(Convert.ToInt32(QuantityStocks ), Shortloss, @"exitshortloss", @"sell");
              }

              Please if you can help me , i aprecciated.

              Regards
              Attached Files
              Last edited by walter739; 12-06-2019, 05:14 AM.

              Comment


                #8
                Hello walter739,

                If you wanted to use the swing as a price, you would need to select it from the ExitShortStopMarket command as its price instead of Shortloss which you have used. In the syntax you provided you used the input Shortloss, where you select that you can also select indicators or price values.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Hello Jesse, i change the code but dont work, i need the price of the exit set to swing in the moment of the entry, I annex photo for explain better, I need set the price of the exit in the red circles.

                  }
                  else if (State == State.DataLoaded)
                  {

                  Swing1 = Swing(High, 1);

                  }
                  }

                  protected override void OnBarUpdate()
                  {
                  if (BarsInProgress != 0)
                  return;

                  if (CurrentBars[0] < 1
                  || CurrentBars[1] < 0)
                  return;

                  // Set 1
                  if ((Times[0][0].TimeOfDay >= TimeOpen.TimeOfDay)
                  && (Times[0][0].TimeOfDay <= Timeclose.TimeOfDay)
                  && (DaysOk == true)
                  && (EMA1[0] < EMA2[0])
                  && (CrossBelow(Close, EMA3, 1)))
                  {
                  EnterShort(Convert.ToInt32(QuantityStocks), @"sell");
                  }

                  // Set 2
                  if (Position.MarketPosition == MarketPosition.Short)
                  {
                  ExitShortStopMarket(Convert.ToInt32(QuantityStocks ), Swing1.SwingHigh[0], @"exitshortloss", @"sell");
                  }

                  Thanks for your help
                  Attached Files

                  Comment


                    #10
                    Hello walter739,

                    If you wanted the price at the time of the entry you would need to store the price when you enter and then later reference that price. In your first set you could store the swing price to a user variable and then in the second set use the variable.

                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Hello Jesse, i try this but dont work

                      if (BarsInProgress != 0)
                      return;

                      if (CurrentBars[0] < 2
                      || CurrentBars[1] < 0)
                      return;

                      // Set 1
                      if (Swing1.SwingHigh[1] > Position.AveragePrice)
                      {
                      Shortloss = Shortloss;
                      }

                      // Set 2
                      if ((Times[0][0].TimeOfDay >= TimeOpen.TimeOfDay)
                      && (Times[0][0].TimeOfDay <= Timeclose.TimeOfDay)
                      && (DaysOk == true)
                      && (EMA1[0] < EMA2[0])
                      && (CrossBelow(Close, EMA3, 1)))
                      {
                      EnterShort(Convert.ToInt32(QuantityStocks), @"sell");
                      }

                      // Set 3
                      if (Position.MarketPosition == MarketPosition.Short)
                      {
                      ExitShortStopMarket(Convert.ToInt32(QuantityStocks ), Shortloss, @"exitshortloss", @"sell");
                      }

                      Please how i can set the exit price of swing high in the moment of the entry.

                      Regards

                      Comment


                        #12
                        Hello walter739,

                        In this sample I don't see that you are setting a value to Shortloss, You would need to set a value to that when you call EnterShort in the same set. You had made a condition in set 1 setting Shortloss to its self but that will only be set if the condition you made became true and will also not set a value if there was not a value set to Shortloss already.

                        If you want the swing at the time of the entry setting Shortloss needs to happen in the same set as the entry, it would be a second action in addition to EnterShort. Your set1 as you have it now would not be needed when setting the price during the same set as the entry.



                        I look forward to being of further assistance.
                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          Hello Jesse , thanks for your time.

                          I try with this but no set the exit price in the swing high when entry, please if can help me

                          }
                          else if (State == State.DataLoaded)
                          {

                          Swing1 = Swing(High, 1);

                          }
                          }

                          protected override void OnBarUpdate()
                          {
                          if (BarsInProgress != 0)
                          return;

                          if (CurrentBars[0] < 1
                          || CurrentBars[1] < 0)
                          return;

                          // Set 1
                          if ((Times[0][0].TimeOfDay >= TimeOpen.TimeOfDay)
                          && (Times[0][0].TimeOfDay <= Timeclose.TimeOfDay)
                          && (DaysOk == true)
                          && (EMA1[0] < EMA2[0])
                          && (CrossBelow(Close, EMA3, 1)))
                          {
                          EnterShort(Convert.ToInt32(QuantityStocks), @"sell");
                          Shortloss = Swing1.SwingHigh[0];
                          }

                          // Set 2
                          if (Position.MarketPosition == MarketPosition.Short)
                          {
                          ExitShortStopMarket(Convert.ToInt32(QuantityStocks ), Shortloss, @"exitshortloss", @"sell");
                          }

                          Comment


                            #14
                            Hello walter739,

                            It appears you are setting the price to the swing high, what was the outcome that you observed? Was the exit not submitted at or near the swing high price? How are you currently comparing the price, did you have the strategy add the swing or are you manually adding it?

                            I look forward to being of further assistance.
                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              Hello Jesse, i anexx photo, The exit happens in other swing, not with the price of the swing in the entry (red circles in the photo) .I no understand how is the syntax. . I need set the exit price in the swing high when entry. My estrategy work in strategy builder.

                              Regards
                              Attached Files
                              Last edited by walter739; 12-11-2019, 05:34 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by geddyisodin, Yesterday, 05:20 AM
                              7 responses
                              45 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by gbourque, Today, 06:39 AM
                              2 responses
                              4 views
                              0 likes
                              Last Post gbourque  
                              Started by cre8able, Yesterday, 07:24 PM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by cocoescala, 10-12-2018, 11:02 PM
                              6 responses
                              939 views
                              0 likes
                              Last Post Jquiroz1975  
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              1 response
                              17 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X