• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Two entries with Breakeven

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

    Two entries with Breakeven

    Hello,

    I have a strategy with two orders with 2 stops and 2 profit target,

    I want to enter the first order if the conditions are met, and a second order once the close price is less than something; then move the stoploss1 to breakeven and enter a second order with stoploss at breakeven. Only once in a day for both orders. This is my code, but the second order enters more than once in a day.

    Could you please me tell me what's wrong in my code?

    if (ToTime(Time[0]) == ToTime(8, 0, 0))

    {
    Variable0 = 2021.75;
    SetStopLoss("PT1", CalculationMode.Ticks, StopLoss1, false);
    SetStopLoss("PT2", CalculationMode.Ticks, StopLoss2, false);
    Entrada1 = false;
    Entrada2 = false;

    }

    // Condition set 2
    if ( ToTime(Time[0]) > ToTime(9, 30, 0)
    && ToTime(Time[0]) < ToTime(10, 30, 0)
    && Close[0] < Variable0
    && Open[0] > Close[0]
    && Entrada1 == false
    && Entrada2 == false)
    {
    EnterShort(DefaultQuantity, "PT1");
    SetProfitTarget("PT1", CalculationMode.Ticks, ProfitTarget1);
    SetStopLoss("PT1", CalculationMode.Ticks, StopLoss1, false);
    Entrada1 = true;
    }
    if (Close[1] < (Position.AvgPrice - MovBE * TickSize))
    {
    SetStopLoss ("PT1", CalculationMode.Price, Position.AvgPrice - 1 * TickSize, false);
    EnterShort(DefaultQuantity, "PT2");
    SetStopLoss ("PT2", CalculationMode.Price, Position.AvgPrice - 1 * TickSize, false);
    SetProfitTarget("PT2", CalculationMode.Ticks, ProfitTarget2);
    Entrada2 = true;
    }
    }

    #2
    Hello josefo,


    You could add a check to see if Entrada2 == false, in the if statement of your second condition.


    You could also use the EntriesPerDirection method to specify the maximum number of entries allowed per direction while a position is active. Use the EntryHandling method to set how the orders will be handled when using EntriesPerDirection.


    If you set the EntryHandling method to "EntryHandling.AllEntries", all order entry methods are tracked until the maximum allowable entries set by the EntriesPerDirection property has been reached while in an open position.

    If you set the EntryHandling method to "EntryHandling.UniqueEntries", order entry methods are tracked until the maximum allowable entries set by the EntriesPerDirection property per each uniquely named entry.



    I have included the EntriesPerDirection and EntryHandling help guides to assist you with this further.
    Shawn B.NinjaTrader Customer Service

    Comment


      #3
      Hello Shawn,

      I already have this:

      EntriesPerDirection = 2;
      EntryHandling = EntryHandling.AllEntries;

      ExitOnClose = true;
      ExitOnCloseSeconds = 90;
      CalculateOnBarClose = true;

      Is it enough?

      But still the second order enters more than once per day.

      Thanks in advance.

      Comment


        #4
        Hello, Where you have specified the following:
        Code:
        if (Close[1] <  (Position.AvgPrice - MovBE * TickSize))         {              SetStopLoss ('PT1', CalculationMode.Price, Position.AvgPrice - 1 *  TickSize, false);             EnterShort(DefaultQuantity, 'PT2');              SetStopLoss ('PT2', CalculationMode.Price, Position.AvgPrice - 1 *  TickSize, false);             SetProfitTarget('PT2',  CalculationMode.Ticks, ProfitTarget2);             Entrada2 = true;          }     } 

        You would want to add a check to ensure that action is only taken when Entrada2 is equal to false, along with the other condition. Here is an example of this:
        Code:
        if(Close[1] < (Position.AvgPrice - MovBE * TickSize) && Entrada2 == false)        {
        Shawn B.NinjaTrader Customer Service

        Comment


          #5
          Thanks Shawn,

          Now the orders are working well, but now I do not get to reset the value of the stoploss2, although the stoploss1 reset correctly.

          I have this

          Code:
          	if (Bars.FirstBarOfSession == true)
          			{
          				SetStopLoss("PT1", CalculationMode.Ticks, StopLoss1, false);
          				SetStopLoss("PT2", CalculationMode.Ticks, StopLoss2, false);
          				Entrada1 = false;
          				Entrada2 = false;
          			}
          I don't know why the stoploss2 doesn't reset at firstbarofsesssion.

          Thanks in advance.

          Comment


            #6
            Hello josefo,



            Could you please reply with your script attached, so that I may investigate this behavior further?


            You can attach your strategy to your response by going to File > Utilities > Export NinjaScript > Export selected source files > select your strategy > select the right arrow > Export. The file will be located under (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript.



            You could post the script to your forum reply, or send an email to platformsupport [at] ninjatrader [dot] com with the script as an attachment. In the email please include a link to this forum thread.
            Shawn B.NinjaTrader Customer Service

            Comment


              #7
              Hello Shawn,

              Attached I send you the strategy.

              Thanks in advance.
              Attached Files

              Comment


                #8
                Hello josefo,

                I have tested you script on my end. However, I don't see where there is an issue with your StopLoss resetting.
                Could you please provide more details about what you are experiencing? Are there any steps you made prior to seeing this behavior that may contribute?
                Please send a screenshot of when your strategy does not reset the StopLoss.

                To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.

                Click here for instructions

                Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

                Click here for detailed instruction
                Shawn B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by dkbyond, Today, 06:43 PM
                0 responses
                3 views
                0 likes
                Last Post dkbyond
                by dkbyond
                 
                Started by i2w8am9ii2, Today, 06:05 PM
                0 responses
                1 view
                0 likes
                Last Post i2w8am9ii2  
                Started by YevhenShynkarenko, Today, 05:46 PM
                0 responses
                4 views
                0 likes
                Last Post YevhenShynkarenko  
                Started by Bionian, Today, 04:14 PM
                0 responses
                3 views
                0 likes
                Last Post Bionian
                by Bionian
                 
                Started by dkbyond, Today, 04:03 PM
                0 responses
                5 views
                0 likes
                Last Post dkbyond
                by dkbyond
                 
                Working...
                X