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

Get a stop condition to exit/close all mutiple entrys

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

    Get a stop condition to exit/close all mutiple entrys

    Using the Strategy Wizard, I have 2 profit targets. Because the Wizard does not support order quantity in the Exit... actions I had to set up to Entry orders to associates with my two profit targets.

    So, for a long position the Action coding looks like:
    EnterLongLimit(NmbrContractsPT1, GetCurrentAsk(), "Entry1 DD")
    EnterLongLimit(NmbrContractsPT2, GetCurrentAsk(), "Entry2 DD")

    In set Stops and Targets I have:
    SetProfitTarget("Entry1 DD", CalculateMode.Ticks, PrftTrgt1)
    SetProfitTarget("Entry2 DD", CalculateMode.Ticks, PrftTrgt2)

    Now I have a Condition that when true I want to go flat/close the position. I have in the Action section:
    ExitLong("Stop1", "Entry1 DD")
    ExitLong("Stop1", "Entry1 DD")

    Now when BackTesting using the Strategy Analyzer the above to statements to exit the position appears to work fine. Those two statements appear to work fine on historical data when the Strategy is applied to a chart.

    However I have a problem in real-time. If none of the Profit Targets have been met but but my flat/close position condition is true then it takes two bars to close the position. 'Entry1 DD' is closed on the first bar and 'Entry2 DD' is closed on the 2nd bar. As I said: in backtesting and on historical data the whole position is always closed on the 1st bar that the flat/close condition is true. In real-time it always takes 2 bars to close out the position if none of the Profit Targets have been met.

    If Profit Target1 has been met and the flat/close condition is then met. The 'Entry2 DD' is closed on the 1st bar.

    It would appear that when you have multiple active positions then only 1 ExitLong statement can be worked per bar.

    Strategy parameter settings:
    Entries per direction = 2
    Entry handling = UniqueEntries

    #2
    Hi scjohn,

    In your flat/close section please confirm that you have one that is for "Entry1 DD" and one for "Entry2 DD" because right now it would appear you have a typo. Alternatively to going flat with two ExitLong()s you can just close your position by passing in the amount of shares you entered with (you can use Position.Quantity).
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      That's a typo on the 2nd ExitLong( ). I doubled checked the code.
      ExitLong("Stop1", "Entry1 DD")
      ExitLong("Stop2", "Entry2 DD")

      The problem is that none of the Exit... actions in the Strategy Wizard support a quantity parameter. I am trying to keep this with in the structure of the Strategy Wizard.

      Another problem I observed today in running in real time is that if Profit Target1 is met and then the Stop condition is met before Profit Target 2. The ExitLong for Entry2 will be executed on the 2nd bar of the true condition and not the first. It is like only one Exit.. action will be executed per bar.

      If I had 3 targets, therefore 3 ExitLong( ) to handle each of the 3 entries. It would take 3 bars to close all 3 of the entrries.

      Comment


        #4
        I am having difficulty understanding exactly how your entry/exits are meant to work. Are you just trying to scale in/scale out gradually?
        Tell me if this understanding is correct:
        • EnterLong->another condition true->EnterLong again->another condition true->EnterLong again
        • When profit target 1 is hit->close 1st Enterlong, 2nd PT hit->close 2nd Long, 3rd PT hit->close 3rd Long
        • If a stop is hit anywhere between these, close all open positions.
        Are you using CalculateOnBarClose = true? The option is a checkbox on the second screen of the Strategy Wizard (checked=true). If it is set to true then that is why your orders are executing on the 2nd bar. It realizes it is true at the end of the current bar and it cannot act until the beginning of the second bar.

        Edit: After playing around some more I see what you are talking about now. I will experiment some more and see what exactly is happening.
        Last edited by NinjaTrader_JoshP; 09-12-2007, 11:50 AM.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Okay scjohn. It would appear that this is a bug. For now you can workaround this by not providing the fromEntrySignal name to exit your positions.
          Josh P.NinjaTrader Customer Service

          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
          9 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