Announcement

Collapse
No announcement yet.

EFS Calculate Intraday using prior days' extremes

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

  • EFS Calculate Intraday using prior days' extremes

    I'm trying to write a few studies - the one below the current one I'm working on. Here is what I would like to accomplish (what I have so far only works using intraday bars - i.e., the prior 4 H-O etc is the prior 4 intraday bars)

    I would like a study and alert that triggers on the following conditions:

    1. is updated intraday on anytime timeframe chosen if today is day "0"
    2. upside alert: today's high is greater than or equal to today's open plus the average of the prior four days' intraday highs - open e.g. today's high >= today's open plus average of ((High-Open)day"-1"+(High-Open)day"-2"+(High-Open)day"-3"+(High-Open)day"-4"
    3. downside alert: today's low is less than or equal to today's open plus the average of the prior four days' intraday lows - open e.g. today's low <= today's open plus average of ((Low-Open)day"-1"+(Low-Open)day"-2"+(Low-Open)day"-3"+(Low-Open)day"-4"

    On an intraday basis I want the calculation done using DAILY highs - opens and lows -opens for prior days and then add or subtract that to today's open. Therefore for instance on bonds if the calculations for the daily h-o and l-o for prior days is +7/32 and -7/32 then today for the entire day the upside alert would be equal to the open for the day at 0820 ET +7/32 or -7/32. only when those prices levels are broken on an intraday is the alert generated.

    =======
    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Strategy");
    }

    function main() {
    var avgh = 0, avgl = 0;
    var vHL = high() - low();
    var vVar = vHL * 0.25;
    var vaddvar = vVar * 0.35;

    for(i = -4; i < 0; i++){
    avgh += high(i) - open(i);
    avgl += low(i) - open(i);
    }

    avgh /= 4;
    avgl /= 4;

    if(high() >= open() + avgh){
    Alert.playsound("Alert.wav");
    Alert.addtolist(getsymbol(), "upside alert", Color.black, Color.green);

    }
    if(low() <= open() + avgl){
    Alert.playSound("Alert.wav");
    Alert.addToList(getSymbol(), "downside alert", Color.black, Color.green);

    }


    }

    Thanks!
Working...
X