Here is some code I have been working on. I will go into detail on the code a little later. But this is how you monitor re-entering at a better price after taking a profit. The problem with taking profits on longer term trend following systems is that the logic that got you into the position is probably still true and you will notice your algorithm will re-enter in the same direction. So you need to inform your algorithm not to re-enter until a certain condition is met. In this example, I only re-enter at a better price if the condition that got me into the trade is still valid.
Inputs: swingHiStrength(2),swingLowStrength(2),numDaysToLookBack(30),stopAmt$(500),profitAmt$(1000),getBackInAfterProfAmt$(250);
vars: mp(0),longProfTaken(false),shortProfTaken(false);
mp = marketPosition;
if not(longProfTaken) and mp <> 1 then Buy("BreakOut-B") next bar at highest(h[1],20) on a stop;
if not(shortProfTaken) and mp <>-1 then SellShort("BreakOut-S") next bar at lowest(l[1],20) on a stop;
//If mp[0] = 0 and mp[1] = 1 then print(date," ",exitPrice(1)," ",entryPrice(1));
If longProfTaken then
Begin
If c < exitPrice(1) - getBackInAfterProfAmt$/bigPointValue then
begin
longProfTaken = false;
If mp <> -1 then buy("longRe-Entry") next bar at open;
end;
end;
If shortProfTaken then
Begin
If c > exitPrice(1) + getBackInAfterProfAmt$/bigPointValue then
begin
shortProfTaken = false;
If mp <>-1 then sellShort("shortRe-Entry") next bar at open;
end;
end;
If mp = 1 and c > entryPrice + profitAmt$/bigPointValue then
begin
sell this bar on close;
longProfTaken = true;
end;
If mp =-1 and c < entryPrice - profitAmt$/bigPointValue then
begin
buyToCover this bar on close;
shortProfTaken = true;
end;
If mp = -1 then longProfTaken = false;
If mp = 1 then shortProfTaken = false;
//if mp = 1 then setStopLoss(stopAmt$);
//if mp = 1 then setProfitTarget(profitAmt$);
Hi-Res Edition Just Added to Easing Into EasyLanguage Series
Hello to All! I just published the first book in this series. It is the Foundation Edition and is designed for the new user of EasyLanguage or for those you would like to have a refresher course. There are 13 tutorials ranging from creating Strategies to PaintBars. Learn how to create your own functions or apply stops and profit objectives. Ever wanted to know how to find an inside day that is also a Narrow Range 7 (NR7?) Now you can, and the best part is you get over 4 HOURS OF VIDEO INSTRUCTION – one for each tutorial. All source code is available too, and if you have TradeStation, so are the workspaces. Plus you can always email George for any questions. george.p.pruitt@gmail.com.
This book is for those that have read the Foundation Edition or have some experience working with EasyLanguage and the various functions that help make a trading decision. This book’s audience will be those programmers that want to take an idea, that requires an observation of intraday market movements to make a trading decision, and program it accurately. If you have programmed daily bar systems, and you want to drill down and add some components that require additional market information (like what came first – the high or the low), then you have come to the right place. If you want to buy and sell short in the same day and use trade management principles such as profit targets and stop losses then The Hi-Res Edition is the book you need. There are two paradigms that EasyLanguage covers: daily and intraday bar programming. It’s the same language, but the move from daily to intraday programming can be quite difficult. Learn all the essentials and shortcuts with this edition. 5 HOURS OF VIDEO INSTRUCTION in this Hi-Res edition – one for each tutorial. All source code is available too, and if you have TradeStation, so are the workspaces. Plus you can always email George for any questions. george.p.pruitt@gmail.com.
Pick you your copies today – e-Book or Paperback format!