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

Help with Breakeven

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

    Help with Breakeven

    Hi,

    I am working on a Ninja Script strategy using support / help Guides / nt7 as a guideline but I can't find a way to make a partial exit.

    I enter the market buying 3 contracts and when it reaches Profit >= 6 and hma (10) < hma (50) it sells 2 contracts.

    My first problem is that I cannot find the right code to make the remaining contract to pass to BreakEven.

    The second problem is that when it reaches Profit >= 6 but hma (10) IS NOT < hma (50). I want the code to "forget" that condition, meaning that it only checks that condition once.

    Can anybody help me with this?
    Thanks in advance.


    protected override void OnBarUpdate()

    {

    if (HMA(10)[0] > HMA(20)[0])
    {EnterLong(3);}

    if (Position.MarketPosition == MarketPosition.Long)

    {
    if (Close[0] >= Position.AvgPrice + 8*TickSize
    && HMA(10)[0] < HMA(50)[0])
    {
    ExitLong(2);
    SetStopLoss("",CalculationMode.Price,thestop-(1*TickSize), false); // ?.
    }
    }
    }

    #2
    Hello firecan,

    Similarly to the way there are separate orders with separate targets when creating Atm Strategies, this is also helpful when sending your own orders through code.

    Place each quantity that will act as a separate target as a separate order. Use a signal name for the entry order.

    Then when exiting, exit using the fromSignalName of entry order target that you want to exit (without exiting the others).

    Below I am providing a link to another forum thread where I have posted an example called MultipleTargetsWizardExample.
    http://ninjatrader.com/support/forum...576#post441576
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi again , first of all thanks for your help.

      I managed to make the entries separately (2+1 contracts) and they exit individually as well but I cannot make the to work as "group", meaning that the first entry that exits makes an entry again before the remaining contract is closed.

      Regards.

      Comment


        #4
        Hello firecan,

        This would be up to the conditions in your script.

        You could require that the position be flat when the conditions to enter are true, this would require that all trades are exited before the new entry will occur.

        if (Position.MarketPosition == MarketPosition.Flat /* && conditions to enter */)
        {
        // execute code
        EnterLong("long1");
        EnterLong("long2");
        }

        Below is a link to the help guide on Position.MarketPosition.
        http://ninjatrader.com/support/helpG...etposition.htm


        Or instead, a more complex but specific way would use IOrder variables to track the state of each order and know when each trade is open or closed. This is done by initializing the IOrder variables as null, setting the orders to the variables when submitted, and then setting the (entry and exit) orders to null when the exit orders fill. Then to place any new orders, both entry order IOrder variables must be null. In this way orders can only be made if the exits have occurred.

        Attached is an example of this I've made previously while working on another item.


        (I didn't mention before, but in the strategy parameters when running the script, Entries per direction needs to be set to above 1 for the number of entry orders that will be placed at a time.)
        http://ninjatrader.com/support/helpG...rdirection.htm
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi firescan,

          Were you ever able to get this coded correctly? I am trying to do the same thing and just can't get it right. Any help would be greatly appreciated

          Thanks,

          Samir

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by bortz, 11-06-2023, 08:04 AM
          47 responses
          1,606 views
          0 likes
          Last Post aligator  
          Started by jaybedreamin, Today, 05:56 PM
          0 responses
          8 views
          0 likes
          Last Post jaybedreamin  
          Started by DJ888, 04-16-2024, 06:09 PM
          6 responses
          18 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by Jon17, Today, 04:33 PM
          0 responses
          4 views
          0 likes
          Last Post Jon17
          by Jon17
           
          Started by Javierw.ok, Today, 04:12 PM
          0 responses
          13 views
          0 likes
          Last Post Javierw.ok  
          Working...
          X