Here is some code that I got from bits and pieces from this message board. I
believe that Mike and others posted some of the code. It is a good start for
you to try.
SetTradeDelays(0, 0, 0, 0);
MaxOpenTrades = GetOption("MaxOpenPositions");
if (Status("stocknum") == 0)
{
_TRACE("DBGVIEWCLEAR");
}
rsi2 = RSI(2);
Plot(rsi2, "rsi2", colorViolet, styleLine);// Lightgrey, Violet
Plot(25, "", colorGreen, styleDashed | styleNoLabel);
Plot(70, "", colorRed, styleDashed | styleNoLabel);
// Simple buy and sell rules
Buy = C > MA(C,200) AND RSI(2) < 25 AND Ref(RSI(2) < 25, -1);
BuyPrice = C;
Sell = RSI(2) > 70;
SellPrice = C;
Lang = BarsSince(Buy) < BarsSince(Sell);
//kurz = BarsSince(Short) < BarsSince(Cover);
kurz = 0;
//Plot Trading Ribbon
//Color = IIf( Lang, colorBrightGreen, colorLightGrey );
Color = IIf( Lang, colorBrightGreen, IIf( kurz, colorRed, colorLightGrey ));
Plot( 1, "", Color, styleArea | styleOwnScale | styleNoLabel, 0, 35 );
Title=Name() + " " + Date() + " " + "RSI2 =" + NumToStr(rsi2,3.3) + " "+
EncodeColor(colorYellow) + " TPS Strategy ";
TotalPosition = 100; //Max Pct of Equity of all scaleins
FirstScaleIn = 10; //Pct of Total Position
SecondScaleIn = 20;
ThirdScaleIn = 30;
FourthScaleIn = 40;
FirstScaleInPctOfEqty = ( FirstScaleIn * TotalPosition ) / 100;
SecondScaleInPctOfEqty = ( SecondScaleIn * TotalPosition ) / 100;
ThirdScaleInPctOfEqty = ( ThirdScaleIn * TotalPosition ) / 100;
FourthScaleInPctOfEqty = ( FourthScaleIn * TotalPosition ) / 100;
ScaleInSize = Open - Open;
ScaleInCount = 0;
Dte = DateNum();
PositionScore = 1;
for( i = 0; i < BarCount; i++ )
{
if( Buy[ i ] AND ScaleInCount == 0 )
{
ScaleInCount = 1;
Buy[ i ] = True;
ScaleInSize[ i ] = FirstScaleInPctOfEqty;
_TRACE(" ");
_TRACE("Buy"
+ " Date: " + DateTimeToStr( DateTimeConvert( 2, Dte[ i ] ) )
+ " Buy = " + WriteVal( Buy[ i ], 1.0, 0 )
+ " Size: " + WriteVal( ScaleInSize[ i ], 1.2, 0 )
+ " CLose[i] " + WriteVal( Close[ i ], 1.2, 0 )
+ " CLose[i-1] " + WriteVal( Close[ i-1 ], 1.2, 0 )
);
}
if( ScaleInCount == 2
AND ( Close[ i ] < Close[ i -1 ] )
AND Sell[ i ] == 0 )
{
Buy[ i ] = sigScaleIn;
ScaleInSize[ i ] = SecondScaleInPctOfEqty;
_TRACE("SI2"
+ " Date: " + DateTimeToStr( DateTimeConvert( 2, Dte[ i ] ) )
+ " Buy = " + WriteVal( Buy[ i ], 1.0, 0 )
+ " Size: " + WriteVal( ScaleInSize[ i ], 1.2, 0 )
+ " CLose[i] " + WriteVal( Close[ i ], 1.2, 0 )
+ " CLose[i-1] " + WriteVal( Close[ i-1 ], 1.2, 0 )
);
}
if( ScaleInCount == 3
AND ( Close[ i ] < Close[ i -1 ] )
AND Sell[ i ] == 0 )
{
Buy[ i ] = sigScaleIn;
ScaleInSize[ i ] = ThirdScaleInPctOfEqty;
_TRACE("SI3"
+ " Date: " + DateTimeToStr( DateTimeConvert( 2, Dte[ i ] ) )
+ " Buy = " + WriteVal( Buy[ i ], 1.0, 0 )
+ " Size: " + WriteVal( ScaleInSize[ i ], 1.2, 0 )
+ " CLose[i] " + WriteVal( Close[ i ], 1.2, 0 )
+ " CLose[i-1] " + WriteVal( Close[ i-1 ], 1.2, 0 )
);
}
if( ScaleInCount == 4
AND ( Close[ i ] < Close[ i -1 ] )
AND Sell[ i ] == 0 )
{
Buy[ i ] = sigScaleIn;
ScaleInSize[ i ] = FourthScaleInPctOfEqty;
_TRACE("SI4"
+ " Date: " + DateTimeToStr( DateTimeConvert( 2, Dte[ i ] ) )
+ " Buy = " + WriteVal( Buy[ i ], 1.0, 0 )
+ " Size: " + WriteVal( ScaleInSize[ i ], 1.2, 0 )
+ " CLose[i] " + WriteVal( Close[ i ], 1.2, 0 )
+ " CLose[i-1] " + WriteVal( Close[ i-1 ], 1.2, 0 )
);
}
if( ScaleInCount > 4 OR Sell[ i ] )
{
Buy[ i ] = 0;
ScaleInCount = 0;
}
if( Buy[ i ] )
ScaleInCount = ScaleInCount + 1;
if ( Sell[ i ] )
_TRACE("Sale On Date: "
+ DateTimeToStr( DateTimeConvert( 2, Dte[ i ] )));
}
SetPositionSize( ValueWhen(Buy,ScaleInSize), spsPercentOfEquity );
Filter = 1;
AddColumn(Buy, "Buy", 1.0);
AddColumn(Sell, "Sell", 1.0);
AddColumn(Close, "Close", 1.2);
AddColumn(ScaleInSize, "ScaleInSize", 1.2);
AddColumn(BuyPrice, "BuyPrice", 1.2);
AddColumn(PositionSize, "PositionSize", 1.2);
--- In [email protected], Sidney Kaiser <skbi...@...> wrote:
>
>
> Trying to code up Larry Connors TPS entry conditions.
>
> I finally have to figure out how to scale into a position. Reading though
> the help files and old emails I thought I understood it, but....apparently
> not.
> I was thinking the first buy line would buy one lot and then the other buys
> (currently commented out) would be used for subsequent buys...wrong.
>
> The first buy is scaling into several lots all on its own as can be seen in
> the attached .csv file of a part of the detail log. The buy prices are not
> what I want, see those commented buy statements for that. It looks
> like SigScaleIn is buying successive bars after the initial conditions are
> met for the first buy.
>
> So help me out here. How do I set up the scaling in where there can be as
> many as 4 entries with them being larger by 2x, then 3x, then 4x as many
> shares at individually specified entry price conditions.
>
> RSI2 = RSI( RSIp);
> MA5 = MA( Close, MAfp );
> MA200 = MA( Close, MAsp );
> PositionSize = 1000;
> MAV = ( Close > MA200 AND Volume > 50000 );
>
> Buy = MAV*IIf( Ref(RSI2, -1) < blvl AND RSI2 < blvl, sigScaleIn, 0 ); //
> initial buy
> entry_price1 = ValueWhen( Buy, Close);
> /*
> Buy = MAV*IIf( Close < entry_price1, 2*sigScaleIn, 0); // 2nd buy
> Buy = MAV*IIf( Close < 0.8*entry_price1, 3*sigScaleIn, 0); // 3rd buy
> Buy = MAV*IIf( Close < 0.7*entry_price1, 4*sigScaleIn, 0); // 4th b
> */
> Sell = Cross( RSI2, selvl );
>
> Detail log: see attached .csv file
>
>