Announcement

Collapse
No announcement yet.

Invalid Return error

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

  • Invalid Return error

    I have been trying to write an efs which only colors the bar and returns nothing, but I can't seem to get beyond the "Invalid return" message and I've found nothing in the help to suggest a solution.

    Can someone please help me understand how to troubleshoot this or a solution.

    Thanks in advance.

  • #2
    Snickers
    You need to post your code else it is impossible to determine the cause
    Alex

    Comment


    • #3
      OK. Thought the question was generic enough, but here's the code:

      // Keltner Signal Bar Color Change with Greater than +/-40 Alerts for Ticki

      var newbar = null
      var alerted1 = null
      var alerted2 = null
      var alerted3 = null
      var alerted4 = null
      var DayHigh = null
      var DayLow = null

      function preMain() {
      setPriceStudy(true);

      setStudyTitle("Keltner Bar Signal");
      addBand(alertLev, PS_SOLID, 1, Color.red,"alertLev");
      addBand(0, PS_SOLID, 1, Color.white,"zero");
      addBand(-alertLev, PS_SOLID, 1, Color.lime,"-alertLev");

      setColorPriceBars( true );

      setDefaultPriceBarColor(Color.black)

      var fp1 = new FunctionParameter("nInputLength", FunctionParameter.NUMBER);
      fp1.setName("Length");
      fp1.setDefault(20);

      var fp2 = new FunctionParameter("nRangeFactor", FunctionParameter.NUMBER);
      fp2.setName("Standard Devs");
      fp2.setDefault(1);

      var fp3 = new FunctionParameter("alertLev", FunctionParameter.NUMBER);
      fp3.setName("Alert Level");
      fp3.setDefault(40);
      }

      function ATR(nInputLength,nRangeFactor) {
      var dSum = 0;
      var dH = high(0, -nInputLength);
      var dL = low(0, -nInputLength);
      var dC = close(-1, -nInputLength);
      if (dH == null || dL == null || dC == null) {
      return;
      }
      for (i = 0; i < nInputLength; ++i) {
      var vTrueHigh = Math.max(dH[i], dC[i]);
      var vTrueLow = Math.min(dL[i], dC[i]);
      var vTrueRange = (vTrueHigh - vTrueLow);
      dSum += vTrueRange;
      }
      dSum /= nInputLength;
      return dSum;
      }
      var BarCntr = 0;

      function main(nInputLength, nRangeFactor,alertLev) {
      var bHour = getHour();
      var bMin = getMinute();
      newbar=(getBarState() == BARSTATE_NEWBAR);
      if (newbar) {
      alerted1=false;
      alerted2=false;
      alerted3=false;
      alerted4=false;
      setPriceBarColor( Color.black );
      }
      if(nInputLength == null)
      nInputLength = 20;
      if(nInputLength <= 0)
      nInputLength = 20;

      if(nRangeFactor == null)
      nRangeFactor = 1;
      if(nRangeFactor <= 0)
      nRangeFactor = 1;

      if(alertLev == null)
      alertLev = 40;
      if(alertLev <= 0)
      alertLev = 40;

      if (getBarState() == BARSTATE_NEWBAR)
      BarCntr += 1;

      if (BarCntr < nInputLength) {
      return;
      } else {
      var dKeltnerBasis= call("/Library/KeltnerEMA.efs", nInputLength);
      var dATR = ATR(nInputLength);
      }
      if (high() > dKeltnerBasis + (nRangeFactor * dATR)) {
      setPriceBarColor( Color.red );
      if (!alerted1) {
      Alert.playSound("Boing.wav");
      alerted1=true;
      }
      }
      if (low() < dKeltnerBasis - (nRangeFactor * dATR)) {
      setPriceBarColor( Color.lime );
      if (!alerted2) {
      Alert.playSound("Boing.wav");
      alerted2=true;
      }
      }
      if (high() > alertLev) {
      if (!alerted3) {
      Alert.playSound("Bullet.wav");
      alerted3=true;
      }
      }
      if (low() < -alertLev) {
      if (!alerted4) {
      Alert.playSound("Bullet.wav");
      alerted4=true;
      }
      }
      if (high() == 30) {
      drawShapeRelative(-1, 30, Shape.CIRCLE, null, Color.cyan,
      Image.TOP | Image.ONTOP, savedAlertTag1);
      }
      if (low() == -30) {
      drawShapeRelative(-1, -30, Shape.CIRCLE, null, Color.cyan,
      Image.TOP | Image.ONTOP, savedAlertTag2);
      }
      }
      return;
      }

      Comment


      • #4
        Snickers
        You have one } bracket too many. Remove the one just before the return statement.
        Once you do that you will get another error saying that alertLev is not defined. At that point move the addBand() commands inside main after the point where you set the values for alertLev
        Alex

        Comment

        Working...
        X