Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Scale-in Logic // Berak Even per multiple entry prices

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

    Scale-in Logic // Berak Even per multiple entry prices

    Hi All,
    I'm trying to code a startegy that scales into a position but only if the prior entry order is at break-even. This proves harder with my skill level than I anticipated...
    The logic involves storing Entry prices in variables and bools to mark if a position is true or not. I'm adding the breakeven protective stops with ExitShortStopMarket method to be able to assign an exit signal name to each. I have several problems: I can't assign exit signal name to SetStopLoss method (initial entry) to check if it was triggered to gauge if a position is open. Also, the BarsinceExitExecution does not seem to work but I can't figure out why. Is there a way to check if a position from an entry signal is open in any other way? Third issue I have is that the ExitShortStopMarket method doesn't move stops to breakeven as per the code below.


    // Breakeven Logic

    if (Position.MarketPosition == MarketPosition.Flat)

    {
    SetStopLoss(@"SE1", CalculationMode.Ticks, Stop_Tick, false);
    SetStopLoss(@"SE2", CalculationMode.Ticks, Stop_Tick, false);

    Pos1= false;
    Pos2= false;
    }

    else if ((Position.MarketPosition == MarketPosition.Short)

    && (Pos1= true)
    && (Close[0] < Pos1Price - BE_Trigger*TickSize))
    {
    ExitShortStopMarket(0,true, Convert.ToInt32(DefaultQuantity), Pos1Price-2*TickSize,@"SX1", @"SE1");
    }

    else if ((Position.MarketPosition == MarketPosition.Short)

    && (Pos2= true)
    && (Close[0] < Pos2Price - BE_Trigger*TickSize))
    {
    ExitShortStopMarket(0,true, Convert.ToInt32(DefaultQuantity), Pos2Price-2*TickSize,@"SX2", @"SE2");
    }

    else if ((Position.MarketPosition == MarketPosition.Short)

    && (Pos1= false))

    {
    SetStopLoss(@"SE1", CalculationMode.Ticks, Stop_Tick, false);
    }

    else if ((Position.MarketPosition == MarketPosition.Short)

    && (Pos2= false))

    {
    SetStopLoss(@"SE2", CalculationMode.Ticks, Stop_Tick, false);
    }

    // Pos Variable

    if (BarsSinceExitExecution(0,@"SX1",0)==0)
    {
    Pos1 = false;
    Print("Pos1=false"); //// no print
    }

    if (BarsSinceExitExecution(0, @"SX2", 0) == 0)
    {
    Pos2 = false;
    Print("Pos2=false"); //// no print
    }

    #2
    Please disregard this, I found several errors I made within the code.

    Comment


      #3
      Hello Balage0922,

      Note, use Exit orders such as ExitLongStopMarket() / ExitLongLimit() if you would like to give the exit orders signal names.

      You can also assign the entry order objects to variables in OnOrderUpdate() and then check the variable is null and then use the order.AveragePrice as the entry price of the order.



      Below is a link to examples that assign the order object to variables in OnOrderUpdate().


      BarSinceExitExecution() would give you the number of bars since the last execution.


      This returns -1 if there has not been an exit execution for the specified signal name.
      When you say this does not work, are you printing this value along with TraceOrders and the order object from OnOrderUpdate() to show when the exit order fills and the value of BarsSinceExitExecution for that signal name?
      Provide the output from the prints to further investigate.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thanks Chelsea! will check these.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        58 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        133 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        73 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X