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 dcriador, Yesterday, 10:45 AM
        2 responses
        15 views
        0 likes
        Last Post dcriador  
        Started by SnailHorn, Yesterday, 10:49 PM
        1 response
        10 views
        0 likes
        Last Post SnailHorn  
        Started by manueldecastro, Yesterday, 10:26 AM
        4 responses
        21 views
        0 likes
        Last Post manueldecastro  
        Started by TraderIqbal, 10-20-2023, 10:12 AM
        2 responses
        120 views
        0 likes
        Last Post Funnywo
        by Funnywo
         
        Started by Creamers, 04-27-2024, 05:32 AM
        12 responses
        72 views
        0 likes
        Last Post Creamers  
        Working...
        X