Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Supertrend Crossover Strategy Code

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

    Supertrend Crossover Strategy Code

    Dear All,

    I am trying to create a SuperTrend cross over strategy similar to MA Crossovers.

    The Supertrend is working fine when used alone as below :

    SuperTrendTS1 = SuperTrendTS(Close, SuperTrendMode.ATR, 7, 1.3, MovingAverageType.HMA, 7, false, false, false);
    if (SuperTrendTS1.UpTrend[0] > 0)
    {EnterLong(1000);}

    if (SuperTrendTS1.DownTrend[0] > 0)
    { EnterShort(1000); }

    Now I am trying to code a crossover as below :

    SuperTrendTS1 = SuperTrendTS(Close, SuperTrendMode.ATR, 7, 1.3, MovingAverageType.HMA, 7, false, false, false);
    SuperTrendTS2 = SuperTrendTS(Close, SuperTrendMode.ATR, 14, 1.3, MovingAverageType.HMA, 14, false, false, false);

    if (SuperTrendTS1.UpTrend[0] > SuperTrendTS2.UpTrend[0])
    { EnterLong(1000); }

    if (SuperTrendTS1.DownTrend[0] < SuperTrendTS2.DownTrend[0])
    { EnterShort(1000); }


    Kindly let me know if I am writing the code for crossover correctly.

    The link to the SuperTrend indicator : https://ninjatraderecosystem.com/use.../tssupertrend/

    Many Thanks.

    #2
    Hello DEBEX7,

    Thank you for your post.

    Your conditions don't quite check for a crossover and you will likely need to modify them to ensure they are triggered during a crossover only. For example, here is your condition to EnterLong():
    Code:
    if (SuperTrendTS1.UpTrend[0] > SuperTrendTS2.UpTrend[0])
    This would check if the UpTrend value for the current bar from SuperTrendTS1 is greater than the UpTrend value for SuperTrendTS2. As long as it is greater, the condition will be true. For a crossover, you would need to use CrossAbove() or modify the condition to check if the TS1 UpTrend value from 1 bar ago was less than the TS2 UpTrend from 1 bar ago and if now it is greater. This would indicate that it was below on the last bar, but above on the current bar which means it crossed over.

    The condition for EnterShort() is similar:
    Code:
    if (SuperTrendTS1.DownTrend[0] < SuperTrendTS2.DownTrend[0])
    This would check if the DownTrend value for the current bar from SuperTrendTS1 is greater than the DownTrend value for SuperTrendTS2. You could consider using CrossBelow() or checking if the TS1 DownTrend value from 1 bar ago was less than the TS2 DownTrend value and if it is now greater on the current bar. For more information on using CrossAbove() and CrossBelow(), please see the following links:Please let us know if we may be of further assistance.

    Comment


      #3
      Hi Emily,

      Good Day !!! Thanks for the guidance.

      I shall use the Crossover code for the Supertrends now. Shall let you know if there is any issue.

      Regards,
      Debex7

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      77 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      53 views
      0 likes
      Last Post CarlTrading  
      Working...
      X