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.



      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 techgetgame, Yesterday, 11:42 PM
        0 responses
        8 views
        0 likes
        Last Post techgetgame  
        Started by sephichapdson, Yesterday, 11:36 PM
        0 responses
        2 views
        0 likes
        Last Post sephichapdson  
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,613 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Yesterday, 05:56 PM
        0 responses
        10 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        20 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Working...
        X