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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      90 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      137 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      120 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      69 views
      0 likes
      Last Post PaulMohn  
      Working...
      X