Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple long entries not possible on the same instrument

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

    Multiple long entries not possible on the same instrument

    Hi

    I have created 2 strategies (let's call them Strategy A and B) in NT 8 and both of them go long or short based on certain criterias. It doesn't matter which one goes long/short first A or B, the system does not not go long/short on the other strategy even though all the criterias are met.

    Each long/shirt entry has it's own unique signal name. The strategy dialog box for both A and B have Entry Handling = "Unique entries" and Entry per direction = 1. The start behavior is set to "Immediately submit, synchronize account" for both A and B.

    Based on the above setup, even though the criteria are met for both, I can only get one of them to fire long or short but not both. Note: Per the criteria A and/or B can only go long or short. They cannot have a scenario where one goes long and the other short.

    Can someone let me know if there is another setting that needs to be set either in code or on the strategy window to get both of them to fire off, with their own proft target and stop loss?

    I have provided a snippet of the code below. The code will be the same for A and B with the exception of the time, long and short entry values. These values are setup in the strategy window.

    public class StrategyA : Strategy
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"StrategyA";
    Name = "StrategyA";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling =EntryHandling.UniqueEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 1;
    LongMaxEntry = 1;
    LongMinEntry = 1;
    ProfitTargetPrice = 1;
    StopLossTicks = 1;
    ShortMaxEntry = 1;
    ShortMinEntry = 1;
    LongEnabled = false;
    ShortEnabled = false;
    DefaultQuantity = 1;
    }
    else if (State == State.Configure)
    {

    SetProfitTarget("StrategyA", CalculationMode.Price, ProfitTargetPrice);
    SetStopLoss("StrategyA", CalculationMode.Ticks, StopLossTicks, false);


    }
    }

    protected override void OnBarUpdate()
    {

    //Print("Order Name " Order.Name + " " + Time[0]);
    // Condition set 1
    if (ToTime(Time[0]) >= ToTime(startMHours, startMinutes, startSeconds)
    && GetCurrentBid() > LongMaxEntry
    && GetCurrentBid() < LongMinEntry
    && true == LongEnabled)
    {
    EnterLong(DefaultQuantity, "StrategyA");
    }

    // Condition set 2
    if (ToTime(Time[0]) >= ToTime(startMHours, startMinutes, startSeconds)
    && GetCurrentAsk() < ShortMaxEntry
    && GetCurrentAsk() > ShortMinEntry
    && true == ShortEnabled)
    {
    Print("Enter Short");
    EnterShort(DefaultQuantity, "StrategyA");
    }
    }
    Last edited by hotsalami; 05-13-2016, 08:16 AM.

    #2
    Hello hotsalami,

    Thanks for your post.

    In looking at your condition sets, is set two correct?

    It has the time condition as an equals instead of greater than or equals.

    It say Print long but has Entershort()?
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul..yes, thank you noticing that. I was only testing the long side.. The condition 2 should have saids

      // Condition set 2
      if (ToTime(Time[0]) >= ToTime(startMHours, startMinutes, startSeconds)

      I have corrected it in the original post.

      Comment


        #4
        Hello hotsalami,

        Thanks for your reply.

        The start behavior you have selected is the issue here. What happens is that when A goes long (for example) you would have a long strategy position and a long account position. When strategy B then is enabled it will immediately close the account long position and then will go long leaving you with: Strategy A strategy position Long, Strategy B position long, but account position will only be the last strategy that was enabled, long (in this example Strategy B). You can observe this by looking at the strategies in the control center as it will show both the strategy position and the account position.

        I made a short video of this: http://screencast.com/t/yrEOeJ5AlR

        Please review the helpguide here: http://ninjatrader.com/support/helpG..._positions.htm
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thanks Paul for the update..Excellent use of the video!

          I am pretty sure I am reading the help file incorrectly, but as I understand it, on the Order Handling part of the strategy window, I can specify the entry handling to be unique and the entries per direction = 1. What I thought what the ""Unique Entries" is that for a given strategy with a unique name and Signal name (EnterLong(DefaultQuantity, "StratgeyA", EnterLong(DefaultQuantity, "StratgeyB", ) that it would add to the position (i.e. if I am already in a long position with signal name A which is setup to have 1 entry per the direction and another order is filled (SingalB) that it would increase the account position = 2? is this not the case?

          Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


          If I wanted both A and B to fire, what is the correct way to do that?

          Again..thanks for the great video.

          Comment


            #6
            Hello hotsalami,

            Thanks for your reply.

            The entries per direction and entry handling would be unique to the given strategy and would not apply to any other strategy regardless of the signal names.

            Testing the default start behavior of "wait until flat" showed that with both (of my examples in the video) A & B running, each was 1 long in the strategy and the account was 2 long. I would offer up that with your sim account you may want to test the various combinations of start behavior to find what works best for you and how you want the strategies and their start-up to behave. Here is another link that provides further information: http://ninjatrader.com/support/helpG..._account_p.htm
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by hotsalami View Post
              Thanks Paul for the update..Excellent use of the video!

              I am pretty sure I am reading the help file incorrectly, but as I understand it, on the Order Handling part of the strategy window, I can specify the entry handling to be unique and the entries per direction = 1. What I thought what the ""Unique Entries" is that for a given strategy with a unique name and Signal name (EnterLong(DefaultQuantity, "StratgeyA", EnterLong(DefaultQuantity, "StratgeyB", ) that it would add to the position (i.e. if I am already in a long position with signal name A which is setup to have 1 entry per the direction and another order is filled (SingalB) that it would increase the account position = 2? is this not the case?

              Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


              If I wanted both A and B to fire, what is the correct way to do that?

              Again..thanks for the great video.
              Unique Entries and entries per direction are relevant to only the strategy that is initiating the orders. They are not cross-strategy properties.

              On the other hand, the "Start Behavior", as it uses the account and strategy both, is necessarily crossed. Your start behavior is the issue, as the strategies try to sync the account to strategy positions by issuing the necessary orders that will sync the strategy position to the account position.

              Pretty much every strategy I write does exactly what you are describing. I have a property that determines whether the strategy takes only long trades or only short trades. I run 2 copies, one to go long, the other to go short. The net effect is that when I get an opposite signal to the current market posture, I am taken logically flat, even though I seem to have simultaneous short and long positions. That way, I have stopped losing money, but whichever strategy gets exited, means that I am immediately and automatically resuming the other trade. Pretty much the 2 together are acting as "get out and reverse, or continue, only after confirmation".

              You will need the settings shown in the picture.
              .

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by judysamnt7, 03-13-2023, 09:11 AM
              4 responses
              59 views
              0 likes
              Last Post DynamicTest  
              Started by ScottWalsh, Today, 06:52 PM
              4 responses
              36 views
              0 likes
              Last Post ScottWalsh  
              Started by olisav57, Today, 07:39 PM
              0 responses
              7 views
              0 likes
              Last Post olisav57  
              Started by trilliantrader, Today, 03:01 PM
              2 responses
              21 views
              0 likes
              Last Post helpwanted  
              Started by cre8able, Today, 07:24 PM
              0 responses
              10 views
              0 likes
              Last Post cre8able  
              Working...
              X