logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
naren.orbit  
#1 Posted : Saturday, June 4, 2011 1:53:17 AM(UTC)
naren.orbit

Rank: Member

Groups: Registered, Registered Users
Joined: 4/26/2011(UTC)
Posts: 14
Location: india

hi friends, can anyone write this Amibroker formula for metastock. buy sell signals cross above -100 and cross below +100. _SECTION_BEGIN("Trend"); ///// Trend Identify ////// SetChartOptions( Mode = 0, Flags = 0, gridFlags = 0) ; x=Param("CCI Period 3 - 35",9,3,50,1); x1=CCI(x); Y=Param("Smooth Factor 3 - 15",5,3,9,1); Y2=DEMA(x1,Y); Z=Param("Signal Line 3 - 9",3,3,5,1); Z2=MA(Y2,Z); Plot(Z2," ",colorGreen,4); Plot(100,"",colorGreen); Plot(-100,"",colorRed); Plot(65,"",colorGreen,styleDashed); Plot(-65,"",colorRed,styleDashed); Plot(0,"",colorBlack); _SECTION_END();
jjstein  
#2 Posted : Saturday, June 4, 2011 4:10:44 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Had to guess which of the "Param" settings are defaults; set the color & style after the indicator is plotted:

{ ****************************}
Periods:=Input("Periods 3-35",3,35,9);
Smooth:=Input("Smooth 3-15",3,15,9);
Signal:=Input("Signal 3-9",3,9,5);

x:=CCI(Periods);
y:=Dema(x,Smooth);
z:=Mov(y,Signal,S);

100; { green }
-100; { red }
65; { green - dashed }
-65; { red - dashed }
0; { black }
z; { green - thick? }
{ ****************************}

naren.orbit  
#3 Posted : Tuesday, June 7, 2011 1:10:51 PM(UTC)
naren.orbit

Rank: Member

Groups: Registered, Registered Users
Joined: 4/26/2011(UTC)
Posts: 14
Location: india

many thanks Johnathan...
Eros  
#4 Posted : Tuesday, September 6, 2011 6:31:39 AM(UTC)
Eros

Rank: Newbie

Groups: Registered, Registered Users
Joined: 9/6/2011(UTC)
Posts: 4

Dear friends ... Could anyone help me convert this amibroker formula to metastock : _SECTION_BEGIN("Suri-FibBands"); //******************************************Suri-FibBands***********************// MALength = Param("MALength",100,0,100,1); //MALength=100; mov = MA(Close,MALength); tr = MA(ATR(14)*1.3, MALength); upperBand1 = mov+4.62*tr; upperBand2 = mov+2.62*tr; upperBand3 = mov+1.62*tr; lowerBand1 = mov-1.62*tr; lowerBand2 = mov-2.62*tr; lowerBand3 = mov-4.62*tr; Plot(upperBand1 ,"ProfitStop",colorGreen,styleLine); Plot(upperBand2 ,"ProfitStop",colorRed,styleLine); Plot(upperBand3 ,"ProfitStop",colorOrange,styleLine); Plot(mov ,"ProfitStop",colorBrown,styleLine); Plot(lowerBand1 ,"ProfitStop",colorOrange,styleLine); Plot(lowerBand2 ,"ProfitStop",colorRed,styleLine); Plot(lowerBand3 ,"ProfitStop",colorGreen,styleLine); Plot(C ,"Price",colorBlue,styleBar); _SECTION_END();
jjstein  
#5 Posted : Tuesday, September 6, 2011 8:28:51 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
You should really start a new thread, y'know...try this code:

MALength:=Input("MALength",1,100,100);
ma:=Mov(CLOSE,MALength,SIMPLE);
tr:=Mov(ATR(14)*1.3,MALength,S);

upperBand1:=ma+4.62*tr;
upperBand2:=ma+2.62*tr;
upperBand3:=ma+1.62*tr;

lowerBand1:=ma-1.62*tr;
lowerBand2:=ma-2.62*tr;
lowerBand3:=ma-4.62*tr;

{ Plot }
upperBand1; { green }
upperBand2; { Red }
upperBand3; { Orange }

ma; { Brown }

lowerBand1; { Orange }
lowerBand2; { Red }
lowerBand3; { Green }


Drag & plot to a chart -- you'll have to set the colors after plotting.

Eros  
#6 Posted : Tuesday, September 6, 2011 9:25:13 PM(UTC)
Eros

Rank: Newbie

Groups: Registered, Registered Users
Joined: 9/6/2011(UTC)
Posts: 4

Thx too much for ur effort Johnathan
henry1224  
#7 Posted : Wednesday, September 7, 2011 6:41:17 AM(UTC)
henry1224

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/29/2004(UTC)
Posts: 1,394
Location: Glastonbury, CT

Was thanked: 2 time(s) in 2 post(s)
You could try this formula to identify zones

MALength:=Input("MALength",1,100,100);
ATRLength:=Input("ATRLength",1,100,10);
ma:=Mov(CLOSE,MALength,S);
tr:=Mov(ATR(ATRLength)*1.3,MALength,S);

UB1:=ma+4.62*tr;
UB2:=ma+2.62*tr;
UB3:=ma+1.62*tr;

LB1:=ma-1.62*tr;
LB2:=ma-2.62*tr;
LB3:=ma-4.62*tr;

Val:=If(MP()>UB1,4,If(MP()<LB3,-4,
If(MP()<UB1 AND MP()>UB2,3,If(MP()>LB3 AND MP()<LB2,-3,
If(MP()<UB2 AND MP()>UB3,2,If(MP()>LB2 AND MP()<LB1,-2,
If(MP()<UB3 AND MP()>Ma,1,If(MP()>LB1 AND MP()<MA,-1,0))))))));

{Plot}
Val
henry1224  
#8 Posted : Wednesday, September 7, 2011 11:23:31 AM(UTC)
henry1224

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/29/2004(UTC)
Posts: 1,394
Location: Glastonbury, CT

Was thanked: 2 time(s) in 2 post(s)
Creating zones to find support and resistance

UserPostedImage
Eros  
#9 Posted : Friday, September 9, 2011 7:18:00 PM(UTC)
Eros

Rank: Newbie

Groups: Registered, Registered Users
Joined: 9/6/2011(UTC)
Posts: 4

Thx Henry But please can you describe more about that formula you shared here ... as I understand it's a formula to be used plus the SuriFib Bands as a confirmation ... but I'll be appreciated if you shared that tactic with me
Eros  
#10 Posted : Saturday, September 10, 2011 1:13:16 AM(UTC)
Eros

Rank: Newbie

Groups: Registered, Registered Users
Joined: 9/6/2011(UTC)
Posts: 4

Actually .. this is the original formula but I don't know how to make it in MS language : MA = Exp. Moving Avg. (Close,34); TR = Exp. Average(TrueRange, 8); UpperBand3= MA+4.23*TR; UpperBand2 = MA + 2.62*TR; UpperBandl = MA+ 1.62*TR; Moving Average (MA); LowerBandl = MA - 1.62*TR; LowerBand2 = MA - 2.62*TR; LowerBand3 = MA - 4.23*TR; if you will help me I'll be very appreciated
henry1224  
#11 Posted : Saturday, September 10, 2011 6:36:30 AM(UTC)
henry1224

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/29/2004(UTC)
Posts: 1,394
Location: Glastonbury, CT

Was thanked: 2 time(s) in 2 post(s)
Eros,
I just wanted to create an exploration so I could find stocks that are oversold and over bought
coolabhi99  
#12 Posted : Tuesday, October 18, 2011 1:01:40 PM(UTC)
coolabhi99

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 10/18/2011(UTC)
Posts: 2

hi friends, can anyone write this Amibroker formula for metastock.


_SECTION_BEGIN("Woodie's CCI Panel Full Stats");
//SetChartBkColor(16) ;
///////////////////////////////
// CCI Panel for Amibroker
// Codded/Added by Dennis, Kris, Wring, Santacs, Yofa (jtoth100)
// Last Update: 10/19/2008
///////////////////////////////
// Go to www.woodiescciclub.com to learn everything about this system.
// You must be a registered user to see the images and downloads.
///////////////////////////////
// Setup Axes and Grid section (right click on chart panel, click on Parameters):
// Scaling: Custom , Min=-250 Max=250
// Show Date Axis = Yes , Show Middle Lines = No
///////////////////////////////
// To activate the timer properly, make sure the following is set:
// click on Tools==>Preferences==>Intraday....
// make sure "Allign minute bars to market hours" is checked...
// make sure "Start time of interval" is checked...
// make sure "Override: Weekly/monthly bars use day of last trade" is checked.
///////////////////////////////
// Tic/PIP values: YM=1.0, ER2=0.10, NQ=0.25, EUR/USD=.0001, USD/JPY=0.01, Stocks=0.01
///////////////////////////////
// Rangebar Settings :
// ER2 1.50
// YM 25
// ES 3
// NQ 3.75
// DAX 5
// ZG 1.5
///////////////////////////////
// Discalimer: For educational purposes only. Trade at your own risk.
///////////////////////////////

// ********************************************************************************************
// Static variable functions used in charts
// ********************************************************************************************

function StaticName( VarName )
{
return Name() + VarName;
}

procedure StaticSet( VarName, VarValue )
{
StaticVarSet(Name() + VarName, VarValue);
}

function StaticGet( VarName )
{
return Nz(StaticVarGet(Name() + VarName));
}

procedure StaticSetText( VarName, VarValue )
{
StaticVarSetText(Name() + VarName, VarValue);
}

function StaticGetText( VarName )
{
return StaticVarGetText(Name() + VarName);
}

// ********************************************************************************************
// Basic panel setup
// ********************************************************************************************

//Disable printing to commentary window
EnableTextOutput(False);

//Version info of the panel
Revision = "$Revision: 39 $";

SetChartOptions(0, chartShowDates);
SetChartOptions(3, chartLogarithmic, chartGridMiddle | chartGridPercent | chartGridMargins);

//Anything to print at the end of the tooltip for debugging purposes
ToolTipDebug = "";

// Bar indexes for titles and commentary
LastBarIndex = BarCount-1;
CurBarIndex = SelectedValue(BarIndex());
if (CurBarIndex > LastBarIndex) //on tick charts SelectedValue(BarIndex()) may point beyond last bar
CurBarIndex = LastBarIndex;

// ********************************************************************************************
// Low level graphics setup
// ********************************************************************************************
if (Status("action") == 1) //indicator
{
MinY = Status("axisminy");
MaxY = Status("axismaxy");
TotalY = MaxY - MinY;

LastVisibleIndex = Status("lastvisiblebarindex");
FirstVisibleIndex = Status("firstvisiblebarindex");
TotalVisibleBars = LastVisibleIndex - FirstVisibleIndex;

PixelWidth = Status("pxwidth");
PixelHeight = Status("pxheight");
ScaleY = PixelHeight / TotalY;
}
else
{
MinY = -300;
MaxY = 300;
TotalY = MaxY - MinY;

LastVisibleIndex = BarCount -1;
FirstVisibleIndex = 0;
TotalVisibleBars = LastVisibleIndex - FirstVisibleIndex;

PixelWidth = 1;
PixelHeight = 1;
ScaleY = PixelHeight / TotalY;
}

FontNameSmall = "Ariel";
FontSizeSmall = 8;
FontWeightSmall = 300;

FontNameNormal = "MS Sans Serif";
FontSizeNormal = 8;
FontWeightNormal = 300;

FontNameBig = "MS Sans Serif";
FontSizeBig = 10;
FontWeightBig=700;

GfxSetOverlayMode(0); //low level graph over chart...
GfxSetBkMode(1); //transparent
GfxSelectPen( StaticGet("ChartBkColor"), 1, 0); //to clear value area
GfxSelectSolidBrush( StaticGet("ChartBkColor") );
GfxSetTextColor( StaticGet("ChartTextColor") );

GfxSetTextAlign(10); //right, buttom
GfxSelectFont(FontNameSmall, FontSizeSmall, FontWeightSmall, True, False, 0);
GfxTextOut("by Yofa", PixelWidth-2, PixelHeight-12 );
GfxTextOut(Revision, PixelWidth-2, PixelHeight );

GfxSetTextAlign(26); //right, baseline
GfxSelectFont(FontNameNormal, FontSizeNormal, FontWeightNormal, False, False, 0);

function GfxMapYtoPixelY(Y)
{
return ( TotalY / 2 - Y ) * ScaleY;
}

_SECTION_END(); //Woodie CCI - Indicators


// Timer

TTMperiod = 6;
Low_ma = EMA(L, TTMperiod);
High_ma = EMA(H, TTMperiod);
Low_third = (High_ma - Low_ma) / 3 + Low_ma;
High_third = 2 * (High_ma - Low_ma) / 3 + Low_ma;
tempnum = Now( 4 ) - TimeNum();
TimeRem = Interval() - ((int(tempnum[BarCount - 1] / 100) * 60) + (tempnum[BarCount - 1] - int(tempnum[BarCount - 1] / 100) * 100));
if (TimeRem[BarCount - 1] < 0) TimeRem = 0;
MinuteVar = int(TimeRem / 60);
SecondsVar = int(frac(TimeRem / 60) * 60);
if (TimeRem[BarCount - 1] > 60)
{
TitleTimeRem = EncodeColor(colorWhite) + MinuteVar + ":" + WriteIf(SecondsVar > 9, "", "0") + SecondsVar;
}
else if (TimeRem[BarCount - 1] > 20)
{
TitleTimeRem = EncodeColor(colorYellow) + MinuteVar + ":" + WriteIf(SecondsVar > 9, "", "0") + SecondsVar;
}
else
{
TitleTimeRem = EncodeColor(colorRed) + MinuteVar + ":" + WriteIf(SecondsVar > 9, "", "0") + SecondsVar;
}

// Background color

SetChartBkColor(ParamColor("Panel color ",colorBlack));

// CCI colors

zcolor= ParamColor("WCCI color",colorCustom12);
z6color= ParamColor("TCCI color",colorCustom9);
patterncolor= ParamColor("Pattern trace color",colorWhite);

// CCI periods

zperiod=Param("WCCI period",14,0,100);
z = CCI(zperiod);
z6period=Param("TCCI period",6,0,1000);
z6 = CCI(z6period);

// Tic/PIP value

TicMult= Param("Tic multiplier(ER2=10,YM=1,ES=4,FOREX=1)",1,0,1000000);
TicDiv= Param("Tic or PIP value(ER2=0.1,YM=1,FOREX=1)",1,0,1000000);

// Rangebar interval

rbint= Param("Rangebar interval:(YM=25.0,AB=1.5,NQ=3.75,ES=3.0)",1.0,0.25,1000000);

// Rangebar counter

rbcounter= round(((rbint-(H-L))) * ticmult);
rbcounterpercent= round((rbcounter/(rbint * ticmult))*100);

// Timer/counter title

timercode= Param("Timer:(minutes=1,rangebar=2)",1,1,2);
timetitle= WriteIf(timercode==1,TitleTimeRem, EncodeColor(colorWhite) + "Countdown " + rbcounter + " (" + rbcounterpercent + "%)");

// Spread

spread= Param("Spread (included in stop)",0,0,1000000);

// Stop value

stopval= Param("Stop above/below entry bar",2,0,1000000);

// Plot grids

PlotTheGrids = ParamToggle("Plot grids","No|Yes",0);
if (PlotTheGrids ==1)
{
PlotGrid(0);
PlotGrid(50);
PlotGrid(75);
PlotGrid(-75);
PlotGrid(-50);
PlotGrid(-100);
PlotGrid(100);
PlotGrid(-200);
PlotGrid(200);

}

// Angle variables

PI = atan(1.00) * 4;
periods = 30;
HighHigh = HHV(H, periods);
LowLow = LLV(L, periods);
range = 25 / (HighHigh - LowLow) * LowLow;

// EMA34 Angle

EMA34 = EMA(C,34);
x1_EMA34 = 0;
x2_EMA34 = 1;
y1_EMA34 = 0;
y2_EMA34 = (Ref(EMA34, -1) - EMA34) / Avg * range;
c_EMA34 = sqrt((x2_EMA34 - x1_EMA34)*(x2_EMA34 - x1_EMA34) + (y2_EMA34 - y1_EMA34)*(y2_EMA34 - y1_EMA34));
angle_EMA34 = round(180 * acos((x2_EMA34 - x1_EMA34)/c_EMA34) / PI);
angle_EMA34 = IIf(y2_EMA34 > 0, - angle_EMA34, angle_EMA34);

// LSMA25 Angle

LSMA25 = LinearReg(C, 25 );
x1_LSMA25 = 0;
x2_LSMA25 = 1;
y1_LSMA25 = 0;
y2_LSMA25 = (Ref(LSMA25, -1) - LSMA25) / Avg * range;
c_LSMA25 = sqrt((x2_LSMA25 - x1_LSMA25)*(x2_LSMA25 - x1_LSMA25) + (y2_LSMA25 - y1_LSMA25)*(y2_LSMA25 - y1_LSMA25));
angle_LSMA25 = round(180 * acos((x2_LSMA25 - x1_LSMA25)/c_LSMA25) / PI);
angle_LSMA25 = IIf(y2_LSMA25 > 0, - angle_LSMA25, angle_LSMA25);

// Color the bars for Woodies Trend Following

function Consecutive( array )
{
return BarsSince( NOT( array ) );
}
function Occurrences( array , period )
{
return Sum( array, period );
}
array = z;
HighBars = Consecutive( array > 0 );
LowBars = Consecutive( array < 0 );
UpCondition = BarsSince( HighBars >= 6 AND Occurrences( array > 100 , 5 ) > 0 );
DnCondition = BarsSince( LowBars >= 6 AND Occurrences( array < -100 , 5 ) > 0 );
UpTrend = ( array > 0 ) AND ( UpCondition < DnCondition );
DnTrend = ( array < 0 ) AND ( UpCondition > DnCondition );
TrTrend = ( HighBars >= 5 AND NOT UpTrend ) OR ( LowBars >= 5 AND NOT DnTrend );
Color = IIf( UpTrend, colorBlue, IIf( DnTrend, colorRed, IIf( TrTrend, colorYellow, colorGrey40 ) ) );

// Plot the Mock CZI on the 100s

ColorANGLE_EMA = IIf(angle_EMA34 >=5,colorTurquoise,
IIf(angle_EMA34 <5 AND angle_EMA34 >=3.57,colorDarkGreen,
IIf(angle_EMA34 <3.57 AND angle_EMA34 >=2.14,colorPaleGreen,
IIf(angle_EMA34 <2.14 AND angle_EMA34 >=.71,colorLime,
IIf(angle_EMA34 <=-1*5,colorDarkRed,
IIf(angle_EMA34 >-1*5 AND angle_EMA34 <=-1*3.57,colorRed,
IIf(angle_EMA34 >-1*3.57 AND angle_EMA34 <=-1*2.14,colorOrange,
IIf(angle_EMA34 >-1*2.14 AND angle_EMA34 <=-1*.71,colorLightOrange,colorYellow))))))));
Plot(100,"", ColorANGLE_EMA , styleLine | styleThick | styleNoLabel);
Plot(-100,"", ColorANGLE_EMA , styleLine | styleThick | styleNoLabel);

// Plot the Mock Sidewinder on the 200s

SW = IIf((abs(angle_EMA34) >= 15) AND (abs(angle_EMA34 + angle_LSMA25) >= 50), IIf(angle_LSMA25 > 0, 2, -2),
IIf((abs(angle_EMA34) >= 0) AND (((angle_EMA34 >= 0) AND (angle_LSMA25 >= 0)) OR ((angle_EMA34 <= 0) AND (angle_LSMA25 <= 0))) AND (abs(angle_EMA34 + angle_LSMA25) >= 5), IIf(angle_LSMA25 > 0, 1, -1), 0));
ColorSW = IIf(abs(SW) == 2, colorBrightGreen,
IIf(abs(SW) == 1, colorYellow, colorRed));
Plot(200,"", ColorSW, styleLine | styleThick | styleNoLabel);
Plot(-200,"", ColorSW, styleLine | styleThick | styleNoLabel);

// Zero line 25lsma

Plot(0,"", IIf(C > LSMA25,colorBrightGreen,IIf(C < LSMA25,colorRed,colorTeal)), styleLine | styleThick | styleNoLabel);

// CCI Points

diffCode=ParamToggle("Plot CCI diff ","No|Yes",1);
CCipointmove= z-Ref(z,-1);
CCIpointmovetitle= WriteIf(diffcode==1 AND abs(CCipointmove)<15,EncodeColor(colorRed) + "\n" + "DIFF " +
abs(round(CCipointmove)) + "\n",WriteIf(diffcode==1 AND abs(CCipointmove)>=15 AND abs(CCipointmove)<20,EncodeColor(colorYellow) + "\n" + "DIFF " +
abs(round(CCipointmove)) + "\n",WriteIf(diffcode==1 AND abs(CCIpointmove)>=20,EncodeColor(colorBrightGreen) + "\n" + "DIFF " +
abs(round(CCipointmove))+ "\n","")));

// Price Panel

Lastpricetitlehi= WriteIf(H>Ref(H,-1),EncodeColor(colorBrightGreen) + Ref(H,-1) + " " + H , EncodeColor(colorWhite)+ Ref(H,-1) + " " + H);
Lastpricetitlelo= WriteIf(L<Ref(L,-1),EncodeColor(colorRed) + Ref(L,-1) + " " + L , EncodeColor(colorWhite) + Ref(L,-1) + " " + L);
Closecolor=WriteIf(C==H AND H>Ref(H,-1),EncodeColor(colorBrightGreen),WriteIf(C==L AND L<Ref(L,-1),EncodeColor(colorRed),EncodeColor(colorWhite)));

//Pivot Points Calculations

pivCode=ParamToggle("Plot pivots ","No|Yes",1);
DayH = TimeFrameGetPrice("H", inDaily, -1);
DayL = TimeFrameGetPrice("L", inDaily, -1);
DayC = TimeFrameGetPrice("C", inDaily, -1);
DayO = TimeFrameGetPrice("O", inDaily);
HiDay = TimeFrameGetPrice("H", inDaily);
LoDay = TimeFrameGetPrice("L", inDaily);
PP = (DayH + DayL + DayO + DayO) / 4 ;
R1 = (2 * PP) - DayL;
S1 = (2 * PP) - DayH;
R2 = PP + R1 - S1;
S2 = PP + S1 - R1;
R3 = R2 + (R1 - PP);
S3 = S2 - (PP - S1);
ppvalue= round(abs((C-pp)/ticdiv));
r1value= round(abs((C-r1)/ticdiv));
s1value= round(abs((C-s1)/ticdiv));
r2value= round(abs((C-r2)/ticdiv));
s2value= round(abs((C-s2)/ticdiv));
r3value= round(abs((C-r3)/ticdiv));
s3value= round(abs((C-s3)/ticdiv));
wptitle= WriteIf(pivCode==1 AND C>=R3, "\n" + EncodeColor(colorYellow)+"R3 " + "-" + (R3value) + "\n" + "\n",
WriteIf(pivCode==1 AND C<=R3 AND C>=R2, "\n" + EncodeColor(colorYellow)+"R3 " + "+" + (R3value) + "\n" + EncodeColor(colorYellow) + "R2 " + "-" + (R2value) + "\n" + "\n",
WriteIf(pivCode==1 AND C<=R2 AND C>=R1, "\n" + EncodeColor(colorYellow)+"R2 " + "+" + (R2value) + "\n" + EncodeColor(colorYellow) + "R1 " + "-" + (R1value) + "\n" + "\n",
WriteIf(pivCode==1 AND C<=R1 AND C>=PP, "\n" + EncodeColor(colorYellow)+"R1 " + "+" + (R1value) + "\n" + EncodeColor(colorYellow) + "PP " + "-" + (PPvalue) + "\n" + "\n",
WriteIf(pivCode==1 AND C<=PP AND C>=S1, "\n" + EncodeColor(colorYellow)+"PP " + "+" + (PPvalue) + "\n" + EncodeColor(colorYellow) + "S1 " + "-" + (S1value) + "\n" + "\n",
WriteIf(pivCode==1 AND C<=S1 AND C>=S2, "\n" + EncodeColor(colorYellow)+"S1 " + "+" + (S1value) + "\n" + EncodeColor(colorYellow) + "S2 " + "-" + (S2value) + "\n" + "\n",
WriteIf(pivCode==1 AND C<=S2 AND C>=S3, "\n" + EncodeColor(colorYellow)+"S2 " + "+" + (S2value) + "\n" + EncodeColor(colorYellow) + "S3 " + "-" + (S3value) + "\n" + "\n",
WriteIf(pivCode==1 AND C<=S3, "\n" + EncodeColor(colorYellow)+"S3 " + "+" + (S3value) + "\n"+ "\n",""))))))));

// HOD , LOD, Range

HiDayTitle = WriteIf(pivCode==1,EncodeColor(colorYellow) + "HOD ","");
HiDayTitle = WriteIf(pivCode==1,HiDayTitle + EncodeColor(colorYellow) + HiDay + " +" + round(abs((HiDay-C)/ticdiv)) + "\n","");
LoDayTitle = WriteIf(pivCode==1,EncodeColor(colorYellow) + "LOD ","");
LoDayTitle = WriteIf(pivCode==1,LoDayTitle + EncodeColor(colorYellow) + LoDay + " -" + round(abs((C-LoDay)/ticdiv)) + "\n"," ");
RangeTitle1 =WriteIf(pivCode==1,EncodeColor(colorYellow) + "Day Range " + EncodeColor(colorYellow) + StrToNum(NumToStr(round((HiDay - LoDay)/ticdiv), 4.4)) + "\n","");

// Pattern codes

Cziquallong= ((angle_EMA34>=5 OR Ref(angle_EMA34,-1)>=5) AND Ref(angle_EMA34,-2)>=5) OR (Ref(angle_EMA34,-1)>=5 AND angle_EMA34>=5);
Cziqualshort= ((angle_EMA34<=-5 OR Ref(angle_EMA34,-1)<=-5) AND Ref(angle_EMA34,-2)<=-5) OR (Ref(angle_EMA34,-1)<=-5 AND angle_EMA34<=-5);

// ZLR Long

Linex_long=Ref(z,-1)>100 AND z<100;
barsfromline_long=BarsSince(Linex_long);
CCIhook_long=z>Ref(z,-1) AND Ref(z,-1)>-100 AND Ref(z,-1)<Ref(z,-2) AND Ref(z,-2)>-100 AND z>0;
SW_trendinglong= sw==1 OR sw==2;
zlrlong1= abs(CCipointmove)>=15 AND SW_trendinglong AND z<120 AND barsfromline_long<=10 AND CCIhook_long AND UpTrend;
zlrnextl= z<120 AND barsfromline_long<10 AND CCIhook_long AND UpTrend;
zlrlong= Cziquallong AND (zlrlong1 OR ( NOT Ref(zlrlong1,-1) AND Ref(zlrnextl,-1) AND abs(CCipointmove)>=15 AND z>=Ref(z,-1) AND SW_trendinglong AND z<120 AND UpTrend));

// ZLR Short

Linex_short=Ref(z,-1)<=-100 AND z>=-100;
barsfromline_short=BarsSince(Linex_short);
CCIhook_short=z<Ref(z,-1) AND Ref(z,-1)<100 AND Ref(z,-1)>Ref(z,-2) AND Ref(z,-2)<100 AND z<0;
SW_trendingshort= sw==-1 OR sw==-2;
zlrshort1= abs(CCipointmove)>=15 AND SW_trendingshort AND z>-120 AND barsfromline_short<=10 AND CCIhook_short AND DnTrend;
zlrnexts= z>-120 AND barsfromline_short<10 AND CCIhook_short AND DnTrend;
zlrshort= Cziqualshort AND (zlrshort1 OR (NOT Ref(zlrshort1,-1) AND Ref(zlrnexts,-1) AND abs(CCipointmove)>=15 AND z<=Ref(z,-1) AND SW_trendingshort AND z>-120 AND DnTrend));

// Famir Long

FamirLinex_long=Ref(z,-1)<=-100 AND z>-100;
Famir_barsfromline_long=BarsSince(FamirLinex_long);
Famir_pivotlong= (Ref(z,-2)>Ref(z,-1)AND Ref(z,-1)>=-55 AND Ref(z,-2)>=-55) OR (Ref(z,-3)>Ref(z,-1) AND Ref(z,-1)>=-55 AND Ref(z,-2)>=-55 AND Ref(z,-3)>=-55)OR (Ref(z,-4)>Ref(z,-1) AND Ref(z,-1)>=-55 AND Ref(z,-2)>=-55 AND Ref(z,-3)>=-55);
Famirhook_long=Famir_pivotlong AND z>Ref(HHV(z,Famir_barsfromline_long),-1) AND (z>=-55 AND z<=55);
Famirlong= Famir_barsfromline_long<10 AND Famirhook_long AND ((DnTrend OR Ref(Dntrend,-BarsSince(z<0))==1) AND NOT UpTrend) AND C>LSMA25;

// Famir Short

FamirLinex_short=Ref(z,-1)>=100 AND z<100;
Famir_barsfromline_short=BarsSince(FamirLinex_short);
Famir_pivotshort= (Ref(z,-2)<Ref(z,-1)AND Ref(z,-1)<=55 AND Ref(z,-2)<=55) OR (Ref(z,-3)<Ref(z,-1)AND Ref(z,-1)<=55 AND Ref(z,-2)<=55 AND Ref(z,-3)<=55) OR (Ref(z,-4)<Ref(z,-1) AND Ref(z,-1)<=55 AND Ref(z,-2)<=55 AND Ref(z,-3)<=55);
Famirhook_short=Famir_pivotshort AND z<Ref(LLV(z,Famir_barsfromline_short),-1) AND (z>=-55 AND z<=55);
Famirshort= Famir_barsfromline_short<10 AND Famirhook_short AND ((UpTrend OR Ref(Uptrend,-BarsSince(z>0))==1) AND NOT DnTrend) AND C<LSMA25;

// HFE

HFEshort=(Ref(z,-1)>200 AND z<200);
HFElong=(Ref(z,-1)<-200 AND z>-200);
HFE= HFEshort OR HFElong;

// VT Long

vtLinex_long=Ref(z,-1)<=-200 AND z>-200;
vt_barsfromline_long=BarsSince(vtLinex_long);
vtlong_A = z<-200;
vtlong_B = Ref(z,-1)<=Ref(z,-2) OR
Ref(z,-2)<=Ref(z,-3) OR
Ref(z,-3)<=Ref(z,-4) OR
Ref(z,-4)<=Ref(z,-5) OR
Ref(z,-5)<=Ref(z,-6) OR
Ref(z,-6)<=Ref(z,-7) OR
Ref(z,-7)<=Ref(z,-8);
vtlong_bs_A = BarsSince(vtlong_A);
vtlong_bs_B = BarsSince(vtlong_b);
Vtlong_bars = vtlong_bs_A>=5 AND vtlong_bs_B<=0;
vt_pivotlong= Vtlong_bars;
swinghibars=BarsSince(z>Ref(HHV(z,vt_barsfromline_long),-1));
vthook_long= vt_pivotlong AND z>Ref(HHV(z,vt_barsfromline_long),-1);
vtlong= z<100 AND vt_barsfromline_long<=11 AND (Ref(HHV(z,vt_barsfromline_long),-1)<0 OR HHV(z,vt_barsfromline_long)<=0) AND vthook_long AND C>Lsma25 AND Ref(swinghibars>=2,-1) AND z>-100;

// VT Short

vtLinex_short=Ref(z,-1)>=200 AND z<200;
vt_barsfromline_short=BarsSince(vtLinex_short);
vtshort_A = z>200 ;
vtshort_B =Ref(z,-1)>=Ref(z,-2) OR
Ref(z,-2)>=Ref(z,-3) OR
Ref(z,-3)>=Ref(z,-4) OR
Ref(z,-4)>=Ref(z,-5) OR
Ref(z,-5)>=Ref(z,-6) OR
Ref(z,-6)>=Ref(z,-7) OR
Ref(z,-7)>=Ref(z,-8);
vtshort_bs_A = BarsSince(vtshort_A);
vtshort_bs_B = BarsSince(vtshort_b);
Vtshort_bars = vtshort_bs_A>=5 AND vtshort_bs_B<=0;
vt_pivotshort= Vtshort_bars;
swinglowbars= BarsSince(z<Ref(LLV(z,vt_barsfromline_short),-1));
vthook_short= vt_pivotshort AND z<Ref(LLV(z,vt_barsfromline_short),-1);
vtshort= z>-100 AND vt_barsfromline_short<=11 AND (Ref(LLV(z,vt_barsfromline_short),-1)>0 OR LLV(z,vt_barsfromline_short)>0) AND vthook_short AND C<Lsma25 AND Ref(swinglowbars>=2,-1) AND z<100;

// GB 100 Long

Linex_longGB=Ref(z,-1)>100 AND z<100;
barsfromline_longGB=BarsSince(Linex_longGB);
CCIhook_longGB= Ref(z,-1)<-100 AND z>-100;
GB100long= z<100 AND barsfromline_longGB<=12 AND Cziquallong AND CCIhook_longGB AND (Ref(UpTrend,-BarsSince(z>0))==1 AND NOT DnTrend);

// GB100 Short

Linex_shortGB=Ref(z,-1)<-100 AND z>-100;
barsfromline_shortGB=BarsSince(Linex_shortGB);
CCIhook_shortGB=Ref(z,-1)>100 AND z<100;
Gb100short= z>-100 AND barsfromline_shortGB<=12 AND Cziqualshort AND CCIhook_shortGB AND (Ref(DnTrend,-BarsSince(z<0))==1 AND NOT UpTrend);

// TT Long

Minuszero=BarsSince(Ref(z,-1)>0) + 1;
TTCCIhook_long= z>Ref(z,-1) AND z>0;
TTlong= Cziquallong AND z<100 AND Ref(UpTrend,-Minuszero)==1 AND LLV(Ref(z,-1),BarsSince(Ref(z,-1)>=100))>-100 AND HHV(Ref(z,-1),BarsSince(Ref(z,-1)< 0))>=100 AND TTCCIhook_long AND Ref(LowBars,-1)>=4 AND Ref(LowBars,-1)<=9;

// TT Short

Pluszero=BarsSince(Ref(z,-1)<0) + 1;
TTCCIhook_short=z<Ref(z,-1) AND z<0;
TTshort= Cziqualshort AND z>-100 AND Ref(DnTrend,-Pluszero)==1 AND HHV(Ref(z,-1),BarsSince(Ref(z,-1)<=-100))<100 AND LLV(Ref(z,-1),BarsSince(Ref(z,-1)>0))<=-100 AND TTCCIhook_short AND Ref(HighBars,-1)>=4 AND Ref(HighBars,-1)<=9;

// PT Long

Phook_long1= Ref(z,-1)>=Ref(z,-2) AND Ref(z,-2)<Ref(z,-3) AND Ref(z,-3)>0;
Phook_long2= Ref(z,-3)>-100 AND Ref(z,-1)>Ref(z,-2) AND Ref(z,-2)<Ref(z,-3) AND Ref(z,-3)<Ref(z,-4) AND Ref(z,-4)>0;
Ptlong= Cziquallong AND (Phook_long1 OR Phook_long2) AND (z>0 AND Ref(z,-1)<0 AND z<120 AND Ref(z,-1)>-100 AND Ref(z,-2)>-100 AND z>Ref(z,-1) AND UpTrend);

// PT Short

Phook_short1= Ref(z,-1)<=Ref(z,-2) AND Ref(z,-2)>Ref(z,-3) AND Ref(z,-3)<0;
Phook_short2= Ref(z,-3)<100 AND Ref(z,-1)<Ref(z,-2) AND Ref(z,-2)>Ref(z,-3) AND Ref(z,-3)> Ref(z,-4) AND Ref(z,-4)<0;
Ptshort= Cziqualshort AND (Phook_short1 OR Phook_short2) AND (z<0 AND Ref(z,-1)>0 AND z>-120 AND Ref(z,-1)<100 AND Ref(z,-2)<100 AND z<Ref(z,-1) AND DnTrend);

// Ghosts (6)
GhostBarIndex = LastBarIndex;
if (LastBarIndex != CurBarIndex)
GhostBarIndex = CurBarIndex;

C14GhostChange = Param("Ghost - Min WCCI change %", 8, 0, 50);
GhostCciShift=300;
C14GhostChange = Param("Ghost - Min WCCI change %", 8, 0, 50);
GhostCciChange=C14GhostChange / 2; //CCI values are shifted up 300 ponts (-300 - + 300 -> 0 - 600)
C14GhostSteepCompToZL=Param("Ghost - Max trend line slope to ZL(CCI/bar)", 8, 0, 30, 1);
C14GhostSteepCompFromZL=Param("Ghost - Max trend line slope from ZL(CCI/bar)", 4, 0, 30, 1);

// Ghost Long (6)
C14Shifted = -Z + GhostCciShift;
C14Shifted = IIf(C14Shifted < 0, 0, C14Shifted);
C14Shifted = IIf(C14Shifted > 600, 600, C14Shifted);

GhostLongLeft = -Peak(C14Shifted, GhostCciChange, 3) + GhostCciShift;
GhostLongHead = -Peak(C14Shifted, GhostCciChange, 2) + GhostCciShift;
GhostLongRight = -Peak(Ref(C14Shifted,-1), GhostCciChange, 1) + GhostCciShift;
GhostLongRightDip = -Ref(Trough(C14Shifted, GhostCciChange, 1), -1) + GhostCciShift;
GhostLongRightDipIndex = BarIndex() - Ref(TroughBars(C14Shifted, GhostCciChange, 1), -1)-1;
GhostLongLeftDip = -Ref(Trough(C14Shifted, GhostCciChange, 2), -1) + GhostCciShift;
GhostLongLeftDipIndex = BarIndex() - Ref(TroughBars(C14Shifted, GhostCciChange, 2), -1) -1;
GhostLongHeadWidth = GhostLongRightDipIndex - GhostLongLeftDipIndex;
GhostLongRightWidth = BarIndex() - GhostLongRightDipIndex;
GhostLongComp = (GhostLongRightDip - GhostLongLeftDip) / GhostLongHeadWidth;
GhostLongBar = ( (GhostLongLeft > GhostLongHead AND GhostLongRight > GhostLongHead AND GhostLongHead <= -100 ) //Ghost
OR (GhostLongLeft < GhostLongHead AND GhostLongRight < GhostLongHead AND GhostLongLeft <= -100)) //MGhost
AND GhostLongLeftDip <= 0
AND GhostLongRightDip <= 0
AND (GhostLongRightDip + GhostLongComp*GhostLongRightWidth <= Z OR Z>0)//WCCI returned above neckline
AND GhostLongHeadWidth < 25
AND GhostLongRightWidth > 1 AND GhostLongRightWidth < 12;
GhostLong = GhostLongBar AND NOT Ref(GhostLongBar,-1) AND Z < 120
AND GhostLongComp >= -C14GhostSteepCompFromZL AND GhostLongComp <= C14GhostSteepCompToZL;

GhostLongRef = BarsSince(GhostLong);

if ( GhostLongRef[GhostBarIndex] <= 5 )
{
GhostLongIndex = GhostBarIndex - GhostLongRef[GhostBarIndex];
GhostLine = LineArray( GhostLongLeftDipIndex[GhostLongIndex],
GhostLongLeftDip[GhostLongIndex],
GhostLongRightDipIndex[GhostLongIndex] + 10,
GhostLongRightDip[GhostLongIndex] + GhostLongComp[GhostLongIndex] * 10,
0, False);
Plot(GhostLine, "", colorWhite, styleThick | styleNoLabel | styleNoTitle);
}
//DEBUG
//Plot(-120, "GhostLongBar", IIf(GhostLongBar, colorGreen, colorRed));
//GhostLine = LineArray( GhostLongLeftDipIndex[CurBarIndex],
// GhostLongLeftDip[CurBarIndex],
// GhostLongRightDipIndex[CurBarIndex] + 10,
// GhostLongLeftDip[CurBarIndex] + GhostLongComp[CurBarIndex]*(GhostLongHeadWidth[CurBarIndex]+10),
// 0, False);
//Plot(GhostLine, "", colorGreen, styleThick);


// Ghost Short (6)
C14Shifted = Z + GhostCciShift;
C14Shifted = IIf(C14Shifted < 0, 0, C14Shifted);
C14Shifted = IIf(C14Shifted > 600, 600, C14Shifted);

GhostShortLeft = Peak(C14Shifted, GhostCciChange, 3) - GhostCciShift;
GhostShortHead = Peak(C14Shifted, GhostCciChange, 2) - GhostCciShift;
GhostShortRight = Peak(C14Shifted, GhostCciChange, 1) - GhostCciShift;
GhostShortRightDip = Ref(Trough(C14Shifted, GhostCciChange, 1), -1) - GhostCciShift;
GhostShortRightDipIndex = BarIndex() - Ref(TroughBars(C14Shifted, GhostCciChange, 1), -1) -1;
GhostShortLeftDip = Ref(Trough(C14Shifted, GhostCciChange, 2), -1) - GhostCciShift;
GhostShortLeftDipIndex = BarIndex() - Ref(TroughBars(C14Shifted, GhostCciChange, 2), -1) -1;
GhostShortHeadWidth = GhostShortRightDipIndex - GhostShortLeftDipIndex;
GhostShortRightWidth = BarIndex() - GhostShortRightDipIndex;
GhostShortComp = (GhostShortRightDip - GhostShortLeftDip) / GhostShortHeadWidth;
GhostShortBar = ( (GhostShortLeft < GhostShortHead AND GhostShortRight < GhostShortHead AND GhostShortHead >= 100) //Ghost
OR (GhostShortLeft > GhostShortHead AND GhostShortRight > GhostShortHead AND GhostShortLeft >= 100)) //MGhost
AND GhostShortLeftDip >= 0
AND GhostShortRightDip >=0
AND (GhostShortRightDip + GhostShortComp*GhostShortRightWidth >= Z OR Z<0) //WCCI returned below neckline
AND GhostShortHeadWidth < 25
AND GhostShortRightWidth > 1 AND GhostShortRightWidth < 12;
GhostShort = GhostShortBar AND NOT Ref(GhostShortBar,-1) AND Z > -120
AND GhostShortComp <= C14GhostSteepCompFromZL AND GhostShortComp >= -C14GhostSteepCompToZL;

GhostShortRef = BarsSince(GhostShort);

if ( GhostShortRef[GhostBarIndex] <= 5 )
{
GhostShortIndex = GhostBarIndex - GhostShortRef[GhostBarIndex];
GhostLine = LineArray( GhostShortLeftDipIndex[GhostShortIndex],
GhostShortLeftDip[GhostShortIndex],
GhostShortRightDipIndex[GhostShortIndex] + 10,
GhostShortRightDip[GhostShortIndex] + GhostShortComp[GhostShortIndex] * 10,
0, False);
Plot(GhostLine, "", colorWhite, styleThick | styleNoLabel | styleNoTitle);
}
//DEBUG
//Plot(120, "GhostShortBar", IIf(GhostShortBar, colorGreen, colorRed));
//GhostLine = LineArray( GhostShortLeftDipIndex[CurBarIndex],
// GhostShortLeftDip[CurBarIndex],
// GhostShortRightDipIndex[CurBarIndex] + 10,
// GhostShortLeftDip[CurBarIndex] + GhostShortComp[CurBarIndex]*(GhostShortHeadWidth[CurBarIndex]+10),
// 0, False);
//Plot(GhostLine, "", colorRed, styleThick);



// Signal Title

PatCode1=ParamToggle("Plot ZLR (1)","No|Yes",1);
PatCode2=ParamToggle("Plot FAMIR (2)","No|Yes",1);
PatCode3=ParamToggle("Plot VT (3)","No|Yes",1);
PatCode4=ParamToggle("Plot GB100 (4)","No|Yes",1);
PatCode5=ParamToggle("Plot TT (5)","No|Yes",1);
PatCode6=ParamToggle("Plot GHOST (6)","No|Yes",1);
PatCode7=ParamToggle("Plot HFE","No|Yes",1);

Signaltitle= WriteIf(PatCode1==1 AND zlrlong,EncodeColor(colorDarkRed) + "\n" + "*** ALERT -- ZLR ***" + "\n",
WriteIf(PatCode1==1 AND zlrshort,EncodeColor(colorDarkRed) + "\n" + "*** ALERT -- ZLR ***" + "\n",
WriteIf(PatCode2==1 AND Famirshort,EncodeColor(colorDarkRed) + "\n" + "*** ALERT -- FAMIR ***" + "\n",
WriteIf(PatCode2==1 AND Famirlong,EncodeColor(colorDarkRed) + "\n" + "*** ALERT -- FAMIR ***" + "\n",
WriteIf(PatCode3==1 AND VTlong AND NOT famirlong,EncodeColor(colorDarkRed) + "\n" + "*** ALERT -- VT ***" + "\n",
WriteIf(PatCode3==1 AND VTshort AND NOT famirshort,EncodeColor(colorDarkRed) + "\n" + "*** ALERT -- VT ***" + "\n",
WriteIf(PatCode4==1 AND GB100long,EncodeColor(colorDarkRed) + "\n" + "*** ALERT -- GB100 ***" + "\n",
WriteIf(PatCode4==1 AND Gb100short,EncodeColor(colorDarkRed) + "\n" + "*** ALERT -- GB100 ***" + "\n",
WriteIf(PatCode5==1 AND TTLong,EncodeColor(colorDarkRed) + "\n" + "*** ALERT -- TT ***" + "\n",
WriteIf(PatCode5==1 AND TTShort,EncodeColor(colorDarkRed) + "\n" + "*** ALERT -- TT ***" + "\n",
WriteIf(PatCode6==1 AND GhostLong,EncodeColor(colorDarkRed) + "\n" + "*** ALERT -- GHOST ***" + "\n",
WriteIf(PatCode6==1 AND GhostShort,EncodeColor(colorDarkRed) + "\n" + "*** ALERT -- GHOST ***" + "\n",
WriteIf(PatCode7==1 AND HFE,EncodeColor(colorDarkRed) + "\n" + "*** ALERT -- HFE ***" + "\n","")))))))))))));

// Pattern signal codes

PlotShapes(IIf(PatCode1==1 AND zlrlong,shapeDigit1,shapeNone),colorBlue,0,Min(z,0),-15);
PlotShapes(IIf(PatCode1==1 AND zlrshort,shapeDigit1+ shapePositionAbove,shapeNone),colorRed,0,Max(z,0),-15);
PlotShapes(IIf(PatCode2==1 AND famirlong,shapeDigit2,shapeNone),colorBlue,0,Min(z,0),-15);
PlotShapes(IIf(PatCode2==1 AND famirShort ,shapeDigit2+ shapePositionAbove,shapeNone),colorRed,0,Max(z,0),-15) ;
PlotShapes(IIf(PatCode3==1 AND vtlong AND NOT famirlong,shapeDigit3,shapeNone),colorBlue,0,Min(z,0),-47);
PlotShapes(IIf(PatCode3==1 AND vtshort AND NOT famirshort,shapeDigit3+ shapePositionAbove,shapeNone),colorRed,0,Max(z,0),-47);
PlotShapes(IIf(PatCode4==1 AND GB100long,shapeDigit4,shapeNone),colorBlue,0,Min(z,0),-60);
PlotShapes(IIf(PatCode4==1 AND GB100short,shapeDigit4+ shapePositionAbove,shapeNone),colorRed,0,Max(z,0),-60);
PlotShapes(IIf(PatCode5==1 AND ttlong,shapeDigit5,shapeNone),colorBlue,0,Min(z,0),-50);
PlotShapes(IIf(PatCode5==1 AND ttshort,shapeDigit5+ shapePositionAbove,shapeNone),colorRed,0,Max(z,0),-50);
PlotShapes(IIf(PatCode6==1 AND GhostLong,shapeDigit6,shapeNone),colorBlue,0,Min(z,0),-50);
PlotShapes(IIf(PatCode6==1 AND GhostShort,shapeDigit6+ shapePositionAbove,shapeNone),colorRed,0,Max(z,0),-50);
PlotShapes(IIf(PatCode7==1 AND HFEshort,shapeCircle,shapeNone),IIf(PatCode7==1 AND HFEshort,colorYellow,shapeNone),0,200,10);
PlotShapes(IIf(PatCode7==1 AND HFElong,shapeCircle,shapeNone),IIf(PatCode7==1 AND HFElong,colorYellow,shapeNone),0,-200,-10) ;

// CCI hook Exit
HookExitLong= z<=Ref(z,-1);
HookExitShort= z>=Ref(z,-1);

// 100 Line Cross Exit Conservative
Cross100longC= z<=Ref(z,-1) AND z<100;
Cross100shortC= z>=Ref(z,-1) AND z>-100;

// 100 Line Cross Exit Aggressive
Cross100longA= Ref(z,-1)>100 AND z<100;
Cross100shortA= Ref(z,-1)<-100 AND z>-100;

// Mplay Exit

MplayExitLong= z<Ref(z,-1) AND Ref(z,-1)<Ref(z,-2) AND C<O;
MplayExitShort= z>Ref(z,-1) AND Ref(z,-1)>Ref(z,-2) AND C>O;

// Heikin-Ashi Exit

HaClose =EMA((O+H+L+C)/4,3);
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
HExitConLong= HaLow < HaOpen;
HExitConShort= HaHigh > HaOpen;

// Exit code
ExitCode= Param("Exits:Hook=1,100xConservative=2,100xAggressive=3,Mplay=4,H-Ashi=5",1,1,5);
ExitCodeTitleLong= IIf(ExitCode==1,HookExitLong,IIf(Exitcode==2,Cross100longC,IIf(Exitcode==3,Cross100longA,IIf(Exitcode==4,MplayExitLong,IIf(Exitcode==5,HExitConLong,0)))));
ExitCodeTitleShort= IIf(ExitCode==1,HookExitShort,IIf(Exitcode==2,Cross100shortC,IIf(Exitcode==3,Cross100shortA,IIf(Exitcode==4,MplayExitShort,IIf(Exitcode==5,HExitConShort,0)))));
AllPatterns =(zlrlong AND patcode1==1) OR (famirlong AND patcode2==1) OR (Vtlong AND patcode3==1) OR (gb100long AND patcode4==1) OR (ttlong AND patcode5==1) OR (GhostLong AND patcode6==1) OR (Hfelong...
coolabhi99  
#13 Posted : Thursday, October 20, 2011 11:18:37 PM(UTC)
coolabhi99

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 10/18/2011(UTC)
Posts: 2

http://imgur.com/qtdLS

This is the screen shot....The bottom window is the Woodies CCI Panel. The red vertical bars indicate bearish trend, Blue indicates Bullish, Grey indicates neutral trend & yellow means pre-trend.

Please help and incase anyone needs any clarifications please let me know.

Regards,

Abhinay
KINGRESEARCH  
#14 Posted : Tuesday, November 19, 2013 5:08:59 AM(UTC)
KINGRESEARCH

Rank: Newbie

Groups ready for retrieval: Registered, Registered Users
You have been a member since:: 11/19/2013(UTC)
Posts: 1

Anyone Can help Me for Converting These Two AMIBROKER FORMULA

for METASTOCK

/*////////////////////////////////////////////////////////////////////////////////////////*/

formula-1

_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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("EMA34");
P = ParamField("Price field",-1);
Plot( EMA( P, 34 ), _DEFAULT_NAME(), ParamColor( "Color", colorBlue ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("Nifty_compare");
PlotForeign("^NSEI-Intraday","NIFTY",ParamColor("Color", colorPink ), styleNoTitle | ParamStyle("Style", styleOwnScale | styleThick) );
_SECTION_END();

_SECTION_BEGIN("Nifty_compare1");
PlotForeign("^NSEI","NIFTY1",ParamColor("Color", colorPink ), styleNoTitle | ParamStyle("Style", styleOwnScale | styleThick) );
_SECTION_END();


_SECTION_BEGIN("Arrow_marks");
periods = Param( "Periods", 20, 1, 200, 1 );
Ksmooth = Param( "%K avg", 12, 1, 200, 1 );
DSmooth = Param( "%D avg", 10, 1, 200, 1 );

y0=LastValue(Trough(StochD(periods , Ksmooth, DSmooth ),1,2));
y1=LastValue(Trough(StochD(periods , Ksmooth, DSmooth ),1,1));
x0=BarCount - 1 - LastValue(TroughBars(StochD(periods , Ksmooth, DSmooth ),1,2));
price_start=Close[x0];
x1=BarCount - 1 - LastValue(TroughBars(StochD(periods , Ksmooth, DSmooth ),1,1));
price_end=Close[x1];
Line = LineArray( x0, y0, x1, y1, 0 );
Buy = y1>y0 AND price_end<price_start;
LastPointBuy = LineArray(x1-1,Close[x1-1],x1,Close[x1],0);
PlotShapes(shapeUpTriangle * Buy, colorGreen,0,LastPointBuy);

y00=LastValue(Peak(StochD(periods , Ksmooth, DSmooth ),1,2));
y11=LastValue(Peak(StochD(periods , Ksmooth, DSmooth ),1,1));
x00=BarCount - 1 - LastValue(PeakBars(StochD(periods , Ksmooth, DSmooth ),1,2));
price_start1=Close[x00];
x11=BarCount - 1 - LastValue(PeakBars(StochD(periods , Ksmooth, DSmooth ),1,1));
price_end1=Close[x11];
Line = LineArray( x00, y00, x11, y11, 0 );
LastPointSell = LineArray(x11-1,Close[x11-1],x11,Close[x11],0);
Sell = y11<y00 AND price_end1>price_start1;
PlotShapes(shapeDownTriangle * Sell, colorRed,0,LastPointSell);
_SECTION_END();



/*_SECTION_BEGIN("Trendline");
ST3=StochK( 20 , 12);
ST33=StochD( 20 , 12, 10 );
Buy=Cross(st3,st33);
Sell=Cross(st33,st3);
PlotShapes( shapeDownArrow * Sell, colorRed );
PlotShapes( shapeUpArrow * Buy, colorGreen );
_SECTION_END();*/

/*_SECTION_BEGIN("MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 200, 1 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("Mid MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 45, 2, 300, 1 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("Long MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 100, 2, 400, 1 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();*/

_SECTION_BEGIN("BBands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 100, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorLightGrey );
Style = ParamStyle("Style") | styleNoRescale;
Plot( BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style );
Plot( BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style );
_SECTION_END();

_SECTION_BEGIN("Price Interpretation");
movshort = ParamField("Short Time MA", 8 );
movmed = ParamField("Mid Time MA", 9 );
movlong = ParamField("Long Time MA", 10 );
btop = ParamField("BBTop", 11 );
bbot = ParamField("BBBottom", 12 );
if( Status("action") == actionCommentary )
{
width = btop - bbot;
lslop = LinRegSlope( C, 30 ) + 100;
lslo = LLV( lslop, 90 );
lshi = HHV( lslop, 90 );
lswidth = lshi - lslo;
trend = 100*( lslop - lslo )/lswidth;

mawidth = MA( width, 100 );
relwidth = 100*(width - mawidth)/mawidth;

_N( tname = Name()+"("+FullName()+")" );

printf("Price and moving averages:\n");
printf( tname + " has closed " + WriteIf( C > movshort, "above" , "below" ) + " its Short time moving average. ");

printf("\nShort time moving average is currently " + WriteIf( movshort > movmed, "above", "below") + " mid-time, AND " + WriteIf( movshort > movlong, "above", "below" ) + " long time moving averages.");

printf("\nThe relationship between price and moving averages is: "+
WriteIf( C > movshort AND movshort > movmed, "bullish",
WriteIf( C < movshort AND movshort < movmed, "bearish", "neutral" ) ) + " in short-term, and "+
WriteIf( movshort > movmed AND movmed > movlong , "bullish",
WriteIf( movshort < movmed AND movmed < movlong, "bearish", "neutral" ) ) + " in mid-long term. ");

printf("\n\nBollinger Bands:\n");
printf(tname+ " has closed " +
WriteIf( C < bbot, "below the lower band by " +
WriteVal( 100 *( bbot-C )/ width, 1.1 ) + "%%. " +
WriteIf( trend < 30, " This combined with the steep downtrend can suggest that the downward trend in prices has a good chance of continuing. However, a short-term pull-back inside the bands is likely.",
WriteIf( trend > 30 AND trend < 70, "Although prices have broken the lower band and a downside breakout is possible, the most likely scenario for "+tname+" is to continue within current trading range.", "" ) ), "" ) +

WriteIf( C > btop, "above the upper band by " +
WriteVal( 100 *( C- btop )/ width, 1.1 ) + "%%. " +
WriteIf( trend > 70, " This combined with the steep uptrend suggests that the upward trend in prices has a good chance of continuing. However, a short-term pull-back inside the bands is likely.",
WriteIf( trend > 30 AND trend < 70, "Although prices have broken the upper band and a upside breakout is possible, the most likely scenario for "+tname+" is to continue within current trading range.", "" ) ), "" ) +

WriteIf( C < btop AND ( ( btop - C ) / width ) < 0.5,
"below upper band by " +
WriteVal( 100 *( btop - C )/ width, 1.1 ) + "%%. ",
WriteIf( C < btop AND C > bbot , "above bottom band by " +
WriteVal( 100 *( C - bbot )/ width, 1.1 ) + "%%. ", "" ) ));

printf("\n"+
WriteIf( ( trend > 30 AND trend < 70 AND ( C > btop OR C < bbot ) ) AND abs(relwidth) > 40,
"This picture becomes somewhat unclear due to the fact that Bollinger Bands are currently",
"Bollinger Bands are " )+
WriteVal( abs( relwidth ), 1.1 ) + "%% " +
WriteIf( relwidth > 0, "wider" , "narrower" ) +
" than normal.");

printf("\n");

printf(
WriteIf( abs( relwidth ) < 40, "The current width of the bands (alone) does not suggest anything conclusive about the future volatility or movement of prices.","")+
WriteIf( relwidth < -40, "The narrow width of the bands suggests low volatility as compared to " + tname + "'s normal range. Therefore, the probability of volatility increasing with a sharp price move has increased for the near-term. "+
"The bands have been in this narrow range for " + WriteVal(BarsSince(Cross(-40,relwidth)),1.0) + " bars. The probability of a significant price move increases the longer the bands remain in this narrow range." ,"")+
WriteIf( relwidth > 40, "The large width of the bands suggest high volatility as compared to " + tname + "'s normal range. Therefore, the probability of volatility decreasing and prices entering (or remaining in) a trading range has increased for the near-term. "+
"The bands have been in this wide range for " + WriteVal(BarsSince(Cross(relwidth,40)),1.0) + " bars.The probability of prices consolidating into a less volatile trading range increases the longer the bands remain in this wide range." ,""));

printf("\n\nThis commentary is not a recommendation to buy or sell. Use at your own risk.");
}
_SECTION_END();



FORMULA 2

_SECTION_BEGIN("Stupid Functions");

function HAI_F1(no)
{
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
return (IIf(avn==1,sup,res));
}

function HAI_F2(no)
{
return (Cross(C,HAI_F1(no)));
}

function HAI_F3(no)
{
return (Cross(HAI_F1(no),C));
}

function HAI_F4(no)
{
prev=AMA2(C,1,0);
d=IIf(C>Ref(Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),-1),Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),
IIf(C<Ref(Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),-1),Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),PREV));
a=Cross(Close,d);
b=Cross(d,Close);
return (IIf(BarsSince(a)<BarsSince(b),1,0));
}

function HAI_F5(no)
{
state = HAI_F4(no);
s=state>Ref(state,-1);
ss=state<Ref(state,-1);
return (state==Ref(state,-1));
}


function HAI_F6(p,n,s,m)
{
return (PDI(p)>MDI(n)AND Signal(s)<MACD(m));
}

function HAI_F7(p,n,s,m)
{
return (MDI(n)>PDI(p)AND Signal(s)>MACD(m));
}


_SECTION_END();


_SECTION_BEGIN("Swing");

no = 22;
sloss = HAI_F1(no);
a = HAI_F2(no);
b = HAI_F3(no);
state = HAI_F4(no);
sss = HAI_F5(no);
uptrend = HAI_F6(20,10,29,22);
downtrend = HAI_F7(20,10,29,13);

style = a * styleStaircase + b * styleStaircase;
PlotShapes(a,style, IIf(a,colorGreen,colorRed), 0, IIf(a,Low,High));
_SECTION_END();

col=IIf(state == 7 ,51,IIf(state ==2,4,1));
Plot(C,"",Col,64);
PlotShapes( shapeUpArrow * a, colorGreen,0,L);
PlotShapes( shapeDownArrow * b, colorRed,0,H);

Filter = a OR b OR sss ;
AddColumn(C,"close",1.2);
AddColumn( IIf( a, 66,1 ), "buy", formatChar, 1, bkcolor =IIf (a,colorYellow, colorPink ));
AddColumn( IIf( b, 83,1 ), "sell", formatChar, 1, bkcolor =IIf (b,colorPink, colorYellow ));
AddColumn( IIf( sss, 87,1 ), "wait", formatChar, 1, bkcolor =IIf (sss,colorYellow, colorRed ));

_SECTION_BEGIN("");
_N(Title = EncodeColor(colorBlack) + "{{NAME}} - {{INTERVAL}} {{DATE}} " );
_SECTION_END();

_SECTION_BEGIN("Intraday AFL System");
Buy = a;
Sell = b;

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-30);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-35);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=30);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=40);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-35);

dist = ATR(20);
for (i=0; i<BarCount; i++) {
if ( Buy )
PlotText("Buy:" + O[ i ], i, L[ i ]-3*dist, colorBlack);
if ( Sell )
PlotText("Sell:" + O[ i ], i, H[ i ]+3*dist, colorBlack);
}
_SECTION_END();

_SECTION_BEGIN("Trend");

Plot( 2, /* defines the height of the ribbon in percent of pane width */"ribbon",
IIf( uptrend, colorGreen, IIf( downtrend, colorRed, 0 )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();

//d = Close > Ref( ChandelierHL(ATR(3),20), -1);
//e =Close < Ref( ChandelierHL(ATR(3),20), -1);
//f = Close < Ref( ChandelierHL(ATR(3),20), -1);
//g = Close > Ref( ChandelierHL(ATR(3),20), -1);

Buy = a AND uptrend ;
Short = b AND downtrend ;
Sell = b AND downtrend ;
Cover = a AND uptrend;

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

Filter=Buy OR Sell;
Filter= Cover OR Short;

AddColumn( Buy, "Buy", 1);
AddColumn(Sell, "Sell", 1);
AddColumn(Close,"Close",1.2);
AddColumn(Volume,"Volume",1.0);

// Plot the Buy and Sell arrows.
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes(shape, IIf(Buy,colorGreen,colorRed), 0, IIf(Buy,Low,High));

//Plot(sloss,"Swing",colorYellow,styleStaircase);

//SetChartBkGradientFill( ParamColor("BgTop", ColorRGB( 172,172,172 )),

//ParamColor("BgBottom", ColorRGB( 172,172,172 )),ParamColor("titleblock",ColorRGB( 172,172,172 )));
//Alerts
AlertIf( Buy, "SOUND C:\\Windows\\Media\ ada.wav", "Buy",1,1+2+4+8);
AlertIf( Short, "SOUND C:\\Windows\\Media\\notify.wav", "Short",2,1+2+4+8);

GraphXSpace = 4;

/* -------------------------------------------------------------------------------------- */

SetChartBkColor(colorDarkOliveGreen =2);
SetChartOptions(0,chartShowArrows|chartShowDates);

/* -------------------------------------------------------------------------------------- */

////////////////////////////////////////////////////////////////////////////////////////////////
messageboard = ParamToggle("Message Board","Show|Hide",0);
showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);

style = a * styleStaircase + b * styleStaircase;

PlotShapes(a,style, IIf(a,colorGreen,colorRed), 0, IIf(a,Low,High));
if (showsl == 0) Plot(sloss,"Stop Loss",colorCustom14,styleDots);
exitlong = Cross(sloss, H);
PlotShapes(exitlong * shapeNone, colorBlack,0,H,-10);
exitshort = Cross(L, sloss);
PlotShapes(exitshort * shapeNone, colorBlack,0,L,-15);

Buy = exitshort;
Sell = exitlong;
//Short = Sell;
//Cover = Buy;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
//Short = ExRem(Short, Cover);
//Cover = ExRem(Cover, Short);
AlertIf( Buy, "", "BUY @ " + C, 1 );
AlertIf( Sell, "", "SELL @ " + C, 2 );

for (i=BarCount-1; i>1; i--) {
if (Buy == 1) {
entry = O;
sig = "BUY";
sl = sloss;
tar1 = entry + (entry * .0040);
tar2 = entry + (entry * .0085);
tar3 = entry + (entry * .0179);
bars = i;
i = 0;
}
if (Sell == 1) {
sig = "SELL";
entry = O;
sl = sloss;
tar1 = entry - (entry * .0040);
tar2 = entry - (entry * .0085);
tar3 = entry - (entry * .0212);
bars = i;
i = 0;
}
}

Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, sloss[BarCount-1], Ref(sloss, -1));
sl = ssl[BarCount-1];

printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago");
printf("\n" + sig + " @ : " + entry + "\nStop Loss : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"+ "\nTarget_1 : " + tar1 + "\nTarget_2 : " + tar2 + "\nTarget_3 : " + tar3);
printf("\nCurrent P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2));

if (messageboard == 0) {
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if (sig =="BUY")
GfxSelectSolidBrush( colorGreen ); // this is the box background color
else
GfxSelectSolidBrush( colorRed ); // this is the box background color

pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 05;
x2 = 200;

y = Status( "pxchartheight" );

GfxSelectPen( colorBlack, 1); // broader color
GfxRoundRect( x, y - 143, x2, y , 7, 7 ) ;
GfxTextOut( ( " "), 10, y-140) ;
GfxTextOut( Name(),13,y-120);

GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-100);
GfxTextOut( ("Trailing SL : " + sl + " "), 13, y-80);
GfxTextOut( ("TGT:1 : " + tar1), 13, y -60);
GfxTextOut( ("TGT:2 : " + tar2), 13,y-40);
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 13, y-20);;
}


//Magfied Market Price
FS=Param("Font Size",30,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True );
GfxSetBkMode( colorBlack );
GfxSetTextColor( ParamColor("Color",colorGreen) );
Hor=Param("Horizontal Position",800,1,1200,1);
Ver=Param("Vertical Position",12,1,830,1);
GfxTextOut(""+C, Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Times New Roman", 11, 700, True );
GfxSetBkMode( colorBlack );
GfxSetTextColor(ParamColor("Color",colorYellow) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor , Ver+45 );
John S  
#15 Posted : Tuesday, November 19, 2013 12:43:50 PM(UTC)
John S

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 11/9/2012(UTC)
Posts: 169

Wow! That is a lot of code. I do not know AmiBroker's language, but I do see that much of this appears to conditionally color plots which MetaStock can only do via the Expert Advisor. But maybe someone else knows.

But even it is possible to replicate this with the various tools in MetaStock, it will take someone a tremendous amount of time. So what I'm saying is that you may have to be prepared to pay someone for this service.


Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.