_automatictrendlinesCCI

#1
1 of 4 automatic trendlines; enjoy!

_SECTION_BEGIN("_automatictrendlinesCCI");
// RSI - TrendlineBreakout
SetChartOptions(0,0,chartGrid100 );
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} < open %g > < high %g > < low %g > < close %g > (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
SetChartBkColor(ParamColor("Outer panel color ",colorBlack)); // color of outer border
SetChartBkGradientFill( ParamColor("Inner panel color upper half",colorBlack),
ParamColor("Inner panel color lower half",colorDarkTeal)//color of inner panel
,ParamColor("behind Text Color", colorBlack));
SetOption("MaxOpenPositions", 2 );
PositionSize = 1000;
GraphXSpace=5;
SetBarsRequired( sbrAll, sbrAll );
SetOption("MaxOpenPositions", 2 );
PositionSize = 1000;
indicatorMode = Status( "action" ) == actionIndicator;
Buy = Short = Sell = Cover = 0;
BuyZone = 0;
ShortZone = 0;

r= Optimize("Reverse ",Param("Reverse ",1,1,28,1),1,28,1);

reverse = r / 100;

tangent = 0;
firstVisible = Status( "FirstVisibleBarIndex" );
LastVisible = Status( "LastVisibleBarIndex" );
isVisible = 0;
breakOut = 0;
graphColor = colorWhite;

pds = Optimize("pds ",Param("pds ",7,1,28,1),1,28,1);

myArray = CCI( pds );
j = 0;
direction[0] = 0;
dd = 0 ;
y[0] = myArray[pds];
x[0] = 0;

for ( i = pds + 1; i < BarCount; i++ )
{
if ( direction[j] == 0 )
{
if ( myArray <= y[j] )
{
y[j] = myArray;
x[j] = i;
}
else
if ( myArray >= y[j]*( 1 + reverse ) )
{
j++;
y[j] = myArray;
direction[j] = 1;
x[j] = i;
}
}
else
{
if ( myArray >= y[j] )
{
y[j] = myArray;
x[j] = i;
}

else
if ( myArray <= y[j]* ( 1 - reverse ) )
{
j++;
y[j] = myArray;
direction[j] = 0;
x[j] = i;

}
}

dd = direction[j];

if ( x[j] >= firstVisible && x[j] <= LastVisible )
isVisible[j] = 1;

if ( j > 2 )
{
dy = ( y[j] - y[j-2] ) ;
dx = x[j] - x[j-2];
tangent[j] = dy / dx;

if ( direction[j] )
{
breakOut[j] = tangent[j] > tangent[j-2] ;

if ( breakOut [j] )
{
BuyZone = 1 ;
graphColor = colorGreen;


}
}

else
{
breakOut[j] = tangent[j] < tangent[j-2];

if ( breakOut[j] )
{
ShortZone = 1;
graphColor = colorDarkRed;


}

}

}

}


Buy =Cover = ExRem( BuyZone, !dd );
Short =Sell = ExRem( ShortZone, dd ) ;
//SetChartOptions(0,0,ChartGrid30 | ChartGrid70 );

if ( IndicatorMode )
{
SetChartOptions( 0,0, ChartGrid50, chartShowDates + chartShowArrows );
Plot ( myArray, "" , Graphcolor );
//PlotOHLC( myArray,myArray,50,myArray, "", IIf( myArray> 50, colorYellow, colorWhite ), styleCloud | styleClipMinMax, 30, 70 );

//PlotShapes( Buy * shapeSmallCircle, colorBrightGreen, 0, BuyPrice, 0 );
PlotShapes( Buy * shapeSmallUpTriangle, colorBrightGreen, 0, myArray );
// PlotShapes( Sell * shapeStar, colorBrightGreen, 0, SellPrice, 0 );
// PlotShapes( Short * shapeSmallCircle, colorRed, 0, BuyPrice, 0 );
PlotShapes( Short * shapeSmallDownTriangle, colorRed, 0, myArray);
// PlotShapes( Cover * shapeStar, colorRed, 0, CoverPrice, 0 );


//-------display trendlines------------//

tlcolor = colorGreen;
myTrendLine = Null;

for ( n = 1; n <= j; n++ )
{
if ( isVisible[n] && n > 3 )
{
if ( direction[n] )
tlcolor = colorGreen;
else
tlcolor = colorRed;

if ( breakOut[n] )
myTrendline = LineArray( x[n-4], y[n-4], x[n-2], y[n-2], 1 );

myTrendline = IIf( BarIndex() > x[n], Null, myTrendline );
Plot( myTrendline, "", tlcolor, styleLine + styleNoRescale | styleNoLabel | styleDashed );
}

//Plot( LineArray( x[n-1], y[n-1], x[n], y[n] ), "", colorViolet, styleLine + styleNoRescale , styleNoLabel ) ; // plots ZigZag
}

}
_SECTION_END();
 
#2
Hi Birdseye

Thank you for the useful gifts you have presented us.
THe price patterns one cant readily read on price chart,can be easily read on RSI and CCI charts and can be traded comfortably.

Casoni
sorry for this trouble!
Number one=colorscheme
For some reason color combination is not comfortable.
would you kindly fix the best colors as default,please!
Number two=date time details not visible at chart bottom,in black blackground-(in white background these are visible)how to get date time visible in white fonts?
best regards to Birdseye
ford
 

KelvinHand

Well-Known Member
#3
Re: _automatictrendlines

4 scripts are identical. Clean up and Combine all 4 into 1.
Can save space and Allow other indicator to add in easily.

- indicator option choice - CCI,RSI, ROC, TRIX
- All period default to 7 except TRIX to 2
Code:
_SECTION_BEGIN("_automatictrendlines");

SetBarsRequired( sbrAll, sbrAll );

SetChartBkColor(ParamColor("Outer panel color ",colorBlack)); // color of outer border
SetChartBkGradientFill( ParamColor("Inner panel color upper half",colorBlack),
ParamColor("Inner panel color lower half",colorDarkTeal)//color of inner panel
,ParamColor("behind Text Color", colorBlack));



_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} < open %g > < high %g > < low %g > < close %g > (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
GraphXSpace=5;


SetOption("MaxOpenPositions", 2 );
PositionSize = 1000;
indicatorMode = Status( "action" ) == actionIndicator;
Buy = Short = Sell = Cover = 0;
BuyZone = 0;
ShortZone = 0;


tangent = 0;
firstVisible = Status( "FirstVisibleBarIndex" );
LastVisible = Status( "LastVisibleBarIndex" );
isVisible = 0;
breakOut = 0;
graphColor = colorWhite;


ParamStr("TRIX Default Period", "2");

indyOpt =ParamList("Indicator", "CCI|RSI|ROC|TRIX");
Period = Param("pds ",7,1,28,1);




r= Optimize("Reverse ",Param("Reverse ",1,1,28,1),1,28,1);
reverse = r / 100;

pds = Optimize("pds ",Period,1,28,1);

switch (indyOpt)
{
  case "RSI":
       SetChartOptions(1,0,chartGrid20 |chartGrid50 |chartGrid80);
       myArray = RSI( pds );
       break;

  case "CCI":
       SetChartOptions(1,0,chartGrid100 );
       myArray = CCI( pds );
       break;

  case "ROC":
       SetChartOptions(1,0,chartGrid0);
       myArray = ROC( Close, pds );
       break;

  case "TRIX":
       SetChartOptions(1,0, chartGrid0);
       pds = Optimize("pds ",Param("pds ",2,1,28,1),1,28,1);
       myArray = Trix( pds );
       break;

}





j = 0;
direction[0] = 0;
dd = 0 ;
y[0] = myArray[pds];
x[0] = 0;

for ( i = pds + 1; i < BarCount; i++ )
{
  if ( direction[j] == 0 )
  {
    if ( myArray[i] <= y[j] )
    {
      y[j] = myArray[i];
      x[j] = i;
    }
    else
    if ( myArray[i] >= y[j]*( 1 + reverse ) )
    {
      j++;
      y[j] = myArray[i];
      direction[j] = 1;
      x[j] = i;
    }
  }
  else
  {
    if ( myArray[i] >= y[j] )
    {
      y[j] = myArray[i];
      x[j] = i;
    }
    else
    if ( myArray[i] <= y[j]* ( 1 - reverse ) )
    {
      j++;
      y[j] = myArray[i];
      direction[j] = 0;
      x[j] = i;

    }
  }

  dd[i] = direction[j];

  if ( x[j] >= firstVisible && x[j] <= LastVisible )
     isVisible[j] = 1;

   if ( j > 2 )
   {
     dy = ( y[j] - y[j-2] ) ;
     dx = x[j] - x[j-2];
     tangent[j] = dy / dx;

     if ( direction[j] )
     {
        breakOut[j] = tangent[j] > tangent[j-2] ;

       if ( breakOut [j] )
       {
         BuyZone[i] = 1 ;
         graphColor[i] = colorGreen;
      }
    }
    else
    {
        breakOut[j] = tangent[j] < tangent[j-2];
        if ( breakOut[j] )
        { 
           ShortZone[i] = 1;
           graphColor[i] = colorDarkRed;
        }

    }

  }

}


Buy =Cover = ExRem( BuyZone, !dd );
Short =Sell = ExRem( ShortZone, dd ) ;
//SetChartOptions(0,0,ChartGrid30 | ChartGrid70 );

if ( IndicatorMode )
{
  //SetChartOptions( 0,0, ChartGrid50, chartShowDates + chartShowArrows );
  Shortname = " USE_"+indyOpt+"("+Pds+")";
  Plot ( myArray, Shortname , Graphcolor );
   //PlotOHLC( myArray,myArray,50,myArray, "", IIf( myArray> 50, colorYellow, colorWhite ), styleCloud | styleClipMinMax, 30, 70 );

   //PlotShapes( Buy * shapeSmallCircle, colorBrightGreen, 0, BuyPrice, 0 );
   PlotShapes( Buy * shapeSmallUpTriangle, colorBrightGreen, 0, myArray );
   // PlotShapes( Sell * shapeStar, colorBrightGreen, 0, SellPrice, 0 );
   // PlotShapes( Short * shapeSmallCircle, colorRed, 0, BuyPrice, 0 );
   PlotShapes( Short * shapeSmallDownTriangle, colorRed, 0, myArray);
   // PlotShapes( Cover * shapeStar, colorRed, 0, CoverPrice, 0 );


//-------display trendlines------------//

tlcolor = colorGreen;
myTrendLine = Null;

for ( n = 1; n <= j; n++ )
{
  if ( isVisible[n] && n > 3 )
  {
    if ( direction[n] )
     tlcolor = colorGreen;
    else
     tlcolor = colorRed;

    if ( breakOut[n] )
       myTrendline = LineArray( x[n-4], y[n-4], x[n-2], y[n-2], 1 );

    myTrendline = IIf( BarIndex() > x[n], Null, myTrendline );
    Plot( myTrendline, "", tlcolor, styleLine + styleNoRescale | styleNoLabel | styleDashed );
  }

  //Plot( LineArray( x[n-1], y[n-1], x[n], y[n] ), "", colorViolet, styleLine + styleNoRescale , styleNoLabel ) ; // plots ZigZag
}

}
_SECTION_END();
 
#5
Hi Birdseye

Thank you for the useful gifts you have presented us.
THe price patterns one cant readily read on price chart,can be easily read on RSI and CCI charts and can be traded comfortably.

Casoni
sorry for this trouble!
Number one=colorscheme
For some reason color combination is not comfortable.
would you kindly fix the best colors as default,please!
Number two=date time details not visible at chart bottom,in black blackground-(in white background these are visible)how to get date time visible in white fonts?
best regards to Birdseye
ford
I agree the default colors I used are not most practical, but you can always change them in the code, or change in parameters
Greetings,
BirdsEye
 
#6
I added the BollingerLineIndicator

_SECTION_BEGIN("_automatictrendlines");

GraphXSpace=10;

indicatorMode = Status( "action" ) == actionIndicator;
Buy = Short = Sell = Cover = 0;
BuyZone = 0;
ShortZone = 0;


tangent = 0;
firstVisible = Status( "FirstVisibleBarIndex" );
LastVisible = Status( "LastVisibleBarIndex" );
isVisible = 0;
breakOut = 0;
graphColor = colorOrange;

ParamStr("TRIX Default Period", "2");

indyOpt =ParamList("Indicator", "RSI|CCI|ROC|TRIX|BLI");
Period = Param("pds ",7,1,28,1);

//bollingerline Indicator
width = Optimize("width ",Param("width ",2,0.1,10,0.1),2,2,0.1);
C1 = C - BBandBot( Close, period, width) ;
C2 = BBandTop (Close,period,width) - BBandBot( Close, period, width);
RS = (AMA( C1, 0.5 ) / AMA( C2, 0.5 ))*100; //smooth
uptrendS = rs > Ref(rs,-1);
downtrendS = rs < Ref(rs,-1);
//einde

r= Optimize("Reverse ",Param("Reverse ",1,1,28,1),1,28,1);
reverse = r / 100;

pds = Optimize("pds ",Period,1,28,1);

switch (indyOpt)
{
case "RSI":
SetChartOptions(1,0,chartGrid20 |chartGrid50 |chartGrid80);
myArray = RSI( pds );
break;

case "CCI":
SetChartOptions(1,0,chartGrid100 );
myArray = CCI( pds );
break;

case "ROC":
SetChartOptions(1,0,chartGrid0);
myArray = ROC( Close, pds );
break;

case "TRIX":
SetChartOptions(1,0, chartGrid0);
pds = Optimize("pds ",Param("pds ",2,1,28,1),1,28,1);
myArray = Trix( pds );
break;

case "BLI":
SetChartOptions(1,0,chartGrid20|chartGrid30 |chartGrid50 |chartGrid70|chartGrid80);
myArray = RS ;
break;
}

j = 0;
direction[0] = 0;
dd = 0 ;
y[0] = myArray[pds];
x[0] = 0;

for ( i = pds + 1; i < BarCount; i++ )
{
if ( direction[j] == 0 )
{
if ( myArray <= y[j] )
{
y[j] = myArray;
x[j] = i;
}
else
if ( myArray >= y[j]*( 1 + reverse ) )
{
j++;
y[j] = myArray;
direction[j] = 1;
x[j] = i;
}
}
else
{
if ( myArray >= y[j] )
{
y[j] = myArray;
x[j] = i;
}
else
if ( myArray <= y[j]* ( 1 - reverse ) )
{
j++;
y[j] = myArray;
direction[j] = 0;
x[j] = i;

}
}

dd = direction[j];

if ( x[j] >= firstVisible && x[j] <= LastVisible )
isVisible[j] = 1;

if ( j > 2 )
{
dy = ( y[j] - y[j-2] ) ;
dx = x[j] - x[j-2];
tangent[j] = dy / dx;

if ( direction[j] )
{
breakOut[j] = tangent[j] > tangent[j-2] ;

if ( breakOut [j] )
{
BuyZone = 1 ;
graphColor = colorGreen;
}
}
else
{
breakOut[j] = tangent[j] < tangent[j-2];
if ( breakOut[j] )
{
ShortZone = 1;
graphColor = colorDarkRed;
}

}

}

}


Buy = Cover = ExRem( BuyZone, !dd );
Short = Sell = ExRem( ShortZone, dd ) ;

if ( IndicatorMode )
{
Shortname = " USE_"+indyOpt+"("+Pds+")";
Plot ( myArray, Shortname , Graphcolor ,styleThick);
}
PlotShapes( Buy * shapeUpArrow , colorGreen, 0, myArray );
PlotShapes( Short * shapeDownArrow , colorRed, 0, myArray);

//-------display trendlines------------//

tlcolor = colorGreen;
myTrendLine = Null;

for ( n = 1; n <= j; n++ )
{
if ( isVisible[n] && n > 3 )
{
if ( direction[n] )
tlcolor = colorGreen;
else
tlcolor = colorRed;

if ( breakOut[n] )
myTrendline = LineArray( x[n-4], y[n-4], x[n-2], y[n-2], 1 );

myTrendline = IIf( BarIndex() > x[n], Null, myTrendline );
Plot( myTrendline, "", tlcolor, styleLine + styleNoRescale | styleNoLabel | styleDashed );
}
}

_SECTION_END();