Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Scaling into a position?

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

    Scaling into a position?

    I will use the following example/toy code to illustrate my issue.

    I start by trying to make (or lose) $100.00 on every trade (call this entry longOne).

    My setup allows me to buy a certain number of shares and then make or lose the $100.00 by setting a stop loss which is priced the same number of cents away from my entry as is my profit target.

    If I win cleanly, I enter once and close out my $100.00 profit.

    If I reach -$50.00, however, I want to add 50% more shares (call this long2). If this happens, my target prices do not change, so if I win, it is $175.00, or if I lose, it costs me $125.00.

    Things currently look like this:


    protected override void Initialize()

    {

    TimeInForce = Cbi.TimeInForce.Day;
    ForceMaximumBarsLookBack256 = false;


    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.UniqueEntries;

    }


    protected override void OnBarUpdate()

    {

    // Long Entry 1

    if ((Position.MarketPosition == MarketPosition.Flat)
    && ((Closes[2][0] < pointA)
    && (Closes[2][0] >= pointB))


    {

    EnterLongLimit(2, true, shares1, entryPrice1, "longOne");
    SetProfitTarget("longOne", CalculationMode.Price, (entryPrice1 + increment);
    SetStopLoss("longOne", CalculationMode.Price, (entryPrice1 - increment), false);

    }


    // Long Entry 2

    else if ((Position.MarketPosition == MarketPosition.Long)
    && ((Closes[2][0] < pointA - (increment/2))
    && (Closes[2][0] >= pointB - (increment/2))

    {

    EnterLongLimit(2, true, shares1 * 0.5, entryPrice1 - (increment/2), "longTwo");
    SetProfitTarget("longTwo", CalculationMode.Price, (entryPrice1 + increment);
    SetStopLoss("longTwo", CalculationMode.Price, (entryPrice1 - increment), false);

    }

    The first Trade fires and is perfectly accurate. The second trade then never fires.
    By the way the Bar Indexed as 2 is a tick bar, not that this really matters, but just for ease of interpretation.

    Any ideas or help?

    Thanks in advance,

    Andrew

    #2
    Andrew,

    Where are you setting pointA and pointB?

    Another thing to note is that you are using the managed approach so you may want to read the following. There are some under-the-hood order handling rules.

    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Point A and Point B are static values, they give me a couple of cents buffer around my predetermined entry points. I could assign them statically in my variables section, but they change daily for the 300 or so stocks on my list so I allow them to update via calculated user defined method each day.


      I am curious about the managed approach; I will read what you linked, but what should I be keeping an eyes on?

      Thanks,

      Andrew

      Comment


        #4
        Andrew,

        It looks like in this case with a static value for these the order may not enter? For example if the price changes to be outside your range.

        Code:
        && ((Closes[2][0] < pointA - (increment/2)) 
        && (Closes[2][0] >= pointB - (increment/2))
        These two lines here both have a subtraction, is one supposed to be a +?

        Also, lets start here :

        Code:
        else if ((Position.MarketPosition == MarketPosition.Long)
        && ((Closes[2][0] < pointA - (increment/2)) 
        && (Closes[2][0] >= pointB - (increment/2))
        
        {
        Print("Second order should happen");
        EnterLongLimit(2, true, shares1 * 0.5, entryPrice1 - (increment/2), "longTwo");
        SetProfitTarget("longTwo", CalculationMode.Price, (entryPrice1 + increment);
        SetStopLoss("longTwo", CalculationMode.Price, (entryPrice1 - increment), false);
        
        }
        Add the Print line and watch your output window when you use this strategy. This will tell you whether or not your conditions were satisfied. If they are, and you do not get your second order then likely you are running into a managed approach under-the-hood item. Sometimes order commands are ignored in the managed approach to reduce unwanted positions. It's sort of a "safe" framework to work within but there is also an unmanaged approach for more order control.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          See my comments inline below:


          Originally posted by NinjaTrader_AdamP View Post
          Andrew,

          It looks like in this case with a static value for these the order may not enter? For example if the price changes to be outside your range.

          Code:
          && ((Closes[2][0] < pointA - (increment/2)) 
          && (Closes[2][0] >= pointB - (increment/2))
          These two lines here both have a subtraction, is one supposed to be a +?

          Response: No, Think of my entry point as a value of 20.00 for a given stock.

          Point A is a double variable which is Price + 0.02 = $20.02
          Point B is a double variable which is Price - 0.02 = $19.98.

          I am comfortable buying anywhere in that range.

          Subtracting (increment/2) from both gives me the range, which is halfway to my stop loss, where I would be comfortable putting on my second long trade.






          Also, lets start here :

          Code:
          else if ((Position.MarketPosition == MarketPosition.Long)
          && ((Closes[2][0] < pointA - (increment/2)) 
          && (Closes[2][0] >= pointB - (increment/2))
          
          {
          Print("Second order should happen");
          EnterLongLimit(2, true, shares1 * 0.5, entryPrice1 - (increment/2), "longTwo");
          SetProfitTarget("longTwo", CalculationMode.Price, (entryPrice1 + increment);
          SetStopLoss("longTwo", CalculationMode.Price, (entryPrice1 - increment), false);
          
          }
          Add the Print line and watch your output window when you use this strategy. This will tell you whether or not your conditions were satisfied. If they are, and you do not get your second order then likely you are running into a managed approach under-the-hood item. Sometimes order commands are ignored in the managed approach to reduce unwanted positions. It's sort of a "safe" framework to work within but there is also an unmanaged approach for more order control.
          Response:

          I will do this tomorrow. Do you have a good link to what I might need to change in the unmanaged approach that I can read up on? Thank you Adam.


          Regards,

          Andrew

          Comment


            #6
            Andrew,

            Ok, let us know how it goes. Likely we will want to see if that set of conditions is being satisfied first, and if it is we can also look at your log to see if there was an order being ignored.

            This may be helpful :



            Also here is more on the unmanaged approach :

            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Adam / Team:

              As suggested below, the Print line has not appeared once today, although the strategy has moved to the "trigger" price numerous times in more than 20 individual securities.

              I assume that this is because of some "under the hood" issues with the managed approach, as described by Adam below.

              I am looking for any next steps I should take and/or advice that would be helpful at this point.

              Thanks and regards,

              Andrew

              Comment


                #8
                Alabell,

                If the print statement didn't execute it means that the condition wasn't satisfied, assuming you are using this :

                else if ((Position.MarketPosition == MarketPosition.Long)
                && ((Closes[2][0] < pointA - (increment/2))
                && (Closes[2][0] >= pointB - (increment/2))
                {
                Print("Second order should happen");
                //other stuff
                The condition, if satisfied, should cause this print statement to execute.

                The under-the-hood items would be shown if you use TraceOrder = true, and you can see if an order was ignored due to internal order handling rules, i.e. it will specifically tell you why the order was ignored.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  Trace is one, can you give me an example of what an error message would say; I have copied 90,000 print lines into a document and I want to search; actually I am guessing the strategy name longTwo would be a good place to start. I will check and report back.

                  Comment


                    #10
                    alabell,

                    Most of them would look something like :

                    7/01/2011 1:00:00 AM Ignored PlaceOrder() method at 7/01/2011 1:00:00 AM: Action=BuyToCover OrderType=Limit Quantity=3,000 LimitPrice=1.2997 StopPrice=0 SignalName=Buy to cover' FromEntrySignal='' Reason='An Exit() method to submit an exit order has been ignore. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.'
                    Adam P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by cre8able, Yesterday, 01:16 PM
                    3 responses
                    11 views
                    0 likes
                    Last Post cre8able  
                    Started by Harry, 05-02-2018, 01:54 PM
                    10 responses
                    3,203 views
                    0 likes
                    Last Post tharton3  
                    Started by ChartTourist, Today, 08:22 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post ChartTourist  
                    Started by LiamTwine, Today, 08:10 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post LiamTwine  
                    Started by Balage0922, Today, 07:38 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post Balage0922  
                    Working...
                    X