Announcement

Collapse
No announcement yet.

Adding one more condition to efs

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

  • Adding one more condition to efs

    Hello ,

    How can i add the following one more condition to the attached efs . The efs defines big candlestick bars .

    Additional condition : the big candle stick bar (black bar ) : high is less than or equal to lower keltner channel (50,2.5)

    (white bar ) : low is greater than or equal to keltner channel (50,2.5)


    Thanks
    Attached Files

  • #2
    try:
    PHP Code:
    //main variables
    var nLastRawTime 0;
    var 
    BLBarOffset 0;

    //---Keltner Start---//
    //KeltnerBands variables
    var bInitialized false;
    var 
    Avg null;
    var 
    Keltner null;
    //---Keltner End---//

    function preMain() {
        
    setPriceStudy(true);
        
    //setStudyTitle("Big B&W Candles");
            
        
    var fp1 = new FunctionParameter("LookbackLength"FunctionParameter.NUMBER);
        
    fp1.setLowerLimit(1);        
        
    fp1.setDefault(5); //Edit this value to set a new default

        
    var fp2 = new FunctionParameter("RangeMult"FunctionParameter.NUMBER);
        
    fp2.setLowerLimit(0.01);        
        
    fp2.setDefault(0.61825); //Edit this value to set a new default
        
        //---Keltner Start---//
        
    var fp3 = new FunctionParameter("Length"FunctionParameter.NUMBER);
        
    fp3.setLowerLimit(2);        
        
    fp3.addOption(20);        
        
    fp3.addOption(50);        
        
    fp3.setDefault(50);

        var 
    fp4 = new FunctionParameter("Multiplier"FunctionParameter.NUMBER);
        
    fp4.setLowerLimit(1);        
        
    fp4.addOption(2.5);        
        
    fp4.setDefault(2.5); 

        var 
    fp5 = new FunctionParameter("Type"FunctionParameter.BOOLEAN);
        
    fp5.setName("Use EMA");
        
    fp5.setDefault(true); 
        
        var 
    fp6 = new FunctionParameter("Source"FunctionParameter.STRING);
        
    fp6.addOption("open"); 
        
    fp6.addOption("high");
        
    fp6.addOption("low");
        
    fp6.addOption("close");
        
    fp6.addOption("hl2");
        
    fp6.addOption("hlc3");
        
    fp6.addOption("ohlc4"); 
        
    fp6.setDefault("hlc3"); 

        var 
    fp7 = new FunctionParameter("Offset"FunctionParameter.NUMBER);
        
    fp7.setLowerLimit(0);
        
    fp7.setDefault(0);

        var 
    fp8 = new FunctionParameter("LineColor1"FunctionParameter.COLOR);
        
    fp8.setDefault(Color.red); 

        var 
    fp9 = new FunctionParameter("LineColor2"FunctionParameter.COLOR);
        
    fp9.setDefault(Color.blue);

        var 
    fp10 = new FunctionParameter("LineThickness"FunctionParameter.NUMBER);
        
    fp10.setLowerLimit(1);        
        
    fp10.setDefault(2); 

        var 
    fp11 = new FunctionParameter("DrawKeltner"FunctionParameter.BOOLEAN);
        
    fp11.setDefault(true); 
        
    //---Keltner End---//
    }

    function 
    main(LookbackLength,RangeMultLengthMultiplier,Type,Source,OffsetLineColor1LineColor2LineThicknessDrawKeltner) {
        
        if (
    nLastRawTime != getValue("rawtime"0)) {
            
    BLBarOffset += 1;
            
    nLastRawTime getValue("rawtime"0);
        }  

        
    //---Keltner Start---//
        
    Keltner calcKeltner(LengthMultiplier,Type,eval(Source),OffsetLineColor1LineColor2LineThickness);
        
    //---Keltner End---//
        
        
    AvgCandleRange = (FindRange(LookbackLength)*RangeMult);
        
        if ((
    Math.abs(close(0)-open(0)) >= AvgCandleRange) && (close(0) < open(0)) && (open(0) - close(0)) >= 0.7 * (high(0) - low(0))) {
          
    //  large Black Bar
            
    if(Keltner[2]>=high(0)){//Keltner conditional
                
    drawTextRelative(0,1"B" Color.whiteColor.redText.CENTER Text.ONTOP Text.RELATIVETOBOTTOMnullnullBLBarOffset+"BWTrnd");
                
    Alert.addToList ("  " " Big Candle Black " Color.green Color.black );
            }
        }
        if ((
    Math.abs(close(0)-open(0)) >= AvgCandleRange) && (close(0) > open(0)) && (close(0) - open(0)) >= 0.7 * (high(0) - low(0))) {
          
    //  large White Bar
            
    if(low(0)>=Keltner[0]){//Keltner conditional
            //your post stated "keltner channel" but I assume you meant "lower keltner channel" (Keltner[2]). Otherwise use Keltner[1] (CenterLine) instead of Keltner[0]
                
    drawTextRelative(0,1"W" Color.whiteColor.greenText.CENTER Text.ONTOP Text.RELATIVETOBOTTOMnullnullBLBarOffset+"BWTrnd");
                
    Alert.addToList (" " "Big Candle White " Color.blue Color.black );
            }
        }
        
        
    //---Keltner Start---//
        
    if(DrawKeltner){
            return new Array( 
    Keltner[0], Keltner[1], Keltner[2] );
        }
        
    //---Keltner End---//
    }


    function 
    FindRange(Length) {
      var 
    x;
      var 
    CandleRange 0;
      for (
    x=-1;x>=-Length;x--) {
        
    CandleRange += Math.abs(close(x)-open(x));
      }
      return (
    CandleRange/Length);
    }

    //---Keltner Start---//
    function calcKeltner(lengthmultiplier,Type,source,offsetLineColor1LineColor2LineThickness){

        if ( !
    bInitialized ) {
            var 
    type=null;
            
    setDefaultBarFgColorLineColor2);
            
    setDefaultBarFgColorLineColor2);
            
    setDefaultBarFgColorLineColor1);
            
    setDefaultBarThicknessLineThickness);
            
    setDefaultBarThicknessLineThickness);
            
    setDefaultBarThicknessLineThickness);                
            
    Type==false?type=0:type=1;
            if(
    type==0){
                
    Avg offsetSeries(sma(length,source()),offset);
            }else if(
    type==1){
                
    Avg offsetSeries(ema(length,source()),offset);
            }
            
    bInitialized true;
        }       

        var 
    AvgRange 0;
        for(var 
    0lengthi++) {
            
    AvgRange += high(-(i+offset)) - low(-(i+offset));
        }
        
        
    AvgRange /= length;
        
        var 
    Basis Avg.getValue(0);
        
    i
        
    var Upper Basis+(AvgRange*multiplier);
        var 
    Lower Basis-(AvgRange*multiplier);

        if(
    getCurrentBarCount()>length) return new Array (Upper,Basis,Lower); 
        else return new Array (
    nullnullnull);    
    }
    //---Keltner End---// 
    Wayne
    Last edited by waynecd; 01-13-2016, 10:10 PM.

    Comment

    Working...
    X