Simple Coding Help - No Promise.

Hello Respected Team,

I am working on an Amibroker RSI Based Exploration. I need to tweek the exploration in such a way that, it should pick

If Index is = 34959 current prices to pick

exploration to show ITM OTM and ATM

34900 CE
34800 CE
34700 CE
34600 CE

34900 PE
35000 PE
35100 PE
35200 PE
35300 PE

and pick respective Close rates from strike prices (Foreign Price)

Strike prices in the following format

INDEX-WK-34900C-I
INDEX-WK-34900P-I

Also, Filter Strike Prices on exploration if the RSI >60 of the strike prices.
 
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));


barcolor = IIf(C >= O,colorGreen,colorRed);
SetBarFillColor(IIf(C > O,ParamColor("Candle UP Color", colorGreen),IIf(C <= O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
PlotOHLC( O, H, L, C, "", barcolor, styleCandle );
_SECTION_END();


_SECTION_BEGIN("SuperTrend");

SetTradeDelays(1,1,1,1);

function ParamOptimize( pname, defaultval, minv, maxv, step )
{
return Optimize( pname,
Param( pname, defaultval, minv, maxv, step ),
minv, maxv, step );
}

StopATRPeriod = ParamOptimize("ATR period", 21, 13, 34,1 );
StopATRFactor = ParamOptimize("ATR multiple", 3.4, 2.1, 5, 0.1 );


HL = H - L;
MAHL = 1.5 * MA( HL, StopATRPeriod );
HiLo = IIf( HL < MAHL, HL, MAHL );
H1 = Ref( H, -1 );
L1 = Ref( L, -1 );
C1 = Ref( C, -1 );
Href = IIf( L <= H1, H - C1, ( H - C1 ) - ( L - H1 ) / 2 );
Lref = IIf( H >= L1, C1 - L, ( C1 - L ) - ( L1 - H ) / 2 );

diff1 = Max( HiLo, HRef );
diff2 = Max( diff1, LRef );

ATRmod = Wilders( diff2, StopATRPeriod );

sup = C - StopATRFactor * ATRmod ;
res = C + StopATRFactor * ATRmod ;
//}

// calculate trailing stop line
trailARRAY = Null;
trailstop = 0;
for( i = 1; i < BarCount; i++ )
{
//if( Started[ i ] == 0 ) continue;

if( C[ i ] > trailstop AND C[ i - 1 ] > trailstop )
trailstop = Max( trailstop, sup[ i ] );
else
if( C[ i ] < trailstop AND C[ i - 1 ] < trailstop )
trailstop = Min( trailstop, res[ i ] );
else
trailstop = IIf( C[ i ] > trailstop, sup[ i ], res[ i ] );

trailARRAY[ i ] = trailstop;
}


Buy_ATR_TSL = Cross( C, trailArray );
Sell_ATR_TSL = Cross( trailArray, C );

Short_ATR_TSL = Sell_ATR_TSL;
Cover_ATR_TSL = Buy_ATR_TSL;


tn = TimeNum();
startTime = 91500; // start in HHMMSS format
endTime = 150559; // end in HHMMSS format
endTime2 = 151400; // end2 in HHMMSS format for session exit
timeOK = tn >= startTime AND tn <= endTime;

Buy = BUY_ATR_TSL AND timeOK;
regular_sell = Sell_ATR_TSL AND timeOK;
session_exit = Cross(tn, endTime2);
Sell = regular_sell OR session_exit;

Short = Short_ATR_TSL AND timeOK;
regular_buy = Buy_ATR_TSL AND timeOK;
session_exit = Cross(tn, endTime2);
Cover = regular_buy OR session_exit;

Sell=ExRem(Sell,Buy);
Buy=ExRem(Buy,Sell) ;

cover=ExRem(cover,short);
short=ExRem(short,cover);

Filter=Buy OR Sell;

BuyPrice=ValueWhen(BUY,C);
SellPrice=ValueWhen(SELL,C);
ShortPrice=ValueWhen(SHORT,C);
CoverPrice=ValueWhen(Cover,C);

TRAILCOLOR =IIf(C>trailARRAY,colorDarkGreen ,colorRed);
Plot( trailARRAY,"trailing stop level", TRAILCOLOR, styleStaircase | styleThick );

PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorGreen, 0, L, Offset = -40 );
PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorLime, 0, L, Offset = -50 );
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorWhite, 0, L, Offset = -45 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, 0, H, Offset = -65 );
PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorRed, 0, H, Offset = 40 );
PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorOrange, 0, H, Offset = 50 );
PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), colorWhite, 0, H, Offset = -45 );
PlotShapes( IIf( Cover, shapeUpArrow, shapeNone ), colorBlue, 0, L, Offset = -65 );


AddColumn(C,"Close");
AddColumn(trailArray,"trailArray");
AddColumn(trailstop,"trailstop");

_SECTION_END();


IN THE ABOVE SUPER TREND I WANT FOLLOWING CHANGES

1. FOR BUY = BUYSIGNAL CANDLE AND NEXT CANDLE AFTER BUY SIGNAL HIGH BREAKOUT BUY
2. FOR SELL= SELL SIGNAL CANDLE AND NEXT CANDLE AFTER SELL SIGNAL LOW BREAKOUT SELL
PLEASE
CORRECTION.png
CORRECTION.png
 

josh1

Well-Known Member
Screenshot_1.png


The above chart has simple 5 MA . Is it possible in AFL to identify first cross of average everyday and plot a line from H L of that bar till the end of day?
 

Romeo1998

Well-Known Member
View attachment 46290

The above chart has simple 5 MA . Is it possible in AFL to identify first cross of average everyday and plot a line from H L of that bar till the end of day?
1623347361760.png


Code:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

e1 = EMA(C,15);
e2 = EMA(C,5);

Plot(e1,"",colorRed,1);
Plot(e2,"",colorBlue,1);
cond1 = Cross(e2,e1);

PlotShapes(IIf(cond1,shapeUpArrow,shapeNone),1,0,L,-12);
newday=DateNum()!=Ref(DateNum(),-1);

condsum = SumSince(newday,cond1);

Title+= "\nCross since new day = " + SelectedValue(condsum);

lowoffirstcond = ValueWhen(Ref(condsum,-1)==0,L);
highoffirstcond = ValueWhen(Ref(condsum,-1)==0,H);

Plot(IIf(condsum>=1,lowoffirstcond,null),"",colorViolet,1);
Plot(IIf(condsum>=1,highoffirstcond,Null),"",colorViolet,1);
Sir if cross is on 1st bar of day, it wont be counted :)
good luck :)
 
Hi:

The following is an AFL of 50 bar breakout in Amibroker but it's throwing errors. Can someone help in rectifying it please?

_DEFAULT_NAME()shows the section name or, if not present, the file name.
The items in {{}} are Short cuts for the Title block.

Alternatively, use:
Title = Name() + " " + Date() + " " + "{{INTERVAL}}" + _DEFAULT_NAME() + " Chart values : " +
" Close Price = " + C +
" EMA(C, " + WriteVal(LongPer, 1) + ") = " + WriteVal(LongMA, 1.3) +
" EMA(C, " + WriteVal(ShortPer, 1) + ") = " + WriteVal(ShortMA, 1.3) +
" HHV(H, " + WriteVal(LongPer, 1) + ") = " + WriteVal(Ref(LastHigh, - 1), 1.3);
*/

PositionScore = 100 / C; /* Set the order for which stock trades when get multiple signals in one bar in backtesting */
PositionSize = - 10; /* trade size will be 10% of available equty */
SetBarsRequired(10000, 10000); /* this ensures that the charts include all bars AND NOT just those on screen */
SetFormulaName("Sample System"); /* name it for backtest report identification */
SetOption("CommissionAmount", 32.95); /* commissions AND cost */
SetOption("CommissionMode", 2); /* set commissions AND costs as $ per trade */
SetOption("InitialEquity", 100000); /* starting capital */
SetOption("MaxOpenPositions", 6); /* I don't want to comit more than 60% of Equity at any one time */
SetOption("PriceBoundChecking", 1); /* trade only within the chart bar's price range */
SetOption("UsePrevBarEquityForPosSizing", 1); /* set the use of last bars equity for trade size */

/*-------------------------------------
Calculate Indicators
Buy = when exp mov Avg crosses AND the High is Highest for 50 bars
Sell = when exp mov Avg crosses back
Cross = first variable moves above the Second variable
-------------------------------------*/
LongPer = Param("Long Period", 50, 30, 100, 5); /* select periods with parameter window */
ShortPer = Param("Short Period", 5, 3, 10, 1);
LongMA = EMA(C, LongPer);
ShortMA = EMA(C, ShortPer);
LastHigh = HHV(H, LongPer);

/*-------------------------------------
Trade
-------------------------------------*/
Buy = Cross(ShortMA, LongMA)AND H > Ref(LastHigh, - 1);
/* ref, - 1 is used for the high to have todays high greater than the previous 50 bar high.
To just use H = = LastHigh couold mean a previous high was equal to current high */
Sell = Cross(LongMA, ShortMA);
/* exrem is one method to remove surplus strade signals */
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

/*-------------------------------------
Automatic Analysis (AA) Settings
This formula can be used for the following purposes:
1 - Indicator, 2 - Commentary, 3 - Scan, 4 - Exploration, 5 - Backtest, Optimize
-------------------------------------*/
TransmitOrder = False; // Set to True to really trade!

AASettings = Status("action");
if (AASettings == 1) {
// [Indicator]
GraphXSpace = 10; /* create empty space of 10% top and bottom of chart */
Plot(C, " Close Price", colorGrey50, styleBar);
Plot(LongMA, " EMA(C, " + WriteVal(LongPer, 1) + ")", colorRed, styleLine|styleNoRescale);
Plot(ShortMA, " EMA(C, " + WriteVal(ShortPer, 1) + ")", colorGreen, styleLine|styleNoRescale);
Plot(Ref(Lasthigh, - 1), " HHV(H, " + WriteVal(LongPer, 1) + ")", colorBlue, styleNoLine|styleDots|styleNoRescale);

/* styleNoRescale in the plots stops the added plots from compressing the original bar chart to the middle of the pane */
PlotShapes(shapeUpArrow * Buy, colorGreen, 0, L, - 10);
PlotShapes(shapeDownArrow * Sell, colorRed, 0, H, - 10);

} else if (AASettings == 2) {
// [Commentary]
"Closing price = " + WriteVal(Close);
"Change since yesterday = " + WriteVal(Close - Ref(Close, -1));
"Percent chg. since yesterday = " + WriteVal(ROC(Close, 1)) + " %";
"MACD = " + WriteVal(MACD()) + " , Signal line = " + WriteVal(Signal());

} else if (AASettings == 3) {
// [Scan]
AlertIf(Buy, "SOUND C:\\PROGRAM FILES\\AMIBROKER\\BUY.WAV", "Buy", 3);
AlertIf(Sell, "SOUND C:\\PROGRAM FILES\\AMIBROKER\\SELL.WAV", "Sell", 3);

} else if (AASettings == 4) {
// [Exploration]
/* We restrict results of exploration to when the Buy AND Sell signals occur */
/* You can use Filter = 1; to display every bar result */
Filter = Buy OR Sell;
AddTextColumn(FullName(), "Company Name");
AddColumn(Buy, "Buy", 1);
AddColumn(Sell, "Sell", 1);
AddColumn(C, "Close", 1.3);
AddColumn(H, "High", 1.3);
AddColumn(LastHigh, "HHV", 1.3);
AddColumn(LongMA, "Long MA", 1, 3);
AddColumn(ShortMA, "Short MA", 1, 3);

} else if (AASettings == 5) {
// [Backtest] //
SetTradeDelays(1, 1, 1, 1);
}
 

Romeo1998

Well-Known Member
Hi:

The following is an AFL of 50 bar breakout in Amibroker but it's throwing errors. Can someone help in rectifying it please?

_DEFAULT_NAME()shows the section name or, if not present, the file name.
The items in {{}} are Short cuts for the Title block.

Alternatively, use:
Title = Name() + " " + Date() + " " + "{{INTERVAL}}" + _DEFAULT_NAME() + " Chart values : " +
" Close Price = " + C +
" EMA(C, " + WriteVal(LongPer, 1) + ") = " + WriteVal(LongMA, 1.3) +
" EMA(C, " + WriteVal(ShortPer, 1) + ") = " + WriteVal(ShortMA, 1.3) +
" HHV(H, " + WriteVal(LongPer, 1) + ") = " + WriteVal(Ref(LastHigh, - 1), 1.3);
*/

PositionScore = 100 / C; /* Set the order for which stock trades when get multiple signals in one bar in backtesting */
PositionSize = - 10; /* trade size will be 10% of available equty */
SetBarsRequired(10000, 10000); /* this ensures that the charts include all bars AND NOT just those on screen */
SetFormulaName("Sample System"); /* name it for backtest report identification */
SetOption("CommissionAmount", 32.95); /* commissions AND cost */
SetOption("CommissionMode", 2); /* set commissions AND costs as $ per trade */
SetOption("InitialEquity", 100000); /* starting capital */
SetOption("MaxOpenPositions", 6); /* I don't want to comit more than 60% of Equity at any one time */
SetOption("PriceBoundChecking", 1); /* trade only within the chart bar's price range */
SetOption("UsePrevBarEquityForPosSizing", 1); /* set the use of last bars equity for trade size */

/*-------------------------------------
Calculate Indicators
Buy = when exp mov Avg crosses AND the High is Highest for 50 bars
Sell = when exp mov Avg crosses back
Cross = first variable moves above the Second variable
-------------------------------------*/
LongPer = Param("Long Period", 50, 30, 100, 5); /* select periods with parameter window */
ShortPer = Param("Short Period", 5, 3, 10, 1);
LongMA = EMA(C, LongPer);
ShortMA = EMA(C, ShortPer);
LastHigh = HHV(H, LongPer);

/*-------------------------------------
Trade
-------------------------------------*/
Buy = Cross(ShortMA, LongMA)AND H > Ref(LastHigh, - 1);
/* ref, - 1 is used for the high to have todays high greater than the previous 50 bar high.
To just use H = = LastHigh couold mean a previous high was equal to current high */
Sell = Cross(LongMA, ShortMA);
/* exrem is one method to remove surplus strade signals */
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

/*-------------------------------------
Automatic Analysis (AA) Settings
This formula can be used for the following purposes:
1 - Indicator, 2 - Commentary, 3 - Scan, 4 - Exploration, 5 - Backtest, Optimize
-------------------------------------*/
TransmitOrder = False; // Set to True to really trade!

AASettings = Status("action");
if (AASettings == 1) {
// [Indicator]
GraphXSpace = 10; /* create empty space of 10% top and bottom of chart */
Plot(C, " Close Price", colorGrey50, styleBar);
Plot(LongMA, " EMA(C, " + WriteVal(LongPer, 1) + ")", colorRed, styleLine|styleNoRescale);
Plot(ShortMA, " EMA(C, " + WriteVal(ShortPer, 1) + ")", colorGreen, styleLine|styleNoRescale);
Plot(Ref(Lasthigh, - 1), " HHV(H, " + WriteVal(LongPer, 1) + ")", colorBlue, styleNoLine|styleDots|styleNoRescale);

/* styleNoRescale in the plots stops the added plots from compressing the original bar chart to the middle of the pane */
PlotShapes(shapeUpArrow * Buy, colorGreen, 0, L, - 10);
PlotShapes(shapeDownArrow * Sell, colorRed, 0, H, - 10);

} else if (AASettings == 2) {
// [Commentary]
"Closing price = " + WriteVal(Close);
"Change since yesterday = " + WriteVal(Close - Ref(Close, -1));
"Percent chg. since yesterday = " + WriteVal(ROC(Close, 1)) + " %";
"MACD = " + WriteVal(MACD()) + " , Signal line = " + WriteVal(Signal());

} else if (AASettings == 3) {
// [Scan]
AlertIf(Buy, "SOUND C:\\PROGRAM FILES\\AMIBROKER\\BUY.WAV", "Buy", 3);
AlertIf(Sell, "SOUND C:\\PROGRAM FILES\\AMIBROKER\\SELL.WAV", "Sell", 3);

} else if (AASettings == 4) {
// [Exploration]
/* We restrict results of exploration to when the Buy AND Sell signals occur */
/* You can use Filter = 1; to display every bar result */
Filter = Buy OR Sell;
AddTextColumn(FullName(), "Company Name");
AddColumn(Buy, "Buy", 1);
AddColumn(Sell, "Sell", 1);
AddColumn(C, "Close", 1.3);
AddColumn(H, "High", 1.3);
AddColumn(LastHigh, "HHV", 1.3);
AddColumn(LongMA, "Long MA", 1, 3);
AddColumn(ShortMA, "Short MA", 1, 3);

} else if (AASettings == 5) {
// [Backtest] //
SetTradeDelays(1, 1, 1, 1);
}
good luck :)

Code:
PositionScore = 100 / C; /* Set the order for which stock trades when get multiple signals in one bar in backtesting */
PositionSize = - 10; /* trade size will be 10% of available equty */
SetBarsRequired(10000, 10000); /* this ensures that the charts include all bars AND NOT just those on screen */
SetFormulaName("Sample System"); /* name it for backtest report identification */
SetOption("CommissionAmount", 32.95); /* commissions AND cost */
SetOption("CommissionMode", 2); /* set commissions AND costs as $ per trade */
SetOption("InitialEquity", 100000); /* starting capital */
SetOption("MaxOpenPositions", 6); /* I don't want to comit more than 60% of Equity at any one time */
SetOption("PriceBoundChecking", 1); /* trade only within the chart bar's price range */
SetOption("UsePrevBarEquityForPosSizing", 1); /* set the use of last bars equity for trade size */

/*-------------------------------------
Calculate Indicators
Buy = when exp mov Avg crosses AND the High is Highest for 50 bars
Sell = when exp mov Avg crosses back
Cross = first variable moves above the Second variable
-------------------------------------*/
LongPer = Param("Long Period", 50, 30, 100, 5); /* select periods with parameter window */
ShortPer = Param("Short Period", 5, 3, 10, 1);
LongMA = EMA(C, LongPer);
ShortMA = EMA(C, ShortPer);
LastHigh = HHV(H, LongPer);


Title = Name() + " " + Date() + " " + "{{INTERVAL}}" + _DEFAULT_NAME() + " Chart values : " +
" Close Price = " + C +
" EMA(C, " + WriteVal(LongPer, 1,1,1) + ") = " + WriteVal(LongMA, 1.3,1,1) +
" EMA(C, " + WriteVal(ShortPer, 1,1,1) + ") = " + WriteVal(ShortMA, 1.3,1,1) +
" HHV(H, " + WriteVal(LongPer, 1,1,1) + ") = " + WriteVal(Ref(LastHigh, - 1), 1.3,1,1);


/*-------------------------------------
Trade
-------------------------------------*/
Buy = Cross(ShortMA, LongMA)AND H > Ref(LastHigh, - 1);
/* ref, - 1 is used for the high to have todays high greater than the previous 50 bar high.
To just use H = = LastHigh couold mean a previous high was equal to current high */
Sell = Cross(LongMA, ShortMA);
/* exrem is one method to remove surplus strade signals */
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

/*-------------------------------------
Automatic Analysis (AA) Settings
This formula can be used for the following purposes:
1 - Indicator, 2 - Commentary, 3 - Scan, 4 - Exploration, 5 - Backtest, Optimize
-------------------------------------*/
TransmitOrder = False; // Set to True to really trade!

AASettings = Status("action");
if (AASettings == 1) {
// [Indicator]
GraphXSpace = 10; /* create empty space of 10% top and bottom of chart */
Plot(C, " Close Price", colorGrey50, styleBar);
Plot(LongMA, " EMA(C, " + WriteVal(LongPer, 1) + ")", colorRed, styleLine|styleNoRescale);
Plot(ShortMA, " EMA(C, " + WriteVal(ShortPer, 1) + ")", colorGreen, styleLine|styleNoRescale);
Plot(Ref(Lasthigh, - 1), " HHV(H, " + WriteVal(LongPer, 1) + ")", colorBlue, styleNoLine|styleDots|styleNoRescale);

/* styleNoRescale in the plots stops the added plots from compressing the original bar chart to the middle of the pane */
PlotShapes(shapeUpArrow * Buy, colorGreen, 0, L, - 10);
PlotShapes(shapeDownArrow * Sell, colorRed, 0, H, - 10);

} else if (AASettings == 2) {
// [Commentary]
"Closing price = " + WriteVal(Close);
"Change since yesterday = " + WriteVal(Close - Ref(Close, -1));
"Percent chg. since yesterday = " + WriteVal(ROC(Close, 1)) + " %";
"MACD = " + WriteVal(MACD()) + " , Signal line = " + WriteVal(Signal());

} else if (AASettings == 3) {
// [Scan]
AlertIf(Buy, "SOUND C:\\PROGRAM FILES\\AMIBROKER\\BUY.WAV", "Buy", 3);
AlertIf(Sell, "SOUND C:\\PROGRAM FILES\\AMIBROKER\\SELL.WAV", "Sell", 3);

} else if (AASettings == 4) {
// [Exploration]
/* We restrict results of exploration to when the Buy AND Sell signals occur */
/* You can use Filter = 1; to display every bar result */
Filter = Buy OR Sell;
AddTextColumn(FullName(), "Company Name");
AddColumn(Buy, "Buy", 1);
AddColumn(Sell, "Sell", 1);
AddColumn(C, "Close", 1.3);
AddColumn(H, "High", 1.3);
AddColumn(LastHigh, "HHV", 1.3);
AddColumn(LongMA, "Long MA", 1, 3);
AddColumn(ShortMA, "Short MA", 1, 3);

} else if (AASettings == 5) {
// [Backtest] //
SetTradeDelays(1, 1, 1, 1);
}
 
Following is a code from this site itself for Wolfe Wave.

Is it possible to modify this AFL to add a scanner/exploration so that once Wave 5 (P5) is identified, a signal is generated by the scanner?

For reference, the attached chart is what the follwing AFL looks like on a chart

Version(5.20);
SetChartBkColor(16);
SetBarsRequired(sbrAll);
GraphXSpace=Param("GraphXSpace",15,-100,300,1);
daynum= Now(9);//day of the week
SatSun= IIf((daynum==1 OR daynum==7),1,0);
dec= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
dec= (Param("Decimals",2,0,7,1)/10)+1;
uc= ParamColor("Up Candle Fill Color",19);
dc= ParamColor("Dn Candle Fill Color",24);
nc= ParamColor("Neutral Fill Color",21);
bc= BarCount-1;
x= BarIndex();
Lx= LastValue(x);
sx= SelectedValue(x);
//==============================
SetBarFillColor(IIf(C>O,uc,IIf(C<O,dc,nc)));
Plot(C,"",IIf(C>Ref(C,-1),34,IIf(C<Ref(C,-1),32,42)),64);
Plot(MA(C,200),"",52,4);
//========= GFX Status =========
lvb= Status("LastVisibleBar");
fvb= Status("FirstVisibleBar");
mny= Status("AxisMiny"); mxy= Status("AxisMaxy");
pxl= Status("pxChartLeft"); pxw= Status("pxChartWidth");
pxh= Status("pxChartHeight"); pxb= Status("pxChartBottom");
mth= mxy-mny;
tvb= lvb-fvb;
function tpX(x) { return pxl+(x-fvb)*pxw/(tvb+1); }
function tpY(y) { return pxb-floor(0.5 +(y-mny)*pxh/mth); }
//======== GFX Flat Line ========
procedure sln(xs,ys,xe,col,thk,sty) {
xs=LastValue(tpx(xs)); ys=LastValue(tpy(ys));
xe=LastValue(tpx(xe)); av=xs>0 AND xe>xs;
GfxSelectPen(col,thk,sty); GfxSetBkColor(16);
IIf(av,GfxPolyline(xs,ys,xe,ys),Null); }
//======== Fib Function =========
f0=0; f1=0; p=0; n=0; d=0;
function fvd(fib) {
fv=fib*d; ffv=IIf(p,f0+fv,f0-fv);
return IIf(ffv>0,ffv,Null); }
//======== Plot Shapes ========
procedure pshp(x,y,shp,co,shf) {
x=SelectedValue(x); y=SelectedValue(y);
PlotShapes(IIf(BarIndex()==x,shp,0),co,0,y,shf); }
//======== Fractal Peak Trough ========
x= BarIndex();
function pkID(nb){ p=H==HHV(H,2*nb)AND Ref(HHV(H,nb),nb)<H;
return p AND LastValue(x)-ValueWhen(p,x)>nb; }
function trID(nb){ t=L==LLV(L,2*nb)AND Ref(LLV(L,nb),nb)>L;
return t AND LastValue(x)-ValueWhen(t,x)>nb; }
//=============================
_SECTION_BEGIN("Select Pivots");
//=============================
//SetBarsRequired(sbrAll,sbrAll);
nn= Param("Fractal Minimum",5,2,150,1);
plf= ParamList("Pivots/Ribbon","Off|Fractals|Ribbon|Both",0);
wwv=ParamToggle("Plot Wolfe Wave","Off|On",1);
cvg= ParamToggle("Require Convergence","Off|On",1);
sym= ParamToggle("Require Symmetry","Off|On",1);
fib=ParamToggle("Fib Retracements","Off|On",1);
mnR= Param("Min Time Retrace %",0.50,0.50,1.00,0.01);//Min % of P1-P2 bars
mxR= Param("Max Time Retrace %",1.62,1.00,4.00,0.01);//Max % of P1-P2 bars
mx5= Param("Max P5 Time Retrace %",2.62,1,5,0.01);//Max % of P2-P3 bars
nmn= Param("Near 5 %",0.62,0.50,0.995,0.001);//% of Retrace
//==================
x= BarIndex();
Lx=LastValue(x);
//==================
pk= pkID(nn); tr= trID(nn);
tx1= ValueWhen(tr,x,1); px2= ValueWhen(pk,x,2);
pk= IIf(pk,IIf(px2<tx1,pk,IIf(ValueWhen(pk,H,2)>H,False,pk)),pk);
px1= ValueWhen(pk,x,1); tx2= ValueWhen(tr,x,2);
tr= IIf(tr,IIf(tx2<px1,tr,IIf(ValueWhen(tr,L,2)<L,False,tr)),tr);
px0= ValueWhen(pk,x,0); tx0= ValueWhen(tr,x,0);
py0= ValueWhen(pk,H,0); ty0= ValueWhen(tr,L,0);
pk= IIf(pk AND px0>x,IIf(px0<tx0,IIf(py0>=H,False,pk),pk),pk);
tr= IIf(tr AND tx0>x,IIf(tx0<px0,IIf(ty0<=L,False,tr),tr),tr);
//===================
px= BarsSince(pk==1); tx= BarsSince(tr==1);
sup= SelectedValue(px) > SelectedValue(tx);
res= SelectedValue(tx)>= SelectedValue(px);
shp=shapeSmallCircle;
col= IIf(pk==1,42,IIf(tr==1,10,IIf(px>tx,19,IIf(tx>px,24,29))));
if(plf=="Ribbon" OR plf=="Both")Plot(2.25,"F
Swing",col,styleOwnScale|styleArea|4096,-1,100);
if(plf=="Fractals" OR plf=="Both"){PlotShapes(shp*pk,42,0,H,5);
PlotShapes(shp*tr,10,0,L,-5);}
//===================
yr1= ValueWhen(pk,H,1); xr1= ValueWhen(pk,x,1);
yr2= ValueWhen(pk,H,2); xr2= ValueWhen(pk,x,2);
yr3= ValueWhen(pk,H,3); xr3= ValueWhen(pk,x,3);
ys1= ValueWhen(tr,L,1); xs1= ValueWhen(tr,x,1);
ys2= ValueWhen(tr,L,2); xs2= ValueWhen(tr,x,2);
ys3= ValueWhen(tr,L,3); xs3= ValueWhen(tr,x,3);
//======== 5 POINT BEAR WAVE ========
be45xR= (xs1-xr2)/(xs2-xr3);
be55xR= (xr1-xs1)/(xr2-xs2);
becvg5= (yr2-ys1)<=(yr3-ys2);
be45xV= be45xR>=mnR AND be45xR<=mxR;
be55xV= be55xR>=mnR AND be55xR<=mx5;
if(sym==0)bexo5= xr1>xs1 AND xs1>xr2 AND xr2>xs2 AND xs2>xr3;
if(cvg==0)bepo5= yr2>yr3 AND yr1>yr2 AND ys1>ys2 AND ys1<yr2;
if(sym==1)bexo5= xr1>xs1 AND xs1>xr2 AND xr2>xs2 AND xs2>xr3 AND be45xV AND
be55xV;
if(cvg==1)bepo5= yr2>yr3 AND yr1>yr2 AND ys1>ys2 AND ys1<yr2 AND becvg5;
bq5= bexo5 AND bepo5;
//===================
x15= SelectedValue(ValueWhen(bq5,xr3));
y15= SelectedValue(ValueWhen(bq5,yr3));//P1
x25= SelectedValue(ValueWhen(bq5,xs2));
y25= SelectedValue(ValueWhen(bq5,ys2));//P2
x35= SelectedValue(ValueWhen(bq5,xr2));
y35= SelectedValue(ValueWhen(bq5,yr2));//P3
x45= SelectedValue(ValueWhen(bq5,xs1));
y45= SelectedValue(ValueWhen(bq5,ys1));//P4
x55= SelectedValue(ValueWhen(bq5,xr1));
y55= SelectedValue(ValueWhen(bq5,yr1));//P5
Ln135= LineArray(x15,y15,x35,y35,1);
Ln245= LineArray(x25,y25,x45,y45,1);
trgt5= LineArray(x15,y15,x45,y45,1);
//========= BEAR PLOTTING =========
if(wwv) {
Plot(Ln135,"",25,4|2048);
Plot(Ln245,"",43,4|2048);
Plot(trgt5,"",42,4|2048);
pshp(x15,y15,shapeDigit1,42,15); pshp(x25,y25,shapeDigit2,42,-15);
pshp(x35,y35,shapeDigit3,42,15); pshp(x45,y45,shapeDigit4,42,-15);
pshp(x55,y55,shapeDigit5,42,15);
}
x5up= ValueWhen(x>x45,Cross(H,Ln135));
x5dn= ValueWhen(x>x45,Cross(Ln135,H));
near= ValueWhen(x>x45,C>Ln245+(Ln135-Ln245)*nmn AND C<Ln135 AND NOT x5up AND
NOT x5dn);
//======== BEAR PRICE & TIME FIBS ========
if(fib) {
//======== Price Fibs ========
p=x45>x35; n=x45<x35; f0=y45; f1=y35; d=y35-y45;//Price Fibs
i618=fvd(0.618); i127=fvd(1.27); i162=fvd(1.62);
//====== Price AP Fibs ======
p=x45>x35; n=x45<x35; f0=y45; f1=y35; d=y35-y25;//AP Fibs
a618=fvd(0.618); a100=fvd(1.00); a127=fvd(1.27);
a162=fvd(1.62); a200=fvd(2.00); a224=fvd(2.24); a262=fvd(2.62);
//======== Time Fibs ========
p=x45>x35; n=x45<x35; f0=x45; f1=x35; d=x35-x25;//Time Fibs
x500=fvd(0.500); x618=fvd(0.618); x100=fvd(1.00);
x162=fvd(1.618); x262=fvd(2.62);
//======== PLOTTING ========
sln(x500,i618,x162,43,1,1); sln(x500,i127,x162,36,1,1);
sln(x500,i162,x162,34,1,1); sln(x500,y35,x162,32,1,1);
sln(x500,a618,x162,43,1,0); sln(x500,a100,x262,55,1,0);
sln(x500,a127,x262,44,1,0); sln(x500,a162,Lx,34,1,0);
sln(x100,a200,Lx,52,1,0); sln(x100,a224,Lx,42,1,0);
sln(x100,a262,Lx,51,1,0);
}
//===================
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx
//======== 5 POINT BULL WAVE ========
bu45xR= (xr1-xs2)/(xr2-xs3);
bu55xR= (xs1-xr1)/(xs2-xr2);
bucvg5= (yr1-ys2)<=(yr2-ys3);
bu45xV= bu45xR>=mnR AND bu45xR<=mxR;
bu55xV= bu55xR>=mnR AND bu55xR<=mx5;
if(sym==0)buxo5= xs1>xr1 AND xr1>xs2 AND xs2>xr2 AND xr2>xs3;
if(cvg==0)bupo5= yr2>ys3 AND yr2>yr1 AND ys3>ys2 AND ys2>ys1 AND yr2>yr1 AND
yr1>ys3;
if(sym==1)buxo5= xs1>xr1 AND xr1>xs2 AND xs2>xr2 AND xr2>xs3 AND bu45xV AND
bu55xV;
if(cvg==1)bupo5= yr2>ys3 AND yr2>yr1 AND ys3>ys2 AND ys2>ys1 AND yr2>yr1 AND
yr1>ys3 AND bucvg5;
pq5= buxo5 AND bupo5;
//===================
x15= SelectedValue(ValueWhen(pq5,xs3));
y15= SelectedValue(ValueWhen(pq5,ys3));//P1
x25= SelectedValue(ValueWhen(pq5,xr2));
y25= SelectedValue(ValueWhen(pq5,yr2));//P2
x35= SelectedValue(ValueWhen(pq5,xs2));
y35= SelectedValue(ValueWhen(pq5,ys2));//P3
x45= SelectedValue(ValueWhen(pq5,xr1));
y45= SelectedValue(ValueWhen(pq5,yr1));//P4
x55= SelectedValue(ValueWhen(pq5,xs1));
y55= SelectedValue(ValueWhen(pq5,ys1));//P5
Ln135= LineArray(x15,y15,x35,y35,1);
Ln245= LineArray(x25,y25,x45,y45,1);
trgt5= LineArray(x15,y15,x45,y45,1);
//========= BULL PLOTTING =========
if(wwv) {
Plot(Ln135,"",27,4|2048);
Plot(Ln245,"",32,4|2048);
Plot(trgt5,"",51,4|2048);
pshp(x15,y15,shapeDigit1,43,-15); pshp(x25,y25,shapeDigit2,43,15);
pshp(x35,y35,shapeDigit3,43,-15); pshp(x45,y45,shapeDigit4,43,15);
pshp(x55,y55,shapeDigit5,10,-15);
}
x5up= ValueWhen(x>x45,Cross(L,Ln135));
x5dn= ValueWhen(x>x45,Cross(Ln135,L));
near= ValueWhen(x>x45,C<Ln245-(Ln245-Ln135)*nmn AND NOT x5up AND NOT x5dn);
//======== BEAR PRICE & TIME FIBS ========
if(fib) {
//======== Price Fibs ========
p=x45<x35; n=x45>x35; f0=y45; f1=y35; d=y45-y35;//Price Fibs
i618=fvd(0.618); i127=fvd(1.27); i162=fvd(1.62);
//====== Price AP Fibs ======
p=x45<x35; n=x45>x35; f0=y45; f1=y35; d=y25-y35;//AP Fibs
a618=fvd(0.618); a100=fvd(1.00); a127=fvd(1.27);
a162=fvd(1.62); a200=fvd(2.00); a224=fvd(2.24); a262=fvd(2.62);
//======== Time Fibs ========
p=x45>x35; n=x45<x35; f0=x45; f1=x35; d=x35-x25;//Time Fibs
x500=fvd(0.500); x618=fvd(0.618); x100=fvd(1.00);
x162=fvd(1.618); x262=fvd(2.62);
//======== PLOTTING ========
sln(x500,i618,x162,43,1,1); sln(x500,i127,x162,36,1,1);
sln(x500,i162,x162,34,1,1); sln(x500,y35,x162,32,1,1);
sln(x500,a618,x162,43,1,0); sln(x500,a100,x262,55,1,0);
sln(x500,a127,Lx,44,1,0); sln(x500,a162,Lx,34,1,0);
sln(x100,a200,Lx,52,1,0); sln(x100,a224,Lx,42,1,0);
sln(x100,a262,Lx,51,1,0);
}
RequestTimedRefresh(1);
Title = "\\c55" + Title = Name() + " " + FullName()+ " \\c32" +
Date() + " \\c43" + "{{INTERVAL}} " +
"\\c55 Open = \\c43" + WriteVal(O,dec) +
"\\c55 High = \\c43" + WriteVal(H,dec) +
"\\c55 Low = \\c32" + WriteVal(L,dec) +
"\\c55 Close = \\c52" + WriteVal(C,dec)+
"\\c55 Volume = \\c43"+ WriteVal(V,dec) +
"\\c55 ATR-9 = \\c42" + WriteVal(ATR(9),dec) +
"\\c55 Fractal =\\c10"+nn+"\\c55 Bars " +
"\\c55 x = " + WriteVal(x,1)+"\n\n" +
"\\c55x4 Retrace = \\c43"+ WriteVal(be45xR,1.2)+"%\n" +
"\\c55x5 Retrace = \\c43"+ WriteVal(be55xR,1.2);
 

Attachments

Similar threads