Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to compare two conditions?

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

    How to compare two conditions?

    In my strategy I want to go long when macd crosses above avg. but only if the current crossover is above the previous one. Any way to do this in the strategy builder? If not can you show me code? Thank you.

    #2
    Hello relogical,

    Thanks for your post.

    This can be done in the strategy builder. You would need to create two double-type variables to store the value of the current cross and the previous cross (I would suggest using the MACD .Avg as the value to save). Set the default value of these to 0. You will also need a bool variable to indicate when cross is found, set the default to false.

    In one set you would check for the cross condition and when true, save the value of the cross into the variable representing the current cross. You would also set the bool true.

    In a 2nd set, you would check that the cross found bool is true and that the current cross variable is less than or equal to the previous cross variable. When these two conditions are true you would assign the current cross variable to the previous cross variable and set the bool to false. So this set reacts to when the cross is less than or equal to the previous one and saves the current into the previous.

    In a 3rd set, you would check to see if the cross found bool is true and that the current cross variable is greater than the previous cross variable. When these two conditions are found you have your entry condition, you would also need to set the bool to false and to save the current cross variable into the previous cross variable This is your entry set.

    Last edited by NinjaTrader_PaulH; 01-27-2022, 07:37 AM.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    55 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    132 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    73 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
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X