var emashort = new MAStudy(15, 0, "Close", MAStudy.EXPONENTIAL); var emalong = new MAStudy(30, 0, "Close", MAStudy.EXPONENTIAL); function preMain() { setPriceStudy(false); } function main() { var esval = emashort.getValue(MAStudy.MA); var elval = emalong.getValue(MAStudy.MA); var pesval = emashort.getValue(MAStudy.MA,-1); var vtime = getValue("Time"); if (vtime == null) return; var sdatetime = vtime.getMonth()+"/"+vtime.getDate()+"/"+vtime.getFullYear()+" "+vtime.getHours()+":"+vtime.getMinutes(); // ENTRIES if (esval > elval) { if (low(-1) <= pesval && high() > high(-1) && high(-2) >= high(-1)) { if (!Strategy.isLong() && ((vtime.getHours() > 3 && vtime.getMinutes() > 10) && vtime.getHours() < 13) ) { Strategy.doLong("3B Buy", Strategy.LIMIT, Strategy.THISBAR,Strategy.DEFAULT,high(-1)+1); debugPrint(sdatetime+" Long Entry: "+high(-1)+1+"\n"); } } } else if (esval < elval) { if (high(-1) >= pesval && low() < low(-1) && low(-2) <= low(-1)) { if (!Strategy.isShort() && ((vtime.getHours() > 3 && vtime.getMinutes() > 10) && vtime.getHours() < 13) ) { Strategy.doShort("3B Short", Strategy.LIMIT, Strategy.THISBAR,Strategy.DEFAULT,low(-1)-1); debugPrint(sdatetime+" Short Entry: "+low(-1)-1+1+"\n"); } } } // EXITS if (Strategy.isLong()) { if (close() < esval) { Strategy.doSell("3B Close Long - STOPPED OUT",Strategy.CLOSE,Strategy.THISBAR); } if (Strategy.isLong() && vtime.getHours() == 13 && vtime.getMinutes() >= 45) { Strategy.doSell("3B Close Long - TIMEOUT",Strategy.CLOSE,Strategy.THISBAR); } } else if (Strategy.isShort()) { if (close() > esval) { Strategy.doCover("3B Close Short - STOPPED OUT",Strategy.CLOSE,Strategy.THISBAR); } if (Strategy.isShort() && vtime.getHours() == 13 && vtime.getMinutes() >= 45) { Strategy.doCover("3B Close Short - TIMEOUT",Strategy.CLOSE,Strategy.THISBAR); } } return; }