Simple Coding Help - No Promise.

hello

i want engulfing candles to be plotted on charts ( if possible like pinbars are plotted on market calls afl on pin bars )

i searched wise stock and find one afl which i also tried to edit --- but no use. it shows syntax errors. if i use the whole afl the chart will look clumsy so i need only engulfing candles..

i dont need exporation only plotting on chart .

i am pasting the edited afl of wise stock trader

_SECTION_BEGIN("CANDLE REWORKING combination of Meta TC TS");
O1 = Ref(O,-1);O2 = Ref(O,-2);O3 = Ref(O,-3);O4 = Ref(O,-4);
H1 = Ref(H,-1);H2 = Ref(H,-2);H3 = Ref(H,-3);H4 = Ref(H,-4);
C1 = Ref(C,-1);C2 = Ref(C,-2);C3 = Ref(C,-3);C4 = Ref(C,-4);
L1 = Ref(L,-1);L2 = Ref(L,-2);L3 = Ref(L,-3);L4 = Ref(L,-4);

GraphXSpace = 5;

/*UP and Down Trend of last 4 days*/

dtrend = (L1 < L2)AND (L2 < L3) AND (L3 < L4);
utrend = (H1 > H2)AND (H2 > H3) AND (H3 > H4);

/*Maximum High Today - (MHT)
Today is the maximum High in the last 5 days*/
MHT= HHV(H,5)==H;

/*Maximum High Yesterday - (MHY)
Yesterday is the maximum High in the last 5 days*/
MHY= HHV(H,5)==Ref ( H, -1);

/*Minimum Low Today - (MLT)
Today is the minimum Low in the last 5 days*/
MLT= LLV(L,5)==L;

/*Minimum Low Yesterday - (MLY)
Yesterday is the minimum Low in the last 5 days*/
MLY= LLV(L,5)==Ref(L,-1);

/*Peircing Percent*/

PiercingPercent = ((C - C1)/C1) * 100;











LongBlackCandle = (O>C AND (O-C)/(.001+H-L)>.6);





LongWhiteCandle = ((C>O) AND ((C-O)/(.001+H-L)>.6));




OpenGap = ((C1 - O)/O) * 100;

CloseGap = ((O - C1)/C1) * 100;





///////************************************** Engulfings ********************************************//////////////
BullishEngulfing = (LongWhiteCandle AND dtrend AND (O1>C1) AND (C>O) AND (C>= O1) AND (C1>= O) AND ((C-O)>(O1-C1)));




_SECTION_BEGIN("");
BI = BarIndex();
BV = BeginValue(BarIndex());
EV = EndValue(BarIndex());
SV = SelectedValue(BarIndex());

BuWholeEngulf = 0;
CurrentBar = SelectedValue( BarIndex() );
FirstBullBar = CurrentBar - 30;
Bar = CurrentBar;

do
{
if ( SelectedValue(Close) >= ( Open[Bar-1]) AND SelectedValue(Close) >= ( Close[Bar-1]) AND SelectedValue(Open) <= ( Open[Bar-1]) AND SelectedValue(Open) <= ( Close[Bar-1]) )
{
BuWholeEngulf = BuWholeEngulf + 1;
Bar--;
}

}
while( Bar> FirstBullBar AND SelectedValue(Close) >= ( Open[Bar-1]) AND SelectedValue(Close) >= ( Close[Bar-1]) AND SelectedValue(Open) <= ( Open[Bar-1]) AND SelectedValue(Open) <= ( Close[Bar-1]));
_SECTION_END();


_SECTION_BEGIN("");








BearishEngulfing = (MHT AND utrend AND LongBlackCandle AND (C1>O1) AND (O>C) AND (O>= C1) AND (O1>= C) AND ((O-C)>(C1-O1)));



_SECTION_BEGIN("");
BI = BarIndex();
BV = BeginValue(BarIndex());
EV = EndValue(BarIndex());
SV = SelectedValue(BarIndex());

BeWholeEngulf = 0;
CurrentBar = SelectedValue( BarIndex() );
FirstBearBar = CurrentBar - 30;
Bar = CurrentBar;

do
{

if ( SelectedValue(Close) <= ( Open[Bar-1]) AND SelectedValue(Close) <= ( Close[Bar-1]) AND SelectedValue(Open) >= ( Open[Bar-1]) AND SelectedValue(Open) >= ( Close[Bar-1]) )
{

BeWholeEngulf = BeWholeEngulf + 1;

Bar--;
}

}
while( Bar> FirstBearBar AND SelectedValue(Close) <= ( Open[Bar-1]) AND SelectedValue(Close) <= ( Close[Bar-1]) AND SelectedValue(Open) >= ( Open[Bar-1]) AND SelectedValue(Open) >= ( Close[Bar-1]));

_SECTION_END();

















/***********************************************************************************
LABELS
***********************************************************************************/

_SECTION_BEGIN("PRASAD SYSTEMS");
Param("DEDICATED TO MY FATHER",5);
_SECTION_END();

_SECTION_BEGIN("");
CANDLE_LABELS_TOGGLE = ParamToggle("Labels","Off|On",1);
if(CANDLE_LABELS_TOGGLE==1)
{

for( a = 0; a < BarCount; a++ )
{


if (BullishEngulfing[a]) (PlotText(" BuE",a,H[a]+2,colorPaleGreen));

if (BearishEngulfing[a]) (PlotText("BeE",a,H[a]+2,colorRed));


}
}

CANDLE_ARROWS_TOGGLE = ParamToggle("CANDLE ARROWS","Off|On",1);
if(CANDLE_ARROWS_TOGGLE==1)
{

(PlotShapes(BullishEngulfing * shapeSmallUpTriangle,colorPaleGreen,0,H,10));


(PlotShapes(BearishEngulfing * shapeSmallDownTriangle,colorLightOrange,0,H,-20));


}
_SECTION_END();




























BULL_ENG = LastValue(Cum(BullishEngulfing));
printf("Bull Eng %g\n",BULL_ENG);
PlotText( "*",BULL_ENG,H[BULL_ENG]+4, colorYellow );

CURRENT_BULL_ENG = Ref(BullishEngulfing,0);




















PRI_CANDLE_BULLISH = WriteIf(BullishEngulfing,"Bullish Engulfing","");

PRI_CANDLE_BEARISH = WriteIf(BearishEngulfing,"Bearish Engulfing","");


/******************************************************************************************
CHART TITLES
***********************************************************************************************/

_SECTION_BEGIN("BACK COLR");

GfxSetOverlayMode(1);
SetChartBkColor( ParamColor("Chart Color", colorBlack));
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/20 ); /* Up down name*/
GfxSetTextAlign( 6 );// center alignment
GfxSetTextColor( ParamColor("Text Color", ColorHSB( 42, 42, 42 ) ));
GfxSetBkMode(0); // transparent
GfxTextOut( Name(), Status("pxwidth")/2, Status("pxheight")/7);
GfxSelectFont("Tahoma", Status("pxheight")/30 );
GfxTextOut( IndustryID(1), Status("pxwidth")/2, Status("pxheight")/5 ); /* Up Down Sector*/

GfxSelectFont("Tahoma", Status("pxheight")/40 );
GfxTextOut( "Feedback [email protected]", Status("pxwidth")/2, Status("pxheight")/4);
GfxSelectFont("Tahoma", Status("pxheight")/20 );
GfxTextOut( " BALKRISHNA CANDLE CHARTS ", Status("pxwidth")/2, Status("pxheight")/15 );

















k = (GetPerformanceCounter()/100)%256;
printf("GetPerformance Counter %g",k);


GfxSelectFont("Arial Narrow", 10, 700 );
GfxSetBkMode(1);
GfxSetTextColor(colorYellow);
GfxTextOut("Dedicated to the loving memory of MY FATHER on his 75th Birth Anniversay - LATE BALKRISHNA RAMCHANDRA RAO 13.10.1935",100+k ,12);
GfxSelectFont("Century Goliath",12,500);
GfxSetBkMode(1);
GfxSetTextColor(colorLime);
GfxTextOut("Prasad Inspirations",80 ,25);
RequestTimedRefresh(1);
_SECTION_END();

SetBarFillColor( IIf(O>C,colorOrange, colorDarkGreen ) );
Plot( C, "Price", IIf( O>C,colorRed, colorGreen ), styleCandle );

Plot(C,"Close",colorWhite,64);
Chg=Ref(C,-1);
Title = EncodeColor(colorYellow)+ Title = Name() + " " + EncodeColor(2) + Date() +EncodeColor(11) + EncodeColor(colorWhite) + "{{INTERVAL}} " +
EncodeColor(55)+ " Open: "+ EncodeColor(colorWhite)+ WriteVal(O,format=1.2) +
EncodeColor(55)+ " High: "+ EncodeColor(colorWhite) + WriteVal(H,format=1.2) +
EncodeColor(55)+ " Low: "+ EncodeColor(colorWhite)+ WriteVal(L,format=1.2) +
EncodeColor(55)+ " Close: "+ WriteIf(C> Chg,EncodeColor(colorBrightGreen),EncodeColor(colorRed))+ WriteVal(C,format=1.2)+
EncodeColor(55)+ " Change: "+ WriteIf(C> Chg,EncodeColor(colorBrightGreen),EncodeColor(colorRed))+ WriteVal(ROC(C,1),format=1.2)+ "%"+
EncodeColor(55)+ " Volume: "+ EncodeColor(colorWhite)+ WriteVal(V,1)



+"\n"+"\n"

+"\n"+EncodeColor(colorWhite)+"> Candle : "+EncodeColor(colorBrightGreen)+PRI_CANDLE_BULLISH +

EncodeColor(colorRed)+PRI_CANDLE_BEARISH + EncodeColor(colorRed)+"."+


"\n"+/***********************************************************************************************
Standards of Cover (Moderate and low Reliability)
/****************************************************************************************************/
EncodeColor(colorOrange)+
WriteIf(BullishEngulfing,"> Prior Trend " + EncodeColor(colorWhite) + ": Bearish.\n"+
EncodeColor(colorOrange)+"> Type " + EncodeColor(colorWhite) + ": Reversal.\n"+
EncodeColor(colorOrange)+"> Confirmation " + EncodeColor(colorWhite) + ": Required.\n"+"\n"+
EncodeColor(colorLightBlue)+"> IMPORTANT FACTORS " + EncodeColor(colorWhite) + "\n"+
EncodeColor(colorYellow)+"1) Disparity of white vs black body is indicative of the\n emerging bull power.\n" +
"2) Higher probability of reversal if there is heavy\n volume on the day of second real body.\n" +
"3) Higher probability of reversal if the second day\n body engulfs more than one real body. \n" +
"4) Greater the open gaps down from previous close\n greater the probability of strong reversal. \n" +
"5) If engulfing body engulfs body and shadow of the\n previous day may be probability of strong reversal. \n \n" +

EncodeColor(colorPink)+" > CONFIRMATION :\n Third Day Confirmation needed in form of a \na) white candle ,\nb) large gap up or \nc) higher close.\n\n" +
EncodeColor(colorRed)+" > CURRENT CANDLE\n"+
EncodeColor(colorAqua)+" * The gap down opening of the current candle is\n "+Prec(OpenGap,1)+" % from previous Day.\n" +
"* The current white body is engulfing the\n preceeding "+BuWholeEngulf+" bodies","")+




EncodeColor(colorOrange)+
WriteIf(BearishEngulfing,"> Prior Trend " + EncodeColor(colorWhite) + ": Bullish.\n"+
EncodeColor(colorOrange)+"> Type " + EncodeColor(colorWhite) + ": Reversal.\n"+
EncodeColor(colorOrange)+"> Confirmation " + EncodeColor(colorWhite) + ": Required.\n"+"\n"+
EncodeColor(colorLightBlue)+"> IMPORTANT FACTORS " + EncodeColor(colorWhite) + "\n"+
EncodeColor(colorYellow)+"1) Disparity of black vs white body is indicative of the\n emerging bear power.\n" +
"2) Higher probability of reversal if there is heavy\n volume on the day of second real body.\n" +
"3) Higher probability of reversal if the second day\n body engulfs more than one real body. \n" +
"4) Greater the open gaps up from previous close\n greater the probability of strong reversal. \n" +
"5) If engulfing body engulfs body and shadow of the\n previous day may be probability of strong reversal. \n \n" +

EncodeColor(colorPink)+" > CONFIRMATION :\n Third Day Confirmation needed in form of a \na) black candle ,\nb) large gap down or \nc) lower close.\n\n" +
EncodeColor(colorRed)+" > CURRENT CANDLE\n"+
EncodeColor(colorAqua)+" * The gap up opening of the current candle is\n "+Prec(CloseGap,1)+" % from previous Day.\n" +
"* The current black body is engulfing the\n preceeding "+BeWholeEngulf+" bodies","") ;
 
Does anyone know the method to calculate the tax on trades in gain? In backtest I would need to climb 26% of the profit of course only on trades in gain.

-should be like this: if tradepoint profit>0 charge commission fee of ...x% of the gain (only on the gain result not on the enterily trade value)

Thanks
 
Last edited:
Dear Experts,

The below AFL (from wisetrader) Scans for stocks with GAP yet to be filled. I want to modify this AFL with Filter that it selects only those stocks where the GAP-length is more than 5% of the HIGH of last candle (in case of GAP-UP) and more than 5% of the LOW of last candle (in case of GAP-Down).

I tried but could not do it. Request the experts to suggest what modification & where in the AFL is to be done.

Thanx

The AFL is -
#_SECTION_BEGIN("GAP by DojiChartTrader TJ");
//****************************************//
// Author: [email protected]
// Web: http://www.chartreader.co.in/
//****************************************//

_N(Title = StrFormat(EncodeColor( colorGold) + "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
SetChartOptions(0,chartShowArrows|chartShowDates);

// Background to suit my blog
SetChartBkColor(ColorRGB(23,23,23));

// Display line chart for tick data automatically
priceStyle = IIf( (Interval(0) == -900), styleLine, styleBar);

// Quick counting of bars by range selector
if (BeginValue(BarIndex()) != 0 AND EndValue(BarIndex()) != BarCount-1) {
range = EndValue(BarIndex())-BeginValue(BarIndex());
Title += StrFormat("\nRange Bars: %g", range);
}

CandleBorder = ParamColor("Candle Border Color", colorBlack );
UpCandleColor = ParamColor("Up Candle Color", colorGreen );
DownCandleColor = ParamColor("Down Candle Color", colorRed );

// set amibroker to display colored bars
Graph0BarColor = IIf( C > O,UpCandleColor ,DownCandleColor);

Plot( C, "Close", CandleBorder, styleNoTitle | ParamStyle("Style") | priceStyle );

//****************************************//
// Author: [email protected]
// Web: http://www.chartreader.co.in/
//****************************************//

_N(Title = StrFormat(EncodeColor( colorGold) + "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
SetChartOptions(0,chartShowArrows|chartShowDates);

// Background to suit my blog
SetChartBkColor(ColorRGB(23,23,23));

// Display line chart for tick data automatically
priceStyle = IIf( (Interval(0) == -900), styleLine, styleBar);

// Quick counting of bars by range selector
if (BeginValue(BarIndex()) != 0 AND EndValue(BarIndex()) != BarCount-1) {
range = EndValue(BarIndex())-BeginValue(BarIndex());
Title += StrFormat("\nRange Bars: %g", range);
}

CandleBorder = ParamColor("Candle Border Color", colorBlack );
UpCandleColor = ParamColor("Up Candle Color", colorGreen );
DownCandleColor = ParamColor("Down Candle Color", colorRed );

// set amibroker to display colored bars
Graph0BarColor = IIf( C > O,UpCandleColor ,DownCandleColor);

Plot( C, "Close", CandleBorder, styleNoTitle | ParamStyle("Style") | priceStyle );



///////////////////////////////////////////////////////////////////////////////
// Gap Finder
// AFL that plots that unfilled Gaps encountered within the last N bars.
// Author : Adheer Pai ([email protected])
///////////////////////////////////////////////////////////////////////////////

// Input : The number of bars ago from where to start looking for gaps.
// Default is 250 : So, by default we search for Gaps found in last 250 trading days ( 1 year )
period = Param("Lookback Period", 250, 15, 500);
// If we do not have enough bars, adjust the period accordingly.
if( BarCount - period - 1 < 0 ) period = BarCount - 2;

bIsGapUp = ( L > Ref(H, -1) ); // Identify GapUp bars
bIsGapDn = ( H < Ref(L, -1) ); // Identify GapDown bars

// We are not interested in Gap Ups and Gap Downs before the Period e.g. before the last 250 bars.
// So we clear the values for bars before the ones we are interested in.
for( i = 0 ; i < (BarCount - 1 - period) ; i++ )
{
bIsGapUp = False;
bIsGapDn = False;
}

// Now plot GapUp bars with a Up-Triangle below its low.
PlotShapes(IIf(bIsGapUp, shapeSmallUpTriangle, shapeNone), colorBlue, 0, L, -12 );
// Now plot GapDown bars with a Down-Triangle below its high.
PlotShapes(IIf(bIsGapDn, shapeSmallDownTriangle, shapeNone), colorRed, 0, H );

// Now walk from the first bar (e.g 250 bars ago, to the current bar)
for( i = (BarCount - period - 1) ; i <= (BarCount - 1) ; i++ )
{
dUpper = 0.0; dLower = 0.0; bFilled = True;
// Is the current bar a Gap-Up bar ?
if( bIsGapUp == True )
{
// If yes, the store the Gap (Upper value) and Lower values.
dUpper = L; dLower = H[i-1]; bFilled = False;
// Now walk till the current bar and see if the Gap values have been filled from Above.
// I.e prices are falling and the gap is being falled.
for( j = i+1; j <= (BarCount - 1) ; j++ )
{
// Check whether the current low is lesser than the Gap high. If yes, the Gap
// has been penetrated.
if( L[j] < dUpper )
{
dUpper = L[j];
// Determine whether the Gap has been fully penetrated - if yes, then the
// Gap has been filled.
if( dUpper <= dLower ) bFilled = True;
}
if( bFilled == True ) break;
}
}
else if( bIsGapDn == True )
{
// Same logic as GapUp - except we check whether the Gap has been pierced from Below.
// i.e Prices are rising and the Gap has been filled.
dUpper = L[i-1]; dLower = H; bFilled = False;
for( j = i+1; j <= (BarCount - 1) ; j++ )
{
if( H[j] > dLower )
{
dLower = H[j];
if( dLower >= dUpper ) bFilled = True;
}
if( bFilled == True ) break; // Gap was filled, so move on to find the next gap.
}
}
if( bFilled == False ) // Gap Not filled - so plot horizontal line at the Gap Level.
{
pLine = LineArray(i-1, dLower, BarCount-1,dLower, 1);
Plot(pLine, "", colorRed, styleDashed);
pLine = LineArray(i-1, dUpper, BarCount-1, dUpper, 1);
Plot(pLine, "", colorBlue, styleDashed);
}
}
_SECTION_END();
 
can any1 help me in implementing "look inside the bar" feature in backtesting.

suppose my system buy when prices cross above ema 14 with stop loss at ema 22 in daily timeframe. in real time i want to execute the order as soon as i get the signal .
but backtesting does not consider intrabar movement.it only consider if closing price of day satisfies my condition. so my idea is to develop an afl to backtest the above system which can consider finer resolution data(suppose 1 min) to look what was happening inside bar. so we can get realistic picture of system performance.
above feature is called by different name in different software-
for ex multichart call it bar magnifier, tradestation call it "look inside the bar" ..or tick by tick backtesting.

pls some1 help me to implement this backtesting feature in amibroker.
thnx
 
to be more precise this is what i want to implement in amibroker-
multichart bar magnifier feature-

The Bar Magnifier backtest feature is important for precise backtesting. Bar magnifier can be considered as a replay of the way a bar was formed. The user can choose a replay frequency that is based on number of ticks or number of minutes.

There is a tradeoff between the level of precision in a replay and memory requirements. Tick-by-tick replay is the most precise, but it also requires the most memory. If the strategy does not require high precision, then replays based on n-ticks or n-minutes may be sufficient.

For example, Bar Magnifier is helpful when both the profit target and stop loss occurred on the same bar. In this situation, it is unclear whether the profit target or the stop loss occurred first. With Bar Magnifier, MultiCharts is able to see how the bar was formed to determine whether the profit target or the stop loss occurred first.
https://www.multicharts.com/trading-software/index.php/Bar_Magnifier
or
tradestation look inside bar feature-
Back-Testing Resolution-

Place a check mark next to Look-Inside-Bar Back-testing to enable the use of a sub-interval to identify price action occurring within each charted strategy bar.

_note_icon.gif Look-Inside-Bar-Backtesting has no effect on real-time data or strategy automation; it is a feature of TradeStation’s strategy backtesting only. It is designed to report more accurate backtesting results; it allows a strategy to examine a finer data interval than appears in your chart so as to more carefully reconstruct the historical trades as they might have occurred in real time. It is not necessary to use Intrabar Order Generation to take advantage of the improved back-test accuracy afforded by Look-Inside-Bar Backtesting. For more information on Intrabar Order Generation, see About Intrabar Order Generation or Format Strategy - Calculation.


If checked, the back-testing resolution is automatically selected based on the type of chart being used.

For weekly and monthly charts, Day is selected

For daily and intraday charts:

If you select Tick you'll be able to identify price action occurring within each charted strategy bar at the tick level.

If you select Intraday you change the number of minutes for each sub-interval used for back-testing.

Enter a value in the Maximum number of bars study will reference box to change the number of bars to reference.

Click OK when you have completed your changes or go on to the next properties section that you want to format.
http://www.clayburg.com/4_steps_system/4_steps_understanding_libbt.htm

pls help me to implementing this backtesting feature in amibroker- i believe amibroker can perform this as thomas mentioned this can be achieved using timeframefunctions.
pls pls help me
 

bunti_k23

Well-Known Member
Anybody willing to help? I managed to get 71% avg accuracy on 5m tf and 77% avg accuracy on 15m tf on a system which im tweaking. But there is only 1 prob, it is looking into the future means it is showing signals after sum bars...im trying to change the other part of the code so that the signal remains in their place and it shd not look into the future...
 
the following is an AFL for scaning/exploring various candle patterns !

i request from esteemed members of this forum that bullish and bearish engulfing candles be also included in this afl .

YOUR HELP WILL BE VERY MUCH APPRECIATED

best regards

HTML:
[QUOTE]Quote:
/************************************************** ****/
/* */
/* PATTERNS.AFL */
/* ============ */
/* (By A. S. Navale) */
/* */
/* This AFL marks different patterns on the chart. */
/* The Patterns to mark can be selected from the */
/* 'Parameters' Drop-down list which appears when */
/* right-click in the chart. By Fefault all patterns */
/* are marked. */
/* */
/* The Title of the chart displays the name of the */
/* pattern made by the candle which is selected. */
/* */
/* The patterns are: Inside Bar (IB), Doji, */
/* Double Doji, 3IB(Double Inside Bar), PopGun and */
/* Master Candle. */
/* */
/* You can also run Exploration to list the stocks */
/* which have the selected pattern. */
/* */
/************************************************** ****/


SetChartOptions(0, chartShowDates | chartWrapTitle);
SetChartBkColor(colorBlack);

DJ = CdDoji();
DblDJ = DJ AND Ref(DJ, -1);

OB = Outside();
IB = Inside();
IIB = IB AND Ref(IB, -1);

PopGun = OB AND Ref(IB, -1);

M = H < Ref(H, -4) AND Ref(H, -1) < Ref(H, -4) AND Ref(H, -2) < Ref(H, -4) AND Ref(H, -3) < Ref(H, -4) AND L > Ref(L, -4) AND Ref(L, -1) > Ref(L, -4) AND Ref(L, -2) > Ref(L, -4) AND Ref(L, -3) > Ref(L, -4);
MC = Null;

for(i = 4; i< BarCount; i++)
{
MC[i - 4] = M[i];
}

VMin = Param("Min Vol", 50000, 100, 1000000000, 100);

Fltr = ParamList("Filter on", "All,Doji,DoubleDoji,InsideBar,3IB,PopGun,MasterCa ndle");

IBTxt = WriteIf(IB, " Inside Bar", "");
IIBTxt = WriteIf(IIB, " 3IB", "");
DblDJTxt = WriteIf(DblDJ, " Double", "");
DJTxt = WriteIf(DJ, " Doji", "");
PGTxt = WriteIf(PopGun, " Pop Gun", "");
MCTxt = WriteIf(MC, " Master Candle", "");


if(Status("action") == actionIndicator)
{
_N(Title = StrFormat("{{NAME}}({{INTERVAL}}), {{DATE}} : {{OHLCX}}, V=%1.0f,", V) + IBTxt + IIBTxt + DblDJTxt + DJTxt + PGTxt + MCTxt);

Plot(C, "", colorLightGrey, styleCandle);
if(Fltr == "All")
{
PlotShapes(IIf(DJ, shapeSmallCircle, shapeNone), colorSkyblue, 0, L);
PlotShapes(IIf(DblDJ, shapeHollowCircle, shapeNone), colorSkyblue, 0, L);
PlotShapes(IIf(PopGun, shapeSmallSquare, shapeNone), colorYellow, 0, H, 12);
PlotShapes(IIf(IB, shapeHollowSmallCircle, shapeNone), colorGold, 0, H, 12);
PlotShapes(IIf(IIB, shapeDigit3, shapeNone), colorPink, 0, H, 12);
PlotShapes(IIf(MC, shapeCircle, shapeNone), colorYellow, 0, H, 12);
}
if(Fltr == "Doji")
{
PlotShapes(IIf(DJ, shapeSmallCircle, shapeNone), colorSkyblue, 0, L);
}
if	(Fltr == "DoubleDoji")
{
PlotShapes(IIf(DblDJ, shapeHollowCircle, shapeNone), colorSkyblue, 0, L);
}
if(Fltr == "PopGun")
{
PlotShapes(IIf(PopGun, shapeSmallSquare, shapeNone), colorYellow, 0, H, 12);
}
if(Fltr == "InsideBar")
{
PlotShapes(IIf(IB, shapeHollowSmallCircle, shapeNone), colorGold, 0, H, 12);
}
if(Fltr == "3IB")
{
PlotShapes(IIf(IIB, shapeDigit3, shapeNone), colorPink, 0, H, 12);
}
if(Fltr == "MasterCandle")
{
PlotShapes(IIf(MC, shapeCircle, shapeNone), colorYellow, 0, H, 12);
} 

}

if(Status("action") == actionExplore)
{
if(Fltr == "All") Filter = (V >= VMin) AND (DJ OR DblDJ OR IB OR IIB OR PopGun OR MC);
if(Fltr == "Doji") Filter = (V >= VMin) AND DJ;
if(Fltr == "DoubleDoji") Filter = (V >= VMin) AND DblDJ;
if(Fltr == "InsideBar") Filter = (V >= VMin) AND IB;
if(Fltr == "3IB") Filter = (V >= VMin) AND IIB;
if(Fltr == "PopGun") Filter = (V >= VMin) AND PopGun;
if(Fltr == "MasterCandle") Filter = (V >= VMin) AND MC;

SetOption("NoDefaultColumns", True);

AddTextColumn(Name(), "SYMBOL");
AddColumn(DateTime(), "DATE & TIME", formatDateTime);
AddColumn(C, "LAST CLOSE", 1.2);
AddColumn(V, "VOLUME", 1.0);
AddTextColumn(IBTxt, "Pattern");
AddTextColumn(IIBTxt, "Pattern");
AddTextColumn(DblDJTxt, "Pattern");
AddTextColumn(DJTxt, "Pattern");
AddTextColumn(PGTxt, "Pattern");
AddTextColumn(MCTxt, "Pattern");

}[/QUOTE]
 

amsin21

Well-Known Member
the following is an AFL for scaning/exploring various candle patterns !

i request from esteemed members of this forum that bullish and bearish engulfing candles be also included in this afl .

YOUR HELP WILL BE VERY MUCH APPRECIATED

best regards

HTML:
Please check these links, may be you can get the logic to meet the requirement.

http://backtestwizard.com/amibroker-afl-bearish-engulfing-pattern/

http://www.wisestocktrader.com/indicators/3212-candle-pattern-exploration

http://www.wisestocktrader.com/indicators/1384-candle-master
 
Last edited:
_SECTION_BEGIN("Background");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(ParamColor("Outer panel",colorGrey40)); // color of outer border
SetChartBkGradientFill( ParamColor("Inner panel upper",colorGrey40),ParamColor("Inner panel lower",colorBlack));
tchoice=Param("Title Selection ",2,1,2,1);

Plot(C, "", IIf(O>=C, colorOrange, colorGreen), ParamStyle("Price Style",styleCandle, maskPrice));


_SECTION_BEGIN("Fib Retracements");
fibs = ParamToggle("Plot Fibs","Off|On",1);
pctH = Param ("Pivot Hi %", 0.325,0.001,2.0,0.002);
HiLB = Param ("Hi LookBack",1,1,BarCount-1,1);
pctL = Param ("Pivot Lo %", 0.325,0.001,2.0,0.002);
LoLB = Param ("Lo LookBack",1,1,BarCount-1,1);
Back = Param ("Extend Left = 2",1,1,500,1);
Fwd = Param("Plot Forward", 0, 0, 500, 1);
text = ParamToggle("Plot Text","Off|On",1);
hts = Param ("Text Shift", -33.5,-50,50,0.10);
style =ParamStyle("Line Style",styleLine,styleNoLabel);
x = BarIndex();
pRp = PeakBars( H, pctH, 1) == 0;
yRp0 = SelectedValue(ValueWhen( pRp, H, HiLB));
xRp0 = SelectedValue(ValueWhen( pRp, x, HiLB));
pSp = TroughBars( L, pctL, 1) == 0;
ySp0 = SelectedValue(ValueWhen( pSp, L, LoLB));
xSp0 = SelectedValue(ValueWhen( pSp, x, LoLB));
Delta = yRp0 - ySp0;

function fib(ret)
{
retval = (Delta * ret);
Fibval = IIf(ret < 1.0
AND xSp0 < xRp0, yRp0 - retval, IIf(ret < 1.0
AND xSp0 > xRp0, ySp0 + retval,IIf(ret > 1.0
AND xSp0 < xRp0, yRp0 - retval, IIf(ret > 1.0
AND xSp0 > xRp0, ySp0 + retval, Null))));
return FibVal;
}

x0 = Min(xSp0,xRp0)-Back;
x1 = (BarCount -1);
//////////////////////////////////////////////////////////////////
r236 = fib(0.236); r236I = LastValue (r236,1);
r382 = fib(0.382); r382I = LastValue (r382,1);
r050 = fib(0.50); r050I = LastValue (r050,1);
r618 = fib(0.618); r618I = LastValue (r618,1);
r786 = fib(0.786); r786I = LastValue (r786,1);
e127 = fib(1.27); e127I = LastValue (e127,1);
e162 = fib(1.62); e162I = LastValue (e162,1);
e200 = fib(2.00); e200I = LastValue (e200,1);
e262 = fib(2.62); e262I = LastValue (e262,1);
e424 = fib(4.24); e424I = LastValue (e424,1);
//////////////////////////////////////////////////////////////////
p00 = IIf(xSp0 > xRp0,ySp0,yRp0); p00I = LastValue (p00,1);
p100 = IIf(xSp0 < xRp0,ySp0,yRp0); p100I = LastValue (p100,1);
color00 =IIf(xSp0 > xRp0,colorLime,colorRed);
color100 =IIf(xSp0 < xRp0,colorLime,colorRed);
//////////////////////////////////////////////////////////////////
numbars = LastValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
//////////////////////////////////////////////////////////////////
if(fibs==1)
{
Plot(LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back),"PR",32,8|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back),"PS",27,8|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r236,x1,r236,Back),"",45,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r382,x1,r382,Back),"",44,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r050,x1,r050,Back),"",41,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r618,x1,r618,Back),"",43,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r786,x1,r786,Back),"",42,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e127,x1,e127,Back),"e127",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e162,x1,e162,Back),"e162",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e200,x1,e200,Back),"p200",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e262,x1,e262,Back),"p262",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e424,x1,e424,Back),"p424",25,style|styleNoRescale,Null, Null,Fwd);
}
//////////////////////////////////////////////////////////////////
if(text==1)
{
PlotText(" 0% = " + WriteVal(p00,fraction), LastValue(BarIndex())-(numbars/hts), p00I + 0.05, color00);
PlotText("23% = " + WriteVal(r236,fraction), LastValue(BarIndex())-(numbars/hts), r236I + 0.05, 45);
PlotText("38% = " + WriteVal(r382,fraction), LastValue(BarIndex())-(numbars/hts), r382I + 0.05, 44);
PlotText("50% = " + WriteVal(r050,fraction), LastValue(BarIndex())-(numbars/hts), r050I + 0.05, 41);
PlotText("62% = " + WriteVal(r618,fraction), LastValue(BarIndex())-(numbars/hts), r618I + 0.05, 43);
PlotText("78% = " + WriteVal(r786,fraction), LastValue(BarIndex())-(numbars/hts), r786I + 0.05, 42);
PlotText("100% = " + WriteVal(p100,fraction), LastValue(BarIndex())-(numbars/hts),p100I + 0.05, color100);
PlotText("127% = " + WriteVal(e127,fraction), LastValue(BarIndex())-(numbars/hts),e127I + 0.05, 47);
PlotText("162% = " + WriteVal(e162,fraction), LastValue(BarIndex())-(numbars/hts),e162I + 0.05, 47);
PlotText("200% = " + WriteVal(e200,fraction), LastValue(BarIndex())-(numbars/hts),e200I + 0.05, 47);
PlotText("262% = " + WriteVal(e262,fraction), LastValue(BarIndex())-(numbars/hts),e262I + 0.05, 47);
PlotText("424% = " + WriteVal(e424,fraction), LastValue(BarIndex())-(numbars/hts),e424I + 0.05, 25);
}
_SECTION_END();
//////////////////////////////////////////////////////////////////
if (tchoice==1 )
{
_N(Title = EncodeColor(colorWhite)+StrFormat(" {{NAME}} - {{INTERVAL}} {{DATE}} Open: %g, High: %g, Low: %g, Close: %g {{VALUES}}",O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
}
//////////////////////////////////////////////////////////////////
if (tchoice==2 )
{
Title = EncodeColor(colorWhite)+ Date() + " Tick = " + EncodeColor(5) + Interval()+
EncodeColor(colorWhite) + " Open = " + EncodeColor(colorWhite) + O +
EncodeColor(colorWhite) + " High = " + EncodeColor(5) + H +
EncodeColor(colorWhite) + " Low = " + EncodeColor(colorRed) + L +
EncodeColor(colorWhite) + " Close = " + EncodeColor(colorWhite) + C + "\n" +
EncodeColor( colorWhite) +"_______________"+"\n"+
EncodeColor( colorWhite) + "424% = " + EncodeColor(25)+ e424 + " " +"\n"+
EncodeColor( colorWhite) + "262% = " + EncodeColor(47)+ e262 + " " +"\n"+
EncodeColor( colorWhite) + "200% = " + EncodeColor(47)+ e200 + " " +"\n"+
EncodeColor( colorWhite) + "162% = " + EncodeColor(47)+ e162 + " " +"\n"+
EncodeColor( colorWhite) + "127% = " + EncodeColor(47)+ e127 + " " +"\n"+
EncodeColor( colorYellow) + " Res = " + EncodeColor(32)+ p100 + " " +"\n"+
EncodeColor( colorWhite) + " 78% = " + EncodeColor(42)+ r786 + " " +"\n"+
EncodeColor( colorWhite) + " 62% = " + EncodeColor(43)+ r618 + " " +"\n"+
EncodeColor( colorWhite) + " 50% = " + EncodeColor(41)+ r050 + " " +"\n"+
EncodeColor( colorWhite) + " 38% = " + EncodeColor(44)+ r382 + " " +"\n"+
EncodeColor( colorWhite) + " 23% = " + EncodeColor(45)+ r236+ " " +"\n"+
EncodeColor( colorYellow) + " Sup = " + EncodeColor(34)+ p00 + " " ;
}
GraphXSpace=5;

SetChartOptions(1, chartShowDates); // put dates at bottom of chart

pr = Param("Elliot Wave minimum % move", 2, 1, 100);
// Beginner Elliot Wave stuff
EWpk = PeakBars(H, pr, 1) == 0;
EWtr = TroughBars(L, pr, 1) == 0;

// Intermediate Elliot Wave stuff
zz = Zig(C, pr);
zzHi = Zig(H, pr);
zzLo = Zig(L, pr);
Avg = (zzHi+zzLo)/2;

// Advanced Elliot Wave stuff
RetroSuccessSecret = IIf(EWpk, zzHi, IIf(EWtr, zzLo, IIf(Avg > Ref(Avg,-1), H, L)));
EW = Zig(RetroSuccessSecret, pr);

// Plot on price chart
/*Plot(C, "Close", colorBlack, styleCandle);*/
Plot(EW, "EW", colorWhite, styleLine);

// Plot buy and sell arrows
Buy = TroughBars(EW, pr, 1) == 0;
Sell = PeakBars(EW, pr, 1) ==0;
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,L,-15);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,L,-15);
PlotShapes(IIf(Buy,shapeSmallCircle,shapeNone),colorWhite,0,BuyPrice,0);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
PlotShapes(IIf(Sell,shapeSmallCircle,shapeNone),colorWhite,0,SellPrice,0);

AlertIf( Buy , "SOUND C:\\Windows\\Media\\Notify.wav", "Audio alert", 2 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\Tada.wav", "Audio alert", 2 );

_SECTION_BEGIN("Elliot Fractals");

/*
The basic definition of an 'up' fractal is a bar high that is both higher than the two bars immediately preceding it
and higher than the two bars immediately following it.
The lows of the bars are NOT considered in determining the up fractal progression.

If two bars in the progression have equal highs followed by two consecutive bars with lower highs,
then a total of six bars rather than the usual five bars will make up the progression.
The first High becomes the counting fractal. Reverse for 'down' fractals.

The 5 bar formation works best on Daily or longer time frame charts.For intraday data charts we often use 9 bar, 13 bar and 21 bar formations for fractal counting
*/
Up5BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND Ref(H,1) < H AND Ref(H,2) < H;
Up6BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND (H == Ref(H,1)) AND Ref(H,2) < H AND Ref(H,3) < H;
Down5BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND Ref(L,1) > L AND Ref(L,2) > L;
Down6BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND (L == Ref(L,1)) AND Ref(L,2) > L AND Ref(L,3) > L;

//TODO: More filtering: Show only troughs that are around atrough in trix(9).

PlotShapes( IIf(Down5BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);
PlotShapes( IIf(Down6BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);

PlotShapes( IIf(Up5BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);
PlotShapes( IIf(Up6BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);

Up = (Up5BarFractal OR Up6BarFractal);
Down = (Down5BarFractal OR Down6BarFractal);
//Removing false fractals:
DownSignal = Flip(Ref(Up,-1), Ref(Down,-1));
UpSignal = Flip(Ref(Down,-1), Ref(Up,-1));

LastHigh[0] = H[0];
LastLow[0] = L[0];

LastLowIndex = 0;
LastHighIndex = 0;
Valid = 0;
for (i=1; i < BarCount; i++)
{

LastHigh = LastHigh[i-1];
LastLow = LastLow[i-1];
if (Up)
{
Valid = True;
if (DownSignal)
{
//Sequence of 2 Up Fractals. Validate only the higher one.
Valid = H >= H[LastHighIndex];
Valid[LastHighIndex] = H[LastHighIndex] > H;
}
LastHigh = Max(H, H[LastHighIndex ]);
LastHighIndex = i;
}

if (Down)
{
Valid = True;
if (UpSignal)
{
//Sequence of 2 Down Fractals. Validate only the lower one.
Valid = L <= L[LastLowIndex];
Valid[LastLowIndex] = L[LastLowIndex] < L;
}

LastLow = Min(L, L[LastLowIndex]);
LastLowIndex = i;
}
}

TrixN = Trix(9);
TroughLow = Ref(TrixN, -3) > TrixN AND Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN AND Ref(TrixN, 3) > TrixN;
TroughHigh = Ref(TrixN, -3) < TrixN AND Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN AND Ref(TrixN, 3) < TrixN;
//TroughLow = Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN;
//TroughHigh = Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN;
ZeroValid = Cross(TrixN, 0) OR Cross(0, TrixN) OR Ref(Cross(TrixN, 0),1) OR Ref(Cross(0, TrixN),1);
ValidLow = TroughLow OR Ref(TroughLow, 1) OR Ref(TroughLow, 2) OR Ref(TroughLow, 3) OR Ref(TroughLow, 4);// OR Ref(TroughLow, 5));
ValidHigh = TroughHigh OR Ref(TroughHigh, 1) OR Ref(TroughHigh, 2) OR Ref(TroughHigh, 3) OR Ref(TroughHigh, 4);// OR Ref(TroughHigh, 5));

//Plot(LastHigh-10 ,"LastHigh", colorBlue, styleLine);
//Plot(LastLow-10 ,"LastLow ", colorRed, styleLine);
//Plot(Valid*5 + 10 ,"LastLow ", colorGreen, styleLine | styleThick);

//PlotShapes( IIf(Down AND Valid,shapeSmallUpTriangle,0) ,colorGreen, 0, L,-12);
//PlotShapes( IIf(Up AND Valid,shapeSmallDownTriangle,0) ,colorRed, 0, H,-12);
Maxi = Up AND (ValidHigh OR ZeroValid);
Mini = Down AND (ValidLow OR ZeroValid);
PlotShapes( IIf(Down AND (ValidLow OR ZeroValid),shapeSmallUpTriangle,0) ,colorBlue, 0, L,-12);
PlotShapes( IIf(Up AND (ValidHigh OR ZeroValid),shapeSmallDownTriangle,0) ,colorOrange, 0, H,-12);
//Plot(UpSignal*3+5,"UpSignal", colorBlue, styleLine| styleThick);
//Plot(DownSignal*3 ,"DownSignal", colorRed, styleLine| styleThick);

/*
LastMaxi = 0;
LastMini = 0;
ElliotLines = 0;
State = 0;
for (i=1; i < BarCount; i++)
{
State = State[i-1];
if (Maxi)
{
State = 1;//down
}

if (Mini)
{
State = 2;
}

}

PlotShapes(IIf(State > 0, shapeSmallCircle, 0), IIf(State == 1, colorRed, colorBlue), 0, IIf(State == 1, H, L), -5);
*/
//Line = LineArray( x0, y0, x1, y1, 1 );
//Plot( Line, "Trend line", colorBlue );

/*
Wave B
Usually 50% of Wave A
Should not exceed 75% of Wave A
Wave C
either 1 x Wave A
or 1.62 x Wave A
or 2.62 x Wave A
*/
function CorrectiveRatios(StartPrice, A, B, C, RatioDelta, Delta)
{

ALength = abs(startPrice - A); BLength = abs(A-B);
CLength = abs(B-C);

Ratio1 = BLength / CLength ;
Cond1 = Ration1 >= 0.5 - RatioDelta AND ratio1 <= 0.75 + RatioDelta;
Cond2 = abs(Clength - ALength) < Delta OR abs(Clength - 1.62 * ALength) < Delta OR abs(CLength - 2.62 * ALength) < Delta;

return Cond1 AND Cond2;
}

function ImpulseRules(StartPrice, One, Two, Three, Four, Five)
{
//Wave 2 should be beneath wave 1 start:
Cond1 = Two > StartPrice AND Two < One;
//Wave 4 - the same:
Cond2 = Four > Two AND Four < Three;
//Wave 5 should be <= wave 3
Cond3 = abs(Three-Two) >= abs(Five - Four);
//Wave 1 should be smaller than wave five, making wave 3 the biggest:
Cond4 = abs(StartPrice - One) < abs(Five - Four);
return Cond1 AND Cond2 AND Cond3 AND Cond4;
}
_SECTION_END();


_SECTION_BEGIN("Ribbon");
uptrend=PDI()>MDI()AND Signal()<MACD();
downtrend=MDI()>PDI()AND Signal()>MACD();


Plot( 1, /*efines the height of the ribbon in percent of pane width */"ribbon",
IIf( uptrend, colorGreen, IIf( downtrend, colorRed,IIf(Signal()<MACD(), colorYellow, 0 ))), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -1, 100 );
_SECTION_END();


_SECTION_BEGIN("Price With Regression Channel");


// Linear Regression Line with 2 Standard Deviation Channels Plotted Above and Below

P = ParamField("Price field",-1);
Daysback = Param("Period for Liner Regression Line",21,1,240,1);
shift = Param("Look back period",0,0,240,1);


// =============================== Math Formula =============================================================

x = Cum(1);
lastx = LastValue( x ) - shift;
aa = LastValue( Ref(LinRegIntercept( p, Daysback), -shift) );
bb = LastValue( Ref(LinRegSlope( p, Daysback ), -shift) );
y = Aa + bb * ( x - (Lastx - DaysBack +1 ) );


// ==================Plot the Linear Regression Line ==========================================================


LRColor = ParamColor("LR Color", colorCycle );
LRStyle = ParamStyle("LR Style");

LRLine = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null );
Plot( LRLine , "LinReg", LRCOLOR, LRSTYLE ); // styleDots );

// ========================== Plot 1st SD Channel ===============================================================

SDP = Param("Standard Deviation", 1.5, 0, 6, 0.1);
SD = SDP/2;

width = LastValue( Ref(SD*StDev(p, Daysback),-shift) ); // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET
SDU = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width , Null ) ;
SDL = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width , Null ) ;

SDColor = ParamColor("SD Color", colorCycle );
SDStyle = ParamStyle("SD Style");

Plot( SDU , "Upper Lin Reg", SDColor,SDStyle );
Plot( SDL , "Lower Lin Reg", SDColor,SDStyle );

// ========================== Plot 2d SD Channel ===============================================================

SDP2 = Param("2d Standard Deviation", 2.0, 0, 6, 0.1);
SD2 = SDP2/2;

width2 = LastValue( Ref(SD2*StDev(p, Daysback),-shift) ); // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET
SDU2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width2 , Null ) ;
SDL2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width2 , Null ) ;

SDColor2 = ParamColor("2 SD Color", colorCycle );
SDStyle2 = ParamStyle("2 SD Style");

Plot( SDU2 , "Upper Lin Reg", SDColor2,SDStyle2 );
Plot( SDL2 , "Lower Lin Reg", SDColor2,SDStyle2 );

// ============================ End Indicator Code ==============================================================

_SECTION_END();


_SECTION_BEGIN("trailing stop atr");
function vstop_func(tr)
{
trailArray[ 0 ] = C[ 0 ]; // initialize
for( i = 1; i < BarCount; i++ )
{
prev = trailArray[ i - 1 ];

if (C[ i ] > prev AND C[ i - 1 ] > prev)
{
trailArray[ i ] = Max(prev,C[ i ] - tr[ i ]);
}
else if (C[ i ] < prev AND C[ i - 1 ] < prev)
{
trailArray[ i ] = Min(prev,C[ i ] + tr[ i ]);
}
else if (C[ i ] > prev)
{
trailArray[ i ] = C[ i ] - tr[ i ];
}
else
{
trailArray[ i ] = C[ i ] + tr[ i ];
}
}
return trailArray;
}

per = Param("per",20, 5, 150, 1);
mult = Param("mult",0.5, 0.5, 4, 0.05);
tr = mult * ATR(per);
trailArray = vstop_func(tr);
//trailArray = Ref(trailArray,-1);

//LISTING 1: Zero-lag moving average

function ZeroLagMA( data, periods )
{
EMA1 = EMA( data, periods );
EMA2 = EMA( EMA1, periods );
Diff = EMA1 - EMA2;
return EMA1 + Diff;
}

Periods = Param("Periods", 20, 2, 100 );

//Plot( ZeroLagMA( Close, Periods ), "ZeroLagMA-"+Periods, colorYellow, styleDashed );

TrailStop = HHV( C - 2 * ATR(10), 15 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10);

_SECTION_BEGIN("ProjHL");
//Function pembulatan
function bulat(Lo)
{
return (
IIf(Lo<= 200,round(Lo/1)*1,
IIf(Lo<= 500,round(Lo/5)*5,
IIf(Lo<=2000,round(Lo/10)*10,
IIf(Lo<=5000,round(Lo/25)*25,
IIf(Lo> 5000,round(Lo/50)*50,0)))))
);
}

GfxSetOverlayMode(0);
GfxSelectFont("Arial",9, 700);
GfxSetTextColor( colorRose );
GfxSetBkMode(0); // transparent
GfxTextOut("PivHL = " + (H+L)/2, 250, 45);
GfxTextOut("Diff = " + (C-((H+L)/2)), 350, 45);
GfxSetTextColor( colorYellow );
GfxTextOut("TStop = " + bulat(TrailStop), 450, 45);
GfxTextOut("TPrc = " + bulat(ProfitTaker), 550, 45);



// PIVOT Calculation
p = bulat( H+ L + C )/3;
GfxSetTextColor( colorLightOrange );
GfxTextOut("Pivot = " +bulat(p), 350, 60);


rph1=(H+C+2*L)/2-L;
rph2=(2*H+L+C)/2-L;
rph3=(H+L+2*C)/2-L;
rpl1=(H+C+2*L)/2-H;
rpl2=(2*H+L+C)/2-H;
rpl3=(H+L+2*C)/2-H;
rph=IIf((C<O),rph1,IIf((C>O),rph2,IIf((C==O),rph3,0)));
rpl=IIf((C<O),rpl1,IIf((C>O),rpl2,IIf((C==O),rpl3,0)));
GfxSetTextColor( colorBrightGreen );
GfxTextOut("Proj-H = " + bulat(rph), 250, 60);
GfxSetTextColor( colorCustom12 );
GfxTextOut("Proj-L = " + bulat(rpl), 450, 60);
GfxSetTextColor( colorOrange );
GfxTextOut("Trail = " + bulat(trailArray), 550, 60);

//2 Week New High-New Low
HI = High > Ref(HHV(High,10),-1);
LI = Low < Ref(LLV(Low,10),-1);
HIV1= Ref(HHV(High,10),-1);
LIV1=Ref(LLV(Low,10),-1);
Variable = WriteIf(H>HIV1,"High",WriteIf(L<LIV1,"Low","Neutral"));
GfxSetTextColor( colorSkyblue );
GfxTextOut("2 WHL: " + HIV1+" : "+LIV1+ " " + Variable,290,75);
_SECTION_END();




hello frnds koi is afl ko right kar dega kya ???4 or 5 error show ho raha he :confused:
mere hisab se ye best afl he ,kisi website se utha kar laya hu :D ,mera mind isme nahi chalta he .......pls koi right copy post kar do bhai log.. :) :sos:
 

Similar threads