• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Updating Stop and Profit Target Values on the Fly

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

    Updating Stop and Profit Target Values on the Fly

    I am trying to use variables as my stop and profit target values but it doesn't seem like they are working. I built this in the strategy wizard then opened it up to finish adding the details that can't be done in the wizard. Basically when I enter a long or short position, at the same time I set Variable0 as the stop (based on MIN Low - a tick) after 1 bar I set Variable1 as the profit target (MAX High - 1 tick). I'm using named entries and pairing my profit targets to those named entries. Stops I leave open for future planning for multiple contracts at different profit targets. Here's the code for setting the profit and stop code and setting the variables:
    SetStopLoss("", CalculationMode.Price, Variable0, false);
    SetStopLoss("", CalculationMode.Price, Variable2, false);
    SetProfitTarget("L1", CalculationMode.Price, Variable1);
    SetProfitTarget("S1", CalculationMode.Price, Variable3);
    EnterLong(DefaultQuantity, "L1");
    Variable0 = MIN(Low, LB_Short)[0];
    Print(" Long Entry " + " Long Stop = " + " " + Variable0 + " " + " Close Price = " + Close[0]);
    // Update Long Position Stop and Target Values
    if (Position.MarketPosition == MarketPosition.Long)
    {
    Variable0 = Low[1] + -1 * TickSize;
    Variable1 = MAX(High, LB_Long)[1] + -1 * TickSize;
    Print(" Position Long - Updating Variables " + " Long Stop = " + Variable0 + " Long Target = " + Variable1 + " Close = " + Close[0]);
    }
    As you can see I also print out the values so I can see what is going on. The intent is to have the profit targets and stops move up for a long in a market trending up. I do the opposite for shorts. the problem is, they don't work. I end up geting out of positions either when the conditions switch to the other bias (long bias to short bias) or the end of day close occurs because I have that flag set.

    Why aren't variables working as targets? They seem to be updating correctly, and I am setting the variables equal to the value of interest from the previous bar [1] not [0] beause exceeeding a max high on bar 0 won't work.
    thanks
    DaveN
    Last edited by daven; 07-26-2010, 04:36 PM. Reason: Typos

    #2
    daven, please ensure you reset your stops and targets when you're in a flat position with your strategy - http://www.ninjatrader.com/support/f...ead.php?t=3222

    Also: TraceOrders are helpful to debug your 'under the hood' order behavior more detailed -

    http://www.ninjatrader.com/support/f...ead.php?t=3627
    BertrandNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by pjsmith, Today, 04:10 AM
    0 responses
    3 views
    0 likes
    Last Post pjsmith
    by pjsmith
     
    Started by tonynt, Today, 02:21 AM
    0 responses
    8 views
    0 likes
    Last Post tonynt
    by tonynt
     
    Started by alstsion, Today, 12:55 AM
    0 responses
    2 views
    0 likes
    Last Post alstsion  
    Started by kandster, Yesterday, 11:49 PM
    0 responses
    3 views
    0 likes
    Last Post kandster  
    Started by priceisking, Yesterday, 05:33 PM
    0 responses
    26 views
    0 likes
    Last Post priceisking  
    Working...
    X