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

Different stop loss modification

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

    Different stop loss modification

    Hi!

    I want to write a strategy for a stop loss modification.
    I wrote it however it doesn't work properly. It works but has different results.

    You may look it on example:

    Lets say my stop loss is 4 ticks
    If I have:
    +5 ticks profit modify stop loss to -3 ticks loss
    +6 ticks profit modify stop loss to -2 ticks loss
    +7 ticks profit modify stop loss to -1 tick loss
    +8 ticks profit modify stop loss to 0 tick break-even
    +9 ticks profit modify stop loss to +1 tick profit
    +10 ticks profit modify stop loss to +2 tick profit
    +11 ticks profit modify stop loss to +3 tick profit

    if (Position.MarketPosition == MarketPosition.Short)
    {
    if(Low[0] <= Position.AvgPrice - (5 * TickSize))
    SetStopLoss("Short1",CalculationMode.Price, Position.AvgPrice + (3*TickSize) ,false);
    ...
    if(Low[0] == Position.AvgPrice - (11 * TickSize))
    SetStopLoss("Short1",CalculationMode.Price, Position.AvgPrice - (3*TickSize),false);
    }

    It check only the last bar low[0] to last entry price.
    If I leave only ONE stop loss modification it works great.

    +8 ticks profit modify stop loss to 0 tick break-even

    It does exactly what I want.
    It finds THE LOWEST LOW from my ENTRY PRICE and compared to current price.
    However when I use all of them it is a mess.

    If you know how to help me to modify stop losses to different parameters I will only appreciate

    Script included

    Thanks,
    Serge
    Last edited by olres7; 10-23-2015, 05:29 PM.

    #2
    Originally posted by olres7 View Post
    Hi!

    I want to write a strategy for a stop loss modification.
    I wrote it however it doesn't work properly. It works but has different results.

    You may look it on example:

    Lets say my stop loss is 4 ticks
    If I have:
    +5 ticks profit modify stop loss to -3 ticks loss
    +6 ticks profit modify stop loss to -2 ticks loss
    +7 ticks profit modify stop loss to -1 tick loss
    +8 ticks profit modify stop loss to 0 tick break-even
    +9 ticks profit modify stop loss to +1 tick profit
    +10 ticks profit modify stop loss to +2 tick profit
    +11 ticks profit modify stop loss to +3 tick profit

    if (Position.MarketPosition == MarketPosition.Short)
    {
    if(Low[0] <= Position.AvgPrice - (5 * TickSize))
    SetStopLoss("Short1",CalculationMode.Price, Position.AvgPrice + (3*TickSize) ,false);
    ...
    if(Low[0] == Position.AvgPrice - (11 * TickSize))
    SetStopLoss("Short1",CalculationMode.Price, Position.AvgPrice - (3*TickSize),false);
    }

    It check only the last bar low[0] to last entry price.
    If I leave only ONE stop loss modification it works great.

    +8 ticks profit modify stop loss to 0 tick break-even

    It does exactly what I want.
    It finds THE LOWEST LOW from my ENTRY PRICE and compared to current price.
    However when I use all of them it is a mess.

    If you know how to help me to modify stop losses to different parameters I will only appreciate

    Script included

    Thanks,
    Serge
    You have your statements in the wrong order. Reverse the order.

    Comment


      #3
      Originally posted by koganam View Post
      You have your statements in the wrong order. Reverse the order.
      What do You mean reverse order?
      Can provide example pls?

      Comment


        #4
        Hello olres7,

        Thanks for your post. You have also submitted a help request and I have just responded to that seeking more information. This post is to clarify that we are working to assist you through the help request submitted.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by olres7 View Post
          What do You mean reverse order?
          Can provide example pls?
          You must process your code in mathematically logical fashion, not necessarily in what is putatively chronological order.

          if(Low[0] == Position.AvgPrice - (11 * TickSize)) is true, then so is (Low[0] <= Position.AvgPrice - (5 * TickSize)).

          The code will be processed in the order that it is written, so if it is written the way that you have, then the smaller offset will always be processed and the other will be ignored.

          Always process from largest offset to smallest. Write your statements in the reverse order to what you have written. There is no other way that I can state it. Perhaps I misunderstand what seems to be misunderstood by you?

          Comment


            #6
            Thank you very much

            Originally posted by koganam View Post
            You must process your code in mathematically logical fashion, not necessarily in what is putatively chronological order.

            if(Low[0] == Position.AvgPrice - (11 * TickSize)) is true, then so is (Low[0] <= Position.AvgPrice - (5 * TickSize)).

            The code will be processed in the order that it is written, so if it is written the way that you have, then the smaller offset will always be processed and the other will be ignored.

            Always process from largest offset to smallest. Write your statements in the reverse order to what you have written. There is no other way that I can state it. Perhaps I misunderstand what seems to be misunderstood by you?

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            435 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            3 views
            0 likes
            Last Post FAQtrader  
            Started by rocketman7, Today, 09:41 AM
            5 responses
            18 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by frslvr, 04-11-2024, 07:26 AM
            9 responses
            126 views
            1 like
            Last Post caryc123  
            Started by selu72, Today, 02:01 PM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_Zachary  
            Working...
            X