Abletrend signals in Amibroker?

#4
_SECTION_BEGIN("SmoothHeikin MA Swing");
SetBarsRequired(200,0);
GraphXSpace = 5;
SetChartOptions(0,chartShowArrows|chartShowDates);
k = Param("K", 1.5, 1, 5, 0.1);
Per = Param("ATR", 3, 1, 30, 0.50);
k1 = Optimize("K", 1, 0.1, 5, 0.1);
Per1 = Optimize("ATR", 3, 1, 30, 0.50);
HACLOSE=(O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
j=Haclose;
//=======================================================================================================================
//=========================Indicator==============================================================================================
f=ATR(14);

rfsctor = WMA(H-L, Per);

revers = k * rfsctor;

Trend = 1;
NW[0] = 0;


for(i = 1; i < BarCount; i++)
{
if(Trend[i-1] == 1)
{
if(j < NW[i-1])
{
Trend = -1;
NW = j + Revers;
}
else
{
Trend = 1;
if((j - Revers) > NW[i-1])
{
NW = j - Revers;
}
else
{
NW = NW[i-1];
}
}
}
if(Trend[i-1] == -1)
{
if(j > NW[i-1])
{
Trend = 1;
NW = j - Revers;
}
else
{
Trend = -1;
if((j + Revers) < NW[i-1])
{
NW = j + Revers;
}
else
{
NW = NW[i-1];
}
}
}
}

//===============system================
Plot(NW, "", IIf(Trend == 1, 3, 25), 1);

Buy=Cover=Cross(j,nw);
Sell=Short=Cross(nw,j);
SWING =WriteIf(j > nw, "UPTREND","DOWNTREND");
GfxSetTextColor( colorLightBlue );
GfxSelectFont("Arial", 8 );
shape = Buy * shapeCircle + Sell * shapeCircle;
_SECTION_END();

_SECTION_BEGIN( "KBrain" );
//========================Initiation================ ========
bts = ParamToggle( "BrainTrend1 signal", "No|Yes" , 1 );
btst = ParamToggle( "BrainTrend1 stop", "No|Yes" , 1 );
btsl = ParamToggle( "BrainTrend1 stop line", "No|Yes" , 1 );
period = Param( "Period", 14, 6, 20, 1 );
x1 = 53;
x2 = 47;
d = 2.3;
f = 7;
s = 1.5;
range = ATR( f );
Range1 = ATR( f ) / d;
Range2 = ( ATR( f ) * s ) / 4;
range3 = ATR( 10 );
R = ( ( HHV( H, period ) - C ) / ( HHV ( H, period ) - LLV ( L, period ) ) ) * -100;
EMA1 = EMA( R, Period );
EMA2 = EMA( EMA1, 5 );
Difference = EMA1 - EMA2;
ZeroLagEMA = EMA1 + Difference;
value2 = abs( ZeroLagEMA );


function PercentR( periods )
{
return -100 * ( HHV( H, periods ) - C ) / ( HHV( H, periods ) - LLV( L, periods ) );
}


for ( i = 1; i < Period - 1; i++ )
{


tm = 1;
bstop = 1;
sstop = 1;
p = 1;
}

for ( i = period + 10; i < BarCount; i++ )
{
C[0] = 0;
Value2[0] = 0;
p[0] = 0;
Plot1[0] = 0;
Plot2[0] = 0;
Val1 = 0;
Val2 = 0;
temp[0] = 0;
Value3[0] = 0;
tm[0] = 0;
p1 = 0;
bt1[0] = 0;
bt2[0] = 0;
r[0] = 0;
bt1a[0] = 0;
bt2a[0] = 0;
istop[0] = Val1[0];
stop = Val1[0];
bstop[0] = 0;
sstop = 0;
//==================================Indicators====== ======================
{
if ( value2 < x2 AND abs( Close - Close[i-2] ) > range1 )
p = 1 ;
else
{
if ( value2 > x1 AND abs( Close - Close[i-2] ) > Range1 )
p = 2 ;

else

p = 0;
}
}

if ( ( value2 < x2 AND p == 1 ) OR ( value2 < x2 AND p == 0 ) )

{
if ( abs( Close - Close[i-2] ) > Range1 )
{
Plot1 = H;
Plot2 = L;
}
else
{
Plot1 = Plot1[i-1];
Plot2 = Plot2[i-1];
}
}
else
{
if ( ( value2 > x1 AND p == 2 ) OR ( value2 > x1 AND p == 0 ) )

{
Plot1 = L;
Plot2 = H;
}
else
{
Plot1 = Plot1[i-1];
Plot2 = Plot2[i-1];
}
}

//==================KBrain Signal ====================================
{
if ( value2 < x2 AND ( abs( Close - Close[i-2] ) > Range1 ) )
{
if ( p == 1 OR p == 0 )
Value3 = L - range3;

val1 = Value3;

p = 1;

temp = 1;
}
else
{
temp = temp[i-1];
}

{
if ( value2 > x1 AND ( abs( Close - Close[i-2] ) > Range1 ) )
{
if ( p == 2 OR p == 0 )
Value3 = H + range3;

val2 = Value3;

p = 2;

temp = 2;;
}

}
}

{

if ( temp == 1 AND Plot1 > 0 AND tm != 1 )
tm = 1;

if ( temp == 2 AND Plot2 > 0 AND tm != 2 )
tm = 2;

}

//===============================stop=============== =========================
{
if ( value2 < x2 AND ( abs( Close - Close[i-2] ) > Range1 )AND p != 2 )

{
value3 = L - range3;
va1 = Value3;
p1 = 2;
r = Va1;
bstop = Va1;
bt2 = bt2[i-1];
}

if ( value2 > x1 AND ( abs( Close - Close[i-2] ) > Range1 )AND p != 1 )

{
Value3 = H + range3;
va2 = Value3;
p1 = 1;

r = Va2;
sstop = Value3;
bt1 = bt1[i-1];
}

}



if ( val1 == 0 AND val2 == 0 AND p == 0 )
{
bstop = bstop[i-1];
sstop = sstop[i-1];
}


if ( bstop < bstop[i-1] AND tm == 1 AND tm[i-1] == 1 )
bstop = bstop[i-1];

if ( sstop > sstop[i-1] AND tm == 2 AND tm[i-1] == 2 )
sstop = sstop[i-1];

}

//=============================SYSTEM=============== =======================
Mycolor = IIf( p == 1, colorLime, IIf( p == 2, colorRed, colorBlue ) );

PlotShapes( shapeCircle* ( bts AND tm == 1 AND Ref( tm, -1 ) == 2 ), colorTurquoise, 0, bstop, 0 );

PlotShapes( shapeCircle* ( bts AND tm == 2 AND Ref( tm, -1 ) == 1 ), colorCustom12, 0, sstop, 0 );

PlotShapes( IIf( btst AND p == 1, shapeSmallCircle, Null ), colorTurquoise, 0, bstop, 0 );

Plot( IIf( btsl AND tm == 1, bstop, Null ), "", colorPaleBlue, 1 );

PlotShapes( IIf( btst AND p == 2, shapeSmallCircle, Null ), colorCustom12, 0, sstop, 0 );

Plot( IIf( btsl AND tm == 2, sstop, Null ), "", colorLightYellow, 1 );

Buy = Cover = ( bts AND tm == 1 AND Ref( tm, -1 ) == 2 );

Sell = Short = ( bts AND tm == 2 AND Ref( tm, -1 ) == 1 );

SellPrice = ValueWhen( Sell, C, 1 );

BuyPrice = ValueWhen( Buy, C, 1 );

Long = Flip( Buy, Sell );

Shrt = Flip( Sell, Buy );

_SECTION_END();

//Kwikpop PHPL Stamping starts

_SECTION_BEGIN("Kwikpop PHPL Stamping");
/* TSKPPivot and PivotPop
A PP (Pivot Point) occurs when A900 crosses over/under AutoStop and is
confirmed when ScoreCard value be >= 5/<= -5.
When A900 crosses over AutoStop and ScoreCard confirms with a reading
>= 5, then a new PL (Pivot Low) has been made. The PL point is the bar
that has the lowest low price since the last PH.
When A900 crosses under AutoStop and ScoreCard confirms witha reading
<= -5, then a new PH (Pivot High) and been made. The PH point is the bar
that has the highest high price since the last PL.
One can NOT have two consecutive PHs OR two consecutive PLs.

PP Trend requires 3 Pivot Points. THe PP trend is either Up (PPTrend = 1) or
Down (PPTrend = -1). There are 2 basic Pivot Point patterns: PL-PH-PL or PH-PL-PH.

Note: if 'M/W tick allowance is NOT equal to 0 then you must have Tick Size correctly
specified to get the correct results.

Pivot Pop Up occurs when: Pivot Pop Down occurs when:
Pivot Low Pivot High
Pivot Low has occured within the last X bars Pivot High has occured within the last X bars
A900 >= AutoStop A900 <= AutoStop
Fast2 = 1 Fast2 = -1
ScoreCard >= 5 ScoreCard <= -5
Close > MeanSwingLine (optional) Close < MeanSwingLine (optional)
Close > Upper Bollinger Band Close < Lower Bollinger Band
Close > Open Close < Open

*/
//SetBarsRequired(350, -0);

//user parameters
parmPlotScoreCard = 1;//ParamToggle("Plot KPScoreCard", "No|Yes", 1);
parmPlotA900AutoStop = 0;//ParamToggle("Plot A900/AutoStop", "No|Yes", 0);
parmA900Color = colorWhite;//ParamColor("A900 Color", colorWhite);
parmA900Style = styleLine;//ParamStyle("A900 Style", styleLine, maskAll);
parmAutoStopColor = colorYellow;//ParamColor("AutoStop Color", colorYellow);
parmAutoStopStyle = styleLine;//ParamStyle("AutoStop Style", styleLine, maskAll);
parmPPTextColor = colorBlack;//ParamColor("PP Text color", colorBlack);
parmPPTrndColorUp = colorLightGrey;//ParamColor("PP Trend Up color", colorGreen );
parmPPTrndColorDn = colorLightGrey;//ParamColor("PP Trend Dwn color", colorRed) ;
parmPPTextOffSet = 0.40;//Param("PP OffSet", 0.90, 0.40, 1.5, 0.1);
parmTickMultipler = 0;//Param("M/W tick allowance", 0, 0, 10, 1);
parmA900AutoStopX = 0;//ParamToggle("Plot A900/AutoStop Cross", "No|Yes");
parmA900AutoStopColorX = colorBlack;//ParamColor("A900/AutoStop Cross Color", colorBlack);
ParmSCThreshold = 5;//Param("ScoreCard Threshold", 5, 1, 9, 1);
parmVoice = 0;//ParamToggle("Pivot Voice", "No|Yes", 0);
parmPivotPop = 1;//ParamToggle("PivotPop", "No|Yes", 1);
parmBarCancel = 4;//Param("Bar Cancel", 4, 1, 20, 1);
parmFilter = ParamList("Filter", "None|KPMSL|KPWaterLevel|KPMedium", 0);
parmPlotFilter = 0;//ParamToggle("Plot Filter", "No|Yes", 0);
parmFilterColor = ColorRGB(127,255,212);//ParamColor("Filter Color", ColorRGB(127,255,212));
parmFilterStyle = styleLine;//ParamStyle("Filter Style", styleLine, maskAll);
parmBBPeriod = 20;//Param("Bollinger Band Period", 20, 2, 30, 1);
parmBBSD = 1;//Param("Bollinger Band width", 1.0, 0.5, 3.0, 0.5);
ParmPlotPPIndicators = 0;//ParamToggle("Plot Pivot Pop indicators", "No|Yes", 0);
parmBBColor = colorBlack;//ParamColor("BBands Color", colorBlack);
parmBBStyle = styleLine;//ParamStyle("BBands Style", styleLine, maskAll);
ParmDebug = 0;//ParamToggle("Debug", "No|Yes", 0);

// constants
_N(PaneName = Name() + Interval(2)+ _SECTION_NAME());
_N(NewBarName = "NewBar" + PaneName);

//functions
function NewBarP()
{
PrevDT = StaticVarGet( NewBarName);
DT = LastValue(DateTime());
StaticVarSet( NewBarName,DT);
return DT != PrevDT;
}
function MRoundP(Number, Multiple )
{
if(Multiple == 0 )
{

xMultiple = 0.01; }
else
{
xMultiple = Multiple;
}
Divided = Number / xMultiple;
intDivided = int(Divided);
intDivided = intDivided + round(Divided - intDivided);
return intDivided * xMultiple;
}

/*

// kasi Amibroker solution to eliminate ticker
//miscellaneous setups
ObjAB = CreateObject("Broker.Application");
ticker = objAB.Stocks(Name() );
if(ticker.TickSize == 0)
{
TickValue = 0.01; //set TickValue to a penney
}
else
{
TickValue = ticker.TickSize; // use Tick Size for this symbol
}
*/
//ticker = objAB.Stocks(Name() );
if(TickSize == 0)
{
TickValue = 0.01; //set TickValue to a penney
}
else
{
TickValue = TickSize; // use Tick Size for this symbol
}

NewBarSignal = NewBarP();
// KP Indicators
KPA900 = E_TSKPA900(Close);
KPAutoStop = E_TSKPAUTOSTOP(High,Low,Close);
Ctmpl = E_TSKPCOLORTMPL(Open,High,Low,Close,Volume); //ScoreCard
KPScoreCard = 0;
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd0 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd1 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd2 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd3 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd4 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd5 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd6 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd7 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd8 > 0, 1, -1);

if(parmDebug == 1)
{
printf("a900: %0.6f% \nAutoStop: %0.6f%\nScoreCard: %0.0f%\n", KPA900, KPAutoStop, KPScoreCard);
}
if(parmPlotScoreCard == 1)
{
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g% (%0.4f%) {{VALUES}}", O, H, L, C, SelectedValue( C - Ref(C, -1)) ));
//if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
//{
//ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.2f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
//}
Color = IIf(KPScoreCard >= parmSCThreshold, colorBlue, IIf(KPScoreCard <= -parmSCThreshold, colorRed, colorYellow) );
// kasi
//Plot( C, "Close", Color , styleNoTitle | styleBar | GetPriceStyle() );
Plot( C, "Close", Color , styleNoTitle | styleBar | styleLine );
}
//user want A900/AutoStop plotted
if(parmPlotA900AutoStop == 1)
{
Plot(KPA900, "A900", parmA900Color, parmA900Style);
Plot(KPAutoStop, "AutoStop", parmAutoStopColor, parmAutoStopStyle);
}
// find A900/AutoStop cross over/under with ScoreCard confirmation.
XOUp = (KPA900 > KPAutoStop) AND (KPScoreCard >= parmSCThreshold); // New Pivot Low
XODn = (KPA900 < KPAutoStop) AND (KPScoreCard <= -parmSCThreshold); // New Pivot High
if(parmDebug == 1)
{
printf(WriteIf(XOUp, "before= XOUp: True", "before= XOUp: False") + WriteIf(XODn, " XODn: True\n", " XODn: False\n") );
}
//remove duplicate signals
XOUp = ExRem(XOUp, XODn);
XODn = ExRem(XODn, XOUp);

if(parmDebug == 1)
{
printf(WriteIf(XOUp, "after= XOUp: True", "after= XOUp: False") + WriteIf(XODn, " XODn: True\n", " XODn: False\n") );
}
//find the current Pivot Points - PL and PH
//remember XOUp = 1 means a PL and XODn =1 means a PH
PLBars = IIf(XOUp, LowestSinceBars(XODn, L ,1), 0); //find the bar that produced the Lowest Low
PHBars = IIf(XODn, HighestSinceBars(XOUp, H, 1),0); //find the bar that produced the Highest High
//PLPrice = IIf(XOUp, Ref(L, -PLBars), 0);
//PHPrice = IIf(XODn, Ref(H, -PHBars),0);
PLPrice = Ref(L, -PLBars);
PHPrice = Ref(H, -PHBars);

//keep track of the previous Pivot Points
PrevPLBars = Ref(BarsSince(XOUp), -1) +1;
PrevPHBars = Ref(BarsSince(XODn), -1) +1;
PrevPLPrice = Ref(PLPrice, -prevPLBars);
PrevPHPrice = Ref(PHPrice, -PrevPHBars );
PivotsCloseEnough = TickValue * parmTickMultipler;
/*
// kasi Amibroker solution to eliminate ticker
PLDifference = MroundP(PLPrice - PRevPLPrice, ticker.TickSize);
PHDifference = MroundP(PHPrice - PrevPHPrice, ticker.TickSize);
*/
PLDifference = MroundP(PLPrice - PRevPLPrice, TickSize);
PHDifference = MroundP(PHPrice - PrevPHPrice, TickSize);
PPTrend = IIf(XOUp AND (PLDifference > PivotsCloseEnough) AND PrevPHPrice > PrevPLPrice AND PRevPHPrice > PLPrice, 1,
IIf(XOUp AND (PLDifference < - PivotsCloseEnough) AND PRevPHPrice > PrevPLPrice AND PrevPHPrice > PLPrice, -1,
IIf(XODn AND (PHDifference > PivotsCloseEnough) AND PrevPLPrice < PrevPHprice AND PrevPLPrice < PHPrice, 1,
IIf(XODn AND (PHDifference < -PivotsCloseEnough) AND PrevPLPrice < PrevPHPrice AND PrevPLPrice < PHPrice, -1, 0)) ));
/*
PPTrend = IIf(XOUp AND PLPrice > PRevPLPrice AND PrevPHPrice > PrevPLPrice AND PRevPHPrice > PLPrice, 1,
IIf(XOUp AND PLPrice < PRevPLPrice AND PRevPHPrice > PrevPLPrice AND PrevPHPrice > PLPrice, -1,
IIf(XODn AND PHPrice > PrevPHPrice AND PrevPLPrice < PrevPHprice AND PrevPLPrice < PHPrice, 1,
IIf(XODn AND PHPrice < PrevPHPrice AND PrevPLPrice < PrevPHPrice AND PrevPLPrice < PHPrice, -1, 0)) ));
*/
if(ParmDebug)
{
printf("Current PH Bar: %g% /Price: %g%\n", PHBars, PHPrice);
printf("Current PL Bar: %g% /Price: %g%\n", PLBars, PLPrice);
printf("Previous PH Bar: %g% /Price: %g%\n", PrevPHBars, PrevPHPrice);
printf("Previous PL Bar: %g% /Price: %g%\n", PrevPLBars, PrevPLPrice) ;
printf("PP Trend: %g%\n", PPTrend);
printf("PHPrice - PrevPHPrice: %g%\nPLPrice - PrevPLPrice: %g%\nPivotsCloseEnough: %g%\n", PHDifference, PLDifference, PivotsCloseEnough);
}
//PLot pivots as text
dist = 1* ATR(10);
//for( i = 0; i < BarCount -1; i++)
for( i = 0; i < BarCount ; i++)
{
if(XOUp[i ] == 1 ) //cross up -plot the Pivot Low

//swingLow = PLPrice[ i ];
{ // kasi kwikpop pivots
//PlotText("PL", i - PLBars, PLPrice - dist , parmPPTextColor, IIf(PPTrend == 1, parmPPTrndColorUp, IIf(PPTrend == -1, parmPPTrndColorDn, colorYellow) ));
//PlotText(WriteVal(PLPrice[ i ],1.3), i - PLBars, PLPrice - dist , parmPPTextColor, IIf(PPTrend == 1, parmPPTrndColorUp, IIf(PPTrend == -1, parmPPTrndColorDn, colorDefault) ));
PlotText(WriteVal(PLPrice[ i ],1.3), i - PLBars, PLPrice - dist , parmPPTextColor, IIf(PPTrend == 1, parmPPTrndColorUp, IIf(PPTrend == -1, parmPPTrndColorDn,ColorRGB(225,225,225)) ));


}
if(XODn[i ] == 1 ) //cross down - plot the pivot high
//swinghigh = PHPrice[ i ];
{// kasi kwikpop pivots
//PlotText("PH", i - PHBars, PHPrice + dist, parmPPTextColor, IIf(PPTrend == 1, parmPPTrndColorUp, IIf(PPTrend == -1, parmPPTrndColorDn, colorYellow) ));
//PlotText(WriteVal(PHPrice[ i ],1.3), i - PHBars, PHPrice + dist, parmPPTextColor, IIf(PPTrend == 1, parmPPTrndColorUp, IIf(PPTrend == -1, parmPPTrndColorDn, colorDefault) ));
PlotText(WriteVal(PHPrice[ i ],1.3), i - PHBars, PHPrice + dist, parmPPTextColor, IIf(PPTrend == 1, parmPPTrndColorUp, IIf(PPTrend == -1, parmPPTrndColorDn,ColorRGB(225,225,225)) ));

}
} //end For
// Plot A900/AutoStop cross over/under
if(parmA900AutoStopX == 1)
{
PlotShapes(IIf(Cross(KPA900, KPAutoStop), shapeUpTriangle, shapeNone), parmA900AutoStopColorX, 0, L, -20);
PlotShapes(IIf(Cross(KPAutoStop, KPA900), shapeDownTriangle, shapeNone), parmA900AutoStopColorX, 0, H , -20);
}
//PHLine = LineArray(BarCount - LastValue(PHBars) -3, LastValue(PHPrice), BarCount - LastValue(PHBars) +2, LastValue(PHPrice), 0);
//Plot(PHLine, "PH", colorBlack, styleLine);
//PLLine = LineArray(BarCount - LastValue(PLBars) -3, LastValue(PLPrice), BarCount - LastValue(PLBars) +2, LastValue(PLPrice), 0);
//Plot(PLLine, "PL", colorBlack, styleLine);
// identify M, lazy M, W and Lazy W formations
//voice
if(parmVoice ==1)
{
if(NewBarSignal)
{
if( LastValue(Ref(XODn, -1)) == 1 AND LastValue(Ref(PPTrend, -1)) == 1) Say(Interval(2) + " New pivot. Higher high.");
if( LastValue(Ref(XODn, -1)) == 1 AND LastValue(Ref(PPTrend, -1)) == -1) Say(Interval(2) + " New pivot. Lower high.");
if( LastValue(Ref(XODn, -1)) == 1 AND LastValue(Ref(PPTrend, -1)) == 0) Say(Interval(2) + " New pivot. M Top.");
if( LastValue(Ref(XOUp,-1)) ==1 AND LastValue(Ref(PPTrend, -1)) == 1) Say(Interval(2) + " New pivot. Higher low.");
if( LastValue(Ref(XOUp,-1)) ==1 AND LastValue(Ref(PPTrend, -1)) == -1) Say(Interval(2) + " New pivot. Lower low.");
if( LastValue(Ref(XOUp,-1)) ==1 AND LastValue(Ref(PPTrend, -1)) == 0) Say(Interval(2) + " New pivot. W bottom.");
}
}
//Pivot Pop code
if(parmPivotPop == 1)
{
//Kp indicators for Pivot Pop
dummy = E_TSKPFAST2(Open, High, Low, Close, Volume);
KPFast2 = IIf(tskp_fast2val1 > 0, 1, -1);
BarsSinceXOUp =BarsSince(XOUp);
BarsSinceXODn = BarsSince(XODn);

switch(parmFilter)
{
case "None":
PopFilter = True;
break;
case "KPMSL":
swVal = E_TSKPSWINGLINE(High, Low, Close);
KPMSL = tskp_swmean;
PopFilter = IIf(BarsSinceXOUp < BarsSinceXODn AND (C > KPMSL), True, IIf(BarsSinceXODn < BarsSinceXOUp AND (C < KPMSL), True, False));
break;
case "KPWaterLevel":
KPWaterlevel = E_TSKPWATERLEVEL(Open,High,Low,Close,Volume);
PopFilter = IIf(BarsSinceXOUp < BarsSinceXODn AND (C > KPWaterLevel), True, IIf(BarsSinceXODn < BarsSinceXOUp AND (C < KPWaterLevel), True, False));
break;
case "KPMedium":
dummy = E_TSKPMEDIUM(Close);
KPMediumUp = tskp_mediumup;
KPMediumDn = tskp_mediumdown;
KPMediumMA = tskp_mediumma;
KPMedium = KPMediumUp + KPMediumDn;
PopFilter = IIf(BarsSinceXOUp < BarsSinceXODn AND (KPMedium > KPMediumMA), True, IIf(BarsSinceXODn < BarsSinceXOUp AND (KPMedium < KPMediumMA), True, False));
break;
}

//calculations
UBB = BBandTop(C, parmBBPeriod, parmBBSD);
LBB = BBandBot(C, parmBBPeriod, parmBBSD);

if(parmDebug == 1)
{
printf("Fast2: %1.0f% \nUBB: %0.6f%\nLBB: %0.6f%\nC: %g%\n", KPFast2, UBB, LBB, C);
printf("Bars since Last XOUp: %1.0f%\nBars since last XODn: %1.0f%\n", BarsSinceXOUp, BarsSinceXODn );
printf("Bars since PPTrnd =1: %1.0f%\nBars since PPTrnd = -1: %1.0f%\n", BarsSince(PPTrend ==1), BarsSince(PPTrend == -1) );
printf("ParmFilter: " + parmFilter + "\nPopFilter: %g%\n", PopFilter);
switch(parmFilter)
{
case "None":
break;
case "KPMSL":
printf("KPMSL: %g%\n", KPMSL);
break;
case "KPWaterLevel":
printf("KPWaterlevel: %g%\n", KPWaterLevel);
break;
case "KPMedium":
printf("KPMedium: %g%\nKPMediumMA: %g%\n", KPMedium, KPMediumMA);
break;
}
}
PPopUp = (BarsSince(PPTrend == 1) <= parmBarCancel) AND (BarsSince(XOUp) <= parmBarCancel) AND (KPA900 >= KPAutoStop) AND(KPFast2 == 1) AND (KPScoreCard >= 5)
AND PopFilter
AND (C > UBB) AND (C > O) ;
PPopUp = IIf( PPopUp AND Sum(PPopUP, BarsSince(XOUp)+1) == 1, True, False ); //keep only the 1st signal
PPopDn = (BarsSince(PPTrend == -1) <= parmBarCancel) AND (BarsSince(XODn) <= parmBarCancel) AND (KPA900 <= KPAutoStop) AND(KPFast2 == -1) AND (KPScoreCard <= -5)
AND PopFilter
AND (C < LBB) AND (C < O) ;
PPopDn = IIf( PPopDn AND Sum(PPopDn, BarsSince(XODn) + 1) == 1, True, False); //keep only the first signal
if(parmDebug == 1)
{
printf(WriteIf(PPopUp,"PPopUp: True", "PPopUp: False") + WriteIf(PPopDn, " PPopDn: True\n", " PPopDn: False\n") );
printf("PPopUp sum: %1.0f% \nPPopDn sum: %1.0f%", Sum(PPopUP, BarsSince(XOUp)) , Sum(PPopDn, BarsSince(XODn)) );
}
// Plots
// kasi PlotShapes(IIf(PPopUp, shapeHollowUpArrow, shapeNone), colorDarkBlue, 0, L, -30);
//PlotShapes(IIf(PPopDn, shapeHollowDownArrow, shapeNone), colorDarkRed, 0, H, -30);

if(ParmPlotPPIndicators == 1) //plot the Pivot Pop Indicators
{
Plot(UBB, "Upper BB", parmBBColor, parmBBStyle);
Plot(LBB, "Lower BB", parmBBColor, parmBBStyle);
if(parmPlotA900AutoStop == 1)
{
Plot(KPA900, "A900", parmA900Color, parmA900Style);
Plot(KPAutoStop, "AutoStop", parmAutoStopColor, parmAutoStopStyle);
}
Plot( 0.5, "Fast2", IIf(tskp_fast2val1 > 0, parmPPTrndColorUp, parmPPTrndColorDn) , styleArea | styleNoLabel | styleOwnScale , 0, 10);
} //endif parmPlotPPIndicators
if(parmPlotFilter == 1)
{
switch(parmFilter)
{
case "None":
break;
case "KPMSL":
Plot(KPMSL, "KPMSL", parmFilterColor, parmFilterStyle);
break;
case "KPWaterLevel":
Plot(KPWaterLevel, "KPWaterLevel", parmFilterColor, parmFilterStyle);
break;
case "KPMedium":
// HMM how to print Medium on a price chart
break;
}
} //endif parmPlotFilter
} // end if parmPivotPop
_SECTION_END();

// Kwikpop ends
 

Similar threads

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?