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

Different take profit exit conditions

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

    Different take profit exit conditions

    Ok yes I do realize this is most likely beyond support offered by NT staff, but if anyone else can help would be appreciated. I enter a trade with 2 positions and stoploss set at x pips. I am looking to exit 1 lot at x pips profit and move the 2nd lot stoploss to breakeven and then set its new take profit at x pips. Any help and point in a direction to read would be greatly appreciated, with chocolate on top.

    #2
    What I usually do is break down a task into individual components. I tackle component 1, ensure it works as expected and then layer on component 2.

    So in your case, I would start by creating a strategy that enters 1 lot, exits at predetermined stop and profit. Get this to work as you expect. Then add the next layer of logic, move the target to the next end point, then add logic to move stop to breakeven once first profit level is reached. Once you have this working, then work on adding the second position.
    RayNinjaTrader Customer Service

    Comment


      #3
      Thanks for that, yes I completely agree a task needs to be broken down into steps. So this is for other members of the forum who can help if possible please. I am looking at how exactly to close different lots at different set targets. I have no problems making a system that enters 2 lots and then exits at a specified target (thanks to the great auto system generator in NT) my problem lies with moving stops to breakeven and then setting a new take profit level. If there was example code that came with NT I would look at it but from what Ive seen the examples dont get this complex.

      Comment


        #4
        creztor,
        I am trying to do the same as you do.

        I tell you what I did, however I am still missing one piece, namely the entry price.
        But you see my way of thinking

        First I think that CalculateOn BarClose should be set to false, because the moment T1 is reached you want to set the stoploss to breakeven.
        If you want to trade at the end of the bar you might include in your entry conditions
        if(Bars.PercentComplete>0.9 the entry will be executed when 90 % or more of the bar is completed.
        Lets take the long side.

        the entry might look like
        Enterlong(1,"ContractL1");
        EnterLong(1,"ContractL2");

        In the initialize section you might put
        SetProfitTarget("ContractL1", CalculationMode etc ); //for ContractL1
        SetStopLoss("ContractL1"',CalculationMode etc ); // for ContractL1
        SetStopLoss("ContractL2"',CalculationMode etc ); // for ContractL2


        In the OnBarUpdate section you might put
        // reset Stoploss at flat position
        if(Position.MarketPosition==MarketPosition.Flat)
        SetStopLoss("ContractL1",CalculationMode etc);
        SetStopLoss("ContractL2",CalculationMode etc);
        (you might reset here profittarget for ContractL2)

        // Move StopLoss to Breakeven after T1
        if(Position.Quantity==1)
        SetStopLoss("ContractL2",CalculationMode.Price,Entryprice+TickSize,false);
        Here you can also put a (new) profittarget for ContractL2

        I still have to find out how to get the the entry price of ContractL2. I have seen something like Position.AvgPrice

        I hope that this is usefull. Should appreciate your - and from anybody else- comments.

        Comment


          #5
          creztor

          If you separate the entry order in separate orders of 1 contract you need to put in the initialize section
          (if you have 5 separate orders)

          EntriesPerDirection=5

          I was just running the strategy on live data and it took only 1 contract.

          Comment


            #6
            How does roll in forex effect the entry price of a position if you use the Position.AvgPrice method to retrieve that price to use for exit orders?

            Comment


              #7
              What do you mean by roll? Position.AvgPrice in a strategy is based on executions in the strategy and not your account position.

              More information on that here - http://www.ninjatrader-support.com/v...ead.php?t=4033
              RayNinjaTrader Customer Service

              Comment


                #8
                My fault, I had a typo in my code and couldn't figure out why it was generating the wrong order. I have that part working now. Thank you.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by jclose, Today, 09:37 PM
                0 responses
                4 views
                0 likes
                Last Post jclose
                by jclose
                 
                Started by WeyldFalcon, 08-07-2020, 06:13 AM
                10 responses
                1,413 views
                0 likes
                Last Post Traderontheroad  
                Started by firefoxforum12, Today, 08:53 PM
                0 responses
                10 views
                0 likes
                Last Post firefoxforum12  
                Started by stafe, Today, 08:34 PM
                0 responses
                10 views
                0 likes
                Last Post stafe
                by stafe
                 
                Started by sastrades, 01-31-2024, 10:19 PM
                11 responses
                169 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Working...
                X