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 Shansen, 08-30-2019, 10:18 PM
              24 responses
              938 views
              0 likes
              Last Post spwizard  
              Started by Max238, Today, 01:28 AM
              0 responses
              3 views
              0 likes
              Last Post Max238
              by Max238
               
              Started by rocketman7, Today, 01:00 AM
              0 responses
              2 views
              0 likes
              Last Post rocketman7  
              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  
              Working...
              X