Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cross strategy Question - false signals

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

    Cross strategy Question - false signals

    Hi Folks,

    I'm new to the forum and greatly appreciate any advice that might be thrown at me...

    I have created a strategy that is based on the cross of 2 moving HMA's. The strategy is based on "each tick" (not price/bar close). It plays both long and short currently with no stop loss setting (cross above = long, cross below = short). The strategy is successful at switching from long to short and vise versa. However, the problem I am having is that the strategy occasionally takes really bad trades due to the crosses occurring and then quickly uncrossing (which I assume does not count as cross in the other direction - IE switch from long to short or short to long) as seen in the example below. A short was taken.
    Click image for larger version

Name:	image.png
Views:	311
Size:	11.5 KB
ID:	1260815

    So my question is, what is the simplest way for me to set the strategy to wait just a bit longer to make sure that cross is truly confirmed. Is there maybe a way to tell the strategy to wait a certain amount of time after a cross has occurred and verify the cross is still effective before taking a trade? Or perhaps there is a better way? I just need to get rid of these false signals even if it means potentially missing out on a little more profit, if I can avoid the bigger losses.

    I am open to ideas. FYI, I'm not a programmer but am comfortable with setting up anything in the conditions, inputs, variables etc.​

    #2
    Hello tjames3245,

    In the strategy builder the options to wait time would be pretty limited, the next best solution would be to check if there was a crossing with OnBarClose as the calculation mode. That would ensure the crossing either happened or didn't once all the bar data has been processed. In manual coding you could make it wait a number of ticks or an amount of seconds as an example.

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello tjames3245,

      In the strategy builder the options to wait time would be pretty limited, the next best solution would be to check if there was a crossing with OnBarClose as the calculation mode. That would ensure the crossing either happened or didn't once all the bar data has been processed. In manual coding you could make it wait a number of ticks or an amount of seconds as an example.
      Hi Jesse,

      I have tried the onbarclose method and it works but it really kills my entries and exits in terms of profit taking. So it wouldn't work for me.

      Is there any way you could point me in the right direction as to what coding would look like for it to wait a certain number of ticks or seconds? That would help a lot. I could probably make a copy of my strategy and then unlock that copy and use the code to test it.

      Also, would that type of coding still ensure that if the condition (the cross) is not true after x amount of ticks/seconds, the trade won't be placed? That really is the ultimate goal.
      Last edited by tjames3245; 07-18-2023, 08:30 AM.

      Comment


        #4
        Hello tjames3245,

        a very simple way to do that with ticks would be to increment a counter and use a bool variable. That could actually be accomplished in the builder and could be tested in realtime, that wouldnt work historically though. There is a sample of incrementing a series in the following link. The basic workflow would be to use a bool variable and set it to true as the action of your crossover condition. In a set after that you could check if the bool is true and increment the counter. In a third set you could check if the counter is greater than a certain amount and also if the crossover is still true. If so submit the order and reset the bool variable to false and the counter back to 0.

        Is there a way to increment an int in the strategy builder? When I go to set an int equal to itself there's no way to add 1 to it as well. Just wondering if this is possible in the wizard.


        A way to do that in code would be like the following:

        Code:
        private bool enableTradeCondition = false;
        private int tickCount = 0;
        protected override void OnBarUpdate()
        {
           if(CrossAbove(EMA(12), EMA(24), 1))
           {
              enableTradeCondition = true;
              tickCount = 0;
           }
           if(enableTradeCondition == true)
           {
               tickCount++;
           }
        
            if(tickCount > 50 && CrossAbove(EMA(12), EMA(24), 1))
           {
               EnterLong();
               enableTradeCondition = false;
               tickCount = 0;
           }​
        }

        Comment


          #5
          Thank you for your quick reply... So I've edited code and was able to get it to work. However, it will only take trades with your code when tick is set to 1.

          Anything greater than 1 tick in the settings for long or short, does not seem to execute.

          Any ideas?
          Last edited by tjames3245; 07-18-2023, 08:01 PM.

          Comment


            #6
            Hello tjames3245,

            Are you referring to the bars type size or the tickCount variable in that code?

            If what you modified is not working you can use Prints to see what part is not working.

            Comment


              #7
              Originally posted by NinjaTrader_Jesse View Post
              Hello tjames3245,

              Are you referring to the bars type size or the tickCount variable in that code?

              If what you modified is not working you can use Prints to see what part is not working.
              so It looks like I was able to rectify this and it is working as planned but it is still killing my entries and exits...


              Do you happen to know if there is a code/variable I could create that would set things to wait a certain amount of time instead of ticks/price? What I really want is for the strategy to wait X amount of seconds to confirm the cross is still true and then proceed with long or short entry. I think that is the only way I can get this to work...

              I have tried multiple C# based setups and none of them seem to work for delays. They just refused to execute.

              Do you have any suggestions for a time based code rather than ticks?

              Comment


                #8
                Hello tjames3245,

                To delay for an amount of time you would need to calculate a time in the future from right now which equals the time of right now plus the offset. You can use any C# DateTime methods like AddSeconds with a DateTime object to add an amount of time.

                https://learn.microsoft.com/en-us/do...tframework-4.8

                Code:
                private DateTime futureTime = DateTime.MaxValue;
                protected override void OnBarUpdate()
                {
                   if (CrossAbove(EMA(12), EMA(24), 1))
                   {
                      futureTime = Time[0].AddSeconds(10);
                   }
                   if (Time[0] >= futureTime)
                   {
                      EnterLong();
                      futureTime = DateTime.MaxValue;
                    }
                }

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                52 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                130 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                70 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                43 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                47 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X