Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

two entries auto breakeven

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

    two entries auto breakeven

    Hi Guys,

    Í am making some progress. I have everything working with 2 indepentendt entries. Now I am putting in a trigger to make an auto breakeven but am having trouble naming the stops.

    The name for the stop is "Long1b"
    protectedoverridevoid Initialize()
    SetStopLoss("Long1b", CalculationMode.Ticks, Stop, false);

    The below statement is incorrect with a n o overload error.
    if (Close[0] > Position.AvgPrice + (triggerlevel) * TickSize)
    {
    SetStopLoss(
    "Long1b",CalculationMode.Price, Position.AvgPrice);
    PlaySound(
    @"C:\Program Files (x86)\NinjaTrader 7\sounds\AutoBreakEven.wav");
    }

    This statement is correct and compiles ok.

    if (Close[0] > Position.AvgPrice + (triggerlevel) * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice);
    PlaySound(
    @"C:\Program Files (x86)\NinjaTrader 7\sounds\AutoBreakEven.wav");
    }

    Thanks raef

    #2
    You are missing the "bool simulated" ?


    Syntax
    SetStopLoss(double currency)
    SetStopLoss(double currency, bool simulated)
    SetStopLoss(CalculationMode mode, double value)
    SetStopLoss(string fromEntrySignal, CalculationMode mode, double value, bool simulated)


    simulated
    If true, will simulate the stop order and submit as market once triggered


    Originally posted by raefon72 View Post
    Hi Guys,

    Í am making some progress. I have everything working with 2 indepentendt entries. Now I am putting in a trigger to make an auto breakeven but am having trouble naming the stops.

    The name for the stop is "Long1b"
    protectedoverridevoid Initialize()
    SetStopLoss("Long1b", CalculationMode.Ticks, Stop, false);

    The below statement is incorrect with a n o overload error.
    if (Close[0] > Position.AvgPrice + (triggerlevel) * TickSize)
    {
    SetStopLoss(
    "Long1b",CalculationMode.Price, Position.AvgPrice);
    PlaySound(
    @"C:\Program Files (x86)\NinjaTrader 7\sounds\AutoBreakEven.wav");
    }

    This statement is correct and compiles ok.

    if (Close[0] > Position.AvgPrice + (triggerlevel) * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice);
    PlaySound(
    @"C:\Program Files (x86)\NinjaTrader 7\sounds\AutoBreakEven.wav");
    }

    Thanks raef

    Comment


      #3
      I see now because it called the bool statement I have to keep with the previous. Thanks makes a big help.


      now Im down to the trailing stop fingers crossed the force flows through me from here and it all comes together.


      if (Close[0] > Position.AvgPrice + (triggerlevel) * TickSize)
      {
      SetStopLoss(
      "Long1b", CalculationMode.Price,Position.AvgPrice, false);
      SetStopLoss(
      "Long1a", CalculationMode.Price,Position.AvgPrice, false);
      PlaySound(
      @"C:\Program Files (x86)\NinjaTrader 7\sounds\AutoBreakEven.wav");
      }

      Comment


        #4
        Actually I have spoken too soon.

        There is an error in the code
        The strategy is just moving the stop to breakeven on the same bar that it entered on.
        It could be trigger is less then the bar size or the close of the bar was above the entry.

        if (Position.MarketPosition == MarketPosition.Long)
        {

        if (Close[0] > Position.AvgPrice + (Triggerlevel) * TickSize)
        {
        SetStopLoss(
        "Long1a", CalculationMode.Ticks, Position.AvgPrice, false);

        SetStopLoss(
        "Long1b", CalculationMode.Ticks, Position.AvgPrice, false);

        PlaySound(
        @"C:\Program Files (x86)\NinjaTrader 7\sounds\AutoBreakEven.wav");
        }

        Comment


          #5
          Isn't that what you are telling it? SetStopLoos @ Position.AvgPrice?

          Open the output window under tools, and use a Print statement before your stoploss to see where it is setting.


          Print ( "Setting stoploss Position.AvgPrice= " + Position.AvgPrice );





          Originally posted by raefon72 View Post
          Actually I have spoken too soon.

          There is an error in the code
          The strategy is just moving the stop to breakeven on the same bar that it entered on.
          It could be trigger is less then the bar size or the close of the bar was above the entry.

          if (Position.MarketPosition == MarketPosition.Long)
          {

          if (Close[0] > Position.AvgPrice + (Triggerlevel) * TickSize)
          {
          SetStopLoss(
          "Long1a", CalculationMode.Ticks, Position.AvgPrice, false);

          SetStopLoss(
          "Long1b", CalculationMode.Ticks, Position.AvgPrice, false);

          PlaySound(
          @"C:\Program Files (x86)\NinjaTrader 7\sounds\AutoBreakEven.wav");
          }

          Comment


            #6
            Not exactl its suppoed to be Close[0] > Position.AvgPrice + (triggerlevel)
            I have it running on a basic strategy with one entry and it works fine its when I start doing unique entries. A shown below it works correctly.


            if (Close[0] > Position.AvgPrice + (triggerlevel) * TickSize)
            {
            SetStopLoss(CalculationMode.Price, Position.AvgPrice);
            PlaySound(
            @"C:\Program Files (x86)\NinjaTrader 7\sounds\AutoBreakEven.wav");

            }

            Comment


              #7
              raefon72, I would suggest adding prints as sledge suggested and then also work with the TraceOrders feature in NT (also showing up in the output window if enabled) to understand what happens as you move to multiple entries - the AvgPrice you see would still be for the combined strategy position then.

              Comment


                #8
                Thanks.

                I reworked it and it is working ok now I had to restart NT7 and everything works according to plan. Could have been somthing lingering and not initialized from the start.

                Thanks
                Raef

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                647 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                368 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                108 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                571 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                573 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X