Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

stoploss and swinghigh/low indicator

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

    stoploss and swinghigh/low indicator

    Hallo,

    in my strategy I am looking for a possibility to automatic change the stoploss on the last swinghigh or low. Do you have a code snippet für me?

    My trail:

    #region Variables

    private IOrder _long_order = null;
    private bool _long_sent = false;

    private IOrder _short_order = null;
    private bool _short_sent = false;

    double swinghigh_value = 0;
    double swinglow_value = 0;

    protected override void OnBarUpdate()
    {
    // Condition set 1 (LONG)
    if (ToTime(Time[0]) >= 80000 && ToTime(Time[0]) <= 220000
    && WMA(Weighted, 20)[0] > WMA(Weighted, 50)[0]
    && Low[0] > WMA(Weighted, 20)[0]
    && WMA(Weighted, 20)[0] > WMA(Weighted, 20)[4]
    && Close[0] > Swing(5).SwingHigh[0])
    {
    _long_order=EnterLong(DefaultQuantity, "Long");
    }

    // set swinglow_value:
    swinglow_value = Swing(5).SwingLow[0];

    // set the stop loss to swinglow_value:
    SetStopLoss("Long", CalculationMode.Ticks, swinglow_value, false);



    But nothing change ... Where is the error?

    Thanks Blackburn

    #2
    Hello,

    Thank you for your post.

    Do you see the Stop Loss set originally? What value is it set at? Or do you not see the stop placed at all?

    Please try running TraceOrders = true and run the strategy and check for any errors when setting this stop loss:

    MatthewNinjaTrader Product Management

    Comment


      #3
      Hallo Matthew,

      many thanks for the quick response.
      Is the code correct? Or Do you have an other suggestion?

      Blackburn

      Comment


        #4
        Blackburn,

        From what I can tell, the code is correct - can you expand on how it is not behaving as you expect?

        Did you run trace orders? What was the output after running the strategy?
        MatthewNinjaTrader Product Management

        Comment


          #5
          swinglow_value = Swing(5).SwingLow[0]; is a price, so you should use CalculationMode.Price for your SetStopLoss().

          Comment


            #6
            Thanks Koganam,

            that works :-)

            Comment


              #7
              koganam, infinite thanks for all your help.
              AustinNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              93 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              48 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              31 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              34 views
              0 likes
              Last Post TheRealMorford  
              Started by Mindset, 02-28-2026, 06:16 AM
              0 responses
              69 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Working...
              X