Announcement

Collapse
No announcement yet.

Delay

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

  • Delay

    What is s there a way to put a delay or some sort of filter for eliminating multiple signals when testing strageties? Ie: At the MA crossover the alert window will sometimes generate 4-8 seperate long/short signals.

    P.S. Is there a 'delay' sleep or wait command in java script that wont pause the whole system?

    DB

  • #2
    Geoff
    One way to avoid multiple (and potentially false) intrabar signals is to evaluate the conditions that trigger those signals only on completed bars using BARSTATE_NEWBAR. Here is one example of how you could do this.

    PHP Code:
    function preMain(){
        
    setPriceStudy(true);
        
    setCursorLabelName("MA");
    }
     
    var 
    Study null;
     
    function 
    main(){
     
        if(
    Study==nullStudy sma(10);
        
        if(
    getBarState()==BARSTATE_NEWBAR){
            if(
    close(-2)<=Study.getValue(-2)&&close(-1)>Study.getValue(-1)){
                
    Alert.addToList(getSymbol(), "Crossed over"Color.blackColor.lime);
                
    Alert.playSound("ding.wav");
            }
        }
        
        return 
    Study.getValue(0);

    If instead you want to triggger a signal intrabar but only the first time it happens then you would need to use a different logic. Following is a basic example of how you could do this.
    Alex

    PHP Code:
    function preMain(){
        
    setPriceStudy(true);
        
    setCursorLabelName("MA");
    }
     
    var 
    Study null;
    var 
    AlertTriggered false;
     
    function 
    main(){
     
        if(
    Study==nullStudy sma(10);
        
        if(
    getBarState()==BARSTATE_NEWBAR){
            
    AlertTriggered false;
        }
        
        if(
    AlertTriggered==false){
            if(
    close(-1)<=Study.getValue(-1)&&close(0)>Study.getValue(0)){
                
    Alert.addToList(getSymbol(), "Crossed over"Color.blackColor.lime);
                
    Alert.playSound("ding.wav");
                
    AlertTriggered true;
            }
        }
        
        return 
    Study.getValue(0);

    Comment


    • #3
      Thanks I'll give it a shot

      Comment

      Working...
      X