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

SL Condition Within Entry Condition

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

    SL Condition Within Entry Condition

    Hello everyone,

    Currently I have a strategy that sets a stoploss at the Low - 6 ticks or High + 6 ticks @ entry depending upon if it is a long or short. I want to add another option under certain conditions.

    I want to set either one stop loss OR the other, depending upon if a condition is true (if the wick of the entry candle is greater or less than a certain calculated tick value, saved to a variable diffLong or diffShort).

    What would be the proper syntax to make this possible? So far I haven't had any success. I have tried different combinations, including simply adding a condition and action with brackets WITHIN the brackets for the entry condition, I have tried if, else if syntax. Nothing.

    Code:
    if (Condition for Entry)
                {
                    if (ssdiff < 44) {SetStopLoss(@"TestStopShort", CalculationMode.Price, High[0] + 6 * TickSize, false);}
                    SetStopLoss(@"TestStopShort", CalculationMode.Ticks, 20, false);
                    EnterShort(1, Q, @"TestStopShort");
                }
    That is a snippet of my code just so you can see with greater specificity what I am dealing with.

    Thanks for any ideas.

    #2
    Hello lunardiplomacy,

    Thanks for your post.

    Have you tried this:

    if (Condition for Entry)
    {

    if (ssdiff < 44)
    {
    SetStopLoss(@"TestStopShort", CalculationMode.Price, High[0] + 6 * TickSize, false);
    }
    else
    {
    SetStopLoss(@"TestStopShort", CalculationMode.Ticks, 20, false);
    }


    EnterShort(1, Q, @"TestStopShort");
    }
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul, thanks for getting back to me.

      Yes, that syntax was the first that I tried and I thought that should absolutely work, right? But, it doesn't. I just tried again to make sure, and still the same result.

      However, I do have some additional information now. I tried tacking on 'ssdiff < 44' to my entry conditions, just to see if I intentionally ran it on a 100 tick wick, whether it would take a trade or not (it shouldn't), and it did indeed take a trade. Which means something is not right about how the entry is being taken.

      'ssdiff' prints the correct values, so I know it is over 44 when the trade is taken, and therefore calculating correctly. I even set that condition as a bool and added that it has to be true in order for the trade to be taken. And yet, in a test, I saw right before my eyes that it printed false and the diff printed over 100 ticks and still the trade was taken.

      I am so confused, things that should absolutely work are not working. I am going to try to isolate this set of conditions to a new script to see if I can get it to work. In the meantime, any ideas you might have for me in terms of what's going wrong would be greatly appreciated.

      Thank you.

      Comment


        #4
        Hello lunardiplomacy,

        Thanks for your reply.

        Make sure you are checking the "log" tab of the control center when you apply the script as any errors or ignored orders would be noted there.

        Otherwise, I would suggest debugging further and agree with the idea to "... try to isolate this set of conditions to a new script to see if I can get it to work."
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        27 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 02-22-2024, 01:11 AM
        5 responses
        32 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 04-23-2024, 09:53 PM
        2 responses
        49 views
        0 likes
        Last Post wzgy0920  
        Started by Kensonprib, 04-28-2021, 10:11 AM
        5 responses
        193 views
        0 likes
        Last Post Hasadafa  
        Started by GussJ, 03-04-2020, 03:11 PM
        11 responses
        3,235 views
        0 likes
        Last Post xiinteractive  
        Working...
        X