Announcement

Collapse
No announcement yet.

Opening prices

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

  • Opening prices

    Hello again,

    I need the opening price at the beginning of each day, week and month.

    For the day and month I use:

    if (day() != day(-1)) mvVar = open();

    if (month() != month(-1)) myVar = open();

    As there is no week() function that I know of I'm struggling to identify the beginning of the week i.e. Monday.

    So far, I've got this:

    var today = new Date();
    if (today.getDay() == 1) myVar = open();

    but it isn't working. When I use bar replay today.getDay() is always 5 because today (the day I'm actually doing this rather than the day of the bar I'm looking at) is Friday.

    I hope this makes some sense to someone who can help me.

    I just need the opening price on a Monday morning.

    Thank you in advance.

  • #2
    Hi Bob,
    this could be an idea.

    var today = new Date();
    function main() {
    debugPrintln(today.getDay());
    debugPrintln(open(-today.getDay()+1,inv("D")));
    debugPrintln(open(-today.getDay()+1-today.getDay(),inv("D")));
    debugPrintln(open(-today.getDay()+1-2*today.getDay(),inv("D")));
    // and so on ... or you can use a loop
    }

    Comment


    • #3
      What do you think of this:

      if (open(inv("W")) != open(inv("W")).getValue(-1))
      myVar = open(inv("W"));

      I'm assuming that no week will have the same opening price as its previous week.

      It seems to work.

      Comment


      • #4
        Bob, good idea.
        Open(inv("W") make it easier.

        I would do this way:

        var myVar=null;
        function main() {
        if (open(0,inv("W")) != myVar) {
        myVar = open(0,inv("W"));
        debugPrintln(myVar);
        }
        }

        If you want to be sure 99,99%, for weeks with the same opening price you could add a check on the close(inv("W")).

        Massimo

        Comment

        Working...
        X