DEMONSTRATION PURPOSES ONLY
Posted: Sat Sep 22, 2007 9:54 pm
DEMONSTRATION PURPOSES ONLY
WARNING: DO NOT USE THIS CODE TO TRADE YOUR ACCOUNT
I wrote it to test an idea.
Code: Select all
{ $Dyn_SR - Trade when previous Support/Resistance lines crossed }
{Attn: TradeStation
if this is posted on the TradeStation Forum, I, TheRumpledOne, did NOT post it there,
so I can't be blamed for this indicator having my contact info.}
{Programmer: Avery T. Horton, Jr. aka TheRumpledOne,
gifts and donations accepted, PO Box 43575, Tucson, AZ 85733 }
{ ? Copyright 2007 Avery T. Horton, Jr.}
inputs:
iStartDate(1070101), // if not intraday, date to start counting
iPeriods(5),
iQuantity(10);
inputs:
iGreed_PCT( 0 ), {how much you want to make in a day - percentage of stock price}
ShareOrPosition( 1 ), { pass in 1 for per share basis, 2 for position basis }
ProfitTargetAmt( .06 ), { pass in 0 if you don't want a profit target }
StopLossAmt( 0 ), { pass in 0 if you don't want a stop loss }
BreakevenFloorAmt( 0 ), { pass in 0 if you don't want a breakeven stop }
DollarTrailingAmt( 0 ), { pass in 0 if you don't want a dollar trailing stop }
PctTrailingFloorAmt( 0 ), { pass in 0 here and/or in next input if you don't want
a percent trailing stop }
PctTrailingPct( 0 ), { pass in 0 here and/or in previous input if you don't want
a percent trailing stop; else pass in XX for XX percent }
ExitOnClose( false ) ; { pass in true if you want to exit the position at the
close of the day, else pass in false. CAUTION: We recommend that you set this to
TRUE only for back-testing, if at all; in automated execution, the exit order
will NOT be filled at the close of the day; instead, the order can be sent into
the extended session as a limit order. }
variables:
xLastTouch("S") ,
xShortStop(0),
xShortEntry(0),
xLongStop(0),
xLongEntry(0),
xLowestLow(0),
xHighestHigh(0),
xRange(0),
xPosition(0),
oExtremeVal( 0 ),
oExtremeBar( 0 ) ;
variables:
xBars( 0 ),
xPeriods(05),
xOldPeriods(0),
Dynamic_R( 0 ),
Dynamic_S( 0 ),
OldDynamic_R( 0 ),
OldDynamic_S( 0 ),
PrevDynamic_R( 0 ),
PrevDynamic_S( 0 ) ;
{ INITIALIZE }
{ CALCULATIONS }
{save old values}
If Dynamic_R <> PrevDynamic_R
then OldDynamic_R = PrevDynamic_R;
If Dynamic_S <> PrevDynamic_S
then OldDynamic_S = PrevDynamic_S ;
PrevDynamic_R = Dynamic_R ;
PrevDynamic_S = Dynamic_S ;
{ high / low for period }
xBars = xBars + 1;
oExtremeVal = Extremes( L, iPeriods, -1, Dynamic_S , oExtremeBar ) ; // lowest low
oExtremeVal = Extremes( H, iPeriods, 1, Dynamic_R , oExtremeBar ) ; // highest high
If Dynamic_R <> H
and Dynamic_R < PrevDynamic_R
then if PrevDynamic_R <> 0
then Dynamic_R = PrevDynamic_R;
If Dynamic_S <> L
and Dynamic_S > PrevDynamic_S
then if PrevDynamic_S <> 0
then Dynamic_S = PrevDynamic_S;
if high = Dynamic_R
and low = Dynamic_S
then xLastTouch = " "
else begin
if low = Dynamic_S
then xLastTouch = "S" ;
if high = Dynamic_R
then xLastTouch = "R" ;
end ;
if MarketPosition = 0
THEN BEGIN
{
If close crosses above OldDynamic_S
and xLastTouch = "S"
then Buy ( "oDynSR LE") iQuantity shares next bar at OldDynamic_S limit ; // enter LONG
}
If close crosses above PrevDynamic_S
and xLastTouch = "S"
then Buy ( "pDynSR LE") iQuantity shares next bar at PrevDynamic_S limit ; // enter LONG
{
If close crosses below OldDynamic_R
and xLastTouch = "R"
then SellShort ( "oDynSR SE") iQuantity shares next bar at OldDynamic_R limit ; // enter SHORT
}
If close crosses below PrevDynamic_R
and xLastTouch = "R"
then SellShort ( "pDynSR SE") iQuantity shares next bar at PrevDynamic_R limit ; // enter SHORT
END; // if MarketPosition = 0
if MarketPosition = 1
AND close < PrevDynamic_S
then sell ( "pDynSR LX") iQuantity shares next bar at MARKET ;
if MarketPosition = -1
AND close > PrevDynamic_R
then buy to cover ( "pDynSR SX") iQuantity shares next bar at MARKET ;
{*************************************************}
{ T A K E P R O F I T }
{*************************************************}
if ShareOrPosition = 1
then SetStopShare
else SetStopPosition ;
if ProfitTargetAmt > 0 then
SetProfitTarget( ProfitTargetAmt ) ;
if StopLossAmt > 0 then
SetStopLoss( StopLossAmt ) ;
if BreakevenFloorAmt > 0 then
SetBreakeven( BreakevenFloorAmt ) ;
if DollarTrailingAmt > 0 then
SetDollarTrailing( DollarTrailingAmt ) ;
if PctTrailingFloorAmt > 0 and PctTrailingPct > 0 then
SetPercentTrailing( PctTrailingFloorAmt, PctTrailingPct ) ;
if ExitOnClose = true then
SetExitOnClose ;
WARNING: DO NOT USE THIS CODE TO TRADE YOUR ACCOUNT
I wrote it to test an idea.