Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 7/25/2005(UTC) Posts: 1,042
Was thanked: 57 time(s) in 54 post(s)
|
Hi RC
OK, there are a number of things with these formulas that you might want to do differently but consider them as templates. I've provided both indicators and EST code. You can do a number of things with the indicator sell code and I'll get to that. First off here's the EST code windows - Buy Order and Sell Order.
{Buy Order Window} {RCB Buy} X:=OPT1; BuyLong:=Cross(C,Mov(C,10,S)); Ref(BuyLong,-1);
{Sell Order Window} {RCB Sell} BuyLong:=Cross(C,Mov(C,10,S)); BuyLong:=Ref(BuyLong,-1); SellLong:=Cross(Mov(C,100,S),Mov(C,25,S)); ATRange:=Ref(ATR(14),-0) * 1.5; Trade:=If(PREV<=0,If(BuyLong,OPEN,0), {only buy if not in a trade} If(SellLong OR C>PREV+ATRange OR C<PREV-ATRange, {3 sell conditions} -PREV,PREV)); {negative spike for exit, else hold prev value} Ref(Trade<0,-1); {plot a TRUE when negative spike is present}
Now for the indicators.
{RCB Buy} {BuyLong:=Cross(C,Mov(C,10,S));} {Ref(BuyLong,-1);}
{RCB Sell} BuyLong:=Cross(C,Mov(C,10,S)); BuyLong:=Ref(BuyLong,-1); SellLong:=Cross(Mov(C,100,S),Mov(C,25,S)); ATRange:=Ref(ATR(14),-0) * 1.5; Trade:=If(PREV<=0,If(BuyLong,OPEN,0), If(SellLong OR C>PREV+ATRange OR C<PREV-ATRange, -PREV,PREV)); Ref(Trade<0,-1);
Notice that there's not much difference (really only the comments). However, the RCB Sell indicator can tell you a lot about what's happening on a chart.
A final line of "Trade" will show you when a trade is entered AND when it is terminated. You'll have to figure out what delays to keep and what to dispense with but I've attempted to make all the code so that things are seen to happen on the bar following when they actually happened (how most of us trade). By including the delays in the buy and sell code you don't need to add delays to the EST. Using delays with the EST is one of the main reasons why the EST rejects trades without apparent reason. There is a reason though, usually that 100% of equity is applied to each trade and when the price is higher on the Execution bar the EST decides that it cannot afford to buy the number of shares it calculated on the previous bar, so it aborts the trade.
The PREV-based Trade latch is really two quite simple If() functions used in conjunction with PREV. The first If() checks if the latch was reset on the previous bar (<0) or reset some bars early (=0) or never set yet (also =0). If this test is passed then the first If() function allows the latch to accept a buy signal whereby the latch sets to the value of the OPEN 1 bar after the actual signal was detected on the CLOSE of the previous bar. If the Trade latch was already set then the first If() inhibits any new buy signals and passes control to the second If() function. This function checks for any of the three sell conditions being TRUE, and if they are then the latch outputs a negative spike indicating that the trade is coming to an end. If no sell condition is TRUE but the latch is still active then the PREVious (positive) value of the latch continues to be output. Got it?
There are all sorts of changes that you can make to the code but if you change the general structure of the PREV latch you'll probably end up with something that doesn't work well.
Here are some alternative outputs (last lines) that you should try with the Sell indicator.
Trade<0;
Trade;
ABS(Trade);
and so on.
If you use ABS(Trade) you may see some situations where the entry price seems to change mid-way through a trade. This in fact is not what is happening but that a new trade is initiated on the bar immediately following the negative spike/termination of the previous trade. Trying to enter a new trade on the same bar as the previous one terminates is problematic with this code and is beyond the scope of what I've tried to show you here.
Oh, I forgot to mention why I put OPT1 into the EST code. All values of this option should be set to 1, and that might make you think that it does nothing at all. What it does do is it forces the EST to present you with a single bar profit (or loss) summary before you move to the histogram showing all profits and losses. It can be quite difficult to assess whether a system is a winner or loser without that single bar graph to start with.
Roy
|