My amibroker afl collections

#11
Re: "GAIN" AFL FOR intraday players

PctVlt=(ATR(14)/C)*100;//PercentVolatility

PK=IIf(PctVlt<0.5,Peak(Close,0.5,1),
IIf( PctVlt>=0.5 AND PctVlt< 1.0 ,Peak(Close,0.70,1),
IIf( PctVlt>=1.0 AND PctVlt< 1.5 ,Peak(Close,0.90,1),
IIf( PctVlt>=1.5 AND PctVlt< 2.0 ,Peak(Close,1.10,1),
IIf( PctVlt>=2.0 AND PctVlt< 2.5 ,Peak(Close,1.30,1),
IIf( PctVlt>=2.5 AND PctVlt< 3.0 ,Peak(Close,1.50,1),
IIf( PctVlt>=3.0 AND PctVlt< 3.5 ,Peak(Close,1.70,1),
IIf( PctVlt>=3.5 AND PctVlt< 4.0 ,Peak(Close,2.00,1),
Peak(Close,2.20,1) ))))))));

TGH=IIf(PctVlt<0.5,Trough(Close,0.5,1),
IIf( PctVlt>=0.5 AND PctVlt< 1.0 ,Trough(Close,0.75,1),
IIf( PctVlt>=1.0 AND PctVlt< 1.5 ,Trough(Close,1.00,1),
IIf( PctVlt>=1.5 AND PctVlt< 2.0 ,Trough(Close,1.25,1),
IIf( PctVlt>=2.0 AND PctVlt< 2.5 ,Trough(Close,1.50,1),
IIf( PctVlt>=2.5 AND PctVlt< 3.0 ,Trough(Close,1.75,1),
IIf( PctVlt>=3.0 AND PctVlt< 3.5 ,Trough(Close,2.00,1),
IIf( PctVlt>=3.5 AND PctVlt< 4.0 ,Trough(Close,2.25,1),
Trough(Close,2.50,1) ))))))));

Sens=IIf(PctVlt<0.5,0.5,
IIf( PctVlt>=0.5 AND PctVlt< 1.0 ,0.75,
IIf( PctVlt>=1.0 AND PctVlt< 1.5 ,1.00,
IIf( PctVlt>=1.5 AND PctVlt< 2.0 ,1.25,
IIf( PctVlt>=2.0 AND PctVlt< 2.5 ,1.50,
IIf( PctVlt>=2.5 AND PctVlt< 3.0 ,1.75,
IIf( PctVlt>=3.0 AND PctVlt< 3.5 ,2.00,
IIf( PctVlt>=3.5 AND PctVlt< 4.0 ,2.25,
2.50 ))))))));


Color=IIf(BarsSince(Cross(C,Ref(PK,-1)))<BarsSince(Cross(Ref(TGH,-1),C)),colorBrightGreen,colorRed);
Plot(C,"Chaloke.com Peak-Trough",Color,styleCandle);

///////////////////////////////////////////////////////////////////////////////////////////////////////////
_SECTION_BEGIN("RI Auto Trading System");

acc = Param("Acceleration", 0.1, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.06, 0, 1, 0.001 );

Buy = Cross(Open, SAR(acc,accm));
Sell = Cross(SAR(acc,accm), Open );

PlotShapes(IIf(Buy,shapeUpArrow,shapeNone), colorYellow, 0, Low, Offset=-15);
PlotShapes(IIf(Buy,shapeSmallCircle,shapeNone), colorYellow, 0, Low, Offset=-28);

PlotShapes(IIf(Sell, shapeDownArrow,shapeNone), colorWhite, 0, High, Offset=-15);
PlotShapes(IIf(Sell, shapeSmallCircle,shapeNone), colorWhite, 0, High, Offset= 28);

_SECTION_END();

///////////////////////////////////////////////////////////////////////////////////////////////////////////


DayH = TimeFrameGetPrice("H", inDaily, -1); DayHI = LastValue (DayH,1);// yesterdays high
DayL = TimeFrameGetPrice("L", inDaily, -1); DayLI = LastValue (DayL,1); // yesterdays low
DayC = TimeFrameGetPrice("C", inDaily, -1); // yesterdays close
DayO = TimeFrameGetPrice("O", inDaily); // current day open
DayH2= TimeFrameGetPrice("H", inDaily, -2); DayH2I = LastValue (DayH2,1); // Two days before high
DayL2= TimeFrameGetPrice("L", inDaily, -2); DayL2I = LastValue (DayL2,1); // Two days before low
DayH3= TimeFrameGetPrice("H", inDaily, -3); DayH3I = LastValue (DayH3,1); // Three days before high
DayL3= TimeFrameGetPrice("L", inDaily, -3); DayL3I = LastValue (DayL3,1); // Three days before low

numbars = LastValue(Cum(Status("barvisible")));
hts = -33.5;

YHL = ParamToggle("Yesterday HI LO","Show|Hide",1);
if(YHL==1) {
Plot(DayL,"YL",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(DayH,"YH",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
PlotText(" YH " , LastValue(BarIndex())-(numbars/Hts), DayHI, colorTurquoise);
PlotText(" YL " , LastValue(BarIndex())-(numbars/Hts), DayLI, colorTurquoise);
}

TDBHL = ParamToggle("2/3Days before HI LO","Show|Hide",0);
if(TDBHL==1) {
Plot(DayL2,"2DBL",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(DayH2,"2DBH",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(DayL3,"3DBL",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(DayH3,"3DBH",colorTurquoise,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
PlotText(" 2DBH " , LastValue(BarIndex())-(numbars/Hts), DayH2I, colorTurquoise);
PlotText(" 2DBL " , LastValue(BarIndex())-(numbars/Hts), DayL2I, colorTurquoise);
PlotText(" 3DBH " , LastValue(BarIndex())-(numbars/Hts), DayH3I, colorTurquoise);
PlotText(" 3DBL " , LastValue(BarIndex())-(numbars/Hts), DayL3I, colorTurquoise);
}

// Pivot Levels //
PP = (DayL + DayH + DayC)/3; PPI = LastValue (PP,1); // Pivot
R1 = (PP * 2) - DayL; R1I = LastValue (R1,1); // Resistance 1
S1 = (PP * 2) - DayH; S1I = LastValue (S1,1); // Support 1
R2 = PP + R1 - S1; R2I = LastValue (R2,1); // Resistance 2
S2 = PP - R1 + S1; S2I = LastValue (S2,1); // Support 2
R3 = PP + R2 - S1; R3I = LastValue (R3,1); // Resistance 3
S3 = PP - R2 + S1; S3I = LastValue (S3,1); // Support 3

ppl = ParamToggle("Pivot Levels","Show|Hide",1);
if(ppl==1) {
Plot(PP, "PP",colorYellow,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(R1, "R1",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(S1, "S1",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(R2, "R2",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(S2, "S2",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(R3, "R3",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(S3, "S3",colorViolet,styleDots|styleNoLine|styleNoRescale|styleNoTitle);

PlotText(" Pivot ", LastValue(BarIndex())-(numbars/Hts), PPI, colorYellow);
PlotText(" R1 " , LastValue(BarIndex())-(numbars/Hts), R1I, colorViolet);
PlotText(" S1 " , LastValue(BarIndex())-(numbars/Hts), S1I, colorViolet);
PlotText(" R2 " , LastValue(BarIndex())-(numbars/Hts), R2I, colorViolet);
PlotText(" S2 " , LastValue(BarIndex())-(numbars/Hts), S2I, colorViolet);
PlotText(" R3 " , LastValue(BarIndex())-(numbars/Hts), R3I, colorViolet);
PlotText(" S3 " , LastValue(BarIndex())-(numbars/Hts), S3I, colorViolet);
}
// Camerilla Levels //

rg = (DayH - DayL);

H5=DayC+1.1*rg; H5I = LastValue (H5,1);
H4=DayC+1.1*rg/2; H4I = LastValue (H4,1);
H3=DayC+1.1*rg/4; H3I = LastValue (H3,1);
H2=DayC+1.1*rg/6; H2I = LastValue (H2,1);
H1=DayC+1.1*rg/12; H1I = LastValue (H1,1);
L1=DayC-1.1*rg/12; L1I = LastValue (L1,1);
L2=DayC-1.1*rg/6; L2I = LastValue (L2,1);
L3=DayC-1.1*rg/4; L3I = LastValue (L3,1);
L4=DayC-1.1*rg/2; L4I = LastValue (L4,1);
L5=DayC-1.1*rg; L5I = LastValue (L5,1);

pcl = ParamToggle("Camerilla Levels","Show|Hide",0);
if(pcl==1) {
Plot(H5,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(H4,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(H3,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(H2,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(H1,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(L1,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(L2,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(L3,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(L4,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
Plot(L5,"",colorRose,styleDots|styleNoLine|styleNoRescale|styleNoTitle);
PlotText(" H5 = " , LastValue(BarIndex())-(numbars/Hts), H5I +0.05, colorRose);
PlotText(" H4 = " , LastValue(BarIndex())-(numbars/Hts), H4I +0.05, colorRose);
PlotText(" H3 = " , LastValue(BarIndex())-(numbars/Hts), H3I +0.05, colorRose);
PlotText(" H2 = " , LastValue(BarIndex())-(numbars/Hts), H2I +0.05, colorRose);
PlotText(" H1 = " , LastValue(BarIndex())-(numbars/Hts), H1I +0.05, colorRose);
PlotText(" L1 = " , LastValue(BarIndex())-(numbars/Hts), L1I +0.05, colorRose);
PlotText(" L2 = " , LastValue(BarIndex())-(numbars/Hts), L2I +0.05, colorRose);
PlotText(" L3 = " , LastValue(BarIndex())-(numbars/Hts), L3I +0.05, colorRose);
PlotText(" L4 = " , LastValue(BarIndex())-(numbars/Hts), L4I +0.05, colorRose);
PlotText(" L5 = " , LastValue(BarIndex())-(numbars/Hts), L5I +0.05, colorRose);
}

// Current Days Hi Lo //
THL = ParamToggle("Todays Hi Lo","Show|Hide",1);
if(THL==1) {
isRth = TimeNum() >= 084500 & TimeNum() <= 085959;
isdRth = TimeNum() >= 084500 & TimeNum() <= 160000;
aRthL = IIf(isRth, L, 1000000);
aRthH = IIf(isdRth, H, Null);
aRthLd = IIf(isdRth, L, 1000000);
DayH = TimeFrameCompress( aRthH, inDaily, compressHigh );
DayH = TimeFrameExpand( DayH, inDaily, expandFirst );
DayL = TimeFrameCompress( aRthLd, inDaily, compressLow );
DayL = TimeFrameExpand( DayL, inDaily, expandFirst );
Bars = BarsSince(TimeNum() >= 94500 AND TimeNum() < 095959);//,BarIndex(),1); // AND DateNum()==LastValue(DateNum());
x0 = BarCount-LastValue(Bars);
x1 = BarCount-1;
DayHline=LineArray(x0,LastValue(DayH),x1,LastValue (DayH),0);
DayLline=LineArray(x0,LastValue(DayL),x1,LastValue (DayL),0);
DayHlineI = LastValue (DayHline,1);
DayLlineI = LastValue (DayLline,1);
Plot(DayHline,"DayH",colorYellow,styleBar|styleNoRescale|styleNoTitle);
Plot(DayLline,"DayL",colorYellow,styleBar|styleNoRescale|styleNoTitle);
PlotText(" Day Hi " , LastValue(BarIndex())-(numbars/Hts), DayHlineI +0.05, colorYellow);
PlotText(" Day Lo " , LastValue(BarIndex())-(numbars/Hts), DayLlineI +0.05, colorYellow);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////



//Support and resistance levels using RSI.
//graham Kavanagh May 2003
//Load into Indicator Builder
//Sensitivity of the levels can be changed with the variables
//Can test different numbers live with the Param function ctrl-R with open pane
RSIperiod = 5; // Param("RSI p",3,14,30,1);
Percent = 5; // Param("ZIG %",8,9,15,1);
EMAperiod = 5; //Param("EMA p",4,5,10,1);
HHVperiod = 5; //Param("HHV p",3,5,10,1);
NumLine = 1; //Param("Num Lines",3,1,20,1);

Base = DEMA(RSI(RSIperiod),EMAperiod);

for( i = 1; i <= numline; i++ )
{
ResBase = LastValue(Peak(Base,Percent,i));
SupBase = LastValue(Trough(Base,Percent,i));
Plot(ValueWhen( ResBase==Base, HHV(H,HHVperiod) ), "Resist Level", colorRed,
styleDashed);
Plot(ValueWhen( supbase==Base, LLV(L,HHVperiod) ), "Support Level", colorGreen,
styleDashed);
}
Title = Name() + "; " + Date() + ": Support & Resistance Levels using RSI: " +
/*EncodeColor(colorGreen)+ "Support Levels are Green; "+EncodeColor(colorRed)+
"Resistance Levels are Red: "+EncodeColor(colorBlack)+*/ "Num lines
="+WriteVal(numline,1) ;

/////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////
///// Trailing Stop Module /////

P6=Param("Trailing Stop Risk",2.5,2,3.5,0.1);
P7=Param("Trailing Stop LookBack",14,5,25,1);
P8=Param("Trailing Stop PrevLow Switch",0,0,1,1);
PrevLow=IIf(P8==1, Ref(C,-TroughBars(C,5,1)) ,Null);
Plot(PrevLow,"",colorRed);

//Position sizing//
MyTotalPort = Param("MyTotalPort",1000000,10000,10000000,100000);
AcceptableRisk = Param("AcceptableRisk",0.5,0.1,3,0.1);
BarsFromStart = BarsSince(Cross(C,Ref(PK,-1))AND Ref(Color,-1)==colorRed) ;
InitialStopLoss =Ref( H - P6*ATR(P7),-BarsFromStart);
PositionSizing = 0.01*AcceptableRisk*MyTotalPort/( C - InitialStopLoss );

Plot(IIf( HHV(H - P6*ATR(P7),BarsFromStart+1) <C ,HHV(H - P6*ATR(P7),BarsFromStart+1),Null) ,"",colorCustom12,1);

PlotShapes(shapeDownArrow*Cross(Ref(HHV(H - P6*ATR(P7),BarsFromStart+1),-1),C),colorBlack,0,H,Offset=-43);

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("Price");

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} - {{DATE}} "+ EncodeColor(colorYellow)+"Open = "+ EncodeColor(colorYellow) +"%g "+ EncodeColor(colorBrightGreen)+"High = "+ EncodeColor(colorBrightGreen) +"%g "+ EncodeColor(colorRed)+"Low = "+ EncodeColor(colorRed) +"%g "+ EncodeColor(colorYellow) +"Close = "+ EncodeColor(colorYellow) +" %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

////////////////////////////////////////////////////////////////////////////////////////////////

Odd=13;//enter Odd numbers only
CoefOdd=round(Odd/2);

Even=12;//enter Even numbers only
Coefeven=Even/2;
Coefeven2=Coefeven+1;

CongestionPercent=2.8;/*Set % above/below Moving average for congestion / sideways market*/

TriangularOdd=MA(MA(C,CoefOdd),CoefOdd);
TriangularEven=MA(MA(C,Coefeven),Coefeven2);

finalMov_avg=IIf(Odd > even,triangularOdd,TriangularEven);

Color=colorBrightGreen;//select Moving average line color
tickercolor=colorBlack;//select price color

Plot(finalMov_avg,"",IIf(C < finalmov_avg,colorRed,Color),styleDots|styleThick);

////////////////////////////////////////////////////////////////////////////////////////////////



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

Code to automatically identify pivots TRIANGLE

********************************** */
// -- what will be our lookback range for the hh and ll?
farback=Param("How Far back to go",200,12,30,1);
nBars = Param("Number of bars", 12, 1, 30, 1);
// -- Create 0-initialized arrays the size of barcount
aHPivs = H - H;
aLPivs = L - L;
// -- More for future use, not necessary for basic plotting
aHPivHighs = H - H;
aLPivLows = L - L;
aHPivIdxs = H - H;
aLPivIdxs = L - L;
nHPivs = 0;
nLPivs = 0;
lastHPIdx = 0;
lastLPIdx = 0;
lastHPH = 0;
lastLPL = 0;
curPivBarIdx = 0;
// -- looking back from the current bar, how many bars
// back were the hhv and llv values of the previous
// n bars, etc.?
aHHVBars = HHVBars(H, nBars);
aLLVBars = LLVBars(L, nBars);
aHHV = HHV(H, nBars);
aLLV = LLV(L, nBars);
// -- Would like to set this up so pivots are calculated back from
// last visible bar to make it easy to "go back" and see the pivots
// this code would find. However, the first instance of
// _Trace output will show a value of 0
aVisBars = Status("barvisible");
nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));
_TRACE("Last visible bar: " + nLastVisBar);
// -- Initialize value of curTrend
curBar = (BarCount-1);
curTrend = "";
if (aLLVBars[curBar] <
aHHVBars[curBar]) {
curTrend = "D";
}
else {
curTrend = "U";
}
// -- Loop through bars. Search for
// entirely array-based approach
// in future version
for (i=0; i<farback; i++) {
curBar = (BarCount - 1) - i;
// -- Have we identified a pivot? If trend is down...
if (aLLVBars[curBar] < aHHVBars[curBar]) {
// ... and had been up, this is a trend change
if (curTrend == "U") {
curTrend = "D";
// -- Capture pivot information
curPivBarIdx = curBar - aLLVBars[curBar];
aLPivs[curPivBarIdx] = 1;
aLPivLows[nLPivs] = L[curPivBarIdx];
aLPivIdxs[nLPivs] = curPivBarIdx;
nLPivs++;
}
// -- or current trend is up
} else {
if (curTrend == "D") {
curTrend = "U";
curPivBarIdx = curBar - aHHVBars[curBar];
aHPivs[curPivBarIdx] = 1;
aHPivHighs[nHPivs] = H[curPivBarIdx];
aHPivIdxs[nHPivs] = curPivBarIdx;
nHPivs++;
}
// -- If curTrend is up...else...
}
// -- loop through bars
}
// -- Basic attempt to add a pivot this logic may have missed
// -- OK, now I want to look at last two pivots. If the most
// recent low pivot is after the last high, I could
// still have a high pivot that I didn't catch
// -- Start at last bar
curBar = (BarCount-1);
candIdx = 0;
candPrc = 0;
lastLPIdx = aLPivIdxs[0];
lastLPL = aLPivLows[0];
lastHPIdx = aHPivIdxs[0];
lastHPH = aHPivHighs[0];
if (lastLPIdx > lastHPIdx) {
// -- Bar and price info for candidate pivot
candIdx = curBar - aHHVBars[curBar];
candPrc = aHHV[curBar];
if (
lastHPH < candPrc AND
candIdx > lastLPIdx AND
candIdx < curBar) {
// -- OK, we'll add this as a pivot...
aHPivs[candIdx] = 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] = candPrc ;
aHPivIdxs[0] = candIdx;
nHPivs++;
}
} else {
// -- Bar and price info for candidate pivot
candIdx = curBar - aLLVBars[curBar];
candPrc = aLLV[curBar];
if (
lastLPL > candPrc AND
candIdx > lastHPIdx AND
candIdx < curBar) {
// -- OK, we'll add this as a pivot...
aLPivs[candIdx] = 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] = candPrc;
aLPivIdxs[0] = candIdx;
nLPivs++;
}
}
// -- Dump inventory of high pivots for debugging
/*
for (k=0; k<nHPivs; k++) {
_TRACE("High pivot no. " + k
+ " at barindex: " + aHPivIdxs[k] + ", "
+ WriteVal(ValueWhen(BarIndex()==aHPivIdxs[k],
DateTime(), 1), formatDateTime)
+ ", " + aHPivHighs[k]);
}
*/
// -- OK, let's plot the pivots using arrows

PlotShapes(IIf(aHPivs==1, shapeSmallDownTriangle, shapeNone), colorCustom12, 0, High, Offset=-5);
PlotShapes(IIf(aLPivs==1, shapeSmallUpTriangle , shapeNone), colorCustom11, 0, Low, Offset=-5);

Sell = aHPivs == 1 ;
Buy = aLPivs == 1 ;
Filter=Buy OR Sell;
Sell=ExRem(Sell,Buy);
Buy=ExRem(Buy,Sell);

////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("Pivot_Finder");
/* **********************************

Code to automatically identify pivots for STAR

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

// -- what will be our lookback range for the hh and ll?
farback=Param("How Far back to go",200,0,5000,10);
nBars = Param("Number of bars", 12, 5, 40);


// -- Create 0-initialized arrays the size of barcount

aHPivs = H - H;

aLPivs = L - L;

// -- More for future use, not necessary for basic plotting

aHPivHighs = H - H;

aLPivLows = L - L;

aHPivIdxs = H - H;

aLPivIdxs = L - L;

nHPivs = 0;

nLPivs = 0;

lastHPIdx = 0;

lastLPIdx = 0;

lastHPH = 0;

lastLPL = 0;

curPivBarIdx = 0;

// -- looking back from the current bar, how many bars

// back were the hhv and llv values of the previous

// n bars, etc.?

aHHVBars = HHVBars(H, nBars);

aLLVBars = LLVBars(L, nBars);

aHHV = HHV(H, nBars);

aLLV = LLV(L, nBars);

// -- Would like to set this up so pivots are calculated back from

// last visible bar to make it easy to "go back" and see the pivots

// this code would find. However, the first instance of

// _Trace output will show a value of 0

aVisBars = Status("barvisible");

nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));

_TRACE("Last visible bar: " + nLastVisBar);

// -- Initialize value of curTrend

curBar = (BarCount-1);

curTrend = "";

if (aLLVBars[curBar] <

aHHVBars[curBar]) {

curTrend = "D";

}

else {

curTrend = "U";

}

// -- Loop through bars. Search for

// entirely array-based approach

// in future version

for (i=0; i<farback; i++) {

curBar = (BarCount - 1) - i;

// -- Have we identified a pivot? If trend is down...

if (aLLVBars[curBar] < aHHVBars[curBar]) {

// ... and had been up, this is a trend change

if (curTrend == "U") {

curTrend = "D";

// -- Capture pivot information

curPivBarIdx = curBar - aLLVBars[curBar];

aLPivs[curPivBarIdx] = 1;

aLPivLows[nLPivs] = L[curPivBarIdx];

aLPivIdxs[nLPivs] = curPivBarIdx;

nLPivs++;

}

// -- or current trend is up

} else {

if (curTrend == "D") {

curTrend = "U";

curPivBarIdx = curBar - aHHVBars[curBar];

aHPivs[curPivBarIdx] = 1;

aHPivHighs[nHPivs] = H[curPivBarIdx];

aHPivIdxs[nHPivs] = curPivBarIdx;

nHPivs++;

}

// -- If curTrend is up...else...

}

// -- loop through bars

}

// -- Basic attempt to add a pivot this logic may have missed

// -- OK, now I want to look at last two pivots. If the most

// recent low pivot is after the last high, I could

// still have a high pivot that I didn't catch

// -- Start at last bar

curBar = (BarCount-1);

candIdx = 0;

candPrc = 0;

lastLPIdx = aLPivIdxs[0];

lastLPL = aLPivLows[0];

lastHPIdx = aHPivIdxs[0];

lastHPH = aHPivHighs[0];

if (lastLPIdx > lastHPIdx) {

// -- Bar and price info for candidate pivot

candIdx = curBar - aHHVBars[curBar];

candPrc = aHHV[curBar];

if (

lastHPH < candPrc AND

candIdx > lastLPIdx AND

candIdx < curBar) {


// -- OK, we'll add this as a pivot...

aHPivs[candIdx] = 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] = candPrc ;

aHPivIdxs[0] = candIdx;

nHPivs++;

}

} else {


// -- Bar and price info for candidate pivot

candIdx = curBar - aLLVBars[curBar];

candPrc = aLLV[curBar];

if (

lastLPL > candPrc AND

candIdx > lastHPIdx AND

candIdx < curBar) {


// -- OK, we'll add this as a pivot...

aLPivs[candIdx] = 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] = candPrc;

aLPivIdxs[0] = candIdx;

nLPivs++;

}

}

// -- Dump inventory of high pivots for debugging



for (k=0; k<nHPivs; k++) {

_TRACE("High pivot no. " + k

+ " at barindex: " + aHPivIdxs[k] + ", "

+ WriteVal(ValueWhen(BarIndex()==aHPivIdxs[k],

DateTime(), 1), formatDateTime)

+ ", " + aHPivHighs[k]);

}

//////////////////////////////////////////////////////////////////////////////

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

PlotShapes(

IIf(aHPivs==1, shapeStar, shapeNone), colorBrightGreen, 0, H, 15);

PlotShapes(

IIf(aLPivs==1, shapeStar , shapeNone), colorCustom12, 0, L, -20);


//////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////

messageboard = ParamToggle("Message Board","Show|Hide",0);
showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);
no=10;
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);
s5d=IIf(avn==1,sup,res);

if (showsl == 0)
//{Plot(s5d,"Stop Loss",colorCustom14,styleDots);}
exitlong = Cross(s5d, H);
PlotShapes(exitlong * shapeDownArrow, colorBlack,0,H,-10);
exitshort = Cross(L, s5d);
PlotShapes(exitshort * shapeUpArrow, 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 = C;
sig = "BUY";
sl = s5d;
tar1 = entry + (entry * .0056);
tar2 = entry + (entry * .0116);
tar3 = entry + (entry * .0216);

bars = i;
i = 0;
}
if(Sell == 1)
{
sig = "SELL";
entry = C;
sl = s5d;
tar1 = entry - (entry * .0056);
tar2 = entry - (entry * .0116);
tar3 = entry - (entry * .0216);


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

Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);

Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorDarkRed, styleLine|styleLine, Null, Null, Offset);
Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorGreen, styleLine|styleLine, Null, Null, Offset);

for (i=bars; i <BarCount;i++)
{
PlotText(""+sig+"@"+entry, BarCount+1,entry,Null,colorBlue);
PlotText("T1@"+tar1,BarCount+3,tar1,Null,Clr);PlotText("T2@"+tar2,BarCount+3,tar2,Null,Clr);PlotText("T3@"+tar3,BarCount+3,tar3,Null,Clr);

}


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( colorBlue ); // 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 = 5;
x2 = 290;

y = pxHeight;

GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 163, x2, y , 7, 7 ) ;
GfxTextOut( ( " GAIN TRADE "),88,y-165);
GfxTextOut( (" "),27,y-160);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-140) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-120);
GfxTextOut( ("Trailing SL : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 13, y-100);
GfxTextOut( ("TGT:1 : " + tar1), 13, y -80);
GfxTextOut( ("TGT:2 : " + tar2), 13,y-60);
GfxTextOut( ("TGT:3 : " + tar3), 13,y-40);
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 88, y-22);;

}
//////////////////////////////////////////////////////////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("Magnified Market Price");
//by Vidyasagar, [email protected]//
FS=Param("Font Size",30,30,100,1);
GfxSelectFont("Arial", FS, 900, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorYellow) );
Hor=Param("Horizontal Position",800,800,800,800);
Ver=Param("Vertical Position",27,27,27,27);
GfxTextOut(""+C,Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Arial", 12, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor(ParamColor("Color",colorYellow) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor+5, Ver+45 );
_SECTION_END();

////////////////////////////////////////////////////////////////////////////////

_SECTION_BEGIN("trending ribbon");
uptrend=PDI()>MDI()AND Signal()<MACD();
downtrend=MDI()>PDI()AND Signal()>MACD();
Plot( 2, /* defines the height of the ribbon in percent of pane width */"ribbon",
IIf( uptrend, colorGreen, IIf( downtrend, colorRed, colorBlack )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();
GraphXSpace=5;
 

yasu222

Active Member
#12
_SECTION_BEGIN("TEMA");
function ZeroLagTEMA( array, period )
{
TMA1 = TEMA( array, period );
TMA2 = TEMA( TMA1, period );
Diff = TMA1 - TMA2;
return TMA1 + Diff ;
}

/////////////////////
// Heikin-Ashi code
HaClose = (O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );

avp = Param("Up TEMA avg", 34, 1, 100 );
avpdn = Param("Dn TEMA avg", 34, 1, 100 );

// Velvoort is using not original, but modified Heikin-Ashi close
HaClose = ( HaClose + HaOpen + Max( H, HaOpen ) + Min( L, HaOpen ) )/4;

// up average
ZlHa = ZeroLagTEMA( HaClose, avp );
ZlCl = ZeroLagTEMA( ( H + L ) / 2, avp );
ZlDif = ZlCl - ZlHa;

keep1 = Hold( HaClose >= HaOpen, 2 );
keep2 = ZlDif >= 0;
keeping = keep1 OR keep2;
keepall = keeping OR ( Ref( keeping, -1 ) AND ( C > O ) OR C >= Ref( C, -1 ) );
keep3 = abs( C - O ) < ( H - L ) * 0.35 AND H >= Ref( L, -1 );
utr = keepall OR ( Ref( keepall, -1 ) AND keep3 );

// dn average
ZlHa = ZeroLagTEMA( HaClose, avpdn );
ZlCl = ZeroLagTEMA( ( H + L ) / 2, avpdn );
ZlDif = ZlCl - ZlHa;

keep1 = Hold( HaClose < HaOpen, 2 );
keep2 = ZlDif < 0;
keeping = keep1 OR keep2;
keepall = keeping OR ( Ref( keeping, -1 ) AND ( C < O ) OR C < Ref( C, -1 ) );
keep3 = abs( C - O ) < ( H - L ) * 0.35 AND L <= Ref( H, -1 );
dtr = keepall OR ( Ref( keepall, -1 ) AND keep3 );

upw = dtr == 0 AND Ref( dtr, -1 ) AND utr;
dnw = utr == 0 AND Ref( utr, -1 ) AND dtr;

Haco = Flip( upw, dnw );


if( ParamToggle("Chart Type", "Price with color back|HACO wave" ) )
{
Plot( Haco, "Haco", colorRed );
}
else
{
Plot( C, "Close", colorBlack,
ParamStyle( "Style", styleCandle, maskPrice ) );
Plot( 1, "", IIf( Haco , colorPaleGreen, colorRose ),
styleArea | styleOwnScale, 0, 1 );
}
_SECTION_END();

_SECTION_BEGIN("graph");
SetChartOptions(0,chartShowArrows|chartShowDates);
gxs=Param("GRAPH spaceing",10,5,50,5);
GraphXSpace = gxs;
strWeekday = StrMid("SunMonTueWedThuFriSat", SelectedValue(DayOfWeek())*3,3);
_SECTION_END();
_SECTION_BEGIN("NMA ");
k = Optimize("K",Param("K",1.75,1,5,0.25),1,5,0.25);
Per= Optimize("atr",Param("atr",10,3,30,1),3,30,1);
j=(O+H+L+C)/4;
nm= (H-L);
rfsctor = WMA(nm, PER);
revers = K * rfsctor;
Trend = 1;
NW[0] = 0;
for(i = 1; i < BarCount; i++)
{
if(Trend[i-1] == 1)
{
if(j < NW[i-1])
{
Trend = -1;
NW = j + Revers;
}
else
{
Trend = 1;
if((j - Revers) > NW[i-1])
{
NW = j - Revers;
}
else
{
NW = NW[i-1];
}
}
}
if(Trend[i-1] == -1)
{
if(j > NW[i-1])
{
Trend = 1;
NW = j - Revers;
}
else
{
Trend = -1;
if((j + Revers) < NW[i-1])
{
NW = j + Revers;
}
else
{
NW = NW[i-1];
}
}
}
}

Plot(NW, "", IIf(Trend == 1, 6, 4), 4);

//---------------trading -------------

Buy=Cross(j,nw);
Short=Cross(nw,j);
Sell=Cross(nw,j);
Cover=Cross(j,nw);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorSkyblue, 0,Low,-15);
PlotShapes(IIf(Sell, shapeHollowDownArrow, shapeNone),colorLightYellow, 0,High,-15);
PlotShapes(IIf(Cover, shapeHollowUpArrow, shapeNone),colorTan, 0,Low,-25);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorGold, 0,High,-25);
//-----------end--------------
Long=Flip(Buy,Sell OR Cover);
Shrt=Flip(Sell,Buy OR Cover);
NOTrade= NOT (Long OR shrt);
BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);
_SECTION_END();
grid_day = IIf(Day()!=Ref(Day(),-1),1,0);
Plot(grid_day,"",colorDarkGrey,styleHistogram|styleDashed|styleNoLabel|styleOwnScale);
///--------------------------------------------------------------------------------------------------
Candletype=ParamList("Candle Type","Candle|Heinkin",0);
UpCandle = ParamColor("Up Color", colorBrightGreen );
DownCandle = ParamColor("Down Color", colorDarkRed );
Consolidation = ParamColor("Consolidation", colorBlack );
BG2a=HHV(LLV(L,4)+ATR(4),8);
BR2a=LLV(HHV(H,4)-ATR(4),8);
if(Candletype=="Candle")
{
Candlecolor = IIf(Close>BG2a ,UpCandle,IIf(Close < BR2a,DownCandle,Consolidation));
SetBarFillColor( IIf(O <C, colorSeaGreen,colorOrange) );
Plot( Close, "Price", CandleColor, styleCandle );
TimeFrameSet( 2*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
M5 = TimeFrameExpand(BG2,2*Interval(),expandFirst );
MM5=TimeFrameExpand( BR2,2*Interval(),expandFirst );
cM5=TimeFrameExpand( C1, 2*Interval(),expandFirst );
TimeFrameSet( 4*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
M15 = TimeFrameExpand(BG2,4*Interval(),expandFirst );
MM15=TimeFrameExpand(BR2,4*Interval(),expandFirst );
cM15=TimeFrameExpand( C1,4*Interval(),expandFirst );
TimeFrameSet( 6*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
M30 = TimeFrameExpand(BG2,6*Interval(),expandFirst );
MM30=TimeFrameExpand(BR2,6*Interval(),expandFirst );
cM30=TimeFrameExpand( C1,6*Interval(),expandFirst );
TimeFrameSet( 8*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
H1 = TimeFrameExpand(BG2 ,8*Interval(),expandFirst );
HH1=TimeFrameExpand( BR2,8*Interval(),expandFirst );
Ch1=TimeFrameExpand( C1,8*Interval(),expandFirst );
TimeFrameSet( 16*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
H4 = TimeFrameExpand( BG2,16*Interval(),expandFirst );
HH4=TimeFrameExpand( BR2,16*Interval(),expandFirst );
cH4 = TimeFrameExpand( C1,16*Interval(),expandFirst );
Com=("\n "+Name()+ " - Trend in "+Candletype)+"\n "+
EncodeColor(colorLightGrey)+(""+Interval(2)+":")+
WriteIf(Close>BG2a,EncodeColor(colorLime)+" UP",WriteIf(Close<BR2a,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+2*Interval()/60+"m:")+
WriteIf(Cm5>M5,EncodeColor(colorLime)+" UP",WriteIf(Cm5<MM5,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+4*Interval()/60+"m:")+
WriteIf(Cm15>M15,EncodeColor(colorLime)+" UP",WriteIf(Cm15<MM15,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+6*Interval()/60+"m:")+
WriteIf(Cm30>M30,EncodeColor(colorLime)+" UP",WriteIf(Cm30<MM30,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+8*Interval()/60+"m:")+
WriteIf(CH1>H1,EncodeColor(colorLime)+" UP",WriteIf(CH1<HH1,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+16*Interval()/60+"m: ")+
WriteIf(Ch4>H4,EncodeColor(colorLime)+" UP",WriteIf(Ch4<HH4,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~" ));
}
else if(Candletype=="Heinkin")
{
aC =(O+H+L+C)/4;
aO = AMA( Ref( aC, -1 ), 0.5 );
aH = Max( H, Max( aC, aO) );
aL = Min( L, Min( aC, aO) );
BGH=HHV(LLV(aL,4)+ATR(4),8);
BRH=LLV(HHV(aH,4)-ATR(4),8);
co = IIf(ac>BGH ,UpCandle,IIf(ac < BRH,DownCandle,Consolidation));
SetBarFillColor( IIf(aO <aC, colorSeaGreen,colorOrange) );
PlotOHLC(aO,ah,aL,ac ,"Price", Co, styleCandle );
TimeFrameSet( 2*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();
H5 = TimeFrameExpand(BG2H,2*Interval(),expandFirst );
MH5=TimeFrameExpand( BR2H,2*Interval(),expandFirst );
cH5=TimeFrameExpand( C1, 2*Interval(),expandFirst );
TimeFrameSet( 4*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();
H15 = TimeFrameExpand(BG2H,4*Interval(),expandFirst );
MH15=TimeFrameExpand(BR2H,4*Interval(),expandFirst );
cH15=TimeFrameExpand( C1,4*Interval(),expandFirst );
TimeFrameSet( 6*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();
H30 = TimeFrameExpand(BG2H,6*Interval(),expandFirst );
MH30=TimeFrameExpand(BR2H,6*Interval(),expandFirst );
cH30=TimeFrameExpand( C1,6*Interval(),expandFirst );
TimeFrameSet( 8*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();

H1A = TimeFrameExpand(BG2H ,8*Interval(),expandFirst );
HH1A=TimeFrameExpand( BR2H,8*Interval(),expandFirst );
Ch1A=TimeFrameExpand( C1,8*Interval(),expandFirst );
TimeFrameSet( 16*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();
H4 = TimeFrameExpand( BG2H,16*Interval(),expandFirst );
HH4=TimeFrameExpand( BR2H,16*Interval(),expandFirst );
cH4 = TimeFrameExpand( C1,16*Interval(),expandFirst );
Com=("\n "+Name()+ " - Trend in "+Candletype)+"\n "+
EncodeColor(colorLightGrey)+(""+Interval(2)+":")+
WriteIf(aC>BGH,EncodeColor(colorLime)+" UP",WriteIf(aC<BRH,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+2*Interval()/60+"m:")+
WriteIf(cH5>H5,EncodeColor(colorLime)+" UP",WriteIf(cH5<MH5,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+4*Interval()/60+"m:")+
WriteIf(cH15>H15,EncodeColor(colorLime)+" UP",WriteIf(cH15<MH15,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+6*Interval()/60+"m:")+
WriteIf(cH30>H30,EncodeColor(colorLime)+" UP",WriteIf(cH30<MH30,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+8*Interval()/60+"m:")+
WriteIf(Ch1A>H1A,EncodeColor(colorLime)+" UP",WriteIf(Ch1A<HH1A,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+16*Interval()/60+"m: ")+
WriteIf(Ch4>H4,EncodeColor(colorLime)+" UP",WriteIf(Ch4<HH4,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~" ));
}
//---------------------------------------------------------------------------------------
Vr=ParamList("Index",List = "^NSEI,^NSEBANK,NIFTY_F1,RELIANCE.NS,SBIN.NS",0);
SetForeign(Vr);
HaC =(O+H+L+C)/4;
HaO = AMA( Ref( HaC, -1 ), 0.5 );
HaH = Max( H, Max( HaC, HaO) );
HaL = Min( L, Min( HaC, HaO) );
HBG=HHV(LLV(HaL,4)+ATR(4),8);
HBR=LLV(HHV(HaH ,4)-ATR(4),8);
co = IIf(Hac>HBG ,colorAqua,IIf(Hac < HBR,colorCustom12,colorGrey50));
if( SetForeign(Vr) )
{Plot(2, "", Co,styleArea+styleOwnScale | styleNoLabel, -1, 100);
}else{
Plot(2, "", 1,styleArea+styleOwnScale | styleNoLabel, -1, 100);}


//=====================================================================================
TimeFrameSet( 2*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
M5H = TimeFrameExpand(BG2H,2*Interval(),expandFirst );
MM5H=TimeFrameExpand( BR2H,2*Interval(),expandFirst );
cM5H=TimeFrameExpand( C1H, 2*Interval(),expandFirst );
TimeFrameSet( 4*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
M15H = TimeFrameExpand(BG2H,4*Interval(),expandFirst );
MM15H=TimeFrameExpand(BR2H,4*Interval(),expandFirst );
cM15H=TimeFrameExpand( C1H,4*Interval(),expandFirst );
TimeFrameSet( 6*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
M30H = TimeFrameExpand(BG2H,6*Interval(),expandFirst );
MM30H=TimeFrameExpand(BR2H,6*Interval(),expandFirst );
cM30H=TimeFrameExpand( C1H,6*Interval(),expandFirst );
TimeFrameSet( 8*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
H1H = TimeFrameExpand(BG2H ,8*Interval(),expandFirst );
HH1H=TimeFrameExpand( BR2H,8*Interval(),expandFirst );
Ch1H=TimeFrameExpand( C1H,8*Interval(),expandFirst );
TimeFrameSet( 16*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
H4H = TimeFrameExpand( BG2H,16*Interval(),expandFirst );
HH4H=TimeFrameExpand( BR2H,16*Interval(),expandFirst );
cH4H = TimeFrameExpand( C1H,16*Interval(),expandFirst );
RestorePriceArrays();

Comm2=("\n "+VR+ " - Phase in ")+"\n "+
EncodeColor(colorLightYellow)+(""+Interval(2)+":")+
WriteIf(Hac>HBG,EncodeColor(colorLime)+" UP",WriteIf(Hac < HBR,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+2*Interval()/60+"m:")+
WriteIf(cM5H>M5H,EncodeColor(colorLime)+" UP",WriteIf(cM5H<MM5H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+4*Interval()/60+"m:")+
WriteIf(cM15H>M15H,EncodeColor(colorLime)+" UP",WriteIf(cM15H<MM15H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+6*Interval()/60+"m:")+
WriteIf(cM30H>M30H,EncodeColor(colorLime)+" UP",WriteIf(cM30H<MM30H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+8*Interval()/60+"m:")+
WriteIf(Ch1H>H1H,EncodeColor(colorLime)+" UP",WriteIf(Ch1H<HH1H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+16*Interval()/60+"m: ")+
WriteIf(cH4H>H4H,EncodeColor(colorLime)+" UP",WriteIf(cH4H<HH4H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~" ));


//============
//=====Title================================================================================================
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorBlack)+ " " + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorBlue) +
" - " + Date() +" - "+ strWeekday +" - "+"\n" +EncodeColor(colorGreen) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n----------------------"+
EncodeColor(colorTan)+ Com+
EncodeColor(colorGreen)+Comm2+"\n---------system-------------"+"\n"+
EncodeColor(colorBlue)+
WriteIf (Buy AND Ref(shrt,-1), " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Buy AND Ref(NOTrade,-1), " GO LONG at "+C+" ","")+EncodeColor(colorRed)+
WriteIf (Sell AND Ref(NOTrade,-1), " GO Short at "+C+" ","")+
WriteIf (Sell AND Ref(Long,-1), " EXIT LONG / Reverse Signal at "+C+" ","")+
WriteIf (Cover, " cover "+C+" ",""));

_SECTION_END();
_SECTION_BEGIN("Background text");
SetChartOptions(0,chartShowArrows|chartShowDates);
C11=ParamColor("up panel",colorDarkOliveGreen );
C12=ParamColor("dn panel",colorDarkGrey );
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode( 0 );
GfxSetOverlayMode(1);
GfxGradientRect(0,0,pxwidth, pxheight, C11, C12 );
GfxSelectFont("Tahoma", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxTextOut( "ATR Stop&Reverse", Status("pxwidth")/C14, Status("pxheight")/C15*2.5 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxTextOut( " ", Status("pxwidth")/C14, Status("pxheight")/C15*4 );
_SECTION_END();
 
#15
THE EARLIER POSTS ARE WORKING VERY GOOD, BUT WHAT HAPPEND TO THE POSTER, TO POST WRONG CODE. PLEASE RECTIFY AND CODE AND REPOST IT
THANK YOU:clap::clap:
 
#16
THE EARLIER POSTS ARE WORKING VERY GOOD, BUT WHAT HAPPEND TO THE POSTER, TO POST WRONG CODE. PLEASE RECTIFY AND CODE AND REPOST IT
THANK YOU:clap::clap:
nothing serious errors.just remove one space in error msg
try this :

_SECTION_BEGIN("TEMA");
function ZeroLagTEMA( array, period )
{
TMA1 = TEMA( array, period );
TMA2 = TEMA( TMA1, period );
Diff = TMA1 - TMA2;
return TMA1 + Diff ;
}

/////////////////////
// Heikin-Ashi code
HaClose = (O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );

avp = Param("Up TEMA avg", 34, 1, 100 );
avpdn = Param("Dn TEMA avg", 34, 1, 100 );

// Velvoort is using not original, but modified Heikin-Ashi close
HaClose = ( HaClose + HaOpen + Max( H, HaOpen ) + Min( L, HaOpen ) )/4;

// up average
ZlHa = ZeroLagTEMA( HaClose, avp );
ZlCl = ZeroLagTEMA( ( H + L ) / 2, avp );
ZlDif = ZlCl - ZlHa;

keep1 = Hold( HaClose >= HaOpen, 2 );
keep2 = ZlDif >= 0;
keeping = keep1 OR keep2;
keepall = keeping OR ( Ref( keeping, -1 ) AND ( C > O ) OR C >= Ref( C, -1 ) );
keep3 = abs( C - O ) < ( H - L ) * 0.35 AND H >= Ref( L, -1 );
utr = keepall OR ( Ref( keepall, -1 ) AND keep3 );

// dn average
ZlHa = ZeroLagTEMA( HaClose, avpdn );
ZlCl = ZeroLagTEMA( ( H + L ) / 2, avpdn );
ZlDif = ZlCl - ZlHa;

keep1 = Hold( HaClose < HaOpen, 2 );
keep2 = ZlDif < 0;
keeping = keep1 OR keep2;
keepall = keeping OR ( Ref( keeping, -1 ) AND ( C < O ) OR C < Ref( C, -1 ) );
keep3 = abs( C - O ) < ( H - L ) * 0.35 AND L <= Ref( H, -1 );
dtr = keepall OR ( Ref( keepall, -1 ) AND keep3 );

upw = dtr == 0 AND Ref( dtr, -1 ) AND utr;
dnw = utr == 0 AND Ref( utr, -1 ) AND dtr;

Haco = Flip( upw, dnw );


if( ParamToggle("Chart Type", "Price with color back|HACO wave" ) )
{
Plot( Haco, "Haco", colorRed );
}
else
{
Plot( C, "Close", colorBlack,
ParamStyle( "Style", styleCandle, maskPrice ) );
Plot( 1, "", IIf( Haco , colorPaleGreen, colorRose ),
styleArea | styleOwnScale, 0, 1 );
}
_SECTION_END();

_SECTION_BEGIN("graph");
SetChartOptions(0,chartShowArrows|chartShowDates);
gxs=Param("GRAPH spaceing",10,5,50,5);
GraphXSpace = gxs;
strWeekday = StrMid("SunMonTueWedThuFriSat", SelectedValue(DayOfWeek())*3,3);
_SECTION_END();
_SECTION_BEGIN("NMA ");
k = Optimize("K",Param("K",1.75,1,5,0.25),1,5,0.25);
Per= Optimize("atr",Param("atr",10,3,30,1),3,30,1);
j=(O+H+L+C)/4;
nm= (H-L);
rfsctor = WMA(nm, PER);
revers = K * rfsctor;
Trend = 1;
NW[0] = 0;
for(i = 1; i < BarCount; i++)
{
if(Trend[i-1] == 1)
{
if(j < NW[i-1])
{
Trend = -1;
NW = j + Revers;
}
else
{
Trend = 1;
if((j - Revers) > NW[i-1])
{
NW = j - Revers;
}
else
{
NW = NW[i-1];
}
}
}
if(Trend[i-1] == -1)
{
if(j > NW[i-1])
{
Trend = 1;
NW = j - Revers;
}
else
{
Trend = -1;
if((j + Revers) < NW[i-1])
{
NW = j + Revers;
}
else
{
NW = NW[i-1];
}
}
}
}

Plot(NW, "", IIf(Trend == 1, 6, 4), 4);

//---------------trading -------------

Buy=Cross(j,nw);
Short=Cross(nw,j);
Sell=Cross(nw,j);
Cover=Cross(j,nw);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorSkyblue, 0,Low,-15);
PlotShapes(IIf(Sell, shapeHollowDownArrow, shapeNone),colorLightYellow, 0,High,-15);
PlotShapes(IIf(Cover, shapeHollowUpArrow, shapeNone),colorTan, 0,Low,-25);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorGold, 0,High,-25);
//-----------end--------------
Long=Flip(Buy,Sell OR Cover);
Shrt=Flip(Sell,Buy OR Cover);
NOTrade= NOT (Long OR shrt);
BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);
_SECTION_END();
grid_day = IIf(Day()!=Ref(Day(),-1),1,0);
Plot(grid_day,"",colorDarkGrey,styleHistogram|styleDashed|styleNoLabel|styleOwnScale);
///--------------------------------------------------------------------------------------------------
Candletype=ParamList("Candle Type","Candle|Heinkin",0);
UpCandle = ParamColor("Up Color", colorBrightGreen );
DownCandle = ParamColor("Down Color", colorDarkRed );
Consolidation = ParamColor("Consolidation", colorBlack );
BG2a=HHV(LLV(L,4)+ATR(4),8);
BR2a=LLV(HHV(H,4)-ATR(4),8);
if(Candletype=="Candle")
{
Candlecolor = IIf(Close>BG2a ,UpCandle,IIf(Close < BR2a,DownCandle,Consolidation));
SetBarFillColor( IIf(O <C, colorSeaGreen,colorOrange) );
Plot( Close, "Price", CandleColor, styleCandle );
TimeFrameSet( 2*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
M5 = TimeFrameExpand(BG2,2*Interval(),expandFirst );
MM5=TimeFrameExpand( BR2,2*Interval(),expandFirst );
cM5=TimeFrameExpand( C1, 2*Interval(),expandFirst );
TimeFrameSet( 4*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
M15 = TimeFrameExpand(BG2,4*Interval(),expandFirst );
MM15=TimeFrameExpand(BR2,4*Interval(),expandFirst );
cM15=TimeFrameExpand( C1,4*Interval(),expandFirst );
TimeFrameSet( 6*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
M30 = TimeFrameExpand(BG2,6*Interval(),expandFirst );
MM30=TimeFrameExpand(BR2,6*Interval(),expandFirst );
cM30=TimeFrameExpand( C1,6*Interval(),expandFirst );
TimeFrameSet( 8*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
H1 = TimeFrameExpand(BG2 ,8*Interval(),expandFirst );
HH1=TimeFrameExpand( BR2,8*Interval(),expandFirst );
Ch1=TimeFrameExpand( C1,8*Interval(),expandFirst );
TimeFrameSet( 16*Interval() );
BG2=HHV(LLV(L,4)+ATR(4),8);
BR2=LLV(HHV(H,4)-ATR(4),8);
C1=C;
TimeFrameRestore();
H4 = TimeFrameExpand( BG2,16*Interval(),expandFirst );
HH4=TimeFrameExpand( BR2,16*Interval(),expandFirst );
cH4 = TimeFrameExpand( C1,16*Interval(),expandFirst );
Com=("\n "+Name()+ " - Trend in "+Candletype)+"\n "+
EncodeColor(colorLightGrey)+(""+Interval(2)+":")+
WriteIf(Close>BG2a,EncodeColor(colorLime)+" UP",WriteIf(Close<BR2a,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+2*Interval()/60+"m:")+
WriteIf(Cm5>M5,EncodeColor(colorLime)+" UP",WriteIf(Cm5<MM5,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+4*Interval()/60+"m:")+
WriteIf(Cm15>M15,EncodeColor(colorLime)+" UP",WriteIf(Cm15<MM15,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+6*Interval()/60+"m:")+
WriteIf(Cm30>M30,EncodeColor(colorLime)+" UP",WriteIf(Cm30<MM30,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+8*Interval()/60+"m:")+
WriteIf(CH1>H1,EncodeColor(colorLime)+" UP",WriteIf(CH1<HH1,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+16*Interval()/60+"m: ")+
WriteIf(Ch4>H4,EncodeColor(colorLime)+" UP",WriteIf(Ch4<HH4,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~" ));
}
else if(Candletype=="Heinkin")
{
aC =(O+H+L+C)/4;
aO = AMA( Ref( aC, -1 ), 0.5 );
aH = Max( H, Max( aC, aO) );
aL = Min( L, Min( aC, aO) );
BGH=HHV(LLV(aL,4)+ATR(4),8);
BRH=LLV(HHV(aH,4)-ATR(4),8);
co = IIf(ac>BGH ,UpCandle,IIf(ac < BRH,DownCandle,Consolidation));
SetBarFillColor( IIf(aO <aC, colorSeaGreen,colorOrange) );
PlotOHLC(aO,ah,aL,ac ,"Price", Co, styleCandle );
TimeFrameSet( 2*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();
H5 = TimeFrameExpand(BG2H,2*Interval(),expandFirst );
MH5=TimeFrameExpand( BR2H,2*Interval(),expandFirst );
cH5=TimeFrameExpand( C1, 2*Interval(),expandFirst );
TimeFrameSet( 4*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();
H15 = TimeFrameExpand(BG2H,4*Interval(),expandFirst );
MH15=TimeFrameExpand(BR2H,4*Interval(),expandFirst );
cH15=TimeFrameExpand( C1,4*Interval(),expandFirst );
TimeFrameSet( 6*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();
H30 = TimeFrameExpand(BG2H,6*Interval(),expandFirst );
MH30=TimeFrameExpand(BR2H,6*Interval(),expandFirst );
cH30=TimeFrameExpand( C1,6*Interval(),expandFirst );
TimeFrameSet( 8*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();

H1A = TimeFrameExpand(BG2H ,8*Interval(),expandFirst );
HH1A=TimeFrameExpand( BR2H,8*Interval(),expandFirst );
Ch1A=TimeFrameExpand( C1,8*Interval(),expandFirst );
TimeFrameSet( 16*Interval() );
BG2H=HHV(LLV(aL,4)+ATR(4),8);
BR2H=LLV(HHV(aH,4)-ATR(4),8);
C1=aC;
TimeFrameRestore();
H4 = TimeFrameExpand( BG2H,16*Interval(),expandFirst );
HH4=TimeFrameExpand( BR2H,16*Interval(),expandFirst );
cH4 = TimeFrameExpand( C1,16*Interval(),expandFirst );
Com=("\n "+Name()+ " - Trend in "+Candletype)+"\n "+
EncodeColor(colorLightGrey)+(""+Interval(2)+":")+
WriteIf(aC>BGH,EncodeColor(colorLime)+" UP",WriteIf(aC<BRH,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+2*Interval()/60+"m:")+
WriteIf(cH5>H5,EncodeColor(colorLime)+" UP",WriteIf(cH5<MH5,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+4*Interval()/60+"m:")+
WriteIf(cH15>H15,EncodeColor(colorLime)+" UP",WriteIf(cH15<MH15,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+6*Interval()/60+"m:")+
WriteIf(cH30>H30,EncodeColor(colorLime)+" UP",WriteIf(cH30<MH30,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+8*Interval()/60+"m:")+
WriteIf(Ch1A>H1A,EncodeColor(colorLime)+" UP",WriteIf(Ch1A<HH1A,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightGrey)+(" "+16*Interval()/60+"m: ")+
WriteIf(Ch4>H4,EncodeColor(colorLime)+" UP",WriteIf(Ch4<HH4,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~" ));
}
//---------------------------------------------------------------------------------------
Vr=ParamList("Index",List = "^NSEI,^NSEBANK,NIFTY_F1,RELIANCE.NS,SBIN.NS", 0);
SetForeign(Vr);
HaC =(O+H+L+C)/4;
HaO = AMA( Ref( HaC, -1 ), 0.5 );
HaH = Max( H, Max( HaC, HaO) );
HaL = Min( L, Min( HaC, HaO) );
HBG=HHV(LLV(HaL,4)+ATR(4),8);
HBR=LLV(HHV(HaH ,4)-ATR(4),8);
co = IIf(Hac>HBG ,colorAqua,IIf(Hac < HBR,colorCustom12,colorGrey50));
if( SetForeign(Vr) )
{Plot(2, "", Co,styleArea+styleOwnScale | styleNoLabel, -1, 100);
}else{
Plot(2, "", 1,styleArea+styleOwnScale | styleNoLabel, -1, 100);}


//================================================== ===================================
TimeFrameSet( 2*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
M5H = TimeFrameExpand(BG2H,2*Interval(),expandFirst );
MM5H=TimeFrameExpand( BR2H,2*Interval(),expandFirst );
cM5H=TimeFrameExpand( C1H, 2*Interval(),expandFirst );
TimeFrameSet( 4*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
M15H = TimeFrameExpand(BG2H,4*Interval(),expandFirst );
MM15H=TimeFrameExpand(BR2H,4*Interval(),expandFirst );
cM15H=TimeFrameExpand( C1H,4*Interval(),expandFirst );
TimeFrameSet( 6*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
M30H = TimeFrameExpand(BG2H,6*Interval(),expandFirst );
MM30H=TimeFrameExpand(BR2H,6*Interval(),expandFirst );
cM30H=TimeFrameExpand( C1H,6*Interval(),expandFirst );
TimeFrameSet( 8*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
H1H = TimeFrameExpand(BG2H ,8*Interval(),expandFirst );
HH1H=TimeFrameExpand( BR2H,8*Interval(),expandFirst );
Ch1H=TimeFrameExpand( C1H,8*Interval(),expandFirst );
TimeFrameSet( 16*Interval() );
BG2H=HHV(LLV(HaL,4)+ATR(4),8);
BR2H=LLV(HHV(HaH,4)-ATR(4),8);
C1H=HaC;
TimeFrameRestore();
H4H = TimeFrameExpand( BG2H,16*Interval(),expandFirst );
HH4H=TimeFrameExpand( BR2H,16*Interval(),expandFirst );
cH4H = TimeFrameExpand( C1H,16*Interval(),expandFirst );
RestorePriceArrays();

Comm2=("\n "+VR+ " - Phase in ")+"\n "+
EncodeColor(colorLightYellow)+(""+Interval(2)+":") +
WriteIf(Hac>HBG,EncodeColor(colorLime)+" UP",WriteIf(Hac < HBR,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+2*Interval()/60+"m:")+
WriteIf(cM5H>M5H,EncodeColor(colorLime)+" UP",WriteIf(cM5H<MM5H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+4*Interval()/60+"m:")+
WriteIf(cM15H>M15H,EncodeColor(colorLime)+" UP",WriteIf(cM15H<MM15H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+6*Interval()/60+"m:")+
WriteIf(cM30H>M30H,EncodeColor(colorLime)+" UP",WriteIf(cM30H<MM30H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+8*Interval()/60+"m:")+
WriteIf(Ch1H>H1H,EncodeColor(colorLime)+" UP",WriteIf(Ch1H<HH1H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
EncodeColor(colorLightYellow)+(" "+16*Interval()/60+"m: ")+
WriteIf(cH4H>H4H,EncodeColor(colorLime)+" UP",WriteIf(cH4H<HH4H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~" ));


//============
//=====Title======================================== ================================================== ======
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorBlack)+ " " + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorBlue) +
" - " + Date() +" - "+ strWeekday +" - "+"\n" +EncodeColor(colorGreen) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n----------------------"+
EncodeColor(colorTan)+ Com+
EncodeColor(colorGreen)+Comm2+"\n---------system-------------"+"\n"+
EncodeColor(colorBlue)+
WriteIf (Buy AND Ref(shrt,-1), " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Buy AND Ref(NOTrade,-1), " GO LONG at "+C+" ","")+EncodeColor(colorRed)+
WriteIf (Sell AND Ref(NOTrade,-1), " GO Short at "+C+" ","")+
WriteIf (Sell AND Ref(Long,-1), " EXIT LONG / Reverse Signal at "+C+" ","")+
WriteIf (Cover, " cover "+C+" ",""));

_SECTION_END();
_SECTION_BEGIN("Background text");
SetChartOptions(0,chartShowArrows|chartShowDates);
C11=ParamColor("up panel",colorDarkOliveGreen );
C12=ParamColor("dn panel",colorDarkGrey );
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode( 0 );
GfxSetOverlayMode(1);
GfxGradientRect(0,0,pxwidth, pxheight, C11, C12 );
GfxSelectFont("Tahoma", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxTextOut( "ATR Stop&Reverse", Status("pxwidth")/C14, Status("pxheight")/C15*2.5 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxTextOut( " ", Status("pxwidth")/C14, Status("pxheight")/C15*4 );
_SECTION_END();
 

Similar threads