Dear all,
Starting from "Automatic Linear Trend Channel" code (Edward Pottasch), I've created a "Magic Line" system.
The problem is that the plotting of Individual Equity does'nt correspond exactly with the in/out trade signals, and I don't know where is the problem coming from? ...
so I'm not certain either of the backtest and optimization program.
here is the code that I used and a copy of the result:
_SECTION_BEGIN("Magic line 3");
SetOption( "InitialEquity", 30000 );
MaxPositionSizePercent = 12; //Optimize("MaxPosPct",10,5,20,1);
SetPositionSize( MaxPositionSizePercent, spsPercentOfEquity );
Equity( 1, 0 ); // evaluate stops, all quotes
kk = 7; //optimize( "mult", 8, 4, 10, 1 );
Per = 76; //optimize( "period", 110, 50, 120, 2 );
ms = ParamToggle( "Trend", "Regular|Smoothed", 1 );
x = Cum( 1 );
HaClose = ( O + H + L + C ) / 4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
//Plot(HaOpen,"HaOpen",colorWhite, styleLine);
HaHigh = Max( H, Max( HaClose, HaOpen ) );
//Plot(HaHigh,"HaHigh",colorWhite, styleLine);
HaLow = Min( L, Min( HaClose, HaOpen ) );
if ( ms == 0 )
{
nm = ( H - L );
j = ( O + H + L + C ) / 4;
}
else
{
nm = ( HaHigh - HaLow );
j = ( HaOpen + HaHigh + HaLow + HaClose ) / 4;
}
rfsctor = WMA( nm, Per );
revers = kk * rfsctor;
Trend = 1;
NW[0] = 0;
for ( i = 1;i < BarCount;i++ )
{
if ( Trend[i-1] == 1 )
{
if ( j[i] < NW[i-1] )
{
Trend[i] = -1;
NW[i] = j[i] + Revers[i];
}
else
{
Trend[i] = 1;
if ( ( j[i] - Revers[i] ) > NW[i-1] )
{
NW[i] = j[i] - Revers[i];
}
else
{
NW[i] = NW[i-1];
}
}
}
if ( Trend[i-1] == -1 )
{
if ( j[i] > NW[i-1] )
{
Trend[i] = 1;
NW[i] = j[i] - Revers[i];
}
else
{
Trend[i] = -1;
if ( ( j[i] + Revers[i] ) < NW[i-1] )
{
NW[i] = j[i] + Revers[i];
}
else
{
NW[i] = NW[i-1];
}
}
}
}
cp = ( H + L ) / 2;
TrendUp = IIf( Trend == 1, Trend, 0 );
TrendDown = IIf( Trend == -1, Trend, 0 );
totalTrend = IIf( TrendUp, TrendUp, TrendDown );
dtotalTrend = totalTrend - Ref( totalTrend, -1 );
vtotalTrend = ValueWhen( dtotalTrend, dtotalTrend );
cbull = vtotalTrend > 0 AND Ref( vtotalTrend, -1 ) < 0;
cbull = Ref( cbull, 1 );
cbear = vtotalTrend < 0 AND Ref( vtotalTrend, -1 ) > 0;
cbear = Ref( cbear, 1 );
cbull = vtotalTrend > 0 AND Ref( vtotalTrend, -1 ) < 0;
cbull = Ref( cbull, 1 );
cbull[BarCount-1] = 1;
cbear = vtotalTrend < 0 AND Ref( vtotalTrend, -1 ) > 0;
cbear = Ref( cbear, 1 );
cbear[BarCount-1] = 1;
nwbull = Ref( Flip( cbull, cbear ), -1 );
nwbear = Ref( Flip( cbear, cbull ), -1 );
SetChartOptions(1,chartShowArrows|chartShowDates|chartLogarithmic);
//SetBarFillColor( IIf( C > O, ParamColor( "Candle UP Color", colorBlue ), IIf( C<= O, ParamColor( "Candle Down Color", colorDarkRed ), colorLightGrey ) ) );
Plot( C, "Price", IIf( C > O, ParamColor( "Wick UP Color", colorTurquoise), IIf( C <= O, ParamColor( "Wick Down Color", colorRed ), colorLightGrey ) ),64, 0, 0, 0, 0 );
PlotShapes( IIf( x == BarCount, shapeSmallSquare, shapeNone ), colorWhite, 0, j,0 );
Plot( IIf( NW < j, NW, Null ), "\ntrailLong", ParamColor( "ColorTrailLong",colorBlue ), styleStaircase | styleDots, Null, Null, 0, 0, 3 );
Plot( IIf( NW > j, NW, Null ), "\ntrailShort", ParamColor( "ColorTrailShort",colorOrange ), styleStaircase | styleDots, Null, Null, 0, 0, 3 );
Buy = nwbull;
Sell = nwbear;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
PlotShapes(Buy*shapeUpArrow,colorWhite,0,Low-0.20);
PlotShapes(Sell*shapeDownArrow,colorWhite,0,High+0.20);
_SECTION_END();
another point is that I use high definition sreen (3000 x 2000 px) and the arrows (white) apear very small. Do you know how to increase these shapes?
I thank you for your help,
Jiel