Announcement

Collapse
No announcement yet.

Calcuate on first bar that meets criteria

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

  • Calcuate on first bar that meets criteria

    hi -
    I have a script that works well in drawing a 9:30 line at 50% of open/close and one for the open of 10:00 bar.

    I then wrote a quick script (not written very well and some things dont apply in it but works) that will calculate the highest of the bars from 9:36 to 9:54 (did Math.max...etc) and then draw a line then if any bar breaks this line to alert me but....

    I was looking to do this:

    once a bar breaks this line, alert me (which I can do and works)...now what I wanted to do was to find a way as to once it finds this FIRST bar to stop. I only want the first bar to alert me, now it alerts on me on the rest of the ones that are formed throughout the day. I would think this would be very simple but I cant figure out the code...

    One thing I have to figure out next is:
    if any one bar (say 12:00 bar) is below the first bar (9:30 bar)of the days low -.05 cents (the 9:30 bar at this moment) then do not give me any alerts at all even if the another bar later on (say 1:00 bar) breaks the 9:36 to 9:54 line.

    I still cant paste here the code??? agghhh

    I'll have to upload....I tried to paste the code but it wouldnt let me still
    Attached Files

  • #2
    PATRADER

    ...now what I wanted to do was to find a way as to once it finds this FIRST bar to stop. I only want the first bar to alert me, now it alerts on me on the rest of the ones that are formed throughout the day
    To accomplish this you would need to use a flag which changes state the first time the event occurs and that gets reset only once at the beginning of every day. Create a global variable called for example AlertTriggered and set it initally to false
    PHP Code:
    var AlertTriggered false
    Then at the beginning of the main function you create the condition that will reset that variable when a new day starts
    PHP Code:
    if(getDay(0)!=getDay(-1)){
        
    AlertTriggered false;

    At this point add a check for AlertTriggered in your existing condition and when the condition is true you execute your alerts and set AlertTriggered to true
    PHP Code:
    if(AlertTriggered==false && your_condition==true){
        
    //execute your alerts
        
    AlertTriggered true;

    Once the AlertTriggered flag is set to true that will prevent further alerts for the rest of the day since your condition no longer evaluates to true. As a new day starts over the flag is reset thereby allowing for an alert to be triggered when necessary
    Alex

    Comment


    • #3
      thanks

      thank you , it worked nicely....only one alert once it is broken!!

      I already had an AlertTriggered = false from an older program that I ripped this one from. I removed that first. Then added your example.

      It had an alarm for the a condition:
      If (getbarState()==BARSTATE_NEWBAR)
      AlertTriggered = false.

      Now if I was to merge these two scripts then I take it would not be possible because I use the AlertTriggered = false statement for both scripts??

      Comment


      • #4
        PATRADER
        Just rename one of the variables and rearrange the conditions as necessary
        Alex

        Comment

        Working...
        X