Nirvana.afl by MRTQ13

@Amibrokerfans

Have you got an AFL or integrate the code into any afl to print Total Bid Quantity and Total Ask Quantity,

thanks in Advance ,,,,
Code:
_SECTION_BEGIN("Bid Vs Ask Dashboard");

messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
Bid = GetRTData("Bid"); 
Ask = GetRTData("Ask"); 

GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );
GfxSelectSolidBrush( colorBlue ); // this is the box background color

pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");

x = 1000;
x2 =1090;
 
y = pxHeight-400;
 
GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 98, x2, y-50 , 7, 7 ) ;
GfxTextOut( ( "Bid"),x+13,y-100);
GfxTextOut( (" "),x+27,y-100);
GfxTextOut( (""+Bid), x+13, y-80) ; // The text format location

GfxSelectSolidBrush( colorOrange ); 
 
GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x+92, y - 98, x2+92, y-50 , 7, 7 ) ;
GfxTextOut( ( "Ask"),x+13+92,y-100);
GfxTextOut( (" "),x+27+92,y-100);
GfxTextOut( (""+Ask), x+13+92, y-80) ; // The text format location

}

_SECTION_END();
 
Last edited:
Well Thanks a lot Manoj,, but i need to print Total Bid or Ask quantity not only bid and ask quantity,,
can you advise me with that,,, i have data feeds from Globaldatafeeds,,
Thank you,,,
 
well Thanks a lot Manoj for the code,,

i think bidsize will work too in place of bid only
Code:
//Spred Lines//
_SECTION_BEGIN("SPREAD LINES");
messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
Bid = GetRTData("Bid");
Ask = GetRTData("Ask");
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
Plot(BID,"BID",colorLightOrange,styleDots,1) ;
Plot(ASK,"ASK",colorYellow,styleDots,1) ;
}
_SECTION_END();

_SECTION_BEGIN("SCORE BOARD");
messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
szBid = GetRTData("BidSize");
szAsk = GetRTData("AskSize");
Bid = GetRTData("Bid");
Ask = GetRTData("Ask");
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );
GfxSelectSolidBrush( colorBlue ); // this is the box background color
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
x = 1000;
x2 =1090;
y = pxHeight-400;
GfxTextOut( ( "Bid Qty"),x-53,y-100);
GfxTextOut( (" "),x+13,y-100);
GfxTextOut( (""+szBid), x-20, y-80) ; // The text format location
GfxTextOut( ( "Ask Qty"),x+63+92,y-100);
GfxTextOut( (" "),x+13+92,y-100);
GfxTextOut( (""+szAsk), x+93+92, y-80) ; // The text format location
GfxTextOut( ( "Bid"),x+13,y-100);
GfxTextOut( (" "),x+27,y-100);
GfxTextOut( (""+Bid), x+13, y-80) ; // The text format location
GfxTextOut( ( "Ask"),x+13+92,y-100);
GfxTextOut( (" "),x+27+92,y-100);
GfxTextOut( (""+Ask), x+13+92, y-80) ; // The text format location
}
_SECTION_END();
 
i donnot know how to attach the indicator so i copy paste the formula





//+------------------------------------------------------------------+
//| Level Trading.mq4 |
//| by Accel |
//+------------------------------------------------------------------+

#property copyright "Accel"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue

extern int IndicatorNumber=1;
extern color TrendUpColor=Blue;
extern color TrendDownColor=Red;
extern color LevelColor=DarkGray;
extern int Width2LevelConfirmation=3;
extern int Width3LevelConfirmation=5;
extern int Width4LevelConfirmation=7;
extern int Width5LevelConfirmation=10;
extern bool SnapExtremumsToLevelOnChar=True;
extern int FractalBarsOnEachSide=7;
extern int ProceedMaxHistoryBars=2000;
extern int LevelActuality=200;
extern bool RestDefaultTimeframeValues=True;
extern int ExtremumToLevelMaxGap=15;
extern double PriceDeltaFor1Bar=0.4;

int LevelLength[];
int LevelWidth[];
int PriceCrossedLevel;
double long[];
double short[];

int init()
{
IndicatorBuffers(2);
SetIndexBuffer(0,long);
SetIndexBuffer(1,short);
return(0);
}

int deinit()
{
int i=0;

for (i=Bars-1;i>=0;i--)
if (ObjectFind(StringConcatenate("Level_",IndicatorNumber,"_",i))!=-1)
ObjectDelete(StringConcatenate("Level_",IndicatorNumber,"_",i));
for (i=Bars-1;i>=0;i--)
if (ObjectFind(StringConcatenate("Trend_",IndicatorNumber,"_",i))!=-1)
ObjectDelete(StringConcatenate("Trend_",IndicatorNumber,"_",i));
return(0);
}

int LastBarWasHighLow(int LELB, int LEHB)
{
if (LELB==-1 && LEHB!=-1)
return(1);
if (LELB!=-1 && LEHB==-1)
return(-1);
if (LELB!=-1 && LEHB!=-1 && LELB>LEHB)
return(1);
if (LELB!=-1 && LEHB!=-1 && LELB<LEHB)
return(-1);
return(0);
}

int start()
{
int i,j;
int BarsToCheck;
int Stop;
int CurrState; //CurrState=0 - �� ����� �����������, 1-����������� �����, -1-����������� ����
int LastExtremumHighBar=-1;
int LastExtremumLowBar=-1;
int LastExtremumBar=-1;
double iFractalValue=0,jFractalValue=0;

if (IndicatorCounted()<0)
return(-1);

if (Bars-IndicatorCounted()==1)
return(0);

deinit();
SetIndexStyle(0,DRAW_ARROW,0,3);
SetIndexArrow(0,251);
SetIndexStyle(1,DRAW_ARROW,0,3);
SetIndexArrow(1,251);
ArrayInitialize(long,0);
ArrayInitialize(short,0);

if (RestDefaultTimeframeValues==1)
{
switch (Period())
{
case 1: //M1
{
ExtremumToLevelMaxGap=2;
PriceDeltaFor1Bar=0.05;
break;
}
case 5: //M5
{
ExtremumToLevelMaxGap=5;
PriceDeltaFor1Bar=0.1;
break;
}
case 15: //M15
{
ExtremumToLevelMaxGap=8;
PriceDeltaFor1Bar=0.2;
break;
}
case 30: //M30
{
ExtremumToLevelMaxGap=10;
PriceDeltaFor1Bar=0.3;
break;
}
case 60: //H1
{
ExtremumToLevelMaxGap=15;
PriceDeltaFor1Bar=0.4;
break;
}
case 240: //H4
{
ExtremumToLevelMaxGap=25;
PriceDeltaFor1Bar=0.4;
break;
}
case 1440: //D1
{
ExtremumToLevelMaxGap=75;
PriceDeltaFor1Bar=1.5;
break;
}
case 10080: //W1
{
ExtremumToLevelMaxGap=150;
PriceDeltaFor1Bar=5;
break;
}
case 43200: //MN
{
ExtremumToLevelMaxGap=300;
PriceDeltaFor1Bar=24;
break;
}
}
}

if (Width2LevelConfirmation<=1)
Width2LevelConfirmation=2;

if (Width3LevelConfirmation<=Width2LevelConfirmation)
Width3LevelConfirmation=Width2LevelConfirmation+1;

if (Width4LevelConfirmation<=Width3LevelConfirmation)
Width4LevelConfirmation=Width3LevelConfirmation+1;

if (Width5LevelConfirmation<=Width4LevelConfirmation)
Width5LevelConfirmation=Width4LevelConfirmation+1;

PriceCrossedLevel=ExtremumToLevelMaxGap*2;

ArrayResize(LevelLength,Bars);
ArrayInitialize(LevelLength,0);
ArrayResize(LevelWidth,Bars);
ArrayInitialize(LevelWidth,1);

if (FractalBarsOnEachSide<=0)
FractalBarsOnEachSide=1;

//���� ��������
for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{
//���� ������ �������
if (i==Lowest(Symbol(),Period(),MODE_LOW,FractalBarsOnEachSide*2+1,i-FractalBarsOnEachSide))
{
switch (LastBarWasHighLow(LastExtremumLowBar,LastExtremumHighBar))
{
case -1:
{
if (Low<Low[LastExtremumLowBar])
{
long=Low;
long[LastExtremumLowBar]=0;
LastExtremumLowBar=i;
}
break;
}
case 1:
{
if (Low<High[LastExtremumHighBar])
{
long=Low;
LastExtremumLowBar=i;
}
break;
}
case 0:
{
long=Low;
LastExtremumLowBar=i;
break;
}
}
}
//���� ������� �������
if (i==Highest(Symbol(),Period(),MODE_HIGH,FractalBarsOnEachSide*2+1,i-FractalBarsOnEachSide) && long==0)
{
switch (LastBarWasHighLow(LastExtremumLowBar,LastExtremumHighBar))
{
case 1:
{
if (High>High[LastExtremumHighBar])
{
short=High;
short[LastExtremumHighBar]=0;
LastExtremumHighBar=i;
}
break;
}
case -1:
{
if (High>Low[LastExtremumLowBar])
{
short=High;
LastExtremumHighBar=i;
}
break;
}
case 0:
{
short=High;
LastExtremumHighBar=i;
break;
}
}
}
}

//����, ��� ������������� ������ ��������� (������� ����������� ����� ������)
for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{
if (long==Low)
{
Stop=-1;
CurrState=0;
for (j=i-1;j>=0 && Stop==-1;j--)
{
if (CurrState==-1)
if (High[j]>Low+(i-j)*PriceDeltaFor1Bar*Point+PriceCrossedLevel*Point)
Stop=j;
if (CurrState==0)
if (Low[j]<Low+(i-j)*PriceDeltaFor1Bar*Point-PriceCrossedLevel*Point)
CurrState=-1;
}
if (Stop!=-1)
LevelLength=i-Stop;
else
LevelLength=i;
}

if (short==High)
{
Stop=-1;
CurrState=0;
for (j=i-1;j>=0 && Stop==-1;j--)
{
if (CurrState==1)
if (Low[j]<High+(i-j)*PriceDeltaFor1Bar*Point-PriceCrossedLevel*Point)
Stop=j;
if (CurrState==0)
if (High[j]>High+(i-j)*PriceDeltaFor1Bar*Point+PriceCrossedLevel*Point)
CurrState=1;
}
if (Stop!=-1)
LevelLength=i-Stop;
else
LevelLength=i;
}
}

//���������� ������� ������ ������ ���������
for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{
if (LevelLength>0)
{
if (long!=0)
iFractalValue=long;
if (short!=0)
iFractalValue=short;
BarsToCheck=MathMin(LevelActuality,LevelLength);
j=i-1;
LevelLength=BarsToCheck;
while (BarsToCheck>0)
{
if (LevelLength[j]>0)
{
if (long[j]!=0)
jFractalValue=long[j];
if (short[j]!=0)
jFractalValue=short[j];

if (MathAbs(iFractalValue+(i-j)*PriceDeltaFor1Bar*Point-jFractalValue)<ExtremumToLevelMaxGap*Point)
{
BarsToCheck=MathMin(LevelActuality,LevelLength[j]);
LevelLength=i-j+BarsToCheck;
LevelLength[j]=0;
LevelWidth++;
if (SnapExtremumsToLevelOnChar==1)
{
if (long[j]!=0)
{
long[j]=iFractalValue+(i-j)*PriceDeltaFor1Bar*Point;
}
if (short[j]!=0)
{
short[j]=iFractalValue+(i-j)*PriceDeltaFor1Bar*Point;
}
}
}
}
BarsToCheck--;
j--;
}
}
}

//������ �������
for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{
if (long!=0 || short!=0)
{
if (LastExtremumBar!=-1)
{
if (long!=0)
{
ObjectCreate(StringConcatenate("Trend_",IndicatorNumber,"_",i),OBJ_TREND,0,
Time[LastExtremumBar],short[LastExtremumBar],Time,long);
ObjectSet(StringConcatenate("Trend_",IndicatorNumber,"_",i),OBJPROP_COLOR,TrendDownColor);
}
if (short!=0)
{
ObjectCreate(StringConcatenate("Trend_",IndicatorNumber,"_",i),OBJ_TREND,0,
Time[LastExtremumBar],long[LastExtremumBar],Time,short);
ObjectSet(StringConcatenate("Trend_",IndicatorNumber,"_",i),OBJPROP_COLOR,TrendUpColor);
}
ObjectSet(StringConcatenate("Trend_",IndicatorNumber,"_",i),OBJPROP_RAY,0);
ObjectSet(StringConcatenate("Trend_",IndicatorNumber,"_",i),OBJPROP_WIDTH,2);
}
LastExtremumBar=i;
}
}

//������ ������
for (i=MathMin(ProceedMaxHistoryBars,Bars-FractalBarsOnEachSide-1);i>=FractalBarsOnEachSide;i--)
{
if (LevelLength!=0)
{
if (long!=0)
iFractalValue=long;
if (short!=0)
iFractalValue=short;

ObjectCreate(StringConcatenate("Level_",IndicatorNumber,"_",i),OBJ_TREND,0,
Time,iFractalValue,Time[i-LevelLength],iFractalValue+LevelLength*PriceDeltaFor1Bar*Point);
if (i!=LevelLength)
ObjectSet(StringConcatenate("Level_",IndicatorNumber,"_",i),OBJPROP_RAY,0);
ObjectSet(StringConcatenate("Level_",IndicatorNumber,"_",i),OBJPROP_COLOR,LevelColor);
if (LevelWidth>1)
{
ObjectSet(StringConcatenate("Level_",IndicatorNumber,"_",i),OBJPROP_WIDTH,1);
if (LevelWidth>=Width2LevelConfirmation)
ObjectSet(StringConcatenate("Level_",IndicatorNumber,"_",i),OBJPROP_WIDTH,2);
if (LevelWidth>=Width3LevelConfirmation)
ObjectSet(StringConcatenate("Level_",IndicatorNumber,"_",i),OBJPROP_WIDTH,3);
if (LevelWidth>=Width4LevelConfirmation)
ObjectSet(StringConcatenate("Level_",IndicatorNumber,"_",i),OBJPROP_WIDTH,4);
if (LevelWidth>=Width5LevelConfirmation)
ObjectSet(StringConcatenate("Level_",IndicatorNumber,"_",i),OBJPROP_WIDTH,5);
}
else
{
ObjectSet(StringConcatenate("Level_",IndicatorNumber,"_",i),OBJPROP_COLOR,LevelColor);
ObjectSet(StringConcatenate("Level_",IndicatorNumber,"_",i),OBJPROP_STYLE,STYLE_DOT);
}
}
}
return(0);
}


remove error

thank you
 

Rish

Well-Known Member
not working

error more
All your posts are related to searching new things.

RKKGS, try to understand, you can't find out solid methods, which is not available in this earth.

So, avoid searching new things, follow a single system and understand.

You should know, how to read the chart and you should know, how to interpret the levels. You should develop the skill to read the chart. No AFL will generate money for us.


Avoid searching new things, i am not discouraging you, this is fact.

All the best.
 
I have added the following code to the MRTQ13-18062012 CODE in addition to linear regression channels and it looks better.
//Bullish Trend: if candle is above Yellow line Don't take Short position in bullish trend
//Bearish Trend: if candle is below Yellow line Don't take long position in bearish trend
//Blue Line is for ENTRY & EXIT.
//If trend is bullish AND price goes above blue line then BuyAND exit from Buy after price goes below blue line
//If trend is bearish AND price goes below blue line then Sell AND exit from Sell after price goes above blue line
//BUY Cond1-C>tsl2;cond2-C cross tsl1// SELL cond1: C<tsl2 ; cond2: tsl1 cross C//
p1=Optimize("Period 1",7,1,20,1);
p2=Optimize("Period 2",17,10,50,1);
res1=HHV(H,p1);
sup1=LLV(L,p1);
tsl1=IIf(ValueWhen(IIf(C>Ref(res1,-1),1,IIf(C<Ref(sup1,-1),-1,0))!=0,IIf(C>Ref(res1,-1),1,IIf(C<Ref(sup1,-1),-1,0)),1)==1,sup1,res1);
res2=HHV(H,p2);
sup2=LLV(L,p2);
tsl2=IIf(ValueWhen(IIf(C>Ref(res2,-1),1,IIf(C<Ref(sup2,-1),-1,0))!=0,IIf(C>Ref(res2,-1),1,IIf(C<Ref(sup2,-1),-1,0)),1)==1,sup2,res2);
Plot(tsl1,"", colorBlue, styleThick, styleStaircase);
Plot(tsl2,"", colorYellow, styleThick, styleStaircase);
 
HI Can someone backtest this afl in diffferent timeframes. This is Nirvana..and would be obliged if after testing one can suggest the best suitable tf for day trading.

Thanks in advance.
_SECTION_BEGIN("Nirvana_Revised_18062012_mrtq13");
///////////////////////////////////
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkGradientFill( ParamColor("Inner panel upper",colorBlack),ParamColor("Inner panel lower",colorBlack));

Title =
EncodeColor(colorWhite)+ Title = Name () + " | "
+EncodeColor(colorYellow) + Date() +" | " + Interval( 2 )+ " | "
+EncodeColor(colorTurquoise)+ "Op : "+ EncodeColor(colorLightGrey)+ O + " | "
+EncodeColor(colorTurquoise)+ "Hi : "+ EncodeColor(colorLightGrey)+ H + " | "
+EncodeColor(colorTurquoise)+ "Lo : "+ EncodeColor(colorLightGrey)+ L + " | "
+EncodeColor(colorTurquoise)+ "Cls : "+ WriteIf(C> Ref(C, -1),EncodeColor(colorBrightGreen),EncodeColor(colorRed))+ C + " | "
+EncodeColor(colorTurquoise)+ "Change : ("+ WriteIf(C> Ref(C, -1),EncodeColor(colorBrightGreen),EncodeColor(colorRed)) + WriteVal(C-Ref(C,-1))+" Rs."
+EncodeColor(colorTurquoise)+ " /"+ WriteIf(C> Ref(C, -1),EncodeColor(colorBrightGreen),EncodeColor(colorRed))+ WriteVal( ROC( C, 1 ))+""+ " % "
+EncodeColor(colorTurquoise)+ ") | Volume : " + WriteIf(V> Ref(V, -1),EncodeColor(colorBrightGreen),EncodeColor(colorRed))+ WriteVal(V,1);

_SECTION_END();

_SECTION_BEGIN("Nirvana_Ribbon");
GraphXSpace=10;

a = Param("Average Pds", 5, 1, 10, 1 );
n = Param("Short Pds", 14, 5, 21, 1 );
m = Param("Long Pds", 60, 35, 90, 1 );

Var4 =(Low+High+2*Close)/4;
OP = EMA(Var4,a);
res1 = HHV(OP,n);
res2 =HHV(OP,m);
sup2 =LLV(OP,m);
sup1 =LLV(OP,n);

Linecolor = IIf(op>sup1 AND Ref(Op,-1)==Ref(sup1,-1), colorBrightGreen, IIf(op<res1 AND Ref(Op,-1)==Ref(res1,-1), colorRed, 3));
Plot(5, "",Linecolor, styleOwnScale|styleArea|styleNoLabel,-0.5, 350 );
Linecolor = IIf(Op==sup1,11,IIf(Op==res1,10,7));
//Plot(OP, "OP", linecolor, 1+4);
//Plot(res1, "Resistance1", 11, 1);
//Plot(sup1, "Support1", 10, 1);
//Plot(res2, "Resistance2", 4, 1);
//Plot(sup2, "Support2", 5, 1);

_SECTION_END();


_SECTION_BEGIN("colorMeBad"); // added new lines of code

flowerClose =EMA((O+H+L+C)/4,3); // Woodie
m = 17;
a=MA(flowerClose,m)+abs(MA(flowerClose,m)-Ref(MA(flowerClose,m),-1));
b=MA(flowerClose,m)+MA(flowerClose,m)-Ref(MA(flowerClose,m),-1);
balance=IIf(MA(flowerClose,m)<b,b,MA(flowerClose,m ));
pma=balance;
sig = MA(2*balance-EMA(flowerClose,3),1);
//Plot(sig,"Signal", 40, 1); //40 instead of 7
s=(pma>sig);
pm=MA(flowerClose,5);
pmcolor=IIf(pm>Ref(pm,-1),43,13); //42 ins colorLightYellow,13 insrd colorRed
Plot(pm,"CMB", pmcolor,4);
_SECTION_END();


/*
_SECTION_BEGIN("Haiken");

Show_color = ParamToggle("Display CandleColor", "No|Yes", 1);
r1 =5; //Param( "ColorFast avg", 5, 2, 200, 1 );
r2 =10; //Param( "ColorSlow avg", 10, 2, 200, 1 );
r3 =5; //Param( "ColorSignal avg", 5, 2, 200, 1 );

Prd1=4; //Param("ATR Period",4,1,20,1);
Prd2=7; //Param("Look Back",7,1,20,1);
green = HHV(LLV(L,Prd1)+ATR(Prd1),Prd2);
red = LLV(HHV(H,Prd1)-ATR(Prd1),Prd2);

HaClose =EMA((O+H+L+C)/4,3); // Woodie
//HaClose =(O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
//HaClose = ( HaClose + HaOpen + HaHigh + HaLow )/4; // // Velvoort is using not original, but modified Heikin-Ashi close
Temp = Max(High, HaOpen);
Temp = Min(Low,HaOpen);

/*m1=MACD(r1,r2);
s1=Signal(r1,r2,r3);
mycolor=IIf(m1<0 AND m1>s1, ColorRGB(230,230,0),IIf(m1>0 AND m1>s1,colorBrightGreen,IIf(m1>0 AND m1<s1,colorOrange,colorDarkRed)));

if(Show_color)

{
ColorHighliter = myColor;
SetBarFillColor( ColorHighliter );
}*/

//////////
/*
m1=MACD(r1,r2);
s1=Signal(r1,r2,r3);
mycolor=IIf(m1<0 AND m1>s1, ColorRGB(230,230,0),IIf(m1>0 AND m1>s1,colorWhite,IIf(m1>0 AND m1<s1,colorOrange,colorDarkRed)));
if(Show_color)

{
ColorHighliter = mycolor;
SetBarFillColor( ColorHighliter );
}

barColor=IIf(C>Green ,colorWhite,IIf(C < RED,colorRed,colorYellow));
barColor2=IIf(Close > Open, colorWhite, colorRed);

if( ParamToggle("Plot Normal Candle", "No,Yes", 1 ) )
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, " " , barcolor, styleCandle | styleThick );
else
PlotOHLC( Open, High, Low, Close, " " , barcolor2, styleCandle | styleThick );

_SECTION_END();
*/


_SECTION_BEGIN("Flower_HA_Normal Candle");

Show_color = ParamToggle("Display CandleColor", "No|Yes", 1);
r1 =5; //Param( "ColorFast avg", 5, 2, 200, 1 );
r2 =10; //Param( "ColorSlow avg", 10, 2, 200, 1 );
r3 =5; //Param( "ColorSignal avg", 5, 2, 200, 1 );

Prd1=4; //Param("ATR Period",4,1,20,1);
Prd2=7; //Param("Look Back",7,1,20,1);
green = HHV(LLV(L,Prd1)+ATR(Prd1),Prd2);
red = LLV(HHV(H,Prd1)-ATR(Prd1),Prd2);

HaClose =EMA((O+H+L+C)/4,3); // Woodie
//HaClose =(O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
//HaClose = ( HaClose + HaOpen + HaHigh + HaLow )/4;
Temp = Max(High, HaOpen);
Temp = Min(Low,HaOpen);

//////////
m1=MACD(r1,r2);
s1=Signal(r1,r2,r3);
mycolor=IIf(m1<0 AND m1>s1, ColorRGB(230,230,0),IIf(m1>0 AND m1>s1,colorWhite,IIf(m1>0 AND m1<s1,colorOrange,colorDarkRed)));
if(Show_color)

{
ColorHighliter = mycolor;
SetBarFillColor( ColorHighliter );
}

barColor=IIf(C>Green ,colorWhite,IIf(C < RED,colorRed,colorYellow));
barColor2=IIf(Close > Open, colorWhite, colorRed);

if( ParamToggle("Plot Normal Candle", "No,Yes", 1 ) )
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, " " , barcolor, styleCandle | styleThick );
else
PlotOHLC( Open, High, Low, Close, " " , barcolor2, styleCandle | styleThick );

_SECTION_END();




_SECTION_BEGIN("Breakout Setting");
Buyperiods=Param("Breakout periods best is usually 18",5,1,100,1,1);
Sellperiods=Param("Exit Breakout",5,1,100,1,1);
Buy= C>Ref(HHV(High,Buyperiods),-1);
Sell= C<Ref(LLV(Low,Sellperiods),-1);

/* exrem is one method to remove surplus trade signals. It removes excessive signals of arrow */
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

PlotShapes( IIf( Buy, shapeSmallCircle, shapeNone ), colorWhite, layer = 0,yposition = HaLow, offset = -15);
//PlotShapes( IIf( Buy, shapeSmallCircle, shapeNone ), colorWhite, layer = 0,yposition = HaLow, offset = -8);

PlotShapes( IIf( Sell, shapeSmallCircle, shapeNone ), colorRed, layer = 0, yposition = HaHigh, offset = 15);
//PlotShapes( IIf( Sell, shapeSmallCircle, shapeNone ), colorRed, layer = 0, yposition = HaHigh, offset = 8);

_SECTION_END();

_SECTION_BEGIN("Pivot Box");
Hi=Param("High_Period",7,1,50,1);
Lo=Param("Low_Period",7,1,50,1);
A1=ExRemSpan(Ref(High,-2)==HHV(High,Hi),3);
A2=ExRemSpan(Ref(Low,-2)==LLV(Low,Lo),3);
A3=Cross(A1,0.9);
A4=Cross(A2,0.9);
TOP=Ref(HaHigh,-BarsSince(A3));


breakoutLine=Param("BrOutLineLength",10,2,30,0.1);
upDaysback1 = breakoutLine;
upFirstBar1 = BarCount - upDaysBack1;
upst2=TOP;

upYYY2=IIf(BarIndex() >= upFirstbar1,EndValue(upSt2),Null);

Plot(upYYY2,"",ParamColor("BreakoutColor", colorOrange) ,ParamStyle("BreakoutLine",styleLine|styleThick|styleStaircase,maskAll));
//Plot(top,"",11,styleDots+styleLine+styleThick);


bot=Ref(HaLow,-BarsSince(A4));
breakDownLine=Param("BrDownLineLength",10,2,30,0.1 );
dnDaysback1 = breakDownLine;
dnFirstBar1 = BarCount - dnDaysBack1;
dnst2=BOT;

dnYYY2=IIf(BarIndex() >= dnFirstbar1,EndValue(dnSt2),Null);


Plot(dnYYY2,"",ParamColor("BreakDownColor", colorBrightGreen) ,ParamStyle("BreakdownLine",styleLine|styleThick|styleStaircase,maskAll));
//Plot(bot,"",6,styleDots+styleLine);
_SECTION_END();
function T3(price,periods)


{
s = 0.84;
e1=EMA(price,periods);
e2=EMA(e1,Periods);
e3=EMA(e2,Periods);
e4=EMA(e3,Periods);
e5=EMA(e4,Periods);
e6=EMA(e5,Periods);
c1=-s*s*s;
c2=3*s*s+3*s*s*s;
c3=-6*s*s-3*s-3*s*s*s;
c4=1+3*s+s*s*s+3*s*s;
Ti3=c1*e6+c2*e5+c3*e4+c4*e3;
return ti3;
}

//************************************************** ********************************
// Plot price horizontal line *
//************************************************** ********************************/

_SECTION_BEGIN("Price Line");

PriceLineColor=ParamColor("PriceLineColor",ColorRGB(82,82,82));
PriceLevel = ParamField("PriceField", field = 3 );

Daysback = Param("Bars Back",500,10,900,1);
FirstBar = BarCount - DaysBack;
YY = IIf(BarIndex() >= Firstbar,EndValue(PriceLevel),Null);

Plot(YY,"Current Price",PriceLineColor,ParamStyle("LineStyle",styleLine|styleDashed|styleNoTitle|styleNoLabel|styleThick,maskAll));

side = Param("side",1,0,1000,1);

dist = 0;

for( i = 0; i < BarCount; i++ )
{
if(i+side== BarCount) PlotText( "\n " + PriceLevel[ i ], i, YY[ i ]-dist, colorAqua );
}

_SECTION_END();



/*_SECTION_BEGIN("Average 0");
//Average_switch = ParamToggle("Candle On/off", "Off|On");
P = HaClose;
Type = ParamList("Type", "Weighted,Lagless-21,Hull-26,Linear
Regression-45,Exponential,Double Exponential,Tripple
Exponential,Wilders,Simple");
Periods = Param("Periods", 20, 2, 200 );
Displacement = Param("Displacement", 1, -50, 50 );
m = 0;

if( Type == "Weighted" ) m= WMA( P, Periods );
if( Type == "Lagless-21" ) m= 2*EMA(P, Periods)-EMA(EMA(P, Periods), Periods);
if( Type == "Hull-26" ) m= WMA(2*(WMA(P, Periods/2))-WMA(P, Periods) ,4 );
if( Type == "Linear Regression-45" ) m= LinearReg( P, Periods );
if( Type == "Exponential" ) m = EMA( P, Periods );
if( Type == "Double Exponential" ) m = DEMA( P, Periods );
if( Type == "Tripple Exponential" ) m = TEMA( P, Periods );
if( Type == "Wilders" ) m = Wilders( P, Periods );
if( Type == "Simple" ) m = MA( P, Periods );

Plot( m, _DEFAULT_NAME(), ParamColor("Color", colorDarkYellow),ParamStyle("Style",styleLine |styleThick|styleDots|styleNoTitle ,maskAll),Displacement );

_SECTION_END();*/


_SECTION_BEGIN("Bands_Short");
BandDays= Param("DaysBack",40,10,900,1);
HighestHigh = HHV( H, BandDays ) ;
LowestLow = LLV( L, BandDays) ;

KS = ( HHV( H, BandDays ) + LLV( L, BandDays) )/2;

//Plot(HighestHigh ,"HighestHigh ",colorBlue,styleLine | styleStaircase|styleNoRescale| styleNoLabel|styleNoTitle ); // unchecked
//Plot(LowestLow ,"LowestLow ",colorRed,styleLine | styleStaircase ); // unchecked
Plot(KS,"KS",50,styleLine |styleThick | styleStaircase ); //50 instaed of colorBrightGreen

//Plot((KS+HighestHigh )/2,"",colorYellow, styleLine | styleThick | styleStaircase );
//Plot((KS+LowestLow )/2,"",colorYellow, styleLine | styleThick | styleStaircase );

CloudUpColor1=ParamColor("ShortupColor1",ColorRGB( 0,55,55));
CloudUpColor2=ParamColor("ShortupColor2",ColorRGB( 60,15,0));
CloudDownColor1=ParamColor("ShortDnColor1",ColorRGB(0,0,83));
CloudDownColor2= ParamColor("ShortDnColor2",ColorRGB(43,43,89));

CU1=HighestHigh;
CU2=(KS+HighestHigh )/2;

CD1=LowestLow = LLV( L, 22) ;
CD2=(KS+LowestLow )/2;



//PlotOHLC( CU1, CU1,CU2,CU2, "", CloudUpColor1, styleCloud || styleStaircase|styleNoRescale| styleNoLabel|styleNoTitle );
//PlotOHLC( CU2, CU2,KS,KS, "", CloudUpColor2, styleCloud || styleStaircase|styleNoRescale| styleNoLabel|styleNoTitle );

//PlotOHLC( KS, KS,CD2,CD2, "", CloudDownColor1, styleCloud || styleStaircase|styleNoRescale| styleNoLabel|styleNoTitle );
//PlotOHLC( CD2, CD2,CD1,CD1, "", CloudDownColor2, styleCloud || styleStaircase|styleNoRescale| styleNoLabel|styleNoTitle );

_SECTION_END();



_SECTION_BEGIN("Pivot");
nBars = Param("Number of bars", 25, 5, 40);
LP=Param("LookBack Period",250,1,500,1);
bShowTCZ = Param("Show TCZ", 0, 0, 1);
nExploreBarIdx = 0;
nExploreDate = 0;
nCurDateNum = 0;
DN = DateNum();
DT = DateTime();
bTCZLong = False;
bTCZShort = False;
nAnchorPivIdx = 0;
ADX8 = ADX(8);
if(Status("action")==1) {
bDraw = True;
bUseLastVis = 1;
} else {
bDraw = False;
bUseLastVis = False;
bTrace = 1;
nExploreDate = Status("rangetodate");
for (i=LastValue(BarIndex());i>=0;i--) {
nCurDateNum = DN;
if (nCurDateNum == nExploreDate) {
nExploreBarIdx = i;
}
}
}
GraphXSpace=7;
if (bDraw) {
}
aHPivs = H - H;
aLPivs = L - L;
aHPivHighs = H - H;
aLPivLows = L - L;
aHPivIdxs = H - H;
aLPivIdxs = L - L;
aAddedHPivs = H - H;
aAddedLPivs = L - L;
aLegVol = H - H;
aRetrcVol = H - H;
nHPivs = 0;
nLPivs = 0;
lastHPIdx = 0;
lastLPIdx = 0;
lastHPH = 0;
lastLPL = 0;
curPivBarIdx = 0;
aHHVBars = HHVBars(H, nBars);
aLLVBars = LLVBars(L, nBars);
aHHV = HHV(H, nBars);
aLLV = LLV(L, nBars);
nLastVisBar = LastValue(
Highest(IIf(Status("barvisible"), BarIndex(), 0)));
curBar = IIf(nlastVisBar > 0 AND bUseLastVis, nlastVisBar,
IIf(Status("action")==4 AND nExploreBarIdx > 0, nExploreBarIdx,
LastValue(BarIndex())));
curTrend = "";
if (aLLVBars[curBar] < aHHVBars[curBar])
curTrend = "D";
else
curTrend = "U";
if (curBar >= LP) {
for (i=0; i<LP; i++) {
curBar = IIf(nlastVisBar > 0 AND bUseLastVis,
nlastVisBar-i,
IIf(Status("action")==4 AND nExploreBarIdx > 0,
nExploreBarIdx-i,
LastValue(BarIndex())-i));
if (aLLVBars[curBar] < aHHVBars[curBar]) {
if (curTrend == "U") {
curTrend = "D";
curPivBarIdx = curBar - aLLVBars[curBar];
aLPivs[curPivBarIdx] = 1;
aLPivLows[nLPivs] = L[curPivBarIdx];
aLPivIdxs[nLPivs] = curPivBarIdx;
nLPivs++;
}
} else {
if (curTrend == "D") {
curTrend = "U";
curPivBarIdx = curBar - aHHVBars[curBar];
aHPivs[curPivBarIdx] = 1;
aHPivHighs[nHPivs] = H[curPivBarIdx];
aHPivIdxs[nHPivs] = curPivBarIdx;
nHPivs++;
}
}
}
}
curBar =
IIf(nlastVisBar > 0 AND bUseLastVis,
nlastVisBar,
IIf(Status("action")==4 AND nExploreBarIdx > 0,
nExploreBarIdx,
LastValue(BarIndex()))
);
if (nHPivs >= 2 AND nLPivs >= 2) {
lastLPIdx = aLPivIdxs[0];
lastLPL = aLPivLows[0];
lastHPIdx = aHPivIdxs[0];
lastHPH = aHPivHighs[0];
nLastHOrLPivIdx = Max(lastLPIdx, lastHPIdx);
nAddPivsRng = curBar - nLastHOrLPivIdx;
aLLVAfterLastPiv = LLV(L, nAddPivsRng);
nLLVAfterLastPiv = aLLVAfterLastPiv[curBar];
aLLVIdxAfterLastPiv = LLVBars(L, nAddPivsRng);
nLLVIdxAfterLastPiv = curBar - aLLVIdxAfterLastPiv[curBar];
aHHVAfterLastPiv = HHV(H, nAddPivsRng);
nHHVAfterLastPiv = aHHVAfterLastPiv[curBar];
aHHVIdxAfterLastPiv = HHVBars(H, nAddPivsRng);
nHHVIdxAfterLastPiv = curBar - aHHVIdxAfterLastPiv[curBar];
if (lastHPIdx > lastLPIdx) {

/* There are at least two possibilities here. One is that
the previous high was higher, indicating that this is a
possible short retracement or one in the making.
The other is that the previous high was lower, indicating
that this is a possible long retracement in the working.
However, both depend on opposing pivots. E.g., if I find
higher highs, what if I have lower lows?

If the highs are descending, then I can consider:
- a lower low, and leave it at that
- a higher high and higher low
- a lower low and another lower high
*/
if (aHPivHighs[0] < aHPivHighs[1]) {

if (nLLVAfterLastPiv < aLPivLows[0] AND
(nLLVIdxAfterLastPiv - lastHPIdx - 1) >= 1
AND nLLVIdxAfterLastPiv != curBar ) {

// -- OK, we'll add this as a pivot.
// Mark it for plotting...
aLPivs[nLLVIdxAfterLastPiv] = 1;
aAddedLPivs[nLLVIdxAfterLastPiv] = 1;

// ...and then rearrange elements in the
// pivot information arrays
for (j=0; j<nLPivs; j++) {
aLPivLows[nLPivs-j] = aLPivLows[nLPivs-(j+1)];
aLPivIdxs[nLPivs-j] = aLPivIdxs[nLPivs-(j+1)];
}
aLPivLows[0] = nLLVAfterLastPiv;
aLPivIdxs[0] = nLLVIdxAfterLastPiv;
nLPivs++;

// -- Test whether to add piv given last piv is high
// AND we have lower highs
}

// -- Here, the last piv is a high piv, and we have
// higher-highs. The most likely addition is a
// Low piv that is a retracement.
} else {

if (nLLVAfterLastPiv > aLPivLows[0] AND
(nLLVIdxAfterLastPiv - lastHPIdx - 1) >= 1
AND nLLVIdxAfterLastPiv != curBar ) {

// -- OK, we'll add this as a pivot.
// Mark it for plotting...
aLPivs[nLLVIdxAfterLastPiv] = 1;
aAddedLPivs[nLLVIdxAfterLastPiv] = 1;

// ...and then rearrange elements in the
// pivot information arrays
for (j=0; j<nLPivs; j++) {
aLPivLows[nLPivs-j] = aLPivLows[nLPivs-(j+1)];
aLPivIdxs[nLPivs-j] = aLPivIdxs[nLPivs-(j+1)];
}
aLPivLows[0] = nLLVAfterLastPiv;
aLPivIdxs[0] = nLLVIdxAfterLastPiv;
nLPivs++;

// -- Test whether to add piv given last piv is high
// AND we have lower highs
}
// -- The last piv is a high and we have higher highs
// OR lower highs
}

/* ************************************************** **************
Still finding missed pivot(s). Here, the last piv is a low piv.
************************************************** ************** */
} else {

// -- First case, lower highs
if (aHPivHighs[0] < aHPivHighs[1]) {

if (nHHVAfterLastPiv < aHPivHighs[0] AND
(nHHVIdxAfterLastPiv - lastLPIdx - 1) >= 1
AND nHHVIdxAfterLastPiv != curBar ) {

// -- OK, we'll add this as a pivot.
// Mark that for plotting
aHPivs[nHHVIdxAfterLastPiv] = 1;
aAddedHPivs[nHHVIdxAfterLastPiv] = 1;

// ...and then rearrange elements in the
// pivot information arrays
for (j=0; j<nHPivs; j++) {
aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-(j+1)];
aHPivIdxs[nHPivs-j] = aHPivIdxs[nhPivs-(j+1)];
}
aHPivHighs[0] = nHHVAfterLastPiv;
aHPivIdxs[0] = nHHVIdxAfterLastPiv;
nHPivs++;

// -- Test whether to add piv given last piv is high
// AND we have lower highs
}

// -- Second case when last piv is a low piv, higher highs
// Most likely addition is high piv that is a retracement.
// Considering adding a high piv as long as it is higher
} else {

// -- Where I have higher highs,
if (nHHVAfterLastPiv > aHPivHighs[0] AND
(nHHVIdxAfterLastPiv - lastLPIdx - 1) >= 1
AND nHHVIdxAfterLastPiv != curBar ) {

// -- OK, we'll add this as a pivot.
// Mark it for plotting...
aHPivs[nHHVIdxAfterLastPiv] = 1;
aAddedHPivs[nHHVIdxAfterLastPiv] = 1;

// ...and then rearrange elements in the
// pivot information arrays
for (j=0; j<nHPivs; j++) {
aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-(j+1)];
aHPivIdxs[nHPivs-j] = aHPivIdxs[nhPivs-(j+1)];
}
aHPivHighs[0] = nHHVAfterLastPiv;
aHPivIdxs[0] = nHHVIdxAfterLastPiv;
nHPivs++;

// -- Test whether to add piv given last piv is high
// AND we have lower highs
}

}

}

// -- If there are at least two of each
}

/* ****************************************
// -- Done with finding pivots
***************************************** */


if (bDraw) {

// -- OK, let's plot the pivots using arrows

/*PlotShapes( IIf(aHPivs==1, shapeHollowSmallSquare, shapeNone), colorRed, layer = 0, yposition = HaHigh, offset = 10);
//PlotShapes( IIf(aHPivs==1, shapeSmallCircle, shapeNone), colorRed, layer = 0, yposition = HaHigh, offset = 10);



PlotShapes( IIf(aAddedLPivs==1, shapeHollowSmallSquare, shapeNone), colorYellow, layer = 0, yposition = HaLow, offset = -10);
//PlotShapes( IIf(aAddedLPivs==1, shapeSquare, shapeNone), colorBlack, layer = 0, yposition = HaLow, offset = -14);


//PlotShapes( IIf(aAddedLPivs==1, shapeSmallCircle, shapeNone), colorYellow, layer = 0, yposition = HaLow, offset = -9);*/


//PlotShapes( IIf(aHPivs==1, shapeSmallCircle, shapeNone), colorCustom12, layer = 0, yposition = HaHigh, offset = 9);
PlotShapes( IIf(aHPivs==1, shapeHollowSmallSquare, shapeNone), colorRed, layer = 0, yposition = HaHigh, offset = 12); //color=custom12

//PlotShapes( IIf(aAddedHPivs==1, shapeSmallCircle, shapeNone), colorCustom10,layer = 0, yposition = HaHigh, offset = 9);
PlotShapes( IIf(aAddedHPivs==1, shapeHollowSmallSquare, shapeNone), colorYellow, layer = 0, yposition = HaHigh, offset = 12);

//PlotShapes( IIf(aLPivs==1, shapeSmallCircle, shapeNone), colorPaleGreen, layer = 0, yposition = HaLow, offset = -9);
PlotShapes( IIf(aLPivs==1, shapeHollowSmallSquare, shapeNone), colorBrightGreen, layer = 0, yposition = HaLow, offset = -12);//col=brightgreen

//PlotShapes( IIf(aAddedLPivs==1, shapeSmallCircle, shapeNone), colorYellow, layer = 0, yposition = HaLow, offset = -10);
PlotShapes( IIf(aAddedLPivs==1, shapeHollowSmallSquare, shapeNone), colorYellow, layer = 0, yposition = HaLow, offset = -13);

}



/* ****************************************
// -- Done with discovering and plotting pivots
***************************************** */

// -- I'm going to want to look for possible retracement
risk = 0;
profInc = 0;
nLeg0Pts = 0;
nLeg0Bars = 0;
nLeg0Vol = 0;
nLeg1Pts = 0;
nLeg1Bars = 0;
nLeg1Vol = 0;
nLegBarsDiff = 0;
nRtrc0Pts = 0;
nRtrc0Bars = 0;
nRtrc0Vol = 0;
nRtrc1Pts = 0;
nRtrc1Bars = 0;
nRtrc1Vol = 0;

minRtrc = 0;
maxRtrc = 0;
minLine = 0;
maxLine = 0;
triggerLine = 0;
firstProfitLine = 0;
triggerInc = 0;
triggerPrc = 0;
firstProfitPrc = 0;
retrcPrc = 0;
retrcBar = 0;
retrcBarIdx = 0;
retrcRng = 0;
aRetrcPrc = H-H;
aRetrcPrcBars = H-H;
aRetrcClose = C;
retrcClose = 0;

// -- Do TCZ calcs. Arrangement of pivs very specific
// for this setup.
if (nHPivs >= 2 AND
nLPivs >=2 AND
aHPivHighs[0] > aHPivHighs[1] AND
aLPivLows[0] > aLPivLows[1]) {

tcz500 =
(aHPivHighs[0] -
(.5 * (aHPivHighs[0] - aLPivLows[1])));

tcz618 =
(aHPivHighs[0] -
(.618 * (aHPivHighs[0] - aLPivLows[1])));

tcz786 =
(aHPivHighs[0] -
(.786 * (aHPivHighs[0] - aLPivLows[0])));

retrcRng = curBar - aHPivIdxs[0];
aRetrcPrc = LLV(L, retrcRng);
aRetrcPrcBars = LLVBars(L, retrcRng);

retrcPrc = aRetrcPrc[curBar];
retrcBarIdx = curBar - aRetrcPrcBars[curBar];
retrcClose = aRetrcClose[retrcBarIdx];

// -- bTCZLong setup?
bTCZLong = (

// -- Are retracement levels arranged in
// tcz order?

// .500 is above .786 for long setups
tcz500 >= (tcz786 * (1 - .005))
AND
// .681 is below .786 for long setups
tcz618 <= (tcz786 * (1 + .005))
AND

// -- Is the low in the tcz range
// -- Is the close >= low of tcz range
// and low <= high of tcz range
retrcClose >= ((1 - .01) * tcz618)
AND
retrcPrc <= ((1 + .01) * tcz500)
);

// -- risk would be high of signal bar minus low of zone
//risk = 0;

// -- lower highs and lower lows
} else if (nHPivs >= 2 AND nLPivs >=2
AND aHPivHighs[0] < aHPivHighs[1]
AND aLPivLows[0] < aLPivLows[1]) {

tcz500 =
(aHPivHighs[1] -
(.5 * (aHPivHighs[1] - aLPivLows[0])));

tcz618 =
(aHPivHighs[0] -
(.618 * (aHPivHighs[1] - aLPivLows[0])));

tcz786 =
(aHPivHighs[0] -
(.786 * (aHPivHighs[0] - aLPivLows[0])));

retrcRng = curBar - aLPivIdxs[0];
aRetrcPrc = HHV(H, retrcRng);
retrcPrc = aRetrcPrc[curBar];
aRetrcPrcBars = HHVBars(H, retrcRng);
retrcBarIdx = curBar - aRetrcPrcBars[curBar];
retrcClose = aRetrcClose[retrcBarIdx];

bTCZShort = (
// -- Are retracement levels arranged in
// tcz order?

// .500 is below .786 for short setups
tcz500 <= (tcz786 * (1 + .005))
AND
// .681 is above .786 for short setups
tcz618 >= (tcz786 * (1 - .005))
AND

// -- Is the close <= high of tcz range
// and high >= low of tcz range
retrcClose <= ((1 + .01) * tcz618)
AND
retrcPrc >= ((1 - .01) * tcz500)
);

// -- Risk would be top of zone - low of signal bar
//risk = 0;
}

// -- Show zone if present
if (bTCZShort OR bTCZLong) {

// -- Be prepared to see symmetry
if (bTCZShort) {
if (aLPivIdxs[0] > aHPivIdxs[0]) {
// -- Valuable, useful symmetry information
nRtrc0Pts = aHPivHighs[0] - aLPivLows[1];
nRtrc0Bars = aHPivIdxs[0] - aLPivIdxs[1] + 1;
nRtrc1Pts = retrcPrc - aLPivLows[0];
nRtrc1Bars = retrcBarIdx - aLPivIdxs[0] + 1;
} else {
nRtrc0Pts = aHPivHighs[1] - aLPivLows[1];
nRtrc0Bars = aHPivIdxs[1] - aLPivIdxs[1] + 1;
nRtrc1Pts = aHPivHighs[0] - aLPivLows[0];
nRtrc1Bars = aHPivIdxs[0] - aLPivIdxs[0] + 1;
}
} else { // bLongSetup
if (aLPivIdxs[0] > aHPivIdxs[0]) {
nRtrc0Pts = aHPivHighs[0] - aLPivLows[1];
nRtrc0Bars = aHPivIdxs[0] - aLPivIdxs[1] + 1;
nRtrc1Pts = retrcPrc - aLPivLows[0];
nRtrc1Bars = retrcBarIdx - aLPivIdxs[0] + 1;
} else {
nRtrc0Pts = aHPivHighs[1] - aLPivLows[0];
nRtrc0Bars = aLPivIdxs[0] - aHPivIdxs[1] + 1;
nRtrc1Pts = aHPivHighs[0] - aLPivLows[0];
nRtrc1Bars = aLPivIdxs[0] - aHPivIdxs[0] + 1;
}
}

if (bShowTCZ) {
Plot(
LineArray( IIf(bTCZLong, aHPivIdxs[0], aLPivIdxs[0]),
tcz500, curBar, tcz500 , 0),
"tcz500", colorPaleBlue, styleLine);
Plot(
LineArray( IIf(bTCZLong, aHPivIdxs[0], aLPivIdxs[0]),
tcz618, curBar, tcz618, 0),
"tcz618", colorPaleBlue, styleLine);
Plot(
LineArray( IIf(bTCZLong, aHPivIdxs[0], aLPivIdxs[0]),
tcz786, curBar, tcz786, 0),
"tcz786", colorTurquoise, styleLine);
}

// -- if (bShowTCZ)
}


// **************************
// END INDICATOR CODE
// **************************


_SECTION_END();

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

flowerClose = EMA((Open+High+Low+Close)/4,3) ;
flowerOpen = EMA((Ref(Open,-1) + Ref(flowerClose,-1))/2,3);
Temp = Max(High, flowerOpen);
flowerHigh = EMA(Max(Temp, flowerClose),3);
Temp = Min(Low,flowerOpen);
flowerLow = EMA(Min(Temp, flowerClose),3);

//------------//



//#include <T3.AFL>;

/* _SECTION_BEGIN("trending ribbon");

//BT=ParamColor("BT", colorRed );

TimeFrameSet (inDaily);
uptrend=PDI()>MDI()AND Signal()<MACD();
downtrend=MDI()>PDI()AND Signal()>MACD();
//UTM3=IIf( uptrend, colorGreen, IIf( downtrend, colorRed, colorLightGrey ));

TimeFrameRestore();

UpA=uptrend;
DownB=downtrend;


Trend1 = WriteIf( UpA,"Up1", "");
Trend2 = WriteIf( DownB,"Down1", "");


RequestTimedRefresh( 0 );
GfxSelectFont( "Tahoma", 12, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( Trend1 =="Up1")
{
GfxSelectSolidBrush( 34 ); //ColorRGB(0,70,0) 30 to 34

}
else

if ( Trend2 =="Down1")

{
GfxSelectSolidBrush( 25); //ColorRGB(70,0,0)// 48 to 25

}
else

if ( Trend2 =="")

{
GfxSelectSolidBrush( colorGrey40 );

}


GfxSelectPen( colorBlack, 0 ); // broader color
//GfxRoundRect( 15,305,135,215, 5, 5 );
GfxRectangle( 15,121,95,131 );
_SECTION_END();*/


_SECTION_BEGIN("Trendslong");

//CT=ParamColor("CT", colorRed );

UpTrendCond3 = Cross ( T3( flowerclose, 7), T3( flowerclose, 9) );
dnTrendCond3 = Cross ( T3( flowerclose, 9),T3( flowerclose, 7) );


upt3= T3( flowerclose, 7)> T3( flowerclose, 9) ;
dnTrend3 = T3( flowerclose, 9)>T3( flowerclose, 7) ;


//for Trend1

Trendslongup= WriteIf(upt3,"trendlongup", "");
Trendslongdown= WriteIf( dnTrend3,"trendlongdn", "");
//Trendslongcon= WriteIf( UpTrendCond3,"trendlongcon", "");

if ( Trendslongup =="trendlongup")
{
GfxSelectSolidBrush(34 ); //ColorRGB(0,90,0)

}
else

if (Trendslongdown =="trendlongdn")

{
GfxSelectSolidBrush(25 ); //ColorRGB(90,0,0)

}

else

if (Trendslongdown =="")

{
GfxSelectSolidBrush( colorYellow );

}

GfxSelectFont( "Arial", 10, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorBlack );

GfxSelectPen( colorBlack, 1 ); // broader color
GfxRectangle( 15,109,95,119 );




_SECTION_END();


_SECTION_BEGIN("Trendsmid");

//DT=ParamColor("DT", colorRed );

UpTrendCond2 = Cross ( T3( flowerclose, 5), T3( flowerclose, 7) );
dnTrendCond2 = Cross (T3( flowerclose, 7), T3( flowerclose, 5) );
upt2= T3( flowerclose, 5)> T3( flowerclose, 7) ;
dnTrend2 = T3( flowerclose, 7)>T3( flowerclose, 5) ;



//for trend2

Trendmidup= WriteIf(upt2,"trendmidup", "");
Trendmiddown= WriteIf( dnTrend2,"trendmiddn", "");
Trendmidcon= WriteIf( UpTrendCond2,"trendmidcon", "");

if ( Trendmidup =="trendmidup")
{
GfxSelectSolidBrush( 34 ); //ColorRGB(0,120,0)

}
else

if (Trendmiddown =="trendmiddn")

{
GfxSelectSolidBrush(25 ); //ColorRGB(120,0,0)

}

else

if (Trendmidcon =="trendmidcon")

{
GfxSelectSolidBrush( 14 ); //colorYellow

}

GfxSelectFont( "Arial", 10, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorBlack );

GfxSelectPen( colorBlack, 1 ); // broader color
GfxRectangle( 15,97,95,107 );

_SECTION_END();

_SECTION_BEGIN("Trendsshort");

//ET=ParamColor("ET", colorRed );

UpTrendCond1 = Cross( flowerClose, T3( flowerClose, 5 ) );
dnTrendCond1 = Cross( T3( flowerClose, 5 ),flowerClose );
upt1=flowerClose > T3( flowerClose, 5 ) ;
dnTrend1 = flowerClose< T3( flowerClose, 5 );



//for Trend1

Trendshortup= WriteIf(upt1,"trendup", "");
Trendshortdown= WriteIf( dnTrend1,"trenddn", "");
Trendshortcon= WriteIf( UpTrendCond1,"trendcon", "");

if ( Trendshortup =="trendup")
{
GfxSelectSolidBrush( 34 ); //ColorRGB(0,150,0)

}
else

if (Trendshortdown =="trenddn")

{
GfxSelectSolidBrush(25 ); //ColorRGB(150,0,0)

}

else

if (Trendshortcon =="trendcon")

{
GfxSelectSolidBrush( colorYellow );

}

GfxSelectFont( "Arial", 10, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorBlack );

GfxSelectPen( colorBlack, 1 ); // broader color
GfxRectangle( 15,85,95,95 );




_SECTION_END();



_SECTION_BEGIN("Rays");

//FT=ParamColor("FT", colorRed );

Pp1=3;
Pp2=2;

CS33=HHV(LLV(flowerHigh,Pp1)-ATR(Pp2),4);
CR33=HHV(LLV(flowerHigh,Pp1)-ATR(Pp2),5);

AtrupTrendCond1 = flowerClose> CS33 ;
AtrdnTrendCond1 =CS33>flowerClose ;


ATRup = WriteIf(AtrupTrendCond1,"atrup", "");
ATRdown= WriteIf( AtrdnTrendCond1,"atrdn", "");

if ( ATRup =="atrup")
{
GfxSelectSolidBrush( 34 ); //ColorRGB(0,180,0)

}
else

if (ATRdown =="atrdn")

{
GfxSelectSolidBrush( 25); //ColorRGB(180,0,0)

}

else

if ( ATRdown =="")

{
GfxSelectSolidBrush( colorGrey40 );

}

GfxSelectFont( "Arial", 10, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorBlack );

GfxSelectPen( colorBlack, 1 ); // broader color
GfxRectangle( 15,73,95,83 );

_SECTION_END();


_SECTION_BEGIN("Exit_Beast-3");

//GT=ParamColor("GT", colorRed );

EntrylookbackPeriod=10;
EntryATRperiod=1.9;
EntrySig = C > ( LLV( flowerLow, EntrylookbackPeriod ) + EntryATRperiod * ATR( 10 ) );
ExitSig = C < ( HHV( flowerHigh, EntrylookbackPeriod ) -EntryATRperiod * ATR( 10 ) );


RequestTimedRefresh( 0 );
GfxSelectFont( "Tahoma", 12, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

EntryB = WriteIf( EntrySig,"eu", "");
ExitB = WriteIf( ExitSig,"ed", "");

if ( EntryB =="eu")
{
GfxSelectSolidBrush( 34 ); //ColorRGB(0,210,0)

}
else

if ( ExitB =="ed")

{
GfxSelectSolidBrush( 25); //ColorRGB(210,0,0)

}

else

if ( ExitB =="")

{
GfxSelectSolidBrush( colorGrey40 );

}

GfxSelectFont( "Arial", 10, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorBlack );

GfxSelectPen( colorBlack, 1 ); // broader color
GfxRectangle( 15,61,95,71 );// changing the value of x,y,rad x-70, y-90, rad-24

_SECTION_END();



_SECTION_BEGIN("CCI9-2");

//HT=ParamColor("HT", colorRed );

ccidn=CCI(8) < 0;
cciup=CCI(9) > 0;


ccresult1 = WriteIf( cciup,"cu", "");
ccresult2 = WriteIf( ccidn,"cd", "");




RequestTimedRefresh( 0 );
GfxSelectFont( "Tahoma", 12, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( ccresult1 =="cu")
{
GfxSelectSolidBrush( 34 ); //ColorRGB(0,240,0)

}
else

if ( ccresult2 =="cd")

{
GfxSelectSolidBrush(25 ); //

}

else

if ( ccresult2 =="")

{
GfxSelectSolidBrush( colorGrey40 );

}

GfxSelectFont( "Arial", 10, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorBlack );

GfxSelectPen( colorBlack, 1 ); // broader color
GfxRectangle( 15,49,95,59 );




_SECTION_END();




_SECTION_BEGIN("%BB7-1");

//IT=ParamColor("IT", colorRed );
p=7;
x=((C+2*StDev(C,p)-MA(C,p))/(4*StDev(C,p)))*100;
bbdown= x < 40;
bbup= x > 40;

bbresult1 = WriteIf( bbup,"bu", "");
bbresult2 = WriteIf( bbdown,"bd", "");
bbresult3 = WriteIf( C,"bearishrevers", "");



RequestTimedRefresh( 0 );
GfxSelectFont( "Tahoma", 12, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( bbresult1 =="bu")
{
GfxSelectSolidBrush(34 ); //ColorRGB(62,255,62)

}
else

if ( bbresult2 =="bd")

{
GfxSelectSolidBrush(25 ); //ColorRGB(255,62,62)

}

else

if ( bbresult2 =="")

{
GfxSelectSolidBrush( colorGrey40 );

}

GfxSelectFont( "Arial", 10, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorBlack );

GfxSelectPen( colorBlack, 1 ); // broader color
GfxRectangle( 15,37,95,47 );//


_SECTION_END();


_SECTION_BEGIN("Fast_trend");
//JT=ParamColor("JT", colorRed );

Prd3=5; //Param("Daily_Period1",8,1,200,1);
Prd4=8; //Param("Daily_Period2",15,1,200,1);
TimeFrameSet (inDaily);


TM3 = T3 ( C , Prd3) ;
TM4 = T3 ( C , Prd4) ;

TimeFrameRestore();

A=C>TM3 AND C<TM4;
B=C>TM3 AND C>TM4;
C=C<TM3 AND C>TM4;
D=C<TM3 AND C<TM4;

result1 = WriteIf( A,"bullrevers", "");
result2 = WriteIf( B,"bull", "");
result3 = WriteIf( C,"bearishrevers", "");
result4 = WriteIf( D,"bear", "");


RequestTimedRefresh( 0 );
GfxSelectFont( "Tahoma", 12, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( result1 =="bullrevers")
{
GfxSelectSolidBrush( 17 ); // colorwhite

}
else

if ( result2 =="bull")

{
GfxSelectSolidBrush( 34 ); //ColorRGB(113,255,113)

}

else

if ( result3 =="bearishrevers")

{
GfxSelectSolidBrush( 36 ); // colorGrey40

}

else

if ( result4 =="bear")

{
GfxSelectSolidBrush( 25 ); //ColorRGB(255,113,113)
OP = "M";

}

GfxSelectFont( "Arial", 10, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );//text color black to white

GfxSelectPen( colorBlack,1); // broader color
GfxRectangle( 15,25,95,35 );// rectangle instead circle

//GfxTextOut( OP ,92,235) ;// this line added

_SECTION_END();
 

Raj232

Well-Known Member
PHP:
www. 4shared. com/file/Pzm87qNeba/OK_Rocket_JET.htm
The signals are great, I would like to have the signals automatically traded from Amibroker to the broker terminal on only watch it happen.

Anyone with the code to trade the same in broker terminal...
:thumb::thumb::thumb:
.
 

Similar threads