Announcement

Collapse
No announcement yet.

here's the full version of the ema pivotpoint crossover efs

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

  • here's the full version of the ema pivotpoint crossover efs

    Alex,

    I still seem to be having problems, here's the full version of the code if you want to take a look at it. Any help or suggestions would be greatly appreciated.

    Thanks,
    Tom

    Last edited by XLYTH; 08-03-2004, 04:37 PM.

  • #2
    Tom
    There are a lot of syntax errors in your efs such as getvalue instead of getValue and ShapeONTOP instead of Shape.ONTOP.
    I would suggest that you review the errors indicated by the Formula Output Window and you should be able to get the efs running.
    Alex


    Originally posted by XLYTH
    Alex,

    I still seem to be having problems, here's the full version of the code if you want to take a look at it. Any help or suggestions would be greatly appreciated.

    Thanks,
    Tom

    //USER DEFINED VARIABLES

    var nRisk = 0.05;
    var nReward = 0.05;
    var nSpread = 0.05;

    var vOpenTime = 930;
    var vHoldTime = 1545;
    var vCloseTime = 1558;


    //SYSTEM VARIABLES

    var nStopPrice = 0;
    var nTargetPrice = 0;
    var vResult = "Flat";


    var vFast = new MAStudy(5, 0, "Close", MAStudy.EXPONENTIAL);
    var vSlow = new MAStudy(13, 0, "Close", MAStudy.EXPONENTIAL);


    function premain() {

    setPriceStudy(true);
    setStudyTitle("EMA PIVOT CROSSOVER");
    setShowCursorLabel(true);
    }

    function main() {

    var aPivots = null;
    aPivots = callFunction("/Pivots/PivotPointAll.efs","main");
    if(aPivots == null) return;

    var vR2 = aPivots[0];
    var vR1 = aPivots[1];
    var vPP = aPivots[2];
    var vS1 = aPivots[3];
    var vS2 = aPivots[4];

    //CHECK FOR CORRECT PIVOT POINT VALUES
    debugPrintln(vR2,vR1,vPP,vS1,vS2);



    if ((vFast != null) && (vSlow != null) && (close() != null) && (getHour()*100+getMinute() >= vOpenTime)) {
    //LOOKS FOR LONG SETUPS
    if(!Strategy.isInTrade() && (vFast.getValue(MAStudy.MA) > vSlow.getValue(MAStudy.MA)) && (getHour()*100+getMinute() <= vHoldTime)) {

    if( (vFast.getValue(MAStudy.MA) >= vS2) && (open() <= (vS2 + nSpread))) { //LONG AT S2
    Strategy.doLong("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    drawShapeRelative(0, low() -0.25, Shape.UPARROW, null, Color.lime, ShapeONTOP, getvalue("rawtime") + "Buy");
    nStopPrice = (vS2 - nRisk);
    nTargetPrice = (vS1 - nReward);
    tResult = "Long";
    }
    else if((vFast.getValue(MAStudy.MA) >= vS1) && (open() <= (vS1 + nSpread))) { //LONG AT S1
    Strategy.doLong("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    drawShapeRelative(0, low() -0.25, Shape.UPARROW, null, Color.lime, ShapeONTOP, getvalue("rawtime") + "Buy");
    nStopPrice = (vS1 - nRisk);
    nTargetPrice = (vPP - nReward);
    tResult = "Long";
    }
    else if((vFast.getValue(MAStudy.MA) >= vPP) && (open() <= (vPP + nSpread))) { //LONG AT PP
    Strategy.doLong("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    drawShapeRelative(0, low() -0.25, Shape.UPARROW, null, Color.lime, ShapeONTOP, getvalue("rawtime") + "Buy");
    nStopPrice = (vPP - nRisk);
    nTargetPrice = (vR1 - nReward);
    tResult = "Long";
    }
    else if((vFast.getValue(MAStudy.MA) >= vR1 ) && (open() <= (vR1 + nSpread))) { //LONG AT R1
    Strategy.doLong("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    drawShapeRelative(0, low() -0.25, Shape.UPARROW, null, Color.lime, ShapeONTOP, getvalue("rawtime") + "Buy");
    nStopPrice = (vR1 - nRisk);
    nTargetPrice = (vR2 - nReward);
    tResult = "Long";
    }
    else if((vFast.getValue(MAStudy.MA) >= vR2 ) && (open() <= (vR2 + nSpread))) { //LONG AT R2
    Strategy.doLong("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    drawShapeRelative(0, low() -0.25, Shape.UPARROW, null, Color.lime, ShapeONTOP, getvalue("rawtime") + "Buy");
    nStopPrice = (vR2 - nRisk);
    nTargetPrice = (vR2 + 1);
    tResult = "Long";
    }
    }
    //LOOKS FOR SHORT SETUPS
    else if(!Strategy.isInTrade() && (vFast < vSlow) && (getHour()*100+getMinute() <= vHoldTime)) {

    if((vFast.getValue(MAStudy.MA) <= vS2) && (open() <= (vS2 - nSpread))) { //SHORT AT S2
    Strategy.doShort("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    drawShapeRelative(0, high() -0.25, Shape.UPARROW, null, Color.red, ShapeONTOP, getvalue("rawtime") + "Sell");
    nStopPrice = (vS2 + nRisk);
    nTargetPrice = (vS2 - 1);
    tResult = "Short";
    }
    else if((vFast.getValue(MAStudy.MA) <= vS1) && (open() <= (vS1 - nSpread))) { //SHORT AT S1
    Strategy.doShort("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    drawShapeRelative(0, high() -0.25, Shape.UPARROW, null, Color.red, ShapeONTOP, getvalue("rawtime") + "Sell");
    nStopPrice = (vS1 + nRisk);
    nTargetPrice = (vS2 + nReward);
    tResult = "Short";
    }
    else if((vFast.getValue(MAStudy.MA) <= vPP) && (open() <= (vPP - nSpread))) { //SHORT AT PP
    Strategy.doShort("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    drawShapeRelative(0, high() -0.25, Shape.UPARROW, null, Color.red, ShapeONTOP, getvalue("rawtime") + "Sell");
    nStopPrice = (vPP + nRisk);
    nTargetPrice = (vS1 + nReward);
    tResult = "Short";
    }
    else if((vFast.getValue(MAStudy.MA) <= vR1 ) && (open() <= (vR1 - nSpread))) { //SHORT AT R1
    Strategy.doShort("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    drawShapeRelative(0, high() -0.25, Shape.UPARROW, null, Color.red, ShapeONTOP, getvalue("rawtime") + "Sell");
    nStopPrice = (vR1 + nRisk);
    nTargetPrice = (vPP + nReward);
    tResult = "Short";
    }
    else if((vFast.getValue(MAStudy.MA) <= vR2 ) && (open() <= (vR2 - nSpread))) { //SHORT AT R2
    Strategy.doShort("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    drawShapeRelative(0, high() -0.25, Shape.UPARROW, null, Color.red, ShapeONTOP, getvalue("rawtime") + "Sell");
    nStopPrice = (vR2 + nRisk);
    nTargetPrice = (vR1 + nReward);
    tResult = "Short";
    }
    }
    //CURRENTLY IN A TRADE: HANDLES STOP, PROFIT TARGETS, AND CLOSES POSITIONS AT END OF DAY
    else if(Strategy.isInTrade()) {

    if ((Strategy.isLong()) && (close() <= nStopPrice)) { //LONG STOP
    Strategy.doSell("", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT, 0);
    drawShapeRelative(0, high() +0.25, Shape.DOWNARROW, null, Color.blue, Shape.ONTOP, getValue("rawtime") + "longStop");
    tResult = "Flat";
    }
    else if ((Strategy.isShort()) && (close() >= nStopPrice)) { //SHORT STOP
    Strategy.doCover("", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT, 0);
    DrawShapeRelative(0, low() -0.25, ShapeUPARROW, null, Color.blue, Shape.ONTOP, getValue("rawtime") + "shortStop");
    tResult = "Flat";
    }
    else if ((Strategy.isLong()) && (high() >= nTargetPrice)) { //LONG PROFIT TARGET
    Strategy.doSell("", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT, 0);
    DrawShapeRelative(0, high() +0.25, ShapeDOWNARROW, null, Color.magenta, Shape.ONTOP, getValue("rawtime") + "longPT");
    tResult = "Flat";
    }
    else if ((Strategy.isShort()) && (low() <= nTargetPrice)) { //SHORT PROFIT TARGET
    Strategy.doCover("", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT, 0);
    DrawShapeRelative(0, low() -0.25, ShapeUPARROW, null, Color.magenta, Shape.ONTOP, getValue("rawtime") + "shortPT");
    tResult = "Flat";
    }
    else if ((Strategy.isLong()) && (getHour()*100+getMinute() >= vCloseTime)) { //CLOSES LONGS AT END OF DAY
    Strategy.doSell("", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT, 0);
    DrawShapeRelative(0, high() +0.25, ShapeDOWNARROW, null, Color.magenta, Shape.ONTOP, getValue("rawtime") + "longEOD");
    tResult = "Flat";
    }
    else if ((Strategy.isShort()) && (getHour()*100+getMinute() >= vCloseTime)) { //CLOSES SHORTS AT END OF DAY
    Strategy.doCover("", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT, 0);
    DrawShapeRelative(0, low() -0.25, ShapeUPARROW, null, Color.magenta, Shape.ONTOP, getValue("rawtime") + "shortEOD");
    tResult = "Flat";
    }
    }
    }

    return;

    }

    Comment


    • #3
      Tom
      As an aside (and following up on this thread) I checked the values returned by the callFunction() and they appear to be correct. I would suggest at this point that you comment out the debugPrintln() as it will only slow down the execution of the efs.
      Alex

      Comment

      Working...
      X