Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss Question - Exiting Immediately

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

    SetStopLoss Question - Exiting Immediately

    Hi,

    Below I have included my code. I am simply trying to test the value from my oscillator for bar0 and compare it to bar1. I believe I have everything correct, but for some reason, when it goes into my "if" test, it doesn't draw a dot and only prints my test text. Also, on my chart, I see an entry, followed by an immediate exit at same price.

    I have commented out SetStopLoss everywhere else.

    What I want is to move my StopLoss to the high or low of the last bar if my condition is met. I would appreciate any help.

    Thanks,

    BEGIN CODE:

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

    if (bar0 < bar1) // If my osc reading for last bar, is less than 2 bars ago.
    {
    DrawDot(
    "L1Break" + CurrentBar, false, 0, 0, Color.Green);
    SetStopLoss(
    "L1", CalculationMode.Price, Low[1], false);
    Print("L1Break Bar0 Is Less than Bar1 and we are Long"
    }

    }

    if (Position.MarketPosition == MarketPosition.Short)
    {
    if (bar0 > bar1) // If my osc reading for last bar, is greater than osc reading 2 bars ago.
    {
    DrawDot(
    "S1Break" + CurrentBar, false, 0, 0, Color.Red);
    SetStopLoss(
    "S1", CalculationMode.Price, High[1], false);
    Print(
    "S1Break Bar0 Is Greater than Bar1 and we are Short");
    }
    }

    #2
    Ok,

    I did some testing and here is what is happening. (Yes, trace orders is true).

    My default SetStopLoss is set to 500.00 cash.

    Now when my logic is triggered in my if statement, the if bar0 is greater than bar1 or the reverse, it forks into my nest as it should, but it seems to set the stoploss to the default value of 500 and as such on the TF it is seeing that as price 500 (calc mode = price) and taking down my order right away.

    So I guess my question is, why is my strategy ignorning my SetStopLoss statement in my code listed in the prior post and defaulting instead to the 500 value set initially in the initialize() section of the code?


    Thanks

    Comment


      #3
      I had some code that tested "if flat" and then set the SetStopLoss to the default of 500 cash.

      That seems to be where the problem lies. I either need to stop labeling my entries, or I need to provide the code as follows:

      if (Position.MarketPosition == MarketPosition.Flat)
      {
      // SetStopLoss(Stop); //Old Setting/Original
      SetStopLoss("L1", CalculationMode.Ticks, StopLoss, false);
      SetStopLoss(
      "S1", CalculationMode.Ticks, StopLoss, false);
      }

      NT can you confirm this was my problem?

      My guess is that because I was labeling my entries, it would use the stop value as "price" instead of cash. I don't understand exactly why, but I think this was the issue.


      Thanks

      Comment


        #4
        r2kTrader, great you found a resolution - correct you would need to reset the stoploss once you're flat, as shown in this reference sample here - http://www.ninjatrader-support2.com/...ead.php?t=3222
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          r2kTrader, great you found a resolution - correct you would need to reset the stoploss once you're flat, as shown in this reference sample here - http://www.ninjatrader-support2.com/...ead.php?t=3222
          Bertrand,

          Thank you for the prompt reply.

          Ok, check, but?

          Can I use a generic SetStopLoss()? It seems when I did that, that it defaulted to say $500.00 (which is what StopLoss variable is set to, trading the TF which is about 525 as I write this post) and as such, it was defaulting my stop loss to Calcmode.price of 500 which in turn seemed to put me in/out of trades in same cycle.

          I know there is a link somewhere that goes over this whole dilio, but I couldn't find it or remember it. (of course because I need it now).

          Comment


            #6
            r2kTrader, you're welcome - I'm not sure what you mean by generic StopLoss - best pratice is to set it to the specific calculation mode you need, leaving this to none would default it to using cash values - http://www.ninjatrader-support.com/H...tStopLoss.html

            For the Dot you want to place, you would need to enter a valid values for the Y axis display, yours is set at 0 in your code.
            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Mizzouman1, Today, 07:35 AM
            4 responses
            18 views
            0 likes
            Last Post Mizzouman1  
            Started by philmg, Today, 01:17 PM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Started by cre8able, Today, 01:01 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by manitshah915, Today, 12:59 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by ursavent, Today, 12:54 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X