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 NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      62 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      134 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      75 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      50 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X