Announcement

Collapse
No announcement yet.

Averaging System with multiple entry's and exit's

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

  • Averaging System with multiple entry's and exit's

    Hi,
    I have hit a mental block, I am new to efs and have attached my code so far.
    I have tried to add a daily reset to the bInit routine of the bLong1, bLong 2... variables but have managed to stop the code giving me any trades at all! I have since removed this but it is still not giving me any trades. Any help debugging this would be great!

    When it was working, the strategy would enter the first buy, the second buy and the third buy and exit at the exit signal correctly, but then it would not enter at the first buy level the next day because the bLong1 variable was still true. Any tips on the best way to code the variables to reset each day would be great as well,
    thanks in advance


    //*********************
    function preMain() {
    var aFPArray = new Array();
    setPriceStudy(true);
    setCursorLabelName("TodayOpen");

    var x=0;
    aFPArray[x] = new FunctionParameter("UserTime", FunctionParameter.NUMBER);
    with(aFPArray[x++]){
    setName("Start Time For Open (2300)");
    setLowerLimit(0);
    setUpperLimit(2400);
    setDefault(100);
    }
    aFPArray[x] = new FunctionParameter("LineLen", FunctionParameter.NUMBER);
    with(aFPArray[x++]){
    setName("Line Length");
    setLowerLimit(1);
    setDefault(200);
    }
    aFPArray[x] = new FunctionParameter("Res1", FunctionParameter.NUMBER);
    with(aFPArray[x++]){
    setName("Res1");
    setLowerLimit(0);
    setDefault(.5);
    }
    aFPArray[x] = new FunctionParameter("Res2", FunctionParameter.NUMBER);
    with(aFPArray[x++]){
    setName("Res2");
    setLowerLimit(0);
    setDefault(.75);
    }
    aFPArray[x] = new FunctionParameter("Res3", FunctionParameter.NUMBER);
    with(aFPArray[x++]){
    setName("Res3");
    setLowerLimit(0);
    setDefault(1);
    }
    aFPArray[x] = new FunctionParameter("Res4", FunctionParameter.NUMBER);
    with(aFPArray[x++]){
    setName("Res4");
    setLowerLimit(0);
    setDefault(1.25);
    }
    aFPArray[x] = new FunctionParameter("Sup1", FunctionParameter.NUMBER);
    with(aFPArray[x++]){
    setName("Sup1");
    setLowerLimit(0);
    setDefault(.5);
    }
    aFPArray[x] = new FunctionParameter("Sup2", FunctionParameter.NUMBER);
    with(aFPArray[x++]){
    setName("Sup2");
    setLowerLimit(0);
    setDefault(.75);
    }
    aFPArray[x] = new FunctionParameter("Sup3", FunctionParameter.NUMBER);
    with(aFPArray[x++]){
    setName("Sup3");
    setLowerLimit(0);
    setDefault(1);
    }
    aFPArray[x] = new FunctionParameter("Sup4", FunctionParameter.NUMBER);
    with(aFPArray[x++]){
    setName("Sup4");
    setLowerLimit(0);
    setDefault(1.5);
    }
    aFPArray[x] = new FunctionParameter("TodayOnly", FunctionParameter.BOOLEAN);
    with(aFPArray[x++]){
    setDefault(true);
    }
    aFPArray[x] = new FunctionParameter("PriceOffset", FunctionParameter.NUMBER);
    with(aFPArray[x++]){
    setName("Price Offset");
    setLowerLimit(0);
    setDefault(3);
    }
    aFPArray[x] = new FunctionParameter("plotPrice", FunctionParameter.STRING);
    with(aFPArray[x++]){
    setName("Plot Price At");
    addOption("Open Only");
    addOption("Open & Res1");
    addOption("Res1 & Res2 & Res3");
    addOption("Res1 & Res2 & Res3 & Res4")
    setDefault("Open & Res1 & Res2 & Res3 & Res4 & Sup1 & Sup2 & Sup3 & Sup4");
    }
    }
    var nPrice=0;

    var bLong1 = null;
    var bLong2 = null;
    var bLong3 = null;
    var bLong4 = null;

    var bShort1 = null;
    var bShort2 = null;
    var bShort3 = null;
    var bShort4 = null;

    var bInit = false;

    function main(UserTime,LineLen,Res1,Res2,Res3,Res4,Sup1,Sup 2,Sup3,Sup4,TodayOnly,plotPrice,PriceOffset) {
    var xOpen = LineTag = null;
    if(TodayOnly) LineTag = 105;
    else LineTag = gID();
    if(isMonthly() || isWeekly() || isDaily()) return;
    if((hour(0)*100)+minute(0)==UserTime){
    nPrice = open(0);
    drawLineRelative( 0, open(0)+Res1, LineLen, open(0)+Res1, PS_DOT, 1, Color.yellow, "Up"+LineTag );
    drawLineRelative( 0, open(0)+Res2, LineLen, open(0)+Res2, PS_DOT, 1, Color.green, "Up1"+LineTag );
    drawLineRelative( 0, open(0)+Res3, LineLen, open(0)+Res3, PS_DOT, 1, Color.red, "Up2"+LineTag );
    drawLineRelative( 0, open(0)+Res4, LineLen, open(0)+Res4, PS_DOT, 2, Color.red, "Up3"+LineTag );
    drawLineRelative( 0, open(0)-Sup1, LineLen, open(0)-Sup1, PS_DOT, 1, Color.yellow, "Dwn1"+LineTag );
    drawLineRelative( 0, open(0)-Sup2, LineLen, open(0)-Sup2, PS_DOT, 1, Color.green, "Dwn2"+LineTag );
    drawLineRelative( 0, open(0)-Sup3, LineLen, open(0)-Sup3, PS_DOT, 1, Color.red, "Dwn3"+LineTag );
    drawLineRelative( 0, open(0)-Sup4, LineLen, open(0)-Sup4, PS_DOT, 2, Color.red, "Dwn4"+LineTag );
    drawLineRelative( 0, open(0), LineLen, open(0), PS_SOLID, 1, Color.blue, "OpenMid"+LineTag );

    }

    //Start of Strategy Object

    if (getCurrentBarIndex() == 0) return;

    if (bInit == false) {
    var bLong1 = false;
    var bLong2 = false;
    var bLong3 = false;
    var bLong4 = false;
    var bShort1 = false;
    var bShort2 = false;
    var bShort3 = false;
    var bShort4 = false;
    bInit = true;
    }

    //Exit Signals
    if (Strategy.isInTrade() == true) {

    if (Strategy.isShort() == true) {

    if (bShort1 == true && bShort2 == false && bShort3 == false && bShort4 == false) {

    if (low(0)< nPrice && low(-1)>= nPrice) {
    nExitPrice = nPrice;
    Strategy.doCover("Cover Short1 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
    drawShape(Shape.DIAMOND, BelowBar2, Color.green);
    }
    } if (bShort1 == true && bShort2 == true && bShort3 == false && bShort4 == false) {

    if (low(0)< nPrice+Res1 && low(-1)>= nPrice+Res1) {
    nExitPrice = nPrice+Res1;
    Strategy.doCover("Cover Short2 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
    drawShape(Shape.DIAMOND, BelowBar2, Color.green);
    }
    } if (bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == false) {

    if (low(0)< nPrice+Res2 && low(-1)>= nPrice+Res2) {
    nExitPrice = nPrice+Res2;
    Strategy.doCover("Cover Short3 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
    drawShape(Shape.DIAMOND, BelowBar2, Color.green);
    }
    } if (bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == true) {

    if (low(0)< nPrice+Res3 && low(-1)>= nPrice+Res3) {
    nExitPrice = nPrice+Res3;
    Strategy.doCover("Cover Short4 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
    drawShape(Shape.DIAMOND, BelowBar2, Color.green);
    }
    }

    } else if (Strategy.isLong() == true) {

    if (bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false) {

    if (high(0)> nPrice && high(-1)<= nPrice) {
    nExitPrice = nPrice;
    Strategy.doSell("Sell Long1 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
    drawShape(Shape.DIAMOND, AboveBar2, Color.green);
    }
    } if (bLong1 == true && bLong2 == true && bLong3 == false && bLong4 == false) {

    if (high(0)> nPrice-Sup1 && high(-1)<= nPrice-Sup1) {
    nExitPrice = nPrice-Sup1;
    Strategy.doSell("Sell Long2 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
    drawShape(Shape.DIAMOND, AboveBar2, Color.green);
    }
    } if (bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == false) {

    if (high(0)> nPrice-Sup2 && high(-1)<= nPrice-Sup2) {
    nExitPrice = nPrice-Sup2;
    Strategy.doSell("Sell Long3 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
    drawShape(Shape.DIAMOND, AboveBar2, Color.green);
    }
    } if (bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == true) {

    if (high(0)> nPrice-Sup3 && high(-1)<= nPrice-Sup3) {
    nExitPrice = nPrice-Sup3;
    Strategy.doSell("Sell Long4 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
    drawShape(Shape.DIAMOND, AboveBar2, Color.green);
    }
    }
    }
    // Entry Short Signals
    } if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
    if (high(0)> nPrice+Res1 && high(-1)<= nPrice+Res1) {
    nEntryPrice = nPrice+Res1;
    Strategy.doShort("Entry Short1 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
    drawShape(Shape.DOWNARROW, AboveBar2, Color.red);
    bShort1 = true;
    }
    } if (bShort1 == true && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
    if (high(0)> nPrice+Res2 && high(-1)<= nPrice+Res2) {
    nEntryPrice = nPrice+Res2;
    Strategy.doShort("Entry Short2 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
    drawShape(Shape.DOWNARROW, AboveBar2, Color.red);
    bShort2 = true;
    }
    } if (bShort1 == true && bShort2 == true && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
    if (high(0)> nPrice+Res3 && high(-1)<= nPrice+Res3) {
    nEntryPrice = nPrice+Res3;
    Strategy.doShort("Entry Short3 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
    drawShape(Shape.DOWNARROW, AboveBar2, Color.red);
    bShort3 = true;
    }
    } if (bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
    if (high(0)> nPrice+Res4 && high(-1)<= nPrice+Res4) {
    nEntryPrice = nPrice+Res4;
    Strategy.doShort("Entry Short4 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
    drawShape(Shape.DOWNARROW, AboveBar2, Color.red);
    bShort4 = true;
    }
    //Entry Long Signals
    } if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
    if (low(0)< nPrice-Sup1 && low(-1)>= nPrice-Sup1) {
    nEntryPrice = nPrice-Sup1;
    Strategy.doLong("Entry Long1 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
    drawShape(Shape.UPARROW, BelowBar2, Color.blue);
    bLong1 = true;
    }
    } if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false) {
    if (low(0)< nPrice-Sup2 && low(-1)>= nPrice-Sup2) {
    nEntryPrice = nPrice-Sup2;
    Strategy.doLong("Entry Long2 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
    drawShape(Shape.UPARROW, BelowBar2, Color.blue);
    bLong2 = true;
    }
    } if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == true && bLong3 == false && bLong4 == false) {
    if (low(0)< nPrice-Sup3 && low(-1)>= nPrice-Sup3) {
    nEntryPrice = nPrice-Sup3;
    Strategy.doLong("Entry Long3 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
    drawShape(Shape.UPARROW, BelowBar2, Color.blue);
    bLong3 = true;
    }
    } if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == false) {
    if (low(0)< nPrice-Sup4 && low(-1)>= nPrice-Sup4) {
    nEntryPrice = nPrice-Sup4;
    Strategy.doLong("Entry Long4 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
    drawShape(Shape.UPARROW, BelowBar2, Color.blue);
    bLong4 = true;
    }
    }



    if(plotPrice.indexOf("Open")!=-1) drawTextRelative(PriceOffset, nPrice, nPrice, Color.blue, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP");
    if(plotPrice.indexOf("Res1")!=-1){
    drawTextRelative(PriceOffset, nPrice+Res1, nPrice+Res1, Color.yellow, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_H");
    if(plotPrice.indexOf("Res2")!=-1)
    drawTextRelative(PriceOffset, nPrice+Res2, nPrice+Res2, Color.green, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_K");
    if(plotPrice.indexOf("Res3")!=-1)
    drawTextRelative(PriceOffset, nPrice+Res3, nPrice+Res3, Color.red, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_L");
    if(plotPrice.indexOf("Res4")!=-1)
    drawTextRelative(PriceOffset, nPrice+Res4, nPrice+Res4, Color.red, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_M");
    if(plotPrice.indexOf("Sup1")!=-1)
    drawTextRelative(PriceOffset, nPrice-Sup1, nPrice-Sup1, Color.yellow, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_N");
    if(plotPrice.indexOf("Sup2")!=-1)
    drawTextRelative(PriceOffset, nPrice-Sup2, nPrice-Sup2, Color.green, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_O");
    if(plotPrice.indexOf("Sup3")!=-1)
    drawTextRelative(PriceOffset, nPrice-Sup3, nPrice-Sup3, Color.red, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_P");
    if(plotPrice.indexOf("Sup4")!=-1)
    drawTextRelative(PriceOffset, nPrice-Sup4, nPrice-Sup4, Color.red, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_Q");

    }
    }
    var grID = 0;
    function gID() {
    grID ++;
    return( grID );
    }

  • #2
    Open Bands Strategy

    Hi Wayne,
    i dont know if you can take a look at this and something stands out to you that is simple to correct, i just cant seems to get it to show any trades. if so I would be for ever grateful! if not I'll await a replt from the forum i posted. Many thanks.

    PHP Code:
    //http://forum.esignal.com/showthread.php?38494-Bands-based-on-Open-Price
    function preMain() {
        var 
    aFPArray = new Array();
        
    setPriceStudy(true);
        
    setCursorLabelName("TodayOpen");

        var 
    x=0;
        
    aFPArray[x] = new FunctionParameter("UserTime"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]){
            
    setName("Start Time For Open (2300)");
            
    setLowerLimit(0);        
            
    setUpperLimit(2400);        
            
    setDefault(100);
        }
        
    aFPArray[x] = new FunctionParameter("LineLen"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]){
            
    setName("Line Length");
            
    setLowerLimit(1);        
            
    setDefault(200);
        }
        
    aFPArray[x] = new FunctionParameter("Res1"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]){
            
    setName("Res1");
            
    setLowerLimit(0);        
            
    setDefault(.5);
        }
        
    aFPArray[x] = new FunctionParameter("Res2"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]){
            
    setName("Res2");
            
    setLowerLimit(0);        
            
    setDefault(.75);
        }
        
    aFPArray[x] = new FunctionParameter("Res3"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]){
            
    setName("Res3");
            
    setLowerLimit(0);        
            
    setDefault(1);
        }
        
    aFPArray[x] = new FunctionParameter("Res4"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]){
            
    setName("Res4");
            
    setLowerLimit(0);        
            
    setDefault(1.25);
        }
        
    aFPArray[x] = new FunctionParameter("Sup1"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]){
            
    setName("Sup1");
            
    setLowerLimit(0);        
            
    setDefault(.5);
        }
        
    aFPArray[x] = new FunctionParameter("Sup2"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]){
            
    setName("Sup2");
            
    setLowerLimit(0);        
            
    setDefault(.75);
        }
        
    aFPArray[x] = new FunctionParameter("Sup3"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]){
            
    setName("Sup3");
            
    setLowerLimit(0);        
            
    setDefault(1);
        }
        
    aFPArray[x] = new FunctionParameter("Sup4"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]){
            
    setName("Sup4");
            
    setLowerLimit(0);        
            
    setDefault(1.5);
        }
        
    aFPArray[x] = new FunctionParameter("TodayOnly"FunctionParameter.BOOLEAN);
        
    with(aFPArray[x++]){
            
    setDefault(true);
        }
        
    aFPArray[x] = new FunctionParameter("PriceOffset"FunctionParameter.NUMBER);
        
    with(aFPArray[x++]){
            
    setName("Price Offset");
            
    setLowerLimit(0);        
            
    setDefault(3);
        }
        
    aFPArray[x] = new FunctionParameter("plotPrice"FunctionParameter.STRING);
        
    with(aFPArray[x++]){
            
    setName("Plot Price At");
            
    addOption("Open Only");
            
    addOption("Open & Res1");
            
    addOption("Res1 & Res2 & Res3");
            
    addOption("Res1 & Res2 & Res3 & Res4")
            
    setDefault("Open & Res1 & Res2 & Res3 & Res4 & Sup1 & Sup2 & Sup3 & Sup4");
        }
    }


        var 
    bLong1 null;
        var 
    bLong2 null;
        var 
    bLong3 null;
        var 
    bLong4 null;
        var 
    bShort1 null;
        var 
    bShort2 null;
        var 
    bShort3 null;
        var 
    bShort4 null;
        var 
    bInit false;
        var 
    nPrice 0;


    function 
    main(UserTime,LineLen,Res1,Res2,Res3,Res4,Sup1,Sup2,Sup3,Sup4,TodayOnly,plotPrice,PriceOffset) {
        var 
    xOpen  LineTag null;
        if(
    TodayOnlyLineTag 105;
        else 
    LineTag gID();
        if(
    isMonthly() || isWeekly() || isDaily()) return;
        if((
    hour(0)*100)+minute(0)==UserTime){
            
    nPrice open(0);
            
    drawLineRelative0open(0)+Res1LineLenopen(0)+Res1PS_DOT1Color.yellow"Up"+LineTag );
            
    drawLineRelative0open(0)+Res2LineLenopen(0)+Res2PS_DOT1Color.green"Up1"+LineTag );
            
    drawLineRelative0open(0)+Res3LineLenopen(0)+Res3PS_DOT1Color.red"Up2"+LineTag );
            
    drawLineRelative0open(0)+Res4LineLenopen(0)+Res4PS_DOT2Color.red"Up3"+LineTag );
            
    drawLineRelative0open(0)-Sup1LineLenopen(0)-Sup1PS_DOT1Color.yellow"Dwn1"+LineTag );
            
    drawLineRelative0open(0)-Sup2LineLenopen(0)-Sup2PS_DOT1Color.green"Dwn2"+LineTag );
            
    drawLineRelative0open(0)-Sup3LineLenopen(0)-Sup3PS_DOT1Color.red"Dwn3"+LineTag );
            
    drawLineRelative0open(0)-Sup4LineLenopen(0)-Sup4PS_DOT2Color.red"Dwn4"+LineTag );
            
    drawLineRelative0open(0), LineLenopen(0), PS_SOLID1Color.blue"OpenMid"+LineTag ); 
            
        }

    //Start of Strategy Object

        
    if (getCurrentBarIndex() == 0) return;
        
        if (
    bInit == false) {  
            var 
    bLong1 false;
            var 
    bLong2 false;
            var 
    bLong3 false;
            var 
    bLong4 false;
            var 
    bShort1 false;
            var 
    bShort2 false;
            var 
    bShort3 false;
            var 
    bShort4 false;
            
    bInit true;
            
     
    // Entry Short Signals
     
    }  if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
        if (
    high(0)> nPrice+Res1 && high(-1)<= nPrice+Res1) {
        
    nEntryPrice nPrice+Res1;
        
    Strategy.doShort("Entry Short1 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);
            
    drawShape(Shape.DOWNARROWAboveBar2Color.red);
        
    bShort1 true;
            }
        } if (
    bShort1 == true && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
        if (
    high(0)> nPrice+Res2 && high(-1)<= nPrice+Res2) {
        
    nEntryPrice nPrice+Res2;
        
    Strategy.doShort("Entry Short2 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);
            
    drawShape(Shape.DOWNARROWAboveBar2Color.red);
        
    bShort2 true;
            }
        } if (
    bShort1 == true && bShort2 == true && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
        if (
    high(0)> nPrice+Res3 && high(-1)<= nPrice+Res3) {
        
    nEntryPrice nPrice+Res3;
        
    Strategy.doShort("Entry Short3 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);
            
    drawShape(Shape.DOWNARROWAboveBar2Color.red);
        
    bShort3 true;
            }
        } if (
    bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
        if (
    high(0)> nPrice+Res4 && high(-1)<= nPrice+Res4) {
        
    nEntryPrice nPrice+Res4;
        
    Strategy.doShort("Entry Short4 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);
            
    drawShape(Shape.DOWNARROWAboveBar2Color.red);
        
    bShort4 true;   
            }
        
    //Entry Long Signals
        
    } if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
        if (
    low(0)< nPrice-Sup1 && low(-1)>= nPrice-Sup1) {
        
    nEntryPrice nPrice-Sup1;
        
    Strategy.doLong("Entry Long1 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);
            
    drawShape(Shape.UPARROWBelowBar2Color.blue);
        
    bLong1 true;
            }
        } if (
    bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false) {
        if (
    low(0)< nPrice-Sup2 && low(-1)>= nPrice-Sup2) {
        
    nEntryPrice nPrice-Sup2;
        
    Strategy.doLong("Entry Long2 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);
            
    drawShape(Shape.UPARROWBelowBar2Color.blue);
        
    bLong2 true;
            }
        } if (
    bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == true && bLong3 == false && bLong4 == false) {
        if (
    low(0)< nPrice-Sup3 && low(-1)>= nPrice-Sup3) {
        
    nEntryPrice nPrice-Sup3;
        
    Strategy.doLong("Entry Long3 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);
            
    drawShape(Shape.UPARROWBelowBar2Color.blue);
        
    bLong3 true;
            }
        } if (
    bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == false) {
        if (
    low(0)< nPrice-Sup4 && low(-1)>= nPrice-Sup4) {
        
    nEntryPrice nPrice-Sup4;
        
    Strategy.doLong("Entry Long4 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);
            
    drawShape(Shape.UPARROWBelowBar2Color.blue);
        
    bLong4 true;
            }
        }   }
        
    //Exit Signals
    if (Strategy.isInTrade() == true) {
        
        if (
    Strategy.isShort() == true) {
            
            if (
    bShort1 == true && bShort2 == false && bShort3 == false && bShort4 == false) {
                
                if (
    low(0)< nPrice && low(-1)>= nPrice) {
                
    nExitPrice nPrice;
                
    Strategy.doCover("Cover Short1 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);
                
    drawShape(Shape.DIAMONDBelowBar2Color.green);
                }
            } if (
    bShort1 == true && bShort2 == true && bShort3 == false && bShort4 == false) {
                
                if (
    low(0)< nPrice+Res1 && low(-1)>= nPrice+Res1) {
                
    nExitPrice nPrice+Res1;
                
    Strategy.doCover("Cover Short2 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);
                
    drawShape(Shape.DIAMONDBelowBar2Color.green);
                }
            } if (
    bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == false) {
                
                if (
    low(0)< nPrice+Res2 && low(-1)>= nPrice+Res2) {
                
    nExitPrice nPrice+Res2;
                
    Strategy.doCover("Cover Short3 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);
                
    drawShape(Shape.DIAMONDBelowBar2Color.green);
                }
            } if (
    bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == true) {
                
                if (
    low(0)< nPrice+Res3 && low(-1)>= nPrice+Res3) {
                
    nExitPrice nPrice+Res3;
                
    Strategy.doCover("Cover Short4 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);
                
    drawShape(Shape.DIAMONDBelowBar2Color.green);
                }
            }
        
        }  else if (
    Strategy.isLong() == true) {
            
            if (
    bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false) {
                
                if (
    high(0)> nPrice && high(-1)<= nPrice) {
                
    nExitPrice nPrice;
                
    Strategy.doSell("Sell Long1 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);
                
    drawShape(Shape.DIAMONDAboveBar2Color.green);
                }
            } if (
    bLong1 == true && bLong2 == true && bLong3 == false && bLong4 == false) {
                
                if (
    high(0)> nPrice-Sup1 && high(-1)<= nPrice-Sup1) {
                
    nExitPrice nPrice-Sup1;
                
    Strategy.doSell("Sell Long2 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);
                
    drawShape(Shape.DIAMONDAboveBar2Color.green);
                }
            } if (
    bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == false) {
                
                if (
    high(0)> nPrice-Sup2 && high(-1)<= nPrice-Sup2) {
                
    nExitPrice nPrice-Sup2;
                
    Strategy.doSell("Sell Long3 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);
                
    drawShape(Shape.DIAMONDAboveBar2Color.green);
                }
            } if (
    bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == true) {
                
                if (
    high(0)> nPrice-Sup3 && high(-1)<= nPrice-Sup3) {
                
    nExitPrice nPrice-Sup3;
                
    Strategy.doSell("Sell Long4 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);
                
    drawShape(Shape.DIAMONDAboveBar2Color.green);
                }
            }
        }




        if(
    plotPrice.indexOf("Open")!=-1drawTextRelative(PriceOffsetnPricenPriceColor.bluenullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP");
        if(
    plotPrice.indexOf("Res1")!=-1){
            
    drawTextRelative(PriceOffsetnPrice+Res1nPrice+Res1Color.yellownullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_H");
        if(
    plotPrice.indexOf("Res2")!=-1)
            
    drawTextRelative(PriceOffsetnPrice+Res2nPrice+Res2Color.greennullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_K");
        if(
    plotPrice.indexOf("Res3")!=-1)
            
    drawTextRelative(PriceOffsetnPrice+Res3nPrice+Res3Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_L");
        if(
    plotPrice.indexOf("Res4")!=-1)
            
    drawTextRelative(PriceOffsetnPrice+Res4nPrice+Res4Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_M");
        if(
    plotPrice.indexOf("Sup1")!=-1)
            
    drawTextRelative(PriceOffsetnPrice-Sup1nPrice-Sup1Color.yellownullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_N");
        if(
    plotPrice.indexOf("Sup2")!=-1)
            
    drawTextRelative(PriceOffsetnPrice-Sup2nPrice-Sup2Color.greennullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_O");
        if(
    plotPrice.indexOf("Sup3")!=-1)
            
    drawTextRelative(PriceOffsetnPrice-Sup3nPrice-Sup3Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_P");
        if(
    plotPrice.indexOf("Sup4")!=-1)
            
    drawTextRelative(PriceOffsetnPrice-Sup4nPrice-Sup4Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_Q");
            
        }
    }
    var 
    grID 0;
    function 
    gID() {
        
    grID ++;
        return( 
    grID );

    Comment


    • #3
      Hi ferret,

      I'll look at the code in a little while. But a quick review shows that the declaration of local variables inside the bInit block you intend to use outside of bInit is part of the problem, they are not being reset as intended. See test below.
      Just a note that might simplify your code a little: a check of a Boolean variable "(if (Strategy.isLong() == true)" and "if (Strategy.isLong() == false)" can be expressed as "if (Strategy.isLong())" and "if (!Strategy.isLong())".
      PHP Code:
      debugClear();
      var 
      bInit=false;
      var 
      globalTest=0;
      var 
      flag 0;
      function 
      main(){
          var 
      localTest 0;
          if(!
      bInit){
              
      globalTest=1;
              
      localTest 1;
              var 
      bInitTest 0;
              
      bInit=true;
          }
      //variables declared within bInit are local and will be undefined on the 2nd and greater iterations of main since the bInit routine runs only once on the first iteration of main.
          
      if(flag<3){
              
      debugPrintln("11: gbl: "+globalTest+"\tlocal:"+localTest+"\t\tbInt: "+bInitTest);
              
      bInitTest 2;
              
      globalTest 2;
              
      localTest 2;
              
      debugPrintln("13: gbl: "+globalTest+"\tlocal:"+localTest+"\t\tbInt: "+bInitTest);
              
      flag++;
          }
      }
      /*
      13: gbl: 2    local:2        bInt: 2
      11: gbl: 2    local:0        bInt: undefined
      13: gbl: 2    local:2        bInt: 2
      11: gbl: 2    local:0        bInt: undefined
      13: gbl: 2    local:2        bInt: 2
      11: gbl: 1    local:1        bInt: 0
      */ 
      Also the following variables are declared locally and globally:
      var bLong1 = false;
      var bLong2 = false;
      var bLong3 = false;
      var bLong4 = false;
      var bShort1 = false;
      var bShort2 = false;
      var bShort3 = false;
      var bShort4 = false;


      Wayne
      Last edited by waynecd; 08-03-2013, 11:57 AM.

      Comment


      • #4
        Hi,

        This is not an extensive review of the code but just resetting the variables at the beginning of a new day yields trades.
        See http://forum.esignal.com/showthread....n-EOD-troubles for an overview of identifying a new day.

        PHP Code:
        //http://forum.esignal.com/showthread.php?38494-Bands-based-on-Open-Price 
        //http://forum.esignal.com/showthread.php?38847-Averaging-System-with-multiple-entry-s-and-exit-s

        function preMain() {
            var 
        aFPArray = new Array();
            
        setPriceStudy(true);
            
        setCursorLabelName("TodayOpen");

            var 
        0;
            
        aFPArray[x] = new FunctionParameter("UserTime"FunctionParameter.NUMBER);
            
        with(aFPArray[x++]) {
                
        setName("Start Time For Open (2300)");
                
        setLowerLimit(0);
                
        setUpperLimit(2400);
                
        setDefault(100);
            }
            
        aFPArray[x] = new FunctionParameter("LineLen"FunctionParameter.NUMBER);
            
        with(aFPArray[x++]) {
                
        setName("Line Length");
                
        setLowerLimit(1);
                
        setDefault(200);
            }
            
        aFPArray[x] = new FunctionParameter("Res1"FunctionParameter.NUMBER);
            
        with(aFPArray[x++]) {
                
        setName("Res1");
                
        setLowerLimit(0);
                
        setDefault(.5);
            }
            
        aFPArray[x] = new FunctionParameter("Res2"FunctionParameter.NUMBER);
            
        with(aFPArray[x++]) {
                
        setName("Res2");
                
        setLowerLimit(0);
                
        setDefault(.75);
            }
            
        aFPArray[x] = new FunctionParameter("Res3"FunctionParameter.NUMBER);
            
        with(aFPArray[x++]) {
                
        setName("Res3");
                
        setLowerLimit(0);
                
        setDefault(1);
            }
            
        aFPArray[x] = new FunctionParameter("Res4"FunctionParameter.NUMBER);
            
        with(aFPArray[x++]) {
                
        setName("Res4");
                
        setLowerLimit(0);
                
        setDefault(1.25);
            }
            
        aFPArray[x] = new FunctionParameter("Sup1"FunctionParameter.NUMBER);
            
        with(aFPArray[x++]) {
                
        setName("Sup1");
                
        setLowerLimit(0);
                
        setDefault(.5);
            }
            
        aFPArray[x] = new FunctionParameter("Sup2"FunctionParameter.NUMBER);
            
        with(aFPArray[x++]) {
                
        setName("Sup2");
                
        setLowerLimit(0);
                
        setDefault(.75);
            }
            
        aFPArray[x] = new FunctionParameter("Sup3"FunctionParameter.NUMBER);
            
        with(aFPArray[x++]) {
                
        setName("Sup3");
                
        setLowerLimit(0);
                
        setDefault(1);
            }
            
        aFPArray[x] = new FunctionParameter("Sup4"FunctionParameter.NUMBER);
            
        with(aFPArray[x++]) {
                
        setName("Sup4");
                
        setLowerLimit(0);
                
        setDefault(1.5);
            }
            
        aFPArray[x] = new FunctionParameter("TodayOnly"FunctionParameter.BOOLEAN);
            
        with(aFPArray[x++]) {
                
        setDefault(true);
            }
            
        aFPArray[x] = new FunctionParameter("PriceOffset"FunctionParameter.NUMBER);
            
        with(aFPArray[x++]) {
                
        setName("Price Offset");
                
        setLowerLimit(0);
                
        setDefault(3);
            }
            
        aFPArray[x] = new FunctionParameter("plotPrice"FunctionParameter.STRING);
            
        with(aFPArray[x++]) {
                
        setName("Plot Price At");
                
        addOption("Open Only");
                
        addOption("Open & Res1");
                
        addOption("Res1 & Res2 & Res3");
                
        addOption("Res1 & Res2 & Res3 & Res4")
                
        setDefault("Open & Res1 & Res2 & Res3 & Res4 & Sup1 & Sup2 & Sup3 & Sup4");
            }
        }


        var 
        bLong1 null;
        var 
        bLong2 null;
        var 
        bLong3 null;
        var 
        bLong4 null;
        var 
        bShort1 null;
        var 
        bShort2 null;
        var 
        bShort3 null;
        var 
        bShort4 null;
        var 
        bInit false;
        var 
        nPrice 0;


        function 
        main(UserTimeLineLenRes1Res2Res3Res4Sup1Sup2Sup3Sup4TodayOnlyplotPricePriceOffset) {
            var 
        xOpen LineTag null;
            if (
        TodayOnlyLineTag 105;
            else 
        LineTag gID();
            if (
        isMonthly() || isWeekly() || isDaily()) return;
            if (
        day(0) != day(-1)) {
                
        bLong1 false;
                
        bLong2 false;
                
        bLong3 false;
                
        bLong4 false;
                
        bShort1 false;
                
        bShort2 false;
                
        bShort3 false;
                
        bShort4 false;
            }
            if ((
        hour(0) * 100) + minute(0) == UserTime) {
                
        nPrice open(0);
                
        drawLineRelative(0open(0) + Res1LineLenopen(0) + Res1PS_DOT1Color.yellow"Up" LineTag);
                
        drawLineRelative(0open(0) + Res2LineLenopen(0) + Res2PS_DOT1Color.green"Up1" LineTag);
                
        drawLineRelative(0open(0) + Res3LineLenopen(0) + Res3PS_DOT1Color.red"Up2" LineTag);
                
        drawLineRelative(0open(0) + Res4LineLenopen(0) + Res4PS_DOT2Color.red"Up3" LineTag);
                
        drawLineRelative(0open(0) - Sup1LineLenopen(0) - Sup1PS_DOT1Color.yellow"Dwn1" LineTag);
                
        drawLineRelative(0open(0) - Sup2LineLenopen(0) - Sup2PS_DOT1Color.green"Dwn2" LineTag);
                
        drawLineRelative(0open(0) - Sup3LineLenopen(0) - Sup3PS_DOT1Color.red"Dwn3" LineTag);
                
        drawLineRelative(0open(0) - Sup4LineLenopen(0) - Sup4PS_DOT2Color.red"Dwn4" LineTag);
                
        drawLineRelative(0open(0), LineLenopen(0), PS_SOLID1Color.blue"OpenMid" LineTag);

            }

            
        //Start of Strategy Object 

            
        if (getCurrentBarIndex() == 0) return;

            if (
        bInit == false) {
                
        bInit true;
            }
            
        // Entry Short Signals 

            
        if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
                if (
        high(0) > nPrice Res1 && high(-1) <= nPrice Res1) {
                    
        nEntryPrice nPrice Res1;
                    
        Strategy.doShort("Entry Short1 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);
                    
        drawShape(Shape.DOWNARROWAboveBar2Color.red);
                    
        bShort1 true;
                }
            }
            if (
        bShort1 == true && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
                if (
        high(0) > nPrice Res2 && high(-1) <= nPrice Res2) {
                    
        nEntryPrice nPrice Res2;
                    
        Strategy.doShort("Entry Short2 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);
                    
        drawShape(Shape.DOWNARROWAboveBar2Color.red);
                    
        bShort2 true;
                }
            }
            if (
        bShort1 == true && bShort2 == true && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
                if (
        high(0) > nPrice Res3 && high(-1) <= nPrice Res3) {
                    
        nEntryPrice nPrice Res3;
                    
        Strategy.doShort("Entry Short3 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);
                    
        drawShape(Shape.DOWNARROWAboveBar2Color.red);
                    
        bShort3 true;
                }
            }
            if (
        bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
                if (
        high(0) > nPrice Res4 && high(-1) <= nPrice Res4) {
                    
        nEntryPrice nPrice Res4;
                    
        Strategy.doShort("Entry Short4 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);
                    
        drawShape(Shape.DOWNARROWAboveBar2Color.red);
                    
        bShort4 true;
                }
                
        //Entry Long Signals 
            
        }
            if (
        bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
                if (
        low(0) < nPrice Sup1 && low(-1) >= nPrice Sup1) {
                    
        nEntryPrice nPrice Sup1;
                    
        Strategy.doLong("Entry Long1 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);
                    
        drawShape(Shape.UPARROWBelowBar2Color.blue);
                    
        bLong1 true;
                }
            }
            if (
        bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false) {
                if (
        low(0) < nPrice Sup2 && low(-1) >= nPrice Sup2) {
                    
        nEntryPrice nPrice Sup2;
                    
        Strategy.doLong("Entry Long2 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);
                    
        drawShape(Shape.UPARROWBelowBar2Color.blue);
                    
        bLong2 true;
                }
            }
            if (
        bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == true && bLong3 == false && bLong4 == false) {
                if (
        low(0) < nPrice Sup3 && low(-1) >= nPrice Sup3) {
                    
        nEntryPrice nPrice Sup3;
                    
        Strategy.doLong("Entry Long3 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);
                    
        drawShape(Shape.UPARROWBelowBar2Color.blue);
                    
        bLong3 true;
                }
            }
            if (
        bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == false) {
                if (
        low(0) < nPrice Sup4 && low(-1) >= nPrice Sup4) {
                    
        nEntryPrice nPrice Sup4;
                    
        Strategy.doLong("Entry Long4 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);
                    
        drawShape(Shape.UPARROWBelowBar2Color.blue);
                    
        bLong4 true;
                }
            }
        }

        //Exit Signals 
        if (Strategy.isInTrade() == true) {

            if (
        Strategy.isShort() == true) {

                if (
        bShort1 == true && bShort2 == false && bShort3 == false && bShort4 == false) {

                    if (
        low(0) < nPrice && low(-1) >= nPrice) {
                        
        nExitPrice nPrice;
                        
        Strategy.doCover("Cover Short1 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);
                        
        drawShape(Shape.DIAMONDBelowBar2Color.green);
                    }
                }
                if (
        bShort1 == true && bShort2 == true && bShort3 == false && bShort4 == false) {

                    if (
        low(0) < nPrice Res1 && low(-1) >= nPrice Res1) {
                        
        nExitPrice nPrice Res1;
                        
        Strategy.doCover("Cover Short2 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);
                        
        drawShape(Shape.DIAMONDBelowBar2Color.green);
                    }
                }
                if (
        bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == false) {

                    if (
        low(0) < nPrice Res2 && low(-1) >= nPrice Res2) {
                        
        nExitPrice nPrice Res2;
                        
        Strategy.doCover("Cover Short3 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);
                        
        drawShape(Shape.DIAMONDBelowBar2Color.green);
                    }
                }
                if (
        bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == true) {

                    if (
        low(0) < nPrice Res3 && low(-1) >= nPrice Res3) {
                        
        nExitPrice nPrice Res3;
                        
        Strategy.doCover("Cover Short4 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);
                        
        drawShape(Shape.DIAMONDBelowBar2Color.green);
                    }
                }

            } else if (
        Strategy.isLong() == true) {

                if (
        bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false) {

                    if (
        high(0) > nPrice && high(-1) <= nPrice) {
                        
        nExitPrice nPrice;
                        
        Strategy.doSell("Sell Long1 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);
                        
        drawShape(Shape.DIAMONDAboveBar2Color.green);
                    }
                }
                if (
        bLong1 == true && bLong2 == true && bLong3 == false && bLong4 == false) {

                    if (
        high(0) > nPrice Sup1 && high(-1) <= nPrice Sup1) {
                        
        nExitPrice nPrice Sup1;
                        
        Strategy.doSell("Sell Long2 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);
                        
        drawShape(Shape.DIAMONDAboveBar2Color.green);
                    }
                }
                if (
        bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == false) {

                    if (
        high(0) > nPrice Sup2 && high(-1) <= nPrice Sup2) {
                        
        nExitPrice nPrice Sup2;
                        
        Strategy.doSell("Sell Long3 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);
                        
        drawShape(Shape.DIAMONDAboveBar2Color.green);
                    }
                }
                if (
        bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == true) {

                    if (
        high(0) > nPrice Sup3 && high(-1) <= nPrice Sup3) {
                        
        nExitPrice nPrice Sup3;
                        
        Strategy.doSell("Sell Long4 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);
                        
        drawShape(Shape.DIAMONDAboveBar2Color.green);
                    }
                }
            }




            if (
        plotPrice.indexOf("Open") != -1drawTextRelative(PriceOffsetnPricenPriceColor.bluenullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP");
            if (
        plotPrice.indexOf("Res1") != -1) {
                
        drawTextRelative(PriceOffsetnPrice Res1nPrice Res1Color.yellownullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_H");
                if (
        plotPrice.indexOf("Res2") != -1)
                    
        drawTextRelative(PriceOffsetnPrice Res2nPrice Res2Color.greennullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_K");
                if (
        plotPrice.indexOf("Res3") != -1)
                    
        drawTextRelative(PriceOffsetnPrice Res3nPrice Res3Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_L");
                if (
        plotPrice.indexOf("Res4") != -1)
                    
        drawTextRelative(PriceOffsetnPrice Res4nPrice Res4Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_M");
                if (
        plotPrice.indexOf("Sup1") != -1)
                    
        drawTextRelative(PriceOffsetnPrice Sup1nPrice Sup1Color.yellownullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_N");
                if (
        plotPrice.indexOf("Sup2") != -1)
                    
        drawTextRelative(PriceOffsetnPrice Sup2nPrice Sup2Color.greennullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_O");
                if (
        plotPrice.indexOf("Sup3") != -1)
                    
        drawTextRelative(PriceOffsetnPrice Sup3nPrice Sup3Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_P");
                if (
        plotPrice.indexOf("Sup4") != -1)
                    
        drawTextRelative(PriceOffsetnPrice Sup4nPrice Sup4Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_Q");

            }
        }
        var 
        grID 0;

        function 
        gID() {
            
        grID++;
            return (
        grID);

        Wayne
        Last edited by waynecd; 08-03-2013, 11:39 AM.

        Comment


        • #5
          Hi,

          The code also had several extra and some misplaced curly brackets. I think this is closer to what you intend:

          PHP Code:
          //http://forum.esignal.com/showthread.php?38494-Bands-based-on-Open-Price 
          //http://forum.esignal.com/showthread.php?38847-Averaging-System-with-multiple-entry-s-and-exit-s
          function preMain() 

              var 
          aFPArray = new Array(); 
              
          setPriceStudy(true); 
              
          setCursorLabelName("TodayOpen"); 

              var 
          x=0
              
          aFPArray[x] = new FunctionParameter("UserTime"FunctionParameter.NUMBER); 
              
          with(aFPArray[x++])
              { 
                  
          setName("Start Time For Open (2300)"); 
                  
          setLowerLimit(0);         
                  
          setUpperLimit(2400);         
                  
          setDefault(100); 
              } 
              
          aFPArray[x] = new FunctionParameter("LineLen"FunctionParameter.NUMBER); 
              
          with(aFPArray[x++])
              { 
                  
          setName("Line Length"); 
                  
          setLowerLimit(1);         
                  
          setDefault(200); 
              } 
              
          aFPArray[x] = new FunctionParameter("Res1"FunctionParameter.NUMBER); 
              
          with(aFPArray[x++])
              { 
                  
          setName("Res1"); 
                  
          setLowerLimit(0);         
                  
          setDefault(.5); 
              } 
              
          aFPArray[x] = new FunctionParameter("Res2"FunctionParameter.NUMBER); 
              
          with(aFPArray[x++])
              { 
                  
          setName("Res2"); 
                  
          setLowerLimit(0);         
                  
          setDefault(.75); 
              } 
              
          aFPArray[x] = new FunctionParameter("Res3"FunctionParameter.NUMBER); 
              
          with(aFPArray[x++])
              { 
                  
          setName("Res3"); 
                  
          setLowerLimit(0);         
                  
          setDefault(1); 
              } 
              
          aFPArray[x] = new FunctionParameter("Res4"FunctionParameter.NUMBER); 
              
          with(aFPArray[x++])
              { 
                  
          setName("Res4"); 
                  
          setLowerLimit(0);         
                  
          setDefault(1.25); 
              } 
              
          aFPArray[x] = new FunctionParameter("Sup1"FunctionParameter.NUMBER); 
              
          with(aFPArray[x++])
              { 
                  
          setName("Sup1"); 
                  
          setLowerLimit(0);         
                  
          setDefault(.5); 
              } 
              
          aFPArray[x] = new FunctionParameter("Sup2"FunctionParameter.NUMBER); 
              
          with(aFPArray[x++])
              { 
                  
          setName("Sup2"); 
                  
          setLowerLimit(0);         
                  
          setDefault(.75); 
              } 
              
          aFPArray[x] = new FunctionParameter("Sup3"FunctionParameter.NUMBER); 
              
          with(aFPArray[x++])
              { 
                  
          setName("Sup3"); 
                  
          setLowerLimit(0);         
                  
          setDefault(1); 
              } 
              
          aFPArray[x] = new FunctionParameter("Sup4"FunctionParameter.NUMBER); 
              
          with(aFPArray[x++])
              { 
                  
          setName("Sup4"); 
                  
          setLowerLimit(0);         
                  
          setDefault(1.5); 
              } 
              
          aFPArray[x] = new FunctionParameter("TodayOnly"FunctionParameter.BOOLEAN); 
              
          with(aFPArray[x++])
              { 
                  
          setDefault(true); 
              } 
              
          aFPArray[x] = new FunctionParameter("PriceOffset"FunctionParameter.NUMBER); 
              
          with(aFPArray[x++])
              { 
                  
          setName("Price Offset"); 
                  
          setLowerLimit(0);         
                  
          setDefault(3); 
              } 
              
          aFPArray[x] = new FunctionParameter("plotPrice"FunctionParameter.STRING); 
              
          with(aFPArray[x++])
              { 
                  
          setName("Plot Price At"); 
                  
          addOption("Open Only"); 
                  
          addOption("Open & Res1"); 
                  
          addOption("Res1 & Res2 & Res3"); 
                  
          addOption("Res1 & Res2 & Res3 & Res4"
                  
          setDefault("Open & Res1 & Res2 & Res3 & Res4 & Sup1 & Sup2 & Sup3 & Sup4"); 
              } 



              var 
          bLong1 null
              var 
          bLong2 null
              var 
          bLong3 null
              var 
          bLong4 null
              var 
          bShort1 null
              var 
          bShort2 null
              var 
          bShort3 null
              var 
          bShort4 null
              var 
          bInit false
              var 
          nPrice 0


          function 
          main(UserTime,LineLen,Res1,Res2,Res3,Res4,Sup1,Sup2,Sup3,Sup4,TodayOnly,plotPrice,PriceOffset

              var 
          xOpen  LineTag null
              if(
          TodayOnlyLineTag 105
              else 
          LineTag gID(); 
              if(
          isMonthly() || isWeekly() || isDaily()) return; 
              if(
          day(0)!=day(-1))
              {
                  
          bLong1 false
                  
          bLong2 false
                  
          bLong3 false
                  
          bLong4 false
                  
          bShort1 false
                  
          bShort2 false
                  
          bShort3 false
                  
          bShort4 false
              }
              if((
          hour(0)*100)+minute(0)==UserTime)
              { 
                  
          nPrice open(0); 
                  
          drawLineRelative0open(0)+Res1LineLenopen(0)+Res1PS_DOT1Color.yellow"Up"+LineTag ); 
                  
          drawLineRelative0open(0)+Res2LineLenopen(0)+Res2PS_DOT1Color.green"Up1"+LineTag ); 
                  
          drawLineRelative0open(0)+Res3LineLenopen(0)+Res3PS_DOT1Color.red"Up2"+LineTag ); 
                  
          drawLineRelative0open(0)+Res4LineLenopen(0)+Res4PS_DOT2Color.red"Up3"+LineTag ); 
                  
          drawLineRelative0open(0)-Sup1LineLenopen(0)-Sup1PS_DOT1Color.yellow"Dwn1"+LineTag ); 
                  
          drawLineRelative0open(0)-Sup2LineLenopen(0)-Sup2PS_DOT1Color.green"Dwn2"+LineTag ); 
                  
          drawLineRelative0open(0)-Sup3LineLenopen(0)-Sup3PS_DOT1Color.red"Dwn3"+LineTag ); 
                  
          drawLineRelative0open(0)-Sup4LineLenopen(0)-Sup4PS_DOT2Color.red"Dwn4"+LineTag ); 
                  
          drawLineRelative0open(0), LineLenopen(0), PS_SOLID1Color.blue"OpenMid"+LineTag );  
                   
              } 

          //Start of Strategy Object 

              
          if (getCurrentBarIndex() == 0) return; 
               
              if (
          bInit == false
              {   
                  
          bInit true
              }     
          // Entry Short Signals 

              
          if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false
              { 
                  if (
          high(0)> nPrice+Res1 && high(-1)<= nPrice+Res1
                  { 
                      
          nEntryPrice nPrice+Res1
                      
          Strategy.doShort("Entry Short1 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice); 
                      
          drawShape(Shape.DOWNARROWAboveBar2Color.red); 
                      
          bShort1 true
                  }
              }
              if (
          bShort1 == true && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false
              { 
                  if (
          high(0)> nPrice+Res2 && high(-1)<= nPrice+Res2
                  { 
                      
          nEntryPrice nPrice+Res2
                      
          Strategy.doShort("Entry Short2 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice); 
                      
          drawShape(Shape.DOWNARROWAboveBar2Color.red); 
                      
          bShort2 true
                  } 
              }
              if (
          bShort1 == true && bShort2 == true && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false
              { 
                  if (
          high(0)> nPrice+Res3 && high(-1)<= nPrice+Res3
                  { 
                      
          nEntryPrice nPrice+Res3
                      
          Strategy.doShort("Entry Short3 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice); 
                      
          drawShape(Shape.DOWNARROWAboveBar2Color.red); 
                      
          bShort3 true
                  } 
              }
              if (
          bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false
              { 
                  if (
          high(0)> nPrice+Res4 && high(-1)<= nPrice+Res4
                  { 
                      
          nEntryPrice nPrice+Res4
                      
          Strategy.doShort("Entry Short4 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice); 
                      
          drawShape(Shape.DOWNARROWAboveBar2Color.red); 
                      
          bShort4 true;    
                  } 
              }
              
          //Entry Long Signals 
              
              
          if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false
              { 
                  if (
          low(0)< nPrice-Sup1 && low(-1)>= nPrice-Sup1
                  { 
                      
          nEntryPrice nPrice-Sup1
                      
          Strategy.doLong("Entry Long1 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice); 
                      
          drawShape(Shape.UPARROWBelowBar2Color.blue); 
                      
          bLong1 true
                  } 
              }
              if (
          bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false
              { 
                  if (
          low(0)< nPrice-Sup2 && low(-1)>= nPrice-Sup2
                  { 
                      
          nEntryPrice nPrice-Sup2
                      
          Strategy.doLong("Entry Long2 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice); 
                      
          drawShape(Shape.UPARROWBelowBar2Color.blue); 
                      
          bLong2 true
                  } 
              }
              if (
          bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == true && bLong3 == false && bLong4 == false
              { 
                  if (
          low(0)< nPrice-Sup3 && low(-1)>= nPrice-Sup3
                  { 
                      
          nEntryPrice nPrice-Sup3
                      
          Strategy.doLong("Entry Long3 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice); 
                      
          drawShape(Shape.UPARROWBelowBar2Color.blue); 
                      
          bLong3 true
                  } 
              }
              if (
          bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == false
              { 
                  if (
          low(0)< nPrice-Sup4 && low(-1)>= nPrice-Sup4
                  { 
                      
          nEntryPrice nPrice-Sup4
                      
          Strategy.doLong("Entry Long4 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice); 
                      
          drawShape(Shape.UPARROWBelowBar2Color.blue); 
                      
          bLong4 true
                  } 
              }
               
              
          //Exit Signals 
              
          if (Strategy.isInTrade() == true
              { 
               
                  if (
          Strategy.isShort() == true
                  { 
                       
                      if (
          bShort1 == true && bShort2 == false && bShort3 == false && bShort4 == false
                      { 
                           
                          if (
          low(0)< nPrice && low(-1)>= nPrice
                          { 
                              
          nExitPrice nPrice
                              
          Strategy.doCover("Cover Short1 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice); 
                              
          drawShape(Shape.DIAMONDBelowBar2Color.green); 
                          } 
                      }
                      if (
          bShort1 == true && bShort2 == true && bShort3 == false && bShort4 == false
                      { 
                           
                          if (
          low(0)< nPrice+Res1 && low(-1)>= nPrice+Res1
                          { 
                              
          nExitPrice nPrice+Res1
                              
          Strategy.doCover("Cover Short2 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice); 
                              
          drawShape(Shape.DIAMONDBelowBar2Color.green); 
                          } 
                      }
                      if (
          bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == false
                      { 
                           
                          if (
          low(0)< nPrice+Res2 && low(-1)>= nPrice+Res2
                          { 
                              
          nExitPrice nPrice+Res2
                              
          Strategy.doCover("Cover Short3 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice); 
                              
          drawShape(Shape.DIAMONDBelowBar2Color.green); 
                          } 
                      }
                      if (
          bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == true
                      { 
                           
                          if (
          low(0)< nPrice+Res3 && low(-1)>= nPrice+Res3
                          { 
                              
          nExitPrice nPrice+Res3
                              
          Strategy.doCover("Cover Short4 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice); 
                              
          drawShape(Shape.DIAMONDBelowBar2Color.green); 
                          } 
                      } 
                  }  else if (
          Strategy.isLong() == true
                  { 
                       
                      if (
          bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false
                      { 
                           
                          if (
          high(0)> nPrice && high(-1)<= nPrice
                          { 
                              
          nExitPrice nPrice
                              
          Strategy.doSell("Sell Long1 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice); 
                              
          drawShape(Shape.DIAMONDAboveBar2Color.green); 
                          } 
                      }
                      if (
          bLong1 == true && bLong2 == true && bLong3 == false && bLong4 == false
                      { 
                           
                          if (
          high(0)> nPrice-Sup1 && high(-1)<= nPrice-Sup1
                          { 
                              
          nExitPrice nPrice-Sup1
                              
          Strategy.doSell("Sell Long2 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice); 
                              
          drawShape(Shape.DIAMONDAboveBar2Color.green); 
                          } 
                      }
                      if (
          bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == false
                      { 
                           
                          if (
          high(0)> nPrice-Sup2 && high(-1)<= nPrice-Sup2
                          { 
                              
          nExitPrice nPrice-Sup2
                              
          Strategy.doSell("Sell Long3 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice); 
                              
          drawShape(Shape.DIAMONDAboveBar2Color.green); 
                          } 
                      }
                      if (
          bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == true
                      { 
                           
                          if (
          high(0)> nPrice-Sup3 && high(-1)<= nPrice-Sup3
                          { 
                              
          nExitPrice nPrice-Sup3
                              
          Strategy.doSell("Sell Long4 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice); 
                              
          drawShape(Shape.DIAMONDAboveBar2Color.green); 
                          } 
                      } 
                  } 
              }



              if(
          plotPrice.indexOf("Open")!=-1drawTextRelative(PriceOffsetnPricenPriceColor.bluenullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP"); 
              if(
          plotPrice.indexOf("Res1")!=-1drawTextRelative(PriceOffsetnPrice+Res1nPrice+Res1Color.yellownullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_H"); 
              if(
          plotPrice.indexOf("Res2")!=-1drawTextRelative(PriceOffsetnPrice+Res2nPrice+Res2Color.greennullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_K"); 
              if(
          plotPrice.indexOf("Res3")!=-1drawTextRelative(PriceOffsetnPrice+Res3nPrice+Res3Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_L"); 
              if(
          plotPrice.indexOf("Res4")!=-1drawTextRelative(PriceOffsetnPrice+Res4nPrice+Res4Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_M"); 
              if(
          plotPrice.indexOf("Sup1")!=-1drawTextRelative(PriceOffsetnPrice-Sup1nPrice-Sup1Color.yellownullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_N"); 
              if(
          plotPrice.indexOf("Sup2")!=-1drawTextRelative(PriceOffsetnPrice-Sup2nPrice-Sup2Color.greennullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_O"); 
              if(
          plotPrice.indexOf("Sup3")!=-1drawTextRelative(PriceOffsetnPrice-Sup3nPrice-Sup3Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_P"); 
              if(
          plotPrice.indexOf("Sup4")!=-1drawTextRelative(PriceOffsetnPrice-Sup4nPrice-Sup4Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_Q"); 
                   

          var 
          grID 0
          function 
          gID() 

              
          grID ++; 
              return( 
          grID ); 

          Wayne
          Last edited by waynecd; 08-03-2013, 12:05 PM.

          Comment


          • #6
            Thank you!

            Wayne, you dont understand what this means to a mere mortal such as I!
            Thanks so much.
            im going to continue my quest to get a good understanding of Java for efs, but your help is invaluable!
            Thanks again!



            Originally posted by waynecd View Post
            Hi,

            The code also had several extra and some misplaced curly brackets. I think this is closer to what you intend:

            PHP Code:
            //http://forum.esignal.com/showthread.php?38494-Bands-based-on-Open-Price 
            //http://forum.esignal.com/showthread.php?38847-Averaging-System-with-multiple-entry-s-and-exit-s
            function preMain() 

                var 
            aFPArray = new Array(); 
                
            setPriceStudy(true); 
                
            setCursorLabelName("TodayOpen"); 

                var 
            x=0
                
            aFPArray[x] = new FunctionParameter("UserTime"FunctionParameter.NUMBER); 
                
            with(aFPArray[x++])
                { 
                    
            setName("Start Time For Open (2300)"); 
                    
            setLowerLimit(0);         
                    
            setUpperLimit(2400);         
                    
            setDefault(100); 
                } 
                
            aFPArray[x] = new FunctionParameter("LineLen"FunctionParameter.NUMBER); 
                
            with(aFPArray[x++])
                { 
                    
            setName("Line Length"); 
                    
            setLowerLimit(1);         
                    
            setDefault(200); 
                } 
                
            aFPArray[x] = new FunctionParameter("Res1"FunctionParameter.NUMBER); 
                
            with(aFPArray[x++])
                { 
                    
            setName("Res1"); 
                    
            setLowerLimit(0);         
                    
            setDefault(.5); 
                } 
                
            aFPArray[x] = new FunctionParameter("Res2"FunctionParameter.NUMBER); 
                
            with(aFPArray[x++])
                { 
                    
            setName("Res2"); 
                    
            setLowerLimit(0);         
                    
            setDefault(.75); 
                } 
                
            aFPArray[x] = new FunctionParameter("Res3"FunctionParameter.NUMBER); 
                
            with(aFPArray[x++])
                { 
                    
            setName("Res3"); 
                    
            setLowerLimit(0);         
                    
            setDefault(1); 
                } 
                
            aFPArray[x] = new FunctionParameter("Res4"FunctionParameter.NUMBER); 
                
            with(aFPArray[x++])
                { 
                    
            setName("Res4"); 
                    
            setLowerLimit(0);         
                    
            setDefault(1.25); 
                } 
                
            aFPArray[x] = new FunctionParameter("Sup1"FunctionParameter.NUMBER); 
                
            with(aFPArray[x++])
                { 
                    
            setName("Sup1"); 
                    
            setLowerLimit(0);         
                    
            setDefault(.5); 
                } 
                
            aFPArray[x] = new FunctionParameter("Sup2"FunctionParameter.NUMBER); 
                
            with(aFPArray[x++])
                { 
                    
            setName("Sup2"); 
                    
            setLowerLimit(0);         
                    
            setDefault(.75); 
                } 
                
            aFPArray[x] = new FunctionParameter("Sup3"FunctionParameter.NUMBER); 
                
            with(aFPArray[x++])
                { 
                    
            setName("Sup3"); 
                    
            setLowerLimit(0);         
                    
            setDefault(1); 
                } 
                
            aFPArray[x] = new FunctionParameter("Sup4"FunctionParameter.NUMBER); 
                
            with(aFPArray[x++])
                { 
                    
            setName("Sup4"); 
                    
            setLowerLimit(0);         
                    
            setDefault(1.5); 
                } 
                
            aFPArray[x] = new FunctionParameter("TodayOnly"FunctionParameter.BOOLEAN); 
                
            with(aFPArray[x++])
                { 
                    
            setDefault(true); 
                } 
                
            aFPArray[x] = new FunctionParameter("PriceOffset"FunctionParameter.NUMBER); 
                
            with(aFPArray[x++])
                { 
                    
            setName("Price Offset"); 
                    
            setLowerLimit(0);         
                    
            setDefault(3); 
                } 
                
            aFPArray[x] = new FunctionParameter("plotPrice"FunctionParameter.STRING); 
                
            with(aFPArray[x++])
                { 
                    
            setName("Plot Price At"); 
                    
            addOption("Open Only"); 
                    
            addOption("Open & Res1"); 
                    
            addOption("Res1 & Res2 & Res3"); 
                    
            addOption("Res1 & Res2 & Res3 & Res4"
                    
            setDefault("Open & Res1 & Res2 & Res3 & Res4 & Sup1 & Sup2 & Sup3 & Sup4"); 
                } 



                var 
            bLong1 null
                var 
            bLong2 null
                var 
            bLong3 null
                var 
            bLong4 null
                var 
            bShort1 null
                var 
            bShort2 null
                var 
            bShort3 null
                var 
            bShort4 null
                var 
            bInit false
                var 
            nPrice 0


            function 
            main(UserTime,LineLen,Res1,Res2,Res3,Res4,Sup1,Sup2,Sup3,Sup4,TodayOnly,plotPrice,PriceOffset

                var 
            xOpen  LineTag null
                if(
            TodayOnlyLineTag 105
                else 
            LineTag gID(); 
                if(
            isMonthly() || isWeekly() || isDaily()) return; 
                if(
            day(0)!=day(-1))
                {
                    
            bLong1 false
                    
            bLong2 false
                    
            bLong3 false
                    
            bLong4 false
                    
            bShort1 false
                    
            bShort2 false
                    
            bShort3 false
                    
            bShort4 false
                }
                if((
            hour(0)*100)+minute(0)==UserTime)
                { 
                    
            nPrice open(0); 
                    
            drawLineRelative0open(0)+Res1LineLenopen(0)+Res1PS_DOT1Color.yellow"Up"+LineTag ); 
                    
            drawLineRelative0open(0)+Res2LineLenopen(0)+Res2PS_DOT1Color.green"Up1"+LineTag ); 
                    
            drawLineRelative0open(0)+Res3LineLenopen(0)+Res3PS_DOT1Color.red"Up2"+LineTag ); 
                    
            drawLineRelative0open(0)+Res4LineLenopen(0)+Res4PS_DOT2Color.red"Up3"+LineTag ); 
                    
            drawLineRelative0open(0)-Sup1LineLenopen(0)-Sup1PS_DOT1Color.yellow"Dwn1"+LineTag ); 
                    
            drawLineRelative0open(0)-Sup2LineLenopen(0)-Sup2PS_DOT1Color.green"Dwn2"+LineTag ); 
                    
            drawLineRelative0open(0)-Sup3LineLenopen(0)-Sup3PS_DOT1Color.red"Dwn3"+LineTag ); 
                    
            drawLineRelative0open(0)-Sup4LineLenopen(0)-Sup4PS_DOT2Color.red"Dwn4"+LineTag ); 
                    
            drawLineRelative0open(0), LineLenopen(0), PS_SOLID1Color.blue"OpenMid"+LineTag );  
                     
                } 

            //Start of Strategy Object 

                
            if (getCurrentBarIndex() == 0) return; 
                 
                if (
            bInit == false
                {   
                    
            bInit true
                }     
            // Entry Short Signals 

                
            if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false
                { 
                    if (
            high(0)> nPrice+Res1 && high(-1)<= nPrice+Res1
                    { 
                        
            nEntryPrice nPrice+Res1
                        
            Strategy.doShort("Entry Short1 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice); 
                        
            drawShape(Shape.DOWNARROWAboveBar2Color.red); 
                        
            bShort1 true
                    }
                }
                if (
            bShort1 == true && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false
                { 
                    if (
            high(0)> nPrice+Res2 && high(-1)<= nPrice+Res2
                    { 
                        
            nEntryPrice nPrice+Res2
                        
            Strategy.doShort("Entry Short2 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice); 
                        
            drawShape(Shape.DOWNARROWAboveBar2Color.red); 
                        
            bShort2 true
                    } 
                }
                if (
            bShort1 == true && bShort2 == true && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false
                { 
                    if (
            high(0)> nPrice+Res3 && high(-1)<= nPrice+Res3
                    { 
                        
            nEntryPrice nPrice+Res3
                        
            Strategy.doShort("Entry Short3 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice); 
                        
            drawShape(Shape.DOWNARROWAboveBar2Color.red); 
                        
            bShort3 true
                    } 
                }
                if (
            bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false
                { 
                    if (
            high(0)> nPrice+Res4 && high(-1)<= nPrice+Res4
                    { 
                        
            nEntryPrice nPrice+Res4
                        
            Strategy.doShort("Entry Short4 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice); 
                        
            drawShape(Shape.DOWNARROWAboveBar2Color.red); 
                        
            bShort4 true;    
                    } 
                }
                
            //Entry Long Signals 
                
                
            if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false
                { 
                    if (
            low(0)< nPrice-Sup1 && low(-1)>= nPrice-Sup1
                    { 
                        
            nEntryPrice nPrice-Sup1
                        
            Strategy.doLong("Entry Long1 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice); 
                        
            drawShape(Shape.UPARROWBelowBar2Color.blue); 
                        
            bLong1 true
                    } 
                }
                if (
            bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false
                { 
                    if (
            low(0)< nPrice-Sup2 && low(-1)>= nPrice-Sup2
                    { 
                        
            nEntryPrice nPrice-Sup2
                        
            Strategy.doLong("Entry Long2 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice); 
                        
            drawShape(Shape.UPARROWBelowBar2Color.blue); 
                        
            bLong2 true
                    } 
                }
                if (
            bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == true && bLong3 == false && bLong4 == false
                { 
                    if (
            low(0)< nPrice-Sup3 && low(-1)>= nPrice-Sup3
                    { 
                        
            nEntryPrice nPrice-Sup3
                        
            Strategy.doLong("Entry Long3 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice); 
                        
            drawShape(Shape.UPARROWBelowBar2Color.blue); 
                        
            bLong3 true
                    } 
                }
                if (
            bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == false
                { 
                    if (
            low(0)< nPrice-Sup4 && low(-1)>= nPrice-Sup4
                    { 
                        
            nEntryPrice nPrice-Sup4
                        
            Strategy.doLong("Entry Long4 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice); 
                        
            drawShape(Shape.UPARROWBelowBar2Color.blue); 
                        
            bLong4 true
                    } 
                }
                 
                
            //Exit Signals 
                
            if (Strategy.isInTrade() == true
                { 
                 
                    if (
            Strategy.isShort() == true
                    { 
                         
                        if (
            bShort1 == true && bShort2 == false && bShort3 == false && bShort4 == false
                        { 
                             
                            if (
            low(0)< nPrice && low(-1)>= nPrice
                            { 
                                
            nExitPrice nPrice
                                
            Strategy.doCover("Cover Short1 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice); 
                                
            drawShape(Shape.DIAMONDBelowBar2Color.green); 
                            } 
                        }
                        if (
            bShort1 == true && bShort2 == true && bShort3 == false && bShort4 == false
                        { 
                             
                            if (
            low(0)< nPrice+Res1 && low(-1)>= nPrice+Res1
                            { 
                                
            nExitPrice nPrice+Res1
                                
            Strategy.doCover("Cover Short2 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice); 
                                
            drawShape(Shape.DIAMONDBelowBar2Color.green); 
                            } 
                        }
                        if (
            bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == false
                        { 
                             
                            if (
            low(0)< nPrice+Res2 && low(-1)>= nPrice+Res2
                            { 
                                
            nExitPrice nPrice+Res2
                                
            Strategy.doCover("Cover Short3 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice); 
                                
            drawShape(Shape.DIAMONDBelowBar2Color.green); 
                            } 
                        }
                        if (
            bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == true
                        { 
                             
                            if (
            low(0)< nPrice+Res3 && low(-1)>= nPrice+Res3
                            { 
                                
            nExitPrice nPrice+Res3
                                
            Strategy.doCover("Cover Short4 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice); 
                                
            drawShape(Shape.DIAMONDBelowBar2Color.green); 
                            } 
                        } 
                    }  else if (
            Strategy.isLong() == true
                    { 
                         
                        if (
            bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false
                        { 
                             
                            if (
            high(0)> nPrice && high(-1)<= nPrice
                            { 
                                
            nExitPrice nPrice
                                
            Strategy.doSell("Sell Long1 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice); 
                                
            drawShape(Shape.DIAMONDAboveBar2Color.green); 
                            } 
                        }
                        if (
            bLong1 == true && bLong2 == true && bLong3 == false && bLong4 == false
                        { 
                             
                            if (
            high(0)> nPrice-Sup1 && high(-1)<= nPrice-Sup1
                            { 
                                
            nExitPrice nPrice-Sup1
                                
            Strategy.doSell("Sell Long2 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice); 
                                
            drawShape(Shape.DIAMONDAboveBar2Color.green); 
                            } 
                        }
                        if (
            bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == false
                        { 
                             
                            if (
            high(0)> nPrice-Sup2 && high(-1)<= nPrice-Sup2
                            { 
                                
            nExitPrice nPrice-Sup2
                                
            Strategy.doSell("Sell Long3 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice); 
                                
            drawShape(Shape.DIAMONDAboveBar2Color.green); 
                            } 
                        }
                        if (
            bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == true
                        { 
                             
                            if (
            high(0)> nPrice-Sup3 && high(-1)<= nPrice-Sup3
                            { 
                                
            nExitPrice nPrice-Sup3
                                
            Strategy.doSell("Sell Long4 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice); 
                                
            drawShape(Shape.DIAMONDAboveBar2Color.green); 
                            } 
                        } 
                    } 
                }



                if(
            plotPrice.indexOf("Open")!=-1drawTextRelative(PriceOffsetnPricenPriceColor.bluenullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP"); 
                if(
            plotPrice.indexOf("Res1")!=-1drawTextRelative(PriceOffsetnPrice+Res1nPrice+Res1Color.yellownullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_H"); 
                if(
            plotPrice.indexOf("Res2")!=-1drawTextRelative(PriceOffsetnPrice+Res2nPrice+Res2Color.greennullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_K"); 
                if(
            plotPrice.indexOf("Res3")!=-1drawTextRelative(PriceOffsetnPrice+Res3nPrice+Res3Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_L"); 
                if(
            plotPrice.indexOf("Res4")!=-1drawTextRelative(PriceOffsetnPrice+Res4nPrice+Res4Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_M"); 
                if(
            plotPrice.indexOf("Sup1")!=-1drawTextRelative(PriceOffsetnPrice-Sup1nPrice-Sup1Color.yellownullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_N"); 
                if(
            plotPrice.indexOf("Sup2")!=-1drawTextRelative(PriceOffsetnPrice-Sup2nPrice-Sup2Color.greennullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_O"); 
                if(
            plotPrice.indexOf("Sup3")!=-1drawTextRelative(PriceOffsetnPrice-Sup3nPrice-Sup3Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_P"); 
                if(
            plotPrice.indexOf("Sup4")!=-1drawTextRelative(PriceOffsetnPrice-Sup4nPrice-Sup4Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_Q"); 
                     

            var 
            grID 0
            function 
            gID() 

                
            grID ++; 
                return( 
            grID ); 

            Wayne

            Comment


            • #7
              Glad it helped.

              I know it is a typo but just in case:

              ... of Java for efs...
              efs uses javascript.

              Wayne
              Last edited by waynecd; 08-03-2013, 02:02 PM.

              Comment


              • #8
                Hi, thanks for correcting me, yep Javascript.
                Quick q... once the code was applied to a chart i noticed it only enters a trade once per day, i.e enters at sup1 then exits and doesnt do any further trades for that day at any level, if Intrade it will continue to to trade at the next levels which is great. I assume this is due to the bInit? However if flat during the the day I want it to trade again. Do I need to change the bInit?
                Cheers
                Daniel

                Comment


                • #9
                  Re last post what I meant to say was once a trade is exited from i.e sup1 it will not enter another sup1. It will enter sup2 and exit , then not enter another sup2 and so on.

                  Comment


                  • #10
                    Hi,

                    No, I see no use for the bInit routine in the code you posted.
                    bInit is mainly used to set variables, assign series, etc where this only needs to be done once on the first iteration of main. On any future ticks (main iterates on every tick) nothing inside the bInit block executes since bInit is now true.

                    I looked at your code again and see that when you exit a trade you exit all at once.
                    That means that you can reset all appropriate variables at that time.

                    Instead of repeating the variable reset code for each conditional leading to closing all positions you could modify the following block:
                    PHP Code:
                    if(!Strategy.isInTrade() || day(0)!=day(-1))
                    {
                            
                    bLong1 false
                            
                    bLong2 false
                            
                    bLong3 false
                            
                    bLong4 false
                            
                    bShort1 false
                            
                    bShort2 false
                            
                    bShort3 false
                            
                    bShort4 false

                    The above should solve your problem.

                    Below is my initial response, when I didn't realize you exited all open positions at once. Though the variable reset portions don't apply, I will leave it here in case there is anything you can use:

                    To do what you ask you need to reset the appropriate variable that is modified to true when a trade is entered, to false, when the same trade is exited. For example:

                    PHP Code:
                        if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false
                        { 
                            if (
                    low(0)< nPrice-Sup1 && low(-1)>= nPrice-Sup1
                            { 
                                
                    nEntryPrice nPrice-Sup1
                                
                    Strategy.doLong("Entry Long1 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice); 
                                
                    drawShape(Shape.UPARROWBelowBar2Color.blue); 
                                
                    bLong1 true
                            } 
                        } 
                    The above conditional checks for "bLong1 == false", etc. (consider "!bLong1") When the conditional is met a long is entered and "bLong1" is changed to true. Well, that in effect stops the conditional from executing again.
                    To remedy that, reset "bLong1" to false once that particular trade is exited. Continuing with the example:
                    PHP Code:
                            }  else if (Strategy.isLong() == true
                            { 
                                 
                                if (
                    bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false
                                { 
                                     
                                    if (
                    high(0)> nPrice && high(-1)<= nPrice
                                    { 
                                        
                    nExitPrice nPrice
                                        
                    Strategy.doSell("Sell Long1 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice); 
                                        
                    drawShape(Shape.DIAMONDAboveBar2Color.green); 
                                    } 
                                } 
                    This code block checks for "if(bLong1 == true && ..." (consider "if(bLong1 && ...") but doesn't reset "bLong1" to false, so the conditional to enter a trade (1st example) can't execute again. To change that, under "drawShape(..." add "bLong1=false". This resets "bLong1" when the trade is complete.

                    The same concept applies to all the variables in each conditional to enter and exit trades. If any of the variables to initiate a trade are true then that conditional will not execute again. So all the variables in the conditional must be false in order for it to execute.

                    An alternative is to only use the specific variable that affects entering a position when constructing the conditional. For example to only enter a trade when already flat, to enter Long1, instead of:
                    PHP Code:
                        if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false
                        { ... 
                    try something like:
                    PHP Code:
                    if(!Strategy.isInTrade()){... 
                    This ensures you are not in a trade. Now follow with your original conditional for a "Long1" trade as in:
                    PHP Code:
                            if (low(0)< nPrice-Sup1 && low(-1)>= nPrice-Sup1
                            { ... 
                    Note : Some other code blocks continue to look for "bLong1 == true && ..." so you will have to decide on changing the logic on all of them to accomplish what you intend.

                    Based on your code, the above applies to the first long or short position since it looks to enter a 2nd, 3rd, and 4th long/short on subsequent conditionals. For that try:
                    For the 2nd long entry:
                    PHP Code:
                    if(!Strategy.isShort()  && bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false){
                            if (
                    low(0)< nPrice-Sup2 && low(-1)>= nPrice-Sup2
                            { ... 
                    etc.
                    For the 2nd short entry:
                    PHP Code:
                    if(!Strategy.isLong() bShort1 == true && bShort2 == false && bShort3 == false && bShort4 == false){ 
                            if (
                    high(0)> nPrice+Res2 && high(-1)<= nPrice+Res2
                            { ... 
                    and so on for 3rd and 4th entries.

                    Of course you will have to code specifically for your requirements but the point is that the variables that make up the conditionals to enter or exit a particular trade must be reset at some point to enable that specific entry to execute again. The point where the variable must be reset depends entirely on the logic of the strategy.

                    Instead of adding filters to each entry conditional as I explained above, you could enclose your long entries in a:
                    PHP Code:
                    if(!Strategy.isShort()){ 
                    and similarly enclose short entries with:
                    PHP Code:
                    if(!Strategy.isLong){ 
                    like you did for the trade exit signals.

                    Wayne
                    Last edited by waynecd; 08-04-2013, 07:15 PM.

                    Comment


                    • #11
                      Hi Wayne,
                      ok im getting there....however when I change the lines of code from.....
                      //////
                      if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false)
                      {
                      if (high(0)> nPrice+Res1 && high(-1)<= nPrice+Res1)
                      {
                      nEntryPrice = nPrice+Res1;
                      Strategy.doShort("Entry Short1 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
                      drawShape(Shape.DOWNARROW, AboveBar2, Color.red);
                      bShort1 = true;
                      }
                      }
                      /////////
                      to ........



                      // Entry Short Signals

                      if (!Strategy.isInTrade())
                      {
                      if (high(0)> nPrice+Res1 && high(-1)<= nPrice+Res1)
                      {
                      nEntryPrice = nPrice+Res1;
                      Strategy.doShort("Entry Short1 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
                      drawShape(Shape.DOWNARROW, AboveBar2, Color.red);
                      bShort1 = true;
                      }
                      }
                      if (!Strategy.isLong())
                      {
                      if (high(0)> nPrice+Res2 && high(-1)<= nPrice+Res2)
                      {
                      nEntryPrice = nPrice+Res2;
                      Strategy.doShort("Entry Short2 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
                      drawShape(Shape.DOWNARROW, AboveBar2, Color.red);
                      bShort2 = true;
                      }
                      }


                      the '!Strategy.isInTrade () removes all signals from the chart..

                      Any ideas??

                      Many thanks
                      Daniel

                      Comment


                      • #12
                        Hi Daniel,

                        the '!Strategy.isInTrade () removes all signals from the chart..
                        The reason for the bug is that some trades remain open from one day to the next so (!isInTrade()) does not trigger.
                        The solution depends on what trade plan logic you code into the efs. For example, you could close all open trades at a specific time as
                        coded into the example found at.

                        ferret Opening Rg Strategy.efs

                        Note: In the above script, I coded ""StopAllTradingTime"", a time after which no trades should be taken. This avoids entering a trade just before the "close all open trades" time is reached.

                        If instead you prefer to leave a trade open as long as an exit signal is not reached, then revert back to your original code removing the added "!Strategy.isInTrade ()". It is important to note
                        that in that code, at midnight the variables are reset to false so you will have to account for that in your code to not get false data if you are still in a trade at midnight. In other words your trade variables must
                        correlate exactly with the Strategy object trade positions.

                        Wayne
                        Last edited by waynecd; 08-07-2013, 12:49 PM.

                        Comment


                        • #13
                          To clarify:

                          the '!Strategy.isInTrade () removes all signals from the chart..
                          Actually, it plotted all trades for the first day. But since the last trade of the day was never closed, no new trades executed.

                          Wayne

                          Comment


                          • #14
                            I guess the attachment never attached. Here it is.

                            ferret Opening Rg Strategy.efs

                            Wayne
                            Last edited by waynecd; 08-11-2013, 12:14 PM.

                            Comment


                            • #15
                              What's going on? The link works when I post it, but a few days later it is removed??

                              ferret Opening Rg.efs

                              The code is too long so I'll crop it into two posts, just paste them together on your end.
                              PHP Code:
                              //http://forum.esignal.com/showthread.php?38494-Bands-based-on-Open-Price  
                              //http://forum.esignal.com/showthread.php?38847-Averaging-System-with-multiple-entry-s-and-exit-s 
                              debugClear();
                              function 
                              preMain()  
                              {  
                                  var 
                              aFPArray = new Array();  
                                  
                              setPriceStudy(true);  
                                  
                              setCursorLabelName("inTrade",0);  //added to show "in Trade" conditions in Data Window
                                  
                              setCursorLabelName("Long",1);    //added to show "Long" conditions in Data Window
                                  
                              setCursorLabelName("Short",2);  //added to show "Short" conditions in Data     setCursorLabelName("doTrade",2);  //added to show "Trading Period" conditions in Data Window  
                                  
                              setCursorLabelName("InTradingMode",3);  //added to identify trading hours: efs trading = on, efs not trading = off

                                  
                              var x=0;  
                                  
                              aFPArray[x] = new FunctionParameter("TodayOnly"FunctionParameter.BOOLEAN);  
                                  
                              with(aFPArray[x++]) 
                                  {  
                                      
                              setDefault(false);  
                                  }  
                                  
                              aFPArray[x] = new FunctionParameter("TradingStrartTime"FunctionParameter.NUMBER);  
                                  
                              with(aFPArray[x++]) 
                                  {  
                                      
                              setName("Start Time For Open (2300)");  
                                      
                              setLowerLimit(0);          
                                      
                              setUpperLimit(2400);          
                                      
                              setDefault(100);  
                                  }  
                                  
                              aFPArray[x] = new FunctionParameter("StopAllTradingTime"FunctionParameter.NUMBER);  
                                  
                              with(aFPArray[x++]) 
                                  {  
                                      
                              setName("Stop Trading Time (Before 'Close All Open Trades Time')");  
                                      
                              setLowerLimit(0);          
                                      
                              setUpperLimit(2400);          
                                      
                              setDefault(1200);  
                                  }  
                                  
                              aFPArray[x] = new FunctionParameter("CloseAllTime"FunctionParameter.NUMBER);  
                                  
                              with(aFPArray[x++]) 
                                  {  
                                      
                              setName("Close All Open Trades at (i.e., 2300)");  
                                      
                              setLowerLimit(0);          
                                      
                              setUpperLimit(2400);          
                                      
                              setDefault(1300);  
                                  }  
                                  
                              aFPArray[x] = new FunctionParameter("LineLen"FunctionParameter.NUMBER);  
                                  
                              with(aFPArray[x++]) 
                                  {  
                                      
                              setName("Line Length");  
                                      
                              setLowerLimit(1);          
                                      
                              setDefault(200);  
                                  }  
                                  
                              aFPArray[x] = new FunctionParameter("Res1"FunctionParameter.NUMBER);  
                                  
                              with(aFPArray[x++]) 
                                  {  
                                      
                              setName("Res1");  
                                      
                              setLowerLimit(0);          
                                      
                              setDefault(.5);  
                                  }  
                                  
                              aFPArray[x] = new FunctionParameter("Res2"FunctionParameter.NUMBER);  
                                  
                              with(aFPArray[x++]) 
                                  {  
                                      
                              setName("Res2");  
                                      
                              setLowerLimit(0);          
                                      
                              setDefault(.75);  
                                  }  
                                  
                              aFPArray[x] = new FunctionParameter("Res3"FunctionParameter.NUMBER);  
                                  
                              with(aFPArray[x++]) 
                                  {  
                                      
                              setName("Res3");  
                                      
                              setLowerLimit(0);          
                                      
                              setDefault(1);  
                                  }  
                                  
                              aFPArray[x] = new FunctionParameter("Res4"FunctionParameter.NUMBER);  
                                  
                              with(aFPArray[x++]) 
                                  {  
                                      
                              setName("Res4");  
                                      
                              setLowerLimit(0);          
                                      
                              setDefault(1.25);  
                                  }  
                                  
                              aFPArray[x] = new FunctionParameter("Sup1"FunctionParameter.NUMBER);  
                                  
                              with(aFPArray[x++]) 
                                  {  
                                      
                              setName("Sup1");  
                                      
                              setLowerLimit(0);          
                                      
                              setDefault(.5);  
                                  }  
                                  
                              aFPArray[x] = new FunctionParameter("Sup2"FunctionParameter.NUMBER);  
                                  
                              with(aFPArray[x++]) 
                                  {  
                                      
                              setName("Sup2");  
                                      
                              setLowerLimit(0);          
                                      
                              setDefault(.75);  
                                  }  
                                  
                              aFPArray[x] = new FunctionParameter("Sup3"FunctionParameter.NUMBER);  
                                  
                              with(aFPArray[x++]) 
                                  {  
                                      
                              setName("Sup3");  
                                      
                              setLowerLimit(0);          
                                      
                              setDefault(1);  
                                  }  
                                  
                              aFPArray[x] = new FunctionParameter("Sup4"FunctionParameter.NUMBER);  
                                  
                              with(aFPArray[x++]) 
                                  {  
                                      
                              setName("Sup4");  
                                      
                              setLowerLimit(0);          
                                      
                              setDefault(1.5);  
                                  }  
                                  
                              aFPArray[x] = new FunctionParameter("PriceOffset"FunctionParameter.NUMBER);  
                                  
                              with(aFPArray[x++]) 
                                  {  
                                      
                              setName("Price Offset");  
                                      
                              //setLowerLimit(0);          
                                      
                              setDefault(3);  
                                  }  
                                  
                              aFPArray[x] = new FunctionParameter("plotPrice"FunctionParameter.STRING);  
                                  
                              with(aFPArray[x++]) 
                                  {  
                                      
                              setName("Plot Price At");  
                                      
                              addOption("Open Only");  
                                      
                              addOption("Open & Res1");  
                                      
                              addOption("Res1 & Res2 & Res3");  
                                      
                              addOption("Res1 & Res2 & Res3 & Res4")  
                                      
                              setDefault("Open & Res1 & Res2 & Res3 & Res4 & Sup1 & Sup2 & Sup3 & Sup4");  
                                  }  
                                  
                              aFPArray[x] = new FunctionParameter("afterMktHrsBgColor"FunctionParameter.BOOLEAN);  
                                  
                              with(aFPArray[x++]) 
                                  {  
                                      
                              setName("Color Bg of No Trading Hours:");  
                                      
                              setDefault(false);  
                                  }  
                              }  


                                  var 
                              bLong1 null;  
                                  var 
                              bLong2 null;  
                                  var 
                              bLong3 null;  
                                  var 
                              bLong4 null;  
                                  var 
                              bShort1 null;  
                                  var 
                              bShort2 null;  
                                  var 
                              bShort3 null;  
                                  var 
                              bShort4 null;  
                                  var 
                              bInit false;  
                                  var 
                              nPrice 0

                                  var 
                              bCurrentDay false;//for "TodayOnly" code
                                  
                              var doTrade false;//to limit new trades during "no trading" hours

                              function main(TodayOnly,TradingStrartTime,StopAllTradingTime,CloseAllTime,LineLen,Res1,Res2,Res3,Res4,Sup1,Sup2,Sup3,Sup4,PriceOffset,plotPrice,afterMktHrsBgColor)  

                                  
                              //for "TodayOnly" code
                                  
                              if(getBarState()==BARSTATE_ALLBARS)
                                  { 
                                      
                              bCurrentDay=false;
                                  } 
                                  if(
                              isMonthly() || isWeekly() || isDaily()) return; 

                                  if (
                              getCurrentBarIndex() == 0) return;  
                                    
                                  if (
                              bInit == false)  
                                  { 
                                      
                              bInit true;  
                                  }      
                                  if((
                              hour(0)*100)+minute(0)<TradingStrartTimedoTrade false;
                                  if((
                              hour(0)*100)+minute(0)>=StopAllTradingTimedoTrade false;
                                  if((
                              hour(0)*100)+minute(0)==TradingStrartTimedoTrade true;
                                  if(
                              afterMktHrsBgColor)
                                  {
                                      if(
                              doTrade == false && !Strategy.isInTrade()) setBarBgColor(Color.red);//for debug only
                                  
                              }

                                  if(
                              Strategy.isInTrade() == false)
                                  {
                              //a new trade can be initiated when a trade is closed, you can limit the # of trades per day by adding a trade counter filter routine
                                      
                              bLong1 false
                                      
                              bLong2 false
                                      
                              bLong3 false
                                      
                              bLong4 false
                                      
                              bShort1 false
                                      
                              bShort2 false
                                      
                              bShort3 false
                                      
                              bShort4 false
                                  } 
                                  if(
                              getDay(0) != getDay(-1)){
                                      if (
                              bCurrentDay == false){ //borrowed code from Alexis Montenegro 
                                          
                              var xTime getValue("time"); 
                                          var 
                              xDate = new Date();  
                                          var 
                              sTime = (xTime.getMonth()+1+"/"+xTime.getDate()+"/"+xTime.getFullYear()); 
                                          var 
                              sToday = (xDate.getMonth()+1+"/"+xDate.getDate()+"/"+xDate.getFullYear()); 
                                          if ( 
                              sTime == sToday ) {  
                                              
                              bCurrentDay true;  
                                          }  
                                      }  
                                  }
                                  if (
                              TodayOnly == true && bCurrentDay == false){
                                      
                              doTrade false;
                                      
                              //return; 
                                  
                              }   

                              //Start of Strategy Object  

                                  
                              if(Strategy.isInTrade() == true){
                                      if((
                              hour(0)*100)+minute(0)>=CloseAllTime){
                                          if(
                              Strategy.isLong() == true)
                                          {  
                                              
                              Strategy.doSell("Sell Long1 Signal"Strategy.MARKETStrategy.THISBARStrategy.ALL); 
                                              
                              drawShape(Shape.DIAMONDAboveBar2Color.green,"DoSell_EOD"+gID()); 
                                          }
                                          if(
                              Strategy.isShort() == true)
                                          {  
                                              
                              Strategy.doCover("Cover EOD Signal"Strategy.MARKETStrategy.THISBARStrategy.ALL); 
                                              
                              drawShape(Shape.DIAMONDBelowBar2Color.green,"DoCover_EOD"+gID()); 
                                          }
                                      }
                                  }

                                  if(
                              doTrade == true)
                                  {
                                      if((
                              hour(0)*100)+minute(0)==TradingStrartTime
                                      {  
                                          
                              nPrice open(0);  
                                          
                              drawLineRelative0open(0)+Res1LineLenopen(0)+Res1PS_DOT1Color.yellow"Up"+gID() );  
                                          
                              drawLineRelative0open(0)+Res2LineLenopen(0)+Res2PS_DOT1Color.green"Up1"+gID() );  
                                          
                              drawLineRelative0open(0)+Res3LineLenopen(0)+Res3PS_DOT1Color.red"Up2"+gID() );  
                                          
                              drawLineRelative0open(0)+Res4LineLenopen(0)+Res4PS_DOT2Color.red"Up3"+gID() );  
                                          
                              drawLineRelative0open(0)-Sup1LineLenopen(0)-Sup1PS_DOT1Color.yellow"Dwn1"+gID() );  
                                          
                              drawLineRelative0open(0)-Sup2LineLenopen(0)-Sup2PS_DOT1Color.green"Dwn2"+gID() );  
                                          
                              drawLineRelative0open(0)-Sup3LineLenopen(0)-Sup3PS_DOT1Color.red"Dwn3"+gID() );  
                                          
                              drawLineRelative0open(0)-Sup4LineLenopen(0)-Sup4PS_DOT2Color.red"Dwn4"+gID() );  
                                          
                              drawLineRelative0open(0), LineLenopen(0), PS_SOLID1Color.blue"OpenMid"+gID() );   
                                      }  
                                  }

                              // Entry Short Signals  

                                  //if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false)  
                                  
                              if(doTrade == true)
                                  {
                                      if(
                              Strategy.isInTrade() == false)
                                      { 
                                          if (
                              high(0)> nPrice+Res1 && high(-1)<= nPrice+Res1)  
                                          {  
                                              
                              nEntryPrice nPrice+Res1;  
                                              
                              Strategy.doShort("Entry Short1 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);  
                                              
                              drawShape(Shape.DOWNARROWAboveBar2Color.red,"DoShort"+gID());//added tagID
                                              
                              bShort1 true;  
                                          } 
                                      } 
                                      if(
                              Strategy.isLong() == false)
                                      {  
                                          if (
                              bShort1 == true && bShort2 == false && bShort3 == false && bShort4 == false)  
                                          {  
                                              if (
                              high(0)> nPrice+Res2 && high(-1)<= nPrice+Res2)  
                                              {  
                                                  
                              nEntryPrice nPrice+Res2;  
                                                  
                              Strategy.doShort("Entry Short2 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);  
                                                  
                              drawShape(Shape.DOWNARROWAboveBar2Color.red,"S1"+gID());//added tagID
                                                  
                              bShort2 true;  
                                              }  
                                          } 
                                          if (
                              bShort1 == true && bShort2 == true && bShort3 == false && bShort4 == false)  
                                          {  
                                              if (
                              high(0)> nPrice+Res3 && high(-1)<= nPrice+Res3)  
                                              {  
                                                  
                              nEntryPrice nPrice+Res3;  
                                                  
                              Strategy.doShort("Entry Short3 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);  
                                                  
                              drawShape(Shape.DOWNARROWAboveBar2Color.red,"S2"+gID());//added tagID  
                                                  
                              bShort3 true;  
                                              }  
                                          } 
                                          if (
                              bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == false)  
                                          {  
                                              if (
                              high(0)> nPrice+Res4 && high(-1)<= nPrice+Res4)  
                                              {  
                                                  
                              nEntryPrice nPrice+Res4;  
                                                  
                              Strategy.doShort("Entry Short4 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);  
                                                  
                              drawShape(Shape.DOWNARROWAboveBar2Color.red,"S3"+gID());//added tagID  
                                                  
                              bShort4 true;     
                                              }  
                                          } 
                                      }
                                      
                              //Entry Long Signals  
                                       
                                      //if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false)  
                                      
                              if(Strategy.isInTrade() == false)
                                      {  
                                          if (
                              low(0)< nPrice-Sup1 && low(-1)>= nPrice-Sup1)  
                                          {  
                                              
                              nEntryPrice nPrice-Sup1;  
                                              
                              Strategy.doLong("Entry Long1 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);  
                                              
                              drawShape(Shape.UPARROWBelowBar2Color.blue,"DoLong"+gID());//added tagID  
                                              
                              bLong1 true;  
                                          }  
                                      } 
                                      if(
                              Strategy.isShort() == false)
                                      {  
                                          if(
                              bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false)
                                          {
                                              if (
                              low(0)< nPrice-Sup2 && low(-1)>= nPrice-Sup2)  
                                              {  
                                                  
                              nEntryPrice nPrice-Sup2;  
                                                  
                              Strategy.doLong("Entry Long2 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);  
                                                  
                              drawShape(Shape.UPARROWBelowBar2Color.blue,"L1"+gID());//added tagID 
                                                  
                              bLong2 true;  
                                              } 
                                          }
                                          if (
                              bLong1 == true && bLong2 == true && bLong3 == false && bLong4 == false)  
                                          {  
                                              if (
                              low(0)< nPrice-Sup3 && low(-1)>= nPrice-Sup3)  
                                              {  
                                                  
                              nEntryPrice nPrice-Sup3;  
                                                  
                              Strategy.doLong("Entry Long3 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);  
                                                  
                              drawShape(Shape.UPARROWBelowBar2Color.blue,"L2"+gID());//added tagID  
                                                  
                              bLong3 true;  
                                              }  
                                          } 
                                          if (
                              bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == false)  
                                          {  
                                              if (
                              low(0)< nPrice-Sup4 && low(-1)>= nPrice-Sup4)  
                                              {  
                                                  
                              nEntryPrice nPrice-Sup4;  
                                                  
                              Strategy.doLong("Entry Long4 Signal"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, nEntryPrice);  
                                                  
                              drawShape(Shape.UPARROWBelowBar2Color.blue,"L3"+gID());//added tagID 
                                                  
                              bLong4 true;  
                                              }  
                                          } 
                                      } 
                                  } 
                              NOTE: This is only half the code. The second half is in the next post.
                              Last edited by waynecd; 08-13-2013, 01:29 AM.

                              Comment

                              Working...
                              X