Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to set 2 Profit Targets

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

    How to set 2 Profit Targets

    Hi, I'm trying to find out how to build my strategy with 2 target. 1 exiting at 50 ticks and another only if Price Close below SMA 10.

    Could anyone give some hints? Thanks.
    Here is my code below:

    {
    SetProfitTarget("", CalculationMode.Ticks, Target);
    SetStopLoss("", CalculationMode.Ticks, StopLoss, false);

    CalculateOnBarClose = true;
    }

    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (Close[0] > SMA(SMA10)[0] && myBool)
    {
    EnterLong(DefaultQuantity, "");
    myBool = false;
    }

    #2
    Hello john_robertson00,

    Thank you for your post.

    Is the 'Target' used in your SetProfitTarget() the 50 tick profit?

    For the CrossBelow() you can use the following code:
    Code:
    if(CrossBelow(Close, SMA(10)))
    {
    ExitLong();
    }

    Comment


      #3
      Hi Patrick, Thank you for the reply. Correct. Right now I have this code working as:
      once price closes above SMA 10, I enter 1 contract long and only exit if StopLoss or TargetProfit is hit.

      I'm trying to test entering 2 contracts to this strategy and having both contracts with the same StopLoss but 2 Targets. Currently I have SetProfitTarget() coded but this will exit both contracts at 50 ticks.

      I'm not sure how to add 2 ProfitTargets. What you suggested is what I'm looking for, but where do I add that to the code?

      Comment


        #4
        In this case you will want to use different signal names for your entry so you can have different targets and stops for each (even if the stops are at the same level)

        Change EnterLong(DefaultQuantity, "");
        to something like this (please adjust the quantity as desired, as this will place two orders)

        EnterLong(DefaultQuantity, "Order1");
        EnterLong(DefaultQuantity, "Order2");

        Then for your stops/targets do something like this

        SetProfitTarget("Order1", CalculationMode.Ticks, Target1);
        SetStopLoss("Order1", CalculationMode.Ticks, StopLoss, false);
        SetProfitTarget("Order2", CalculationMode.Ticks, Target2);
        SetStopLoss("Order2", CalculationMode.Ticks, StopLoss, false);


        When you run the strategy, in order to get both trades to fire you will need to change your entry settings to UniqueEntries, otherwise only the first will trigger: http://puu.sh/6jJK4.png



        Let me know if I can further assist.
        LanceNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by pechtri, 06-22-2023, 02:31 AM
        9 responses
        122 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by frankthearm, 04-18-2024, 09:08 AM
        16 responses
        66 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by habeebft, Today, 01:18 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by benmarkal, Today, 12:52 PM
        2 responses
        14 views
        0 likes
        Last Post benmarkal  
        Started by f.saeidi, Today, 01:38 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X