I am having trouble translating the following TradeStation code. I get only buy and short signals. I have Amibroker 6.41.0 64 bit program. Here is the TS code
Inputs: Price((H+L)/2),
alpha(.07),
RngFrac(.35),
RevPct(1.015);
Vars: Smooth(0),
ITrend(0),
Trigger(0);
ITrend = (alpha - alpha*alpha/4)*Price + .5*alpha*alpha*Price[1] – (alpha - .75*alpha*alpha)*Price[2] + 2 *(1 – alpha)*ITrend[1] – (1 - alpha)*(1 - alpha)*ITrend[2];
If currentbar < 7 then ITrend = (Price + 2*Price[1] + Price[2]) / 4;
Trigger = 2*Itrend - ITrend[2];
If Trigger Crosses Over ITrend then Buy Next Bar at Close – RngFrac*(High - Low) Limit;
If Trigger Crosses Under ITrend then Sell Short Next Bar at Close + RngFrac*(High - Low) Limit;
If MarketPosition = 1 and Close < EntryPrice/RevPct then Sell Short Next Bar On Open;
If MarketPosition = -1 and Close > RevPct*EntryPrice then Buy Next Bar on Open
********** My AFL code is
SetOption("ReverseSignalForcesExit", True);
Price = (High + Low) / 2;
alpha = 0.07;
RngFrac = 0.35;
RevPct = 1.015;
Smooth = 0;
ITrend = 0;
Trigger = 0;
Position = 0;
bi = BarIndex();
Buy = Sell = Short = Cover = 0;
for ( i = 0; i < BarCount; i++ )
{
if ( i < 2 )
{
ITrend[i] = Price[i];
continue;
}
ITrend[i] = ( alpha - alpha * alpha / 4 ) * Price[i]
- 0.5 * alpha * alpha * Price[i - 1]
- ( alpha - 0.75 * alpha * alpha ) * Price[i - 2]
- 2 * ( 1 - alpha ) * ITrend[i - 1]
- ( 1 - alpha ) * ( 1 - alpha ) * ITrend[i - 2];
ITrend = IIf(BarIndex() < 7, (Price + 2*Ref(Price, -1) + Ref(Price, -2)) / 4, ITrend);
Trigger = 2 * ITrend - Ref(ITrend, -2);
BuySetup = Cross(Trigger, ITrend);
SellSetup = Cross(ITrend, Trigger);
BuyPrice = Close - RngFrac * (High - Low);
ShortPrice = Close + RngFrac * (High - Low);
// --- Exit Conditions ---
SellCond = (Position == 1 AND Close < BuyPrice / RevPct);
CoverCond = (Position == -1 AND Close > ShortPrice * RevPct);
// --- Signals ---
Buy = BuySetup;
Short = SellSetup;
position = Flip( Buy, Sell ) - Flip( Short, Cover );
Sell = SellCond;
Cover = CoverCond;
// --- Plotting ---
Plot(Close, "Price", colorDefault, styleCandle);
I would appreciate any assistance
