Announcement

Collapse
No announcement yet.

entry on break out

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

  • entry on break out

    I am new to any type of coding! However I'm having a go yet dont seem to be able to get my strategy to enter when the price breaks a certain level. I.e sell 1 tick below the break level.
    Can any one help a novice!!!

  • #2
    Hi Ferret,

    Here is an example of breakout strategy. If you have any further questions or require additional assistance please let me know.

    Code:
     function preMain() {
        setPriceStudy(true);
        setStudyTitle("BreakOut Strategy"); 
    
    }
    
    function main(BreakOut_Len) {
    	var vHL = high() - low();
    	var vVar = vHL * 0.25;
    	var vAddVar = vVar * 0.35;
    	var i = 0;
    
    
        if(BreakOut_Len == null)
            BreakOut_Len = 20;
        var i;
        var hh = 0;
        var ll = 0;
        
        for(i = - BreakOut_Len + 1; i < 0; i++) {
            if(i == - BreakOut_Len + 1){
                hh = high(i);
                ll = low(i);
            }
            else {
                hh = Math.max(hh, high(i));
                ll = Math.min(ll, low(i));
            }
        }
    	if(high() > hh && !Strategy.isLong()){
    		Strategy.doLong("Long", Strategy.MARKET, Strategy.NEXTBAR);
    		drawShapeRelative(0, low() - vVar, Shape.UPARROW, "", Color.lime, null, "buyShp" + getValue("time"));
    		drawTextRelative(-1, low() - (vVar + vAddVar), "Buy", Color.black, Color.lime, Text.BOLD | Text.ONTOP, null, null, "buyTxt" + getValue("time"));
    	}
    	if(low() < ll && !Strategy.isShort()){
    		Strategy.doShort("Short", Strategy.MARKET, Strategy.NEXTBAR);
    		drawShapeRelative(0, high() + vVar, Shape.DOWNARROW, "", Color.red, null, "sellShp" + getValue("time"));
    		drawTextRelative(-1, high() + (vVar + vAddVar), "Sell", Color.black, Color.red, Text.BOTTOM | Text.BOLD | Text.ONTOP, null, null, "buyTxt" + getValue("time"));
    	}
    
    	return new Array(hh,ll);
    }
    Regards,
    Andy

    Comment

    Working...
    X