Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Dynamic profit target help needed

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

    Dynamic profit target help needed

    I have an issue with the profit target code
    Code:
    SetProfitTarget("", CalculationMode.Ticks, 4)
    this works great when I have one position on. But when I have 4 positions, it sees every entry as unique, thus it only looks for 4 tick profit on a individual entry. How can I tell Ninjatrader to look for a 4 tick profit of the AVERAGE 4 positions I have active. for example

    1 Position size:
    Long : $1256 Profit target should be $1257

    2 Position Size
    Long $1250
    Long $1210
    AVG is $1230 profit target should be $1231

    3 Position on
    Long 1270
    Long 1250
    Long 1200
    AVE is $1240 profit target now should be $1241

    Long : 1254
    Long : 1250
    Long : 1210
    Long : 1200

    The average position size I have on is ~1228 so it should look for a profit target of 1229

    #2
    Originally posted by wallsteetking View Post
    I have an issue with the profit target code
    Code:
    SetProfitTarget("", CalculationMode.Ticks, 4)
    this works great when I have one position on. But when I have 4 positions, it sees every entry as unique, thus it only looks for 4 tick profit on a individual entry. How can I tell Ninjatrader to look for a 4 tick profit of the AVERAGE 4 positions I have active. for example

    1 Position size:
    Long : $1256 Profit target should be $1257

    2 Position Size
    Long $1250
    Long $1210
    AVG is $1230 profit target should be $1231

    3 Position on
    Long 1270
    Long 1250
    Long 1200
    AVE is $1240 profit target now should be $1241

    Long : 1254
    Long : 1250
    Long : 1210
    Long : 1200

    The average position size I have on is ~1228 so it should look for a profit target of 1229
    So you are price-averaging down?

    In that case, use CalculationMode.Price, and use the Position.AvgPrice as the target price.

    Code:
    SetProfitTarget("", CalculationMode.Price, Position.AvgPrice + 4 * TickSize);
    Last edited by koganam; 04-29-2013, 11:11 AM. Reason: Corrected code to show full profit target.

    Comment


      #3
      Hey thanks this is what I was looking for...
      I have one more question to ask you when I use this code
      Code:
      if (Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) <= -200)
      I noticed Ninjatrader will enter on every bar.. How can I tell ninjatrader to enter only ONCE on -200 loss???

      Comment


        #4
        Originally posted by wallsteetking View Post
        Hey thanks this is what I was looking for...
        I have one more question to ask you when I use this code
        Code:
        if (Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) <= -200)
        I noticed Ninjatrader will enter on every bar.. How can I tell ninjatrader to enter only ONCE on -200 loss???
        Easiest way is to use a boolean flag, and check its state.
        Code:
        private bool CriticalFlag = false;
        Code:
         
        if (!CriticalFlag && Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) <= -200)
        {
        // etc
        CriticalFlag = true;
        }
         
        if (Position.MarketPosition == MarketPosition.Flat) CriticalFlag = false; //we need to reset this somewhere; either when Flat or at next entry.
        Last edited by koganam; 04-29-2013, 09:45 PM.

        Comment


          #5
          I keep getting an error message. First when I put this code inside
          protected override void Initialize()
          Code:
          SetProfitTarget("", CalculationMode.Price, Position.AvgPrice + 4 * TickSize);
          I get this error message in the LOG TAP
          4/29/2013 6:33:44 PM Strategy Failed to call method 'Initialize' for strategy 'A41/48f53ffd20a442cdb2d95d27e369e8bd': 'Position' property can't be accessed from within 'Initialize' method.
          .

          And when I put the code inside protected override void OnBarUpdate() I get this (see picture)
          Attached Files

          Comment


            #6
            Originally posted by wallsteetking View Post
            I keep getting an error message. First when I put this code inside
            Code:
            SetProfitTarget("", CalculationMode.Price, Position.AvgPrice + 4 * TickSize);
            I get this error message in the LOG TAP
            Logic error. You cannot possibly have a position in Initialize(): you cannot access that which you do not have.
            And when I put the code inside protected override void OnBarUpdate() I get this (see picture)
            It looks to me like you again have another logic error, where you called this statement before you were in a position, so this time the code just gave you an average price of zero, the only possibility for a non-existent position, other than to throw an exception. That puts your target at 4 ticks above zero, equal to $1.

            The computer did what you told it. If what the 'puter did does not match your intent, then correct your logic.
            Last edited by koganam; 04-29-2013, 07:42 PM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by andrewtrades, Today, 04:57 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            3 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            436 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            7 views
            0 likes
            Last Post FAQtrader  
            Started by rocketman7, Today, 09:41 AM
            5 responses
            19 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X