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

Strategy Exit on Manual Entries

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

    Strategy Exit on Manual Entries

    I'm trying to set up my strategy to help me manage and automatically exit manual entries.

    I have added
    Code:
     IsAdoptAccountPositionAware = true;
    StartBehavior = StartBehavior.AdoptAccountPosition;
    if(State == State.Historical) return;
    to the code.

    I also have "Adopt Account Position" enabled.

    My exit code is
    Code:
    if (
    (Close[1] < Open[1])
    && (BarsSinceEntryExecution(0,"",0) > 0)
    && (PositionAccount.MarketPosition == MarketPosition.Long)
    )
    {
    ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
    }
    But that doesnt seem to work.
    Any help?

    Thanks!
    Last edited by Ousher; 05-17-2022, 01:09 PM.

    #2
    Hello Ousher,

    Thank you for your post.

    I don't believe you can use BarsSinceEntryExecution here since at the time the position is entered the strategy would not be active. A strategy programmed to adopt the account position would need to be started after the entry is placed and would not know how many bars its been since the execution - that's likely why you're not seeing the exit.

    I should also note here that a strategy using IsAdoptAccountPositionAware = true and StartBehavior = StartBehavior.AdoptAccountPosition will only be able to adopt the current position when its started - entries submitted manually after the strategy is started would not be detected and would cause the strategy position to be out of sync with the account. You would need to disable the strategy each time, enter, and then restart the strategy.

    If you want to submit orders manually and then have the strategy manage those, it would be recommended to create custom buttons within the strategy to submit your entries when triggered, which you can then submit stop and target orders for from the strategy so everything is managed within it.

    You can see an example of submitting entries based on custom button presses on our User App Share here:



    Please let us know if we may be of further assistance to you.

    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Fitspressorest, Today, 01:38 PM
    0 responses
    2 views
    0 likes
    Last Post Fitspressorest  
    Started by Jonker, Today, 01:19 PM
    0 responses
    2 views
    0 likes
    Last Post Jonker
    by Jonker
     
    Started by futtrader, Today, 01:16 PM
    0 responses
    6 views
    0 likes
    Last Post futtrader  
    Started by Segwin, 05-07-2018, 02:15 PM
    14 responses
    1,791 views
    0 likes
    Last Post aligator  
    Started by Jimmyk, 01-26-2018, 05:19 AM
    6 responses
    844 views
    0 likes
    Last Post emuns
    by emuns
     
    Working...
    X