Announcement

Collapse
No announcement yet.

Need Help to apply Bollinger Bands to a DMA

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

  • Need Help to apply Bollinger Bands to a DMA

    I need help in applying Bollinger bands to a displaced moving average. I have no idea how to do this and would greatly appreciate some help anybody could give me as I am new to the Java language. Below is the code for the displaced moving average I want to apply a Standard Deviation to:

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("25X5 DMA");
    //setPlotType(PLOTTYPE_LINE);

    setCursorLabelName("25X5 DMA", 0);
    setDefaultBarThickness(1, 0);
    setDefaultBarFgColor(Color.green, 0);
    }

    function main() {

    var v25x5dma = new MAStudy(25, 5, "Close", MAStudy.SIMPLE);

    return v25x5dma.getValue(MAStudy.MA)

    }

  • #2
    I think this should get you close.

    Perhaps someone else can explain why the DMA line plots differently from the middle bb line?!!?

    Shouldn't it be the same if the DMA is the input?


    PHP Code:
    var fpArray = new Array();

    function 
    preMain() {

        
    setPriceStudy(true);

        
    setStudyTitle("TRO_DMABB"); 

        
    setCursorLabelName("25x5dma ",0);
        
    setCursorLabelName("UprBB"1);
        
    setCursorLabelName("BasBB"2);
        
    setCursorLabelName("LwrBB"3);

        
    setDefaultBarFgColor(Color.purple0);
        
    setDefaultBarFgColor(Color.blue1);
        
    setDefaultBarFgColor(Color.red2);
        
    setDefaultBarFgColor(Color.blue3);

        
    setPlotType(PLOTTYPE_LINE,0);
        
    setPlotType(PLOTTYPE_LINE,1);
        
    setPlotType(PLOTTYPE_LINE,2);
        
    setPlotType(PLOTTYPE_LINE,3);

        
    setDefaultBarThickness(1,0);
        
    setDefaultBarThickness(1,1);
        
    setDefaultBarThickness(1,2);
        
    setDefaultBarThickness(1,3);
     
        var 
    iAlert = new FunctionParameter("iAlert"FunctionParameter.BOOLEAN);
        
    iAlert.setDefaulttrue );

        var 
    iColor01 = new FunctionParameter("iColor01"FunctionParameter.COLOR);
            
    iColor01.setDefaultColor.green );

        var 
    iColor02 = new FunctionParameter("iColor02"FunctionParameter.COLOR);
            
    iColor02.setDefaultColor.red );


        var 
    iColor03 = new FunctionParameter("iColor03"FunctionParameter.COLOR);
            
    iColor03.setDefaultColor.cyan );

        var 
    iColor04 = new FunctionParameter("iColor04"FunctionParameter.COLOR);
            
    iColor04.setDefaultColor.magenta );


    // BUTTON CODE

        
    var iButtonX = new FunctionParameter("iButtonX"FunctionParameter.NUMBER);
        
    iButtonX.setDefault); 

        var 
    iButtonY = new FunctionParameter("iButtonY"FunctionParameter.NUMBER);
        
    iButtonY.setDefault20 ); 

        var 
    iFontSize = new FunctionParameter("iFontSize"FunctionParameter.NUMBER);
            
    iFontSize.setName("Button Font Size");
        
    iFontSize.setDefault10 ); 


        var 
    x=0;
        
    fpArray[x] = new FunctionParameter("Length"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setLowerLimit(1);        
            
    setDefault(20);
        }
        
    fpArray[x] = new FunctionParameter("StdDev"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setLowerLimit(0);    
            
    setDefault(2);
        }
        
    fpArray[x] = new FunctionParameter("Source"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    addOption("open"); 
            
    addOption("high");
            
    addOption("low");
            
    addOption("close");
            
    addOption("hl2");
            
    addOption("hlc3");
            
    addOption("ohlc4"); 
            
    setDefault("close"); 
        }
        
    fpArray[x] = new FunctionParameter("Symbol"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    setDefault();
        }
        
    fpArray[x] = new FunctionParameter("Interval"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    setDefault();
        }

    }


    // BUTTON CODE

    var bEdit         true
    var 
    nColWidth      0;
    var 
    nRowThickness 1;
    var 
    nFontSize     10

    var 
    tInit  false ;

    var 
    v25x5dma null ;
     
    var 
    x25x5dma null ;

    var 
    Symbol   null;
    var 
    Interval null;
    var 
    Source null;

    var 
    bupperBB  null ;
    var 
    bmiddleBB null ;
    var 
    blowerBB  null ;

    askForInput();


    function 
    mainiAlert,     iFontSizeiButtonXiButtonY) {

    // BUTTON CODE

        
    if(getBarState() == BARSTATE_ALLBARS) {
            
    drawTextPixel(  iButtonX iButtonY$TRO_DMABB @URL=EFS:editParameters"Color.whiteColor.green
                
    Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.ONTOP|Text.BOLD|Text.BUTTON
                
    "Comic Sans MS"13"UpExp"); 
           
        return 
    null;
        }




    if(  
    tInit  == false ) {


            if(
    Symbol == null)   Symbol getSymbol();
            if(
    Interval == nullInterval getInterval();
            var 
    vSymbol Symbol+","+Interval;


    Source sma(25close(), sym(vSymbol), 5)  ; 

    Length 20 ;
    StdDev ;
     
    bupperBB  upperBB(Length,StdDev,   Source   );

    bmiddleBB middleBB(Length,StdDev,   Source   );

    blowerBB  lowerBB(Length,StdDev,   Source    ); 
     
    tInit  true ;
    }
        

    x25x5dma  Source.getValue(0) ;

    xupperBB  bupperBB.getValue(0) ;
    xmiddleBB bmiddleBB.getValue(0) ;
    xlowerBB  blowerBB.getValue(0) ; 


    /*

    setBarBgColor(Color.white, 0);

    if(   ) {
         setBarBgColor( , 0);
            if( iAlert == true ) {
        Alert.addToList(getSymbol(), close(0) +"  ", Color.blue, Color.black);
            Alert.playSound("ding.wav");
            }
    }

    if(   ) {
         setBarBgColor( , 0);
            if( iAlert == true ) {
        Alert.addToList(getSymbol(), close(0) +"  ", Color.red, Color.black);
            Alert.playSound("ding.wav");
            }
    }


         setBarFgColor( , 0);
         setBarFgColor( , 1);  

    */

    return new Array( x25x5dma xupperBB xmiddleBB xlowerBB );

    }


    function 
    editParameters() {
        
    askForInput("$TRO_DMABB");
        return;

    Attached Files

    Comment

    Working...
    X