Howard reminded me of the fix for this. Too remove extra buys and sell

buy=ExRem(buy,sell);
sell=ExRem(sell,buy);

Dave

 
  ----- Original Message ----- 
  From: droskill 
  To: [email protected] 
  Sent: Monday, December 22, 2008 12:15 PM
  Subject: [amibroker] Re: Translating a system from Tradestation


  i didn't know that about Barssince - and thanks for the code - it will
  at least be a decent place to start.

  --- In [email protected], "Paul Ho" <paul.t...@...> wrote:
  >
  > strictly speaking, I havent consider the scenario when Barsince 
  > Entry is bigger than 1. The problem with using Barsince, as well as 
  > valuewhen is that, if a new buy signal appears before a exit signal 
  > from the original buy signal appears, then valuewhen, barssince will 
  > take from the new buy signal. and to be do that properly, you will 
  > need a loop that ignore all buy signal until a exit signal is in 
  > place
  > 
  > --- In [email protected], "Paul Ho" <paul.tsho@> wrote:
  > >
  > > I'm no sure Buy next bar at Highest(H, 2) stop means 1 tick above 
  > > the High or equal to the high. I've made it one tick above it.
  > > But the following code will work.
  > > TickSize= 1; //or whatever else
  > > TrueHigh = max(H, ref(c, -1));
  > > TrueLow = min(L, ref(c, -1));
  > > tr = TrueHigh - TrueLow;
  > > Condition1 = tr < Ref(tr, -1) AND tr < Ref(tr, -2);
  > > Condition2 = C > Ref(C, -14) AND C < Ref(C, -2);
  > > Condition3 = C < Ref(C, -14) AND C > Ref(C, -2);
  > > longentrypoint = HHV(H, 2);
  > > Shortentrypoint = LLV(L, 2);
  > > buysetup = Condition1 AND Condition2;
  > > Shortsetup = Condition1 AND Condition3;
  > > Buy = Ref(buysetup, -1) AND H > Ref(Longentrypoint, -1);
  > > Short = Ref(shortsetup, -1) AND L < Ref(Shortentrypoint, -1);
  > > BuyPrice = Longentrypoint + TickSize;
  > > ShortPrice = Shortentrypoint - TickSize;
  > > Sell = C > ValueWhen(Buy, BuyPrice) AND Ref(Buy, -1);
  > > SellPrice = C;
  > > Cover = C < ValueWhen(Short, ShortPrice) AND Ref(Short, -1);
  > > CoverPrice = C;
  > > Your code generates only 1 trade because, you did not put in the 
  > one 
  > > bar delay that is needed before comparsions between prices are 
  > made.
  > > /Paul.
  > > --- In [email protected], "droskill" <droskill@> wrote:
  > > >
  > > > Paul - thanks for the code. It's still generated only one trade 
  > > for
  > > > the SPY.
  > > > 
  > > > I'm wondering about two aspects - as to whether test lines of 
  > code
  > > > will actually work:
  > > > 
  > > > > > Buy = Condition1 AND Condition2;
  > > > > > BuyPrice = HHV(H,2);
  > > > > > 
  > > > > > Sell = C > BuyPrice AND BarsSince(Buy) >= 1;
  > > > 
  > > > Can I use BarsSince Buy this way?
  > > > 
  > > > --- In [email protected], "Paul Ho" <paul.tsho@> wrote:
  > > > >
  > > > > You can make some small changes to bring the definition of 
  > true 
  > > > > range to be in line how they are normally defined.
  > > > > TrueHigh = max(H, ref(c, -1));
  > > > > TrueLow = min(L, ref(c, -1));
  > > > > TrueRange = TrueHigh - TrueLow;
  > > > > /Paul.
  > > > > --- In [email protected], "droskill" <droskill@> wrote:
  > > > > >
  > > > > > Hey all - trying to translate a system but having some 
  > > issues. 
  > > > > Here's
  > > > > > the original EasyLanguage:
  > > > > > 
  > > > > > Input: StopPts (30); { Size of money management stop, 
  > > points }
  > > > > > Var: TR (0); { True Range }
  > > > > > 
  > > > > > TR = TrueRange;
  > > > > > 
  > > > > > Condition1 = TR < TR[1] and TR < TR[2];
  > > > > > Condition2 = C > C[14] and C < C[2];
  > > > > > Condition3 = C < C[14] and C > C[2];
  > > > > > 
  > > > > > If Condition1 and Condition2 then
  > > > > > Buy next bar at Highest(H, 2) stop;
  > > > > > 
  > > > > > If Condition1 and Condition3 then
  > > > > > Sell short next bar at Lowest(L, 2) stop;
  > > > > > 
  > > > > > If MarketPosition = 1 and C > EntryPrice and BarsSinceEntry 
  > >= 
  > > 1 
  > > > > then
  > > > > > Sell this bar at close;
  > > > > > 
  > > > > > If MarketPosition = -1 and C < EntryPrice and BarsSinceEntry 
  > > >= 1 
  > > > > then
  > > > > > Buy to cover this bar at close;
  > > > > > 
  > > > > > If MarketPosition = 1 then
  > > > > > Sell next bar at EntryPrice - StopPts stop;
  > > > > > 
  > > > > > If MarketPosition = -1 then
  > > > > > Buy to Cover next bar at EntryPrice + StopPts stop;
  > > > > > 
  > > > > > 
  > > > > > -----------------------------------
  > > > > > Here's what I've got - it ain't working:
  > > > > > 
  > > > > > TR1 = abs(H-L);
  > > > > > TR2 = abs(H-Ref(C,-1));
  > > > > > TR3 = abs(Ref(C,-1)-L);
  > > > > > 
  > > > > > TRa = Max(TR1,TR2);
  > > > > > TRb = Max(TR2,TR3);
  > > > > > TR = Max(TRa,TRb);
  > > > > > 
  > > > > > Condition1 = TR < Ref(TR,-1) AND TR < Ref(TR,-2);
  > > > > > Condition2 = C > Ref(C,-14) AND C < Ref(C,-2);
  > > > > > Condition3 = C < Ref(C,-14) AND C > Ref(C,-2);
  > > > > > 
  > > > > > Buy = Condition1 AND Condition2;
  > > > > > BuyPrice = HHV(H,2);
  > > > > > 
  > > > > > Sell = C > BuyPrice AND BarsSince(Buy) >= 1;
  > > > > > 
  > > > > > Short = Condition1 AND Condition3;
  > > > > > ShortPrice = LLV(L,2);
  > > > > > 
  > > > > > Cover = C < ShortPrice AND BarsSince(Short) >= 1;
  > > > > > 
  > > > > > ApplyStop(stopTypeLoss,stopModePoint,30,0);
  > > > > > 
  > > > > > ------------------------------
  > > > > > Any thoughts greatly appreciated.
  > > > > >
  > > > >
  > > >
  > >
  >



   

Reply via email to