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

Creating a strategy with single entry and multiple profit targets.

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

    Creating a strategy with single entry and multiple profit targets.

    Hello!

    I have been messing around with my strategy and have made progress, but have run into a snag.

    The underlying of my strategy is to have one entry point, and to scale out of a position. I had an ATM strategy that did this but want to use something similar to it in my strategy. It seems that is not possible to import the ATM but I made something similar in my strategy.

    So what I had to do is actually create two entries at the same time to each order one contract on the NQ
    Each of those entries has a unique ID Long1, and Long2. And each of them has a correlated Stop Loss, and profit target.

    They have the same stop loss and they have different exit parameters. One will exit sooner if it goes south, the other will have a longer leash.

    Here is how the Bones look:


    else if (State == State.Configure)
    {
    SetStopLoss(@"long1", CalculationMode.Ticks, 35, true);
    SetStopLoss(@"long2", CalculationMode.Ticks, 35, true);
    SetProfitTarget(@"long1", CalculationMode.Ticks, 35);
    SetProfitTarget(@"long2", CalculationMode.Ticks, 80);

    (Strategy goes here)

    {
    EnterLongLimit(Convert.ToInt32(1), (GetCurrentBid(0) + (-1 * TickSize)),@"long1");
    EnterLongLimit(Convert.ToInt32(1), (GetCurrentBid(0) + (-1 * TickSize)),@"long2");
    entrySubmit = true;

    if (CrossBelow(Close, SMAF, 1))
    {
    ExitLong((1), "SLongSma", "long1");
    }
    if (CrossBelow(Close, Bollinger1.Middle, 1)
    ExitLong((1), "SLongBB", "long2");

    NOW HERE IS THE ISSUE:

    Often times My strategy will enter and the first long will exit to protect profit. and then soon after get the signal to enter the position again., But only for one more contract.This is creating too many entries for me and a lot of noise I do not want.

    My entries per direction is set to 2, and my StartBehavior = StartBehavior.WaitUntilFlat;

    Then why is it that My Strategy still will enter my long1 position again over and over while I still have my long2 position open that has not been closed yet?

    Is there anyway so that I can make sure it does not enter any more trades until my Long2 has stopped out or reached its profit target? Or is there any other way I can code this to make it work ?

    Thanks for any help.

    Cheers,

    Tim
    Last edited by cryptochef; 10-13-2018, 08:09 AM. Reason: nq, strategy, entry, exit, multiple entries, multipleentries, help

    #2
    Hello Tim,

    Thank you for your note.

    You could set entries per direction to 1 and set Entry Handling to Unique Entries since you are uniquely naming your entry signals. This will allow each unique entry to be taken.

    See Entry Handling,


    There are several ways to prevent entry 1 triggering again before entry 2 to has been closed. It may be easiest to check that you are in a position of flat before either entry is submitted.

    You could use the if statement at the following sample to check that you are flat,


    Or if using a multi instrument script you could use,

    if(Positions[0].MarketPosition == MarketPosition.Flat && Positions[1].MarketPosition == MarketPosition.Flat)
    {
    //Do Something.
    }



    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by jaybedreamin, Today, 05:56 PM
    0 responses
    3 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
    1 view
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    6 views
    0 likes
    Last Post Javierw.ok  
    Started by timmbbo, Today, 08:59 AM
    2 responses
    10 views
    0 likes
    Last Post bltdavid  
    Working...
    X