Announcement

Collapse
No announcement yet.

Rewrite a IF statement

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

  • Rewrite a IF statement

    Im using the below text to find a high on the macd but this way of doing this task is quite cpu intestive, Could any rewrite this to make it less intesive, the purpose of this it to find a bump in the macd


    if ( tracker =="Go" &&
    vSMA12.getValue(MACDStudy.MACD) < -0.2 &&
    vSMA12.getValue(MACDStudy.MACD,-6) > vSMA12.getValue(MACDStudy.MACD,-5) &&
    vSMA12.getValue(MACDStudy.MACD,-5) > vSMA12.getValue(MACDStudy.MACD,-4) &&
    vSMA12.getValue(MACDStudy.MACD,-4) > vSMA12.getValue(MACDStudy.MACD,-3) &&
    vSMA12.getValue(MACDStudy.MACD,-1) < vSMA12.getValue(MACDStudy.MACD) &&
    vSMA12.getValue(MACDStudy.MACD,-2) < vSMA12.getValue(MACDStudy.MACD,-1) &&
    vSMA12.getValue(MACDStudy.MACD,-3) < vSMA12.getValue(MACDStudy.MACD,-2))

  • #2
    Bis...

    There is really no way to shorten your requested if statement.. The conditions have to be met in order for your "trigger" to go off.

    One thing you could do is to modularize this function into components... For example, there appears to be three parts...

    A. tracker =="Go"
    B. vSMA12.getValue(MACDStudy.MACD) < -0.2
    C. the rest...

    You could rewrite it using "conditionals"... like the following..

    var MACDBottom = ((vSMA12.getValue(MACDStudy.MACD,-6) > vSMA12.getValue(MACDStudy.MACD,-5)) &&
    (vSMA12.getValue(MACDStudy.MACD,-5) > vSMA12.getValue(MACDStudy.MACD,-4)) &&
    (vSMA12.getValue(MACDStudy.MACD,-4) > vSMA12.getValue(MACDStudy.MACD,-3)) &&
    (vSMA12.getValue(MACDStudy.MACD,-1) < vSMA12.getValue(MACDStudy.MACD)) &&
    (vSMA12.getValue(MACDStudy.MACD,-2) < vSMA12.getValue(MACDStudy.MACD,-1)) &&
    (vSMA12.getValue(MACDStudy.MACD,-3) < vSMA12.getValue(MACDStudy.MACD,-2)));

    if ( (tracker =="Go") &&
    (vSMA12.getValue(MACDStudy.MACD) < -0.2) &&
    (MACDBottom)) {

    }

    This way, MACDBottom is only called ONCE for as many times as you need to use it. The code will return "true" or "false" for this condition - thus a "conditional".

    Developing code this way will help to resolve some of the CPU issue you are experiencing..

    B
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Thanks once again Brad,

      Thats improved remarkably

      Comment

      Working...
      X