Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Trending market code question

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

    Trending market code question

    Hi all....

    I'm working on a strategy which works best when the market is not trending.

    Here's what keeps happening... the market starts to trend... and of course... there are peaks and valleys in a trend as well as in a sideways market.. so... the strategy sees the highs in an uptrend... and shorts pretty much all of them!

    Then... turns around and goes long in a downtrend on every new low... ouch! Talk about a smackdown!

    It wouldn't be so bad if it only bought the lows in an uptrend or the highs in a downtrend... but when the market is running fairly smoothly downward, the peaks and valleys are tiny in the instrument I trade... so basically I'm getting trending whipsaw.

    Has anyone else pondered ways to keep this from happening using NinjaScript to tell the strategy to only take trades in the direction of the trend once it starts?

    I figured I'd ask the experts and more experienced coders so I can learn as I go. Plus... If I don't figure this out soon... I won't have a head left to scratch.

    -V

    #2
    Originally posted by Aurum View Post
    Hi all....

    I'm working on a strategy which works best when the market is not trending.

    Here's what keeps happening... the market starts to trend... and of course... there are peaks and valleys in a trend as well as in a sideways market.. so... the strategy sees the highs in an uptrend... and shorts pretty much all of them!

    Then... turns around and goes long in a downtrend on every new low... ouch! Talk about a smackdown!

    It wouldn't be so bad if it only bought the lows in an uptrend or the highs in a downtrend... but when the market is running fairly smoothly downward, the peaks and valleys are tiny in the instrument I trade... so basically I'm getting trending whipsaw.

    Has anyone else pondered ways to keep this from happening using NinjaScript to tell the strategy to only take trades in the direction of the trend once it starts?

    I figured I'd ask the experts and more experienced coders so I can learn as I go. Plus... If I don't figure this out soon... I won't have a head left to scratch.

    -V
    Welcome to the club!!!

    Comment


      #3
      Originally posted by Aurum View Post
      Hi all....

      I'm working on a strategy which works best when the market is not trending.

      Here's what keeps happening... the market starts to trend... and of course... there are peaks and valleys in a trend as well as in a sideways market.. so... the strategy sees the highs in an uptrend... and shorts pretty much all of them!

      Then... turns around and goes long in a downtrend on every new low... ouch! Talk about a smackdown!

      It wouldn't be so bad if it only bought the lows in an uptrend or the highs in a downtrend... but when the market is running fairly smoothly downward, the peaks and valleys are tiny in the instrument I trade... so basically I'm getting trending whipsaw.

      Has anyone else pondered ways to keep this from happening using NinjaScript to tell the strategy to only take trades in the direction of the trend once it starts?

      I figured I'd ask the experts and more experienced coders so I can learn as I go. Plus... If I don't figure this out soon... I won't have a head left to scratch.

      -V
      Yes, but first you have to be more precise what YOU mean by: " ... direction of the trend once it starts".

      Comment


        #4
        Originally posted by koganam View Post
        Yes, but first you have to be more precise what YOU mean by: " ... direction of the trend once it starts".

        Thanks for the response, Koganam...

        What I mean by "direction of the trend once it starts" is actually pretty straight-forward.

        Imagine the market is moving in a range... let's say up and down, "consolidating," pretty much the same distance over and over again... let's say 8 ticks. Then... the market "takes off" to the upside. Now, the market is in a uptrend. Higher highs... higher lows... these peaks and valleys are much smaller... let's say 3 to 4 ticks max. Sometimes there is a retracement of a larger amount... but for the most part... the trend is just going up... making tiny swings up and down in the process.

        The strategy I'm building is designed to seek out swings... since those "higher highs" in the uptrend are technically swings (although tiny)... the strategy... which works great in a ranging market.... begins to try and do the same thing in this uptrend... it sells the tiny highs, creating a loss with each short position it opens. The market continues higher... the position gets stopped out... and the strategy shorts it again at the next high... and my profit factor goes out the window.

        What I'm attempting to accomplish, is to let the strategy know what an "uptrend" or a "downtrend" looks like... and to either avoid trading them... or to place trades only in the direction of that trend.

        I think the trade logic would be something like this: "if... 'X' indicator... or 'X' combination of indicators... show 'Y' conditions... the market is no longer in a "range" and to stop taking trades in both directions... and focus only on trading in the new direction (up or down).

        Since I can recognize a trend... there must be a way to get that information into my strategy... but I'm not sure how to make this happen. I'm just curious to see what other solutions traders have come up with using NinjaScript.

        I could use an MA cross for this... but in my strategy, a moving average crossover, used alone, is working out to be too cumbersome. I'm wondering if anyone has used other methods. I'm basically looking for ideas I can then take away and brainstorm with.

        Thanks again for your reply...

        -V

        Comment


          #5
          Originally posted by Aurum View Post
          Thanks for the response, Koganam...

          What I mean by "direction of the trend once it starts" is actually pretty straight-forward.

          Imagine the market is moving in a range... let's say up and down, "consolidating," pretty much the same distance over and over again... let's say 8 ticks. Then... the market "takes off" to the upside. Now, the market is in a uptrend. Higher highs... higher lows... these peaks and valleys are much smaller... let's say 3 to 4 ticks max. Sometimes there is a retracement of a larger amount... but for the most part... the trend is just going up... making tiny swings up and down in the process.

          The strategy I'm building is designed to seek out swings... since those "higher highs" in the uptrend are technically swings (although tiny)... the strategy... which works great in a ranging market.... begins to try and do the same thing in this uptrend... it sells the tiny highs, creating a loss with each short position it opens. The market continues higher... the position gets stopped out... and the strategy shorts it again at the next high... and my profit factor goes out the window.

          What I'm attempting to accomplish, is to let the strategy know what an "uptrend" or a "downtrend" looks like... and to either avoid trading them... or to place trades only in the direction of that trend.

          I think the trade logic would be something like this: "if... 'X' indicator... or 'X' combination of indicators... show 'Y' conditions... the market is no longer in a "range" and to stop taking trades in both directions... and focus only on trading in the new direction (up or down).

          Since I can recognize a trend... there must be a way to get that information into my strategy... but I'm not sure how to make this happen. I'm just curious to see what other solutions traders have come up with using NinjaScript.

          I could use an MA cross for this... but in my strategy, a moving average crossover, used alone, is working out to be too cumbersome. I'm wondering if anyone has used other methods. I'm basically looking for ideas I can then take away and brainstorm with.

          Thanks again for your reply...

          -V
          It sounds as if you are actually asking how to determine if there is a trend? Did I misunderstand?

          Anyhow, here is an example of the structure of suppressing trades, based on a putative situation.
          Code:
          bool IsTrending = Close[0] > TEMA(Close, 21)[0] && Stochastics(3, 50, 3)[0] > 50;
          if (!IsTrending)
          {
          //place trades
          }

          Comment


            #6
            Thank you, koganam, for the excellent recommendation and code example. Just the mention of using the data inside a bool has taught me a ton. It also gives me some ideas about how to use other MA's along with the setup you've mentioned, to get even more granular. Thank you again for your response!

            -V

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by elirion, Yesterday, 09:32 PM
            0 responses
            8 views
            0 likes
            Last Post elirion
            by elirion
             
            Started by cre8able, Yesterday, 09:15 PM
            1 response
            8 views
            0 likes
            Last Post bltdavid  
            Started by cummish, Yesterday, 08:43 PM
            0 responses
            16 views
            0 likes
            Last Post cummish
            by cummish
             
            Started by Option Whisperer, Yesterday, 07:58 PM
            4 responses
            21 views
            0 likes
            Last Post Option Whisperer  
            Started by ETFVoyageur, 05-07-2024, 07:05 PM
            13 responses
            87 views
            0 likes
            Last Post ETFVoyageur  
            Working...
            X