Announcement

Collapse
No announcement yet.

need help

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

  • need help

    this efs is supposed to give LSMA/EMA cross alert in 10min interval. However, when I load it in a 5min chart, it gives me wrong alerts. It toggles between giving me "LSMA Above EMA" and "LSMA below EMA" alerts every 5minute.

    for example:
    2:00pm "LSMA Below EMA"
    2:05pm "LSMA Above EMA"
    2:05pm "LSMA is Up"
    2:10pm "LSMA Below EMA"
    2:15pm "LSMA Above EMA"
    2:15pm "LSMA is Up"
    2:20pm "LSMA Below EMA"
    2:25pm "LSMA Above EMA"
    2:25pm "LSMA is Up"

    Pls advise. thx
    Last edited by Richard Yu; 08-29-2005, 11:25 AM.

  • #2
    Re: need help

    the file...

    the strange thing is that the code works fine if I load it in a 10min chart. So what's wrong? thx.
    Attached Files
    Last edited by Richard Yu; 08-29-2005, 11:54 AM.

    Comment


    • #3
      Hello Richard,

      When you run your formula on a 5 minute chart with setComputeOnClose(), the efs will be evaluated on the close of each 5 minute bar. Your formula is evaluating the higher interval once during the 10 minute interval as well as at the close. What you should do instead is remove setComputeOnClose() from preMain. Then create a local flag and set it to true when the bar state on the 10 minute interval is BARSTATE_NEWBAR using getBarStateInterval(sInv). At that instance, then look back at the -1, -2 and -3 bars of the 10 minute interval data.

      Add the following to the top of main() to create the local flag.

      PHP Code:
      var bNew false;
      if (
      getBarStateInterval("10") == BARSTATE_NEWBARbNew true
      Next, set your study variables to the following bar indexes.

      PHP Code:
      // Part 2: Calculate EMA 
          
      dThisEMA ema(nEMALength,inv(10),-1);
          
      dLastEMA ema(nEMALength,inv(10),-2);
          
      dLastLastEMA ema(nEMALength,inv(10),-3);

          
      dThisLSMA amLib.amLSMA(nLSMALength,inv(10),-1);
          
      dLastLSMA amLib.amLSMA(nLSMALength,inv(10),-2);
          
      dLastLastLSMA amLib.amLSMA(nLSMALength,inv(10),-3); 
      Then add to your conditional statements, a check for && bNew == true to allow the code to only be executed at BARSTATE_NEWBAR of the 10 minute interval. Or you could encapsulate all your conditional statements inside a single condition that just looks for bNew == true.

      PHP Code:
      if (bNew == true) {
          
      // your conditional statements

      The end result recreates the same logic that setComputeOnClose() performs. Try this out and let me know if it works for you.
      Jason K.
      Project Manager
      eSignal - an Interactive Data company

      EFS KnowledgeBase
      JavaScript for EFS Video Series
      EFS Beginner Tutorial Series
      EFS Glossary
      Custom EFS Development Policy

      New User Orientation

      Comment


      • #4
        What I want to do is to get the alert for every 5 min using 10min data. So I use inv(10) and use setComputeOnClose() on a 5min chart. However, I don't understand why my original codes don't work. I believe your suggested codes can give what I need but I am still confused what goes wrong with my original codes.

        Pls note that I orginally decided my code assuming that one alert will be sent out the first time the conditions are met. After that, a flag will be turned on and no more same alerts will be sent out in the same 5min.... Therefore, you can see that in my original codes that I hv already made use of flags... thx.

        Comment


        • #5
          Hello Richard,

          You mentioned that your formula worked while on a 10-minute chart. When running on a 10-minute chart, the formula only evaluates the conditions once every 10 minutes at the close of the 10-minute interval. To recreate this behavior while looking at the 5-minute chart, you need to incorporate the suggestions I made in my previous post. If you evaluate the conditions on the 10-minute data every 5 minutes, its possible that the ema and lsma line are crossing and then uncrossing before the 10-minute interval has completed, which creates the toggling affect you have seen. This should be expected. It's the same as looking at the close (or last) of a bar intra-bar relative to a moving average line. The price can move above and then back below the ma line before the bar closes.

          If you want to generate the alert the first time the two 10-minute series cross, let your formula evaluate on every tick. The first time you detect the cross, set your flag to prevent any further alerts until the current 10-minute interval has closed. At the top of main(), look for bar state new bar with getBarStateInterval("10") and reset your flags only at that instance. This will ensure that you will receive only one alert per 10-minutes.

          PHP Code:
          if (getBarStateInterval("10") == BARSTATE_NEWBAR) {
              
          // reset flags here

          However, keep in mind that by the end of that 10-minute interval, the crossing condition may uncross and be false at that point, which can create false signals. One way to avoid that is by not looking at the current developing 10-minute bar by setting your study variables to the values at bars -1, -2 and -3 of the 10-minute data as previously suggested. That way you are always looking at completed bars and will avoid the toggling effect (false signals).
          Jason K.
          Project Manager
          eSignal - an Interactive Data company

          EFS KnowledgeBase
          JavaScript for EFS Video Series
          EFS Beginner Tutorial Series
          EFS Glossary
          Custom EFS Development Policy

          New User Orientation

          Comment

          Working...
          X