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

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.
      https://ninjatrader.com/support/help...rderupdate.htm
      https://ninjatrader.com/support/help.../nt8/order.htm

      Below is a link to examples that assign the order object to variables in OnOrderUpdate().
      https://ninjatrader.com/support/foru...269#post802269

      BarSinceExitExecution() would give you the number of bars since the last execution.
      https://ninjatrader.com/support/help...texecution.htm

      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.
      https://ninjatrader.com/support/foru...121#post791121
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thanks Chelsea! will check these.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by LavniaCardos, Today, 02:32 AM
        0 responses
        1 view
        0 likes
        Last Post LavniaCardos  
        Started by pstrusi, 11-13-2022, 05:23 PM
        23 responses
        398 views
        0 likes
        Last Post pstrusi
        by pstrusi
         
        Started by Murphy67, Today, 01:10 AM
        2 responses
        12 views
        0 likes
        Last Post DiverG20  
        Started by DiverG20, Today, 02:01 AM
        0 responses
        4 views
        0 likes
        Last Post DiverG20  
        Started by AlexEro, Today, 12:29 AM
        0 responses
        8 views
        0 likes
        Last Post AlexEro
        by AlexEro
         
        Working...
        X