i want to experiment with efs and i want my first condition to be to do something on the first bar of the day.so i want to compare the first bar at 8:30 central to the closing bar at 3:15 and if the open is lower that the close then i want to buy at the open. im very new to efs and i want to learn a little at a time. someone give me a hint at how i would do that.
Announcement
Collapse
No announcement yet.
open of new day
Collapse
X
-
patr82
Enclosed is very basic example of a buy on open strategy that also sets stops and targets (comments are in the script) and can be used for back testing. Run it on an intraday chart set to regular trading hours.
If you are interested in learning about efs then I would suggest going through the various guides that are available in the EFS KnowledgeBase
Alex
PHP Code:function preMain(){
setPriceStudy(true);
setStudyTitle("Buy on Open");
setCursorLabelName("Target",0);
setCursorLabelName("Stop",1);
setDefaultBarFgColor(Color.blue,0);
setDefaultBarFgColor(Color.red,1)
setPlotType(PLOTTYPE_FLATLINES,0);
setPlotType(PLOTTYPE_FLATLINES,1);
setColorPriceBars(true);
setDefaultPriceBarColor(Color.black);
}
var vTarget = null;
var vStop = null;
function main(){
if(getDay(0) != getDay(-1)){ //if a new day
if(open() < close(-1) && !Strategy.isLong()){ //if open less than prior close and not long
Strategy.doLong("Long",Strategy.MARKET,Strategy.THISBAR); //go long on the open
vTarget = open()+4; //set target
vStop = open()-3; //set stop
}
}
if(Strategy.isLong() && high()> vTarget){ //if target reached
Strategy.doSell("Sell",Strategy.LIMIT,Strategy.THISBAR,null,vTarget); //sell at the target price
setPriceBarColor(Color.lime); //color the bar in lime
}
if(Strategy.isLong() && low()< vStop){ //if stop reached
Strategy.doSell("Sell",Strategy.STOP,Strategy.THISBAR,null,vStop); //sell at stop price
setPriceBarColor(Color.red); //color the bar in red
}
if(Strategy.isLong()){ //when long
setPriceBarColor(Color.blue); //color the bar in blue
var targetLine = vTarget; //assign the target price to this variable
var stopLine = vStop; //assign the stop price to this variable
}
return new Array (targetLine,stopLine); //plot target and stop lines
}
-
thanks
alex, thank you very much. i have been looking alot at the knowledge base and will continue. right now im trying to locate in the knowledge base where it tells me how to apply this formula that i have put into the efs editor onto my chart. thanks again. you have been a constant help.
just a simple question. do you like esignal better than tradestation.
Comment
-
patr82
how to apply this formula that i have put into the efs editor onto my chart.
Save the efs in the Formulas folder or any of its subfolders. Then right click the chart select Formulas or the subfolder in which you saved the efs and click the efs. That will apply it to the chart.
just a simple question. do you like esignal better than tradestation
Most definitely yes and without any hesitation
Alex
Comment
-
code
alex, thank you so very much for your help. it works on my chart. and i can take that code and look at it and learn and change things. im not a very good learning by just reading. so is there a good class i could take like c++ or java that would work well so i could learn how to convert all my tradestation code to efs.again youve been a tremendous help.
Comment
-
Mistake at Stop
Hi Alexis,
I tryed the formula with long and short direction (go long, if open is higher than privious day close, go short is open lower than ..., and changed the stop to:
old:
if(Strategy.isShort() && high()> vStop)
changed:
if(Strategy.isShort() && high()>= vStop)
I hoped, that the stop is filled market in the backtest, if the stop is touched.
Example: the stop is 119.79 - if this value reached, stop an close the position
in the pic you can see, that the stop is working, if a part of the bar is higher than the stop (at 10:25).
How I have to change the *.efs, that the stop ist working market in my backtest at 9:10, than the high of the bar is touching first time the stop-limit?
In the pic the position is short.
Thanks, TorsoLast edited by Torso; 02-07-2005, 01:10 AM.
Comment
-
-
Torso
The conditions are set correctly as far as I can see. The reason the strategy is not covering the short at 9:10 is because you are adding a 0.01 for vAbweichung in the commands to cover. Remove that value and you will see that the strategy will cover if the stop is touched.
Alex
Comment
-
TIME
im trying to write in a script in my open program that will exit me at a certain time and this is what i wrote AND inserted into my program and im getting some error. this java is so much more difficult for me still.
if(Strategy.isLong() && time()< 1200){ //if time reached
Strategy.doSell("Sell",Strategy.MARKET,Strategy.TH ISBAR,null,vStop); //sell at stop price
setPriceBarColor(Color.red); //color the bar in red
Comment
-
patr82
Replace time() with (getHour()*100)+getMinute()
Also Strategy.MARKET indicates the Open of a bar. To define a specific price you need to use either Strategy.LIMIT or Strategy.STOP and then verify that the bar has actually breached that level.
I would suggest that you go through the various guides in the EFS KnowledgeBase
Alex
Comment
-
Hi Patr,
try this:
if((getHour() == 15 && getMinute() == 30) && Strategy.isInTrade()) { //if is in trade at 15:30
if(Strategy.isLong()) { //if it is long
Strategy.doSell("Sell",Strategy.CLOSE,Strategy.THI SBAR);//close
}
if(Strategy.isShort()) { //if short
Strategy.doCover("Buy",Strategy.CLOSE,Strategy.THI SBAR);
} //close
}
TorsoLast edited by Torso; 02-08-2005, 04:01 PM.
Comment
Comment