Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question about strategy development

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

    Question about strategy development

    Hello,

    this is a basic question and I should know the answer but I need to make sure:

    what is the difference between the following codes:

    1. If( SMA1 > Close && CrossAbove( SMA2, SMA1, 1))

    2. if( SMA1 > Close)
    If( CrossAbove( SMA2, SMA1, 1)

    I am not sure when to use the “&&” and when to use different “if”

    thank you

    #2
    Hello Jorge.andres.o,

    These two examples would essentially equate the same with how it is coded.

    The first sample is saying if condition 1 and condition 2 are true then do the action. The second sample would be doing the same except you have two individual if conditions. Its only the same because you did not use a condition body or { } the first if statement would only affect the second condition.

    To determine which to use you need to know what actions you need to do. Here are a few examples of how you can structure the conditions.

    Code:
    if(condition1)
        if(Condition 2)
            Print("condition 1 and 2 were true");
    Print("This comes after the conditions and does not apply to either condition");
    If you look at this example the condition 2 will only be checked if condition 1 was true, The Print will always happen because the condition 1 only applies to the next line following it. There were no { } used.

    Code:
    if(condition1)
    {
        Print("1");
        if(Condition 2)
       {
          Print("2");
       }
    }
    If you use condition bodys like this then the Print 1 will only happen if condition 1 happens, Print 2 will only happen if condition 1 and 2 are true.

    It is generally important to use { } to make sure your conditions are specific and apply to all of the lines you need which reside within the { }. This is very important if you need to execute multiple lines of code based on the condition being true.

    You can form conditions like your first sample if you need to make sure multiple conditions are all true at once, if condition 1 and 2 are true do the action:


    Code:
    if(condition1 && condition2)
    {
      Print("action 1");
      Print("action 2");
    }

    Please let me know if I may be of further assistance.

    Comment


      #3
      Thank you Jesse

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      61 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