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

Stop Loss Order Modification

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

    Stop Loss Order Modification

    Hi Josh, I was looking at one of your posts (dated 09-07-2007) about submitting stop loss orders using default values offset from the entry order average fill price, and moditfying the order when a certain profit level has been reached.

    I’ve incorporated the following code into my script which is faily much the same as yours. I have found a couple of issues which I hope you could shed some light on….

    1) In my script which I have incorporated SetStopLoss, within the entry conditions I have BarSinceExit() > 1, and this works without problem with other exit conditions, except for SetStopLoss. After a SetStopLoss has been executed, another entry can be executed immediately in the same bar without waiting for the next bar.
    Is this an issue with SetStopLoss, and is there a way around this?

    2) I have also noticed in the output window that the nested SetStopLoss code loops quite intensively, and although it works, my PC performance has taken a hit! Are there inefficiencies in the code I have not seen?


    Thanks in advance….


    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetStopLoss("", CalculationMode.Ticks, FixedStop, true);
    }


    elseif (Position.MarketPosition == MarketPosition.Long)
    {

    if (High[0] > Position.AvgPrice + 10 * TickSize)
    {
    SetStopLoss("", CalculationMode.Price, (Position.AvgPrice - 20), true);
    }


    if (High[0] > Position.AvgPrice + 40 * TickSize)
    {
    SetStopLoss("", CalculationMode.Price, (Position.AvgPrice + 18), true);
    }


    if (High[0] > Position.AvgPrice + 65 * TickSize)
    {
    SetStopLoss("", CalculationMode.Price, (Position.AvgPrice + 50), true);
    }

    if (High[0] > Position.AvgPrice + 100 * TickSize)
    {
    SetStopLoss("", CalculationMode.Price, (Position.AvgPrice + 80), true);
    }
    Last edited by John833; 11-03-2008, 05:13 AM.

    #2
    Hello,


    For 1. You will need to debug it. See what the value of BarsSinceExit() is after it closes you out of the trade.

    For 2. Depending on your intent with your modification of Position.AvgPrice you may want to use something like Position.AvgPrice + 80 * TickSize.

    Also, reverse the ordering of the if statements. Right now you will submit 4 order modifications to get to your last SetStopLoss.

    Then use else if's:

    else if (Position.MarketPosition == MarketPosition.Long)
    {
    if (High[0] > Position.AvgPrice + 100 * TickSize)
    SetStopLoss(“”, CalculationMode.Price, (Position.AvgPrice + 80 * TickSize, true);
    else if (High[0] > Position.AvgPrice + 65 * TickSize)
    SetStoploss(“”, CalculationMode.Price, (Position.AvgPrice + 50 * TickSize, true);

    ……etc.
    }
    DenNinjaTrader Customer Service

    Comment


      #3
      thanks Ben, thats helpful...

      Comment


        #4
        This could be a very silly question, but if I am not mistaken by reversing the ordering of the if statements as you suggest would still mean that there will still be 4 order modifications to get the last SetStopLoss, so is there any advantage?
        Last edited by John833; 11-03-2008, 12:59 PM.

        Comment


          #5
          Hello,


          You want to reverse the order so that the toughest condition to meet is tested first. This is necessary because your easier conditions would evaluate to true and the tougher conditions would never be reached since you are would be using else if's.

          When the tough conditions are not met they will not submit orders and will move on to the more relaxed conditions. Ultimately when one condition is finally evaluated to true it will place the single order modification and then you will be kicked out of the else-if and no further orders will be placed on this run.
          DenNinjaTrader Customer Service

          Comment


            #6
            Thank you very much, I'll give this a go....

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Zeezee, Today, 12:45 PM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Started by tomasak, Today, 12:54 PM
            0 responses
            0 views
            0 likes
            Last Post tomasak
            by tomasak
             
            Started by swjake, Today, 12:04 PM
            2 responses
            9 views
            0 likes
            Last Post swjake
            by swjake
             
            Started by Richozzy38, Yesterday, 01:06 PM
            5 responses
            24 views
            0 likes
            Last Post Richozzy38  
            Started by tradingnasdaqprueba, 05-07-2024, 03:42 AM
            13 responses
            51 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X