Hi TRO,
I've been looking at the DynamicS/R threads and this looks like a really useful indicator.
However, I don't own TS or ES software - I own Amibroker, and am used to coding in this.
I would like to port the indicator over, but don't understand how the DynamicS/R works.
Would you be able to explain please.
Thanks, AC
TRO_DYNAMIC_SR2CAN - How it works
Moderator: moderators
-
- rank: 50+ posts
- Posts: 79
- Joined: Wed Nov 08, 2006 4:46 pm
- Reputation: 0
- Gender:
Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.
Thank you for your support.
- TheRumpledOne
- rank: 10000+ posts
- Posts: 15538
- Joined: Sun May 14, 2006 9:31 pm
- Reputation: 3035
- Location: Oregon
- Real name: Avery T. Horton, Jr.
- Gender:
- Contact:
Code: Select all
{ _TRO_Dynamic_SR2can - draw fibs between the Support/Resistance lines }
{Attn: TradeStation
if this indicator 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 2006 Avery T. Horton, Jr.}
inputs:
iAlert(false),
iStartDate(1070101), // if not intraday, date to start counting
iPlotFibs(true),
iPlotSR(true),
iPrice( Close ),
iDecimals(2),
iPeriods(5),
// iHigh( HighD(0) ),
// iLow( LowD(0) ),
iFibPlot("R"), // "P" = projections, "R" = retracements
iFib1(.24),
iFib2(.38),
iFib3(.50),
iFib4(.62),
iFib5(.76),
iFib1Color(darkcyan ),
iFib2Color(darkbrown),
iFib3Color(darkgray),
iFib4Color(darkbrown ),
iFib5Color(darkcyan ),
HighColor( red),
LowColor( blue),
idummy("");
variables:
fg8(white),
bg8(black),
xAppType(0),
sFirstPass(true),
tInd(""),
tAlert(""),
xFib1(iFib1),
xFib2(iFib2),
xFib3(iFib3),
xFib4(iFib4),
xFib5(iFib5),
tFib(""),
xLowestLow(0),
xHighestHigh(0),
xRange(0),
xPosition(0),
oExtremeVal( 0 ),
oExtremeBar( 0 ) ;
variables:
Dynamic2_R( 0 ),
Dynamic2_S( 0 ),
OldDynamic2_R( 0 ),
OldDynamic2_S( 0 ),
PrevDynamic2_R( 0 ),
PrevDynamic2_S( 0 ),
xBars( 0 ),
xPeriods(05),
xOldPeriods(0),
Dynamic_R( 0 ),
Dynamic_S( 0 ),
OldDynamic_R( 0 ),
OldDynamic_S( 0 ),
PrevDynamic_R( 0 ),
PrevDynamic_S( 0 ) ;
{commentary variables}
variables:
xcomm(0),
oComm1( "" ),
oComm2( "" ),
oComm3( "" ),
oComm4( "" ),
oComm5( "" ),
oComm6( "" ),
oComm7( "" ),
oComm8( "" ),
oComm9( "" ),
oComm10( "" );
{first time through}
if sFirstPass
then begin
sFirstPass = false;
{ APP TYPE TEST }
sFirstPass = false;
xAppType = GetAppInfo(aiApplicationType); // cUnknown = 0 cChart = 1 cRadarScreen = 2 cOptionStation = 3
end; {if sFirstPass}
{ INITIALIZE }
tInd = "";
tAlert = "";
{ CALCULATIONS }
If date this bar >= iStartDate
then begin
{save old values}
If Dynamic_R <> PrevDynamic_R
then OldDynamic_R = PrevDynamic_R;
If Dynamic_S <> PrevDynamic_S
then OldDynamic_S = PrevDynamic_S ;
OldDynamic_R = PrevDynamic_R ;
OldDynamic_S = PrevDynamic_S ;
PrevDynamic_R = Dynamic_R ;
PrevDynamic_S = Dynamic_S ;
If Dynamic2_R <> PrevDynamic2_R
then OldDynamic2_R = PrevDynamic2_R;
If Dynamic2_S <> PrevDynamic2_S
then OldDynamic2_S = PrevDynamic2_S ;
OldDynamic2_R = PrevDynamic2_R ;
OldDynamic2_S = PrevDynamic2_S ;
PrevDynamic2_R = Dynamic2_R ;
PrevDynamic2_S = Dynamic2_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;
oExtremeVal = Extremes( L of data2 , iPeriods, -1, Dynamic2_S , oExtremeBar ) ; // lowest low
oExtremeVal = Extremes( H of data2, iPeriods, 1, Dynamic2_R , oExtremeBar ) ; // highest high
If Dynamic2_R <> H
and Dynamic2_R < PrevDynamic2_R
then if PrevDynamic2_R <> 0
then Dynamic2_R = PrevDynamic2_R;
If Dynamic2_S <> L
and Dynamic2_S > PrevDynamic2_S
then if PrevDynamic2_S <> 0
then Dynamic2_S = PrevDynamic2_S;
{
If iLow <> iLow[1]
Or iHigh <> iHigh[1]
then begin
}
If iFibPlot = "R"
Or iFibPlot = "r"
then begin
xLowestLow = Dynamic2_S ;
xRange = Dynamic2_R - Dynamic2_S ;
xFib1 = iFib1 * xRange + xLowestLow;
xFib2 = iFib2 * xRange + xLowestLow;
xFib3 = iFib3 * xRange + xLowestLow;
xFib4 = iFib4 * xRange + xLowestLow;
xFib5 = iFib5 * xRange + xLowestLow;
end // If iFibPlot = "R"...
else Begin
// oExtremeVal = Extremes( iLow[iPeriods], iPeriods, -1, xLowestLow , oExtremeBar ) ; // lowest low
// oExtremeVal = Extremes( iHigh[iPeriods], iPeriods, 1, xHighestHigh , oExtremeBar ) ; // highest high
xLowestLow = Dynamic2_S ;
xHighestHigh = Dynamic2_R ;
xRange = xHighestHigh - xLowestLow;
If close > OpenD(0)
then begin
xFib1 = iFib1 * xRange + xHighestHigh; // high projections
xFib2 = iFib2 * xRange + xHighestHigh;
xFib3 = iFib3 * xRange + xHighestHigh;
xFib4 = iFib4 * xRange + xHighestHigh;
xFib5 = iFib5 * xRange + xHighestHigh;
end
else begin
xFib1 = xLowestLow - iFib1 * xRange ; // low projections
xFib2 = xLowestLow - iFib2 * xRange ;
xFib3 = xLowestLow - iFib3 * xRange ;
xFib4 = xLowestLow - iFib4 * xRange ;
xFib5 = xLowestLow - iFib5 * xRange ;
end;
end;
// end; { If iLow <> iLow[1]... }
{ Alert criteria }
If high >= Dynamic_R
then begin
Fg8 = red;
Bg8 = white;
tAlert = "Price touched Resistance" ;
end
else
If Low <= Dynamic_S
then begin
Fg8 = blue;
Bg8 = white;
tAlert = "Price touched Support" ;
end;
{ Alert }
if iAlert
and tAlert <> ""
//and tAlert <> tAlert[1]
then Alert( tAlert ) ;
if iPlotFibs
then begin
Plot1(xFib1 , "fib1", iFib1Color ) ;
Plot2(xFib2 , "fib2", iFib2Color ) ;
Plot3(xFib3 , "fib3", iFib3Color ) ;
Plot4(xFib4 , "fib4", iFib4Color ) ;
Plot5(xFib5 , "fib5", iFib5Color ) ;
end; // iPlotFibs
if iPlotSR
then begin
Plot6(Dynamic_R , "Resistance", HighColor ) ;
Plot7(Dynamic_S , "Support", LowColor ) ;
Plot8(Dynamic2_R , "Res", HighColor ) ;
Plot9(Dynamic2_S , "Sup", LowColor ) ;
end; // iPlotSR
end; // If date >= xStartDate
if xAppType = 2
then begin
Plot18(tAlert , "Alert", yellow ) ;
end;
CommentaryCl( "Dynamic_R: ", NumToStr( Dynamic_R , iDecimals) );
CommentaryCl( "Dynamic_S: ", NumToStr( Dynamic_S , iDecimals) );
There's the code.
IT'S NOT WHAT YOU TRADE, IT'S HOW YOU TRADE IT!
Please do NOT PM me with trading or coding questions, post them in a thread.
Please do NOT PM me with trading or coding questions, post them in a thread.
-
- rank: 50+ posts
- Posts: 79
- Joined: Wed Nov 08, 2006 4:46 pm
- Reputation: 0
- Gender:
Thank you.
I can understand the following - I do not know Tradestation. Could you add in bits where needed please.
1. It goes back 5 bars and finds the highest high/lowest low
I am unsure what this is doing:
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;
2. Key fib levels are calculated between the highest high and lowest low
3. These fib levels are plotted - but I am not sure which bar they start from
I can understand the following - I do not know Tradestation. Could you add in bits where needed please.
1. It goes back 5 bars and finds the highest high/lowest low
I am unsure what this is doing:
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;
2. Key fib levels are calculated between the highest high and lowest low
3. These fib levels are plotted - but I am not sure which bar they start from
- TheRumpledOne
- rank: 10000+ posts
- Posts: 15538
- Joined: Sun May 14, 2006 9:31 pm
- Reputation: 3035
- Location: Oregon
- Real name: Avery T. Horton, Jr.
- Gender:
- Contact:
#1. I don't know how to explain that. <> means not equal to. < means less than and = means equal to. Prev means previous. To understand, you could construct a decision tree. That might help you.
#2 and #3. The fib levels are plotted each bar between dynamic support and resistance.
#2 and #3. The fib levels are plotted each bar between dynamic support and resistance.
IT'S NOT WHAT YOU TRADE, IT'S HOW YOU TRADE IT!
Please do NOT PM me with trading or coding questions, post them in a thread.
Please do NOT PM me with trading or coding questions, post them in a thread.
-
- rank: 50+ posts
- Posts: 79
- Joined: Wed Nov 08, 2006 4:46 pm
- Reputation: 0
- Gender:
Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.
Thank you for your support.
- TheRumpledOne
- rank: 10000+ posts
- Posts: 15538
- Joined: Sun May 14, 2006 9:31 pm
- Reputation: 3035
- Location: Oregon
- Real name: Avery T. Horton, Jr.
- Gender:
- Contact:
what does the extremes function return?
Code: Select all
oExtremeVal = Extremes( L, iPeriods, -1, Dynamic_S , oExtremeBar ) ; // lowest low
- TheRumpledOne
- rank: 10000+ posts
- Posts: 15538
- Joined: Sun May 14, 2006 9:31 pm
- Reputation: 3035
- Location: Oregon
- Real name: Avery T. Horton, Jr.
- Gender:
- Contact:
alichambers wrote:OK-do you have an explanation of how Dynamic S/R is calculated - non-code. I could then use that as a base.
AC
I struggled to understand this code myself. After some cogitation I realized that the Dynamic_SR calculations boil down to this:
Code: Select all
{ Initialize }
if Dynamic_R = 0 then begin
Dynamic_R = Highest(High, iPeriods);
Dynamic_S = Lowest(Low, iPeriods);
end;
{ every pass }
if High = Highest(High, iPeriods) then Dynamic_R = High;
if Low = Lowest(Low, iPeriods) then Dynamic_S = Low;
Expressed in words, if the high of the current bar is equal to the highest high of the last iPeriods, set the dynamic high to the current high; otherwise just leave the dynamic high at whatever value it was before this bar. Similarly for dynamic support. The test of Dynamic_R equal to zero is there only to initialize dynamic support and resistance at the left edge of the chart.
- Jim
- TheRumpledOne
- rank: 10000+ posts
- Posts: 15538
- Joined: Sun May 14, 2006 9:31 pm
- Reputation: 3035
- Location: Oregon
- Real name: Avery T. Horton, Jr.
- Gender:
- Contact:
Jim:
You left out this part, which is the most important!!
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;
You left out this part, which is the most important!!
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;
IT'S NOT WHAT YOU TRADE, IT'S HOW YOU TRADE IT!
Please do NOT PM me with trading or coding questions, post them in a thread.
Please do NOT PM me with trading or coding questions, post them in a thread.
Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.
Thank you for your support.