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 tkaboris, Today, 05:13 PM
              0 responses
              2 views
              0 likes
              Last Post tkaboris  
              Started by GussJ, 03-04-2020, 03:11 PM
              16 responses
              3,281 views
              0 likes
              Last Post Leafcutter  
              Started by WHICKED, Today, 12:45 PM
              2 responses
              19 views
              0 likes
              Last Post WHICKED
              by WHICKED
               
              Started by Tim-c, Today, 02:10 PM
              1 response
              10 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by Taddypole, Today, 02:47 PM
              0 responses
              5 views
              0 likes
              Last Post Taddypole  
              Working...
              X