My afl collection

rajsumi121

Well-Known Member
#1
FOR EXIT

/*
Plot(WMA(C,50),"",colorGold,styleThick|styleLine|styleDots);
Plot(WMA(C,100),"",colorBrightGreen,styleThick|styleLine|styleDashed);
Plot(WMA(C,170),"",colorYellow,styleLine);
Plot(WMA(C,200),"",colorRed,styleLine|styleThick);


//Plot(MA(C,10),"",colorAqua,styleLine);
Plot(MA(C,25),"",colorYellow,styleLine|styleDashed|styleThick);
*/
Prd1=Param("ATR Period",4,1,20,1);
Prd2=Param("Look Back",8,1,20,1);
green = HHV(LLV(L,Prd1)+ATR(Prd1),Prd2);
red = LLV(HHV(H,Prd1)-ATR(Prd1),Prd2);

HighClosePercent = (H - C)*100/H;
HighLowPercent = MA((H - L)*100/H,25);

barColor=IIf(C>Green ,colorBrightGreen,IIf(C < RED,colorRed,IIf(HighClosePercent>5,colorYellow,IIf(HighLowPercent>5 AND ROC(C,1,True)<-3,colorRed,colorWhite))));
SetBarFillColor( IIf(C>Green AND ROC(C,1,True)<-4.5,colorBlue,colorBlack));

flowerOpen = O;
flowerClose = C;
flowerHigh= H;
flowerLow = L;

_SECTION_BEGIN("Price");
PlotOHLC( IIf(flowerOpen<flowerClose, flowerOpen, flowerClose),flowerHigh,flowerLow,IIf(flowerOpen<flowerClose, flowerClose, flowerOpen), "Close", barColor, styleNoTitle | styleCandle);

//Plot (Close,"", IIf( C > O, ParamColor("Up Color", colorWhite ), ParamColor("Down Color", colorRed )),ParamStyle( "Style", styleCandle | styleThick, maskAll));
SetChartOptions(0,chartShowArrows|chartShowDates);
_SECTION_END();



_SECTION_BEGIN("Background");
SetChartOptions(0,chartShowArrows|chartShowDates);
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g
(%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1
)));
}

SetChartBkColor(ParamColor("Outer panel color ",colorBlack)); // color of outer border
SetChartBkGradientFill( ParamColor("Inner panel color upper half",colorBlack),ParamColor("Inner panel color lower half",colorBlack),ParamColor("Titleblock",colorDarkGrey )); //color of inner panel
_SECTION_END();



{
// Data Path
DataPath1 = ParamStr("DataPath ","Data");
_N(DataPath = "mrtq13-"+DataPath1 +"\\"); //this is the folder where data is put


// Define Required Global Variables
global TrailBarStart,PeakValue,TrailStopValue,EvenStopPS,ProfitStopPS,MaxLossPS;
global TurnOver,TitleS,Qty,LeftoverCash,BuyValue,MarketValue,ReturnedTotalbuyprice,RawCashGain;
global CashReturned,TotalbuypriceGain,PSRequiredGain,EvenStopPC,TrailPercent,Title_1,Title_2;
global DBUY,TBUY,DSELL,TSELL,AlertByte,IDList,TotalEquity;

// Set Core Global Variables

_N(VersionStr="ManualStopSet V3.05");
SetBarsRequired(100000, 100000 );

BC = BarCount-1;
BNUM = BarIndex();
DNUM = DateNum();
TNUM = TimeNum();
FirstBarVis = Status("firstvisiblebar");
LastBarVis = Status("lastvisiblebar")-1;
SelectedBar = SelectedValue(BNUM);
AlertByte = 2; Title_1=""; Title_2="";Tally=0;
printf("SelectedBar:"+SelectedBar+"\n");
printf("BarCount:"+BC+"\n");
Overide="No"; //Diagnostics

// Load ID-List (Trade Lists)
// Make sure directory exists.
fmkdir(DataPath);
// Load ID-List.
IDList=""; // Ensure IDList is defined as a string. (If file not exist 1st run).
_N(IDListFile = DataPath + "ID-List");
fh = fopen( IDListFile, "r");
if( fh )
{// If exist, Get list.
IDList = fgets(fh);
fclose( fh );
}
else
{
IDList="<END>,"; // If not exist, Write File when we create a trade.
}

// Determin EOD(0) or IntraDay(1) mode
TimeFrame = Interval();
EODRT = IIf(TimeFrame>=inDaily,0,1);

// Set Parameters
// MSS Param

//TotalEquity = Param("TotalEquity",0,0,10000000,0.01);
BuyAt = Param("EntryPrice",0,0,10000,0.01);
TotalShare=Param("ShareQuantity",0,0,7000,1);
SellAtP = Param("ExitPrice",0,0,10000,0.01);
CommisionX1=0;//CommisionX1 = Param("Commision",0,0,3000,0.01);
StopLoss = Param("StopLoss",7,0,100,0.01); //Percentage of Cash
TrailStop = Param("Fixed TrailingStop",8,0,100,0.01); //Percentage of HH/LL
ProfitStop = Param("ProfitStop",10,0,100,0.01); //Percentage of Cash
HoldingsAdj = Param("HoldingsAdj",0,-100,100,1); //Adj Calc Holdings
MultiTrade = Param("MultiTrade",0,0,9,1); //View/Set Calcs for specific Multi Trade
CreateTrade = ParamTrigger("Create Trade","<Create>");
RemoveTrade = ParamTrigger("Modify Trade<R>","<Remove>");
CloseTrade = ParamTrigger("Modify Trade<C>","<Close>");
OpenTrade = ParamTrigger("Modify Trade<O>","<Re-Open>");
TradeType = ParamToggle( "Long/Short", "Long|Short",0);
//Totalbuyprice = Param("Totalbuyprice",300000,0,700000,0.01);
// CLA Param
DisplayPlot = ParamToggle("DisplayPlot","Single|Multi",0);
TitleStyleT = ParamList("DisplayText","Detail/Tally|Tally|Detail|None");
TitleSlide = Param("TitleSlide",1,0,30,1);

// Set Default BuyBar & BuyAt etc
SellAt=SellAtP;
if (SelectedBar == LastBarVis) SelectedBar = BC;
BuyBar = SelectedBar; SellBar=BC;
if (SellAt == 0) SellAt=C[SellBar];
if (BuyAt == 0) BuyAt=O[BuyBar];

}
///////////////////////////////////////////////////////////////////////
// End of Initialize
///////////////////////////////////////////////////////////////////////



_SECTION_BEGIN("Pivot");
nBars = Param("Number of bars", 15, 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, shapeDownArrow, shapeNone), colorRed, layer = 0, yposition = High, offset = -10);
//PlotShapes( IIf(aHPivs==1, shapeSmallSquare, shapeNone), colorBlack, layer = 0, yposition = High, offset = 12);

PlotShapes( IIf(aAddedHPivs==1, shapeDownArrow, shapeNone), colorRed,layer = 0, yposition = High, offset = -10);
//PlotShapes( IIf(aAddedHPivs==1, shapeSmallSquare, shapeNone), colorBlack, layer = 0, yposition = High, offset = 12);

//PlotShapes( IIf(aLPivs==1, shapeSmallSquare, shapeNone), colorBrightGreen, layer = 0, yposition = Low, offset = -9);
//PlotShapes( IIf(aLPivs==1, shapeSmallSquare, shapeNone), colorBlack, layer = 0, yposition = Low, offset = -12);

//PlotShapes( IIf(aAddedLPivs==1, shapeDownArrow, shapeNone), colorGold, layer = 0, yposition = Low, offset = -15);
//PlotShapes( IIf(aAddedLPivs==1, shapeSmallSquare, shapeNone), colorBlack, layer = 0, yposition = Low, offset = -13);

}

_SECTION_END();


///////////////////////////////////////////////////////////////////////
// Define Procedures/Functions
///////////////////////////////////////////////////////////////////////
procedure RemoveEntry(RemSym)
{
// Remove entry from IDList
NewIDList = "";
for( i = 0; ( sym = StrExtract( IDList, i ) ) != "<END>"; i++ )
{
if (sym != RemSym) {NewIDList = NewIDList + sym + ",";}
}
IDList = NewIDList+"<END>,";

fh = fopen( IDListFile, "w");
if( fh )
{
fputs( IDList , fh );
fclose( fh );
}
}

procedure AddEntry(AddSym)
{
// Add entry to IDList
IDList = AddSym + "," + IDList;
printf(IDList);
fh = fopen( IDListFile, "w");
if( fh )
{
fputs( IDList , fh );
fclose( fh );
}
}

procedure DoCalculation(Sym)
{
// All variables should be global
// printf("Calculating: "+Sym+"\n");
Turnover = (C*V); //For Display

// Manual Flip (If Sell Selected before buy)
// Mabie should also flip SellAt open/close.
if (SellBar < BuyBar)
{
BuyBar1 = BuyBar;BuyBar=SellBar;SellBar=BuyBar1;
BuyAt1 = BuyAt;BuyAt=SellAt;SellAt=BuyAt1;
}

// Calc Holding Stats



Totalbuyprice=TotalShare*BuyAt;
//CommisionX1=(Totalbuyprice*CommisionX1)/100;
FinalBuyValue=Totalbuyprice+CommisionX1;


// Calc Holding Stats
Avail = Totalbuyprice-CommisionX1;
Qty = (int(Avail/BuyAt))+HoldingsAdj;

BuyValue = Qty*BuyAt;
LeftoverCash = (Totalbuyprice-BuyValue)-CommisionX1;
MarketValue = Qty*SellAt;
RawCashGain = ((MarketValue)-(BuyValue))*((TradeType*-2)+1); //LongShortFlip
CashReturned = RawCashGain-(CommisionX1*2);
ReturnedTotalbuyprice = Totalbuyprice+CashReturned;
TotalbuypriceGain = (CashReturned/Totalbuyprice)*100; // Total Percent Gained


Trail_Ref = BC - SellBar;
Range_Ref = SellBar - BuyBar+1;
PeakValue = LastValue(Ref(HHV(H,Range_Ref),-Trail_Ref));
Peak_Ref = LastValue(Ref(HHVBars(H,Range_Ref),-Trail_Ref));
TrailBarStart = SellBar-Peak_Ref;
TrailStopValue = PeakValue - (PeakValue * (TrailStop/100));
TrailPercent = 100-((Close[SellBar]/PeakValue)*100);
// Calc Even Stop
EvenStopValue = (Qty*BuyAt) + (CommisionX1*2);
EvenStopPS = EvenStopValue/Qty;
EvenStopPC = ((EvenStopPS/Buyat)*100)-100;
// Calc Profit Stop
ProfitStopCalc = FinalBuyValue*(ProfitStop/100);
ProfitStopValue = FinalBuyValue+ ProfitStopCalc + (CommisionX1*2);
ProfitStopPS = ProfitStopValue/Qty;
PSRequiredGain = ((ProfitStopPS/BuyAt)*100)-100;
// Calc Loss Stop
MaxLossCalc = Totalbuyprice*(StopLoss/100);
MaxLossValue = Totalbuyprice- MaxLossCalc + (CommisionX1*2);
MaxLossPS = MaxLossValue/Qty;
}




procedure DisplayPlots(Sym,symid)
{
// Plot Vertical Buy Bar. (Blue)
VLine = IIf(BuyBar==BNUM,1,0);
//Plot (VLine ,"BuyBar", colorGrey40, styleHistogram | styleOwnScale,0,1);

// Plot Vertical Sell Bar. (Blue)
// VLine = IIf(SellBar==BNUM,1,0);
// Plot (VLine ,"BuyBar", colorBlue, styleHistogram | styleOwnScale,0,1);

//Plot MultiTrade Number
PlotText(symid,Buybar-1,ProfitStopPS,colorRed,colorWhite);

// Plot Horizontal Buy Bar. (Yellow)
x0 = Buybar ; y0 = BuyAt;
x1 = SellBar ; y1 = y0;
Hline = LineArray(x0,y0,x1,y1,0);
//Plot(HLine ,"BuyPrice",colorTeal ,ParamStyle("BuyStyle",styleLine|styleDashed,maskAll));

// Plot Trade Trend (BuyBar to SellBar/SellAT - Blue Dashed Line)
x0 = Buybar ; y0 = BuyAt;
x1 = Sellbar ; y1 = SellAt;
// y1 = C[Sellbar];
Hline = LineArray(x0,y0,x1,y1,0);
//Plot(HLine ,"TradeTrend",colorOrange,styleLine|styleDashed);

// Plot Long/Short Trail Stop Trend
x0 = TrailBarStart; y0=PeakValue;
x1 = SellBar; y1 = C[SellBar];
Line = IIf((X1 > X0),LineArray(x0,y0,x1,y1,0),LineArray(x1,y1,x0,y0,0) ); //Reverse
//Plot(Line,"TrailStop",colorViolet,styleLine|styleDots);

// Plot TrailStop Horizontal (ColorViolet)
x0 = Buybar ; y0 = TrailStopValue;
x1 = SellBar ; y1=y0;
Hline = LineArray(x0,y0,x1,y1,0);
Plot(HLine ,"TrailStop",ParamColor( "TrailStopColor", colorSeaGreen ),ParamStyle("TrailStopStyle",styleDashed|styleThick,maskAll));;

// Plot BreakEven Horizontal (ColorGreen)
x0 = Buybar ; y0 = EvenStopPS;
x1 = SellBar ; y1=y0;
Hline = LineArray(x0,y0,x1,y1,0);
Plot(HLine ,"EvenStop",ParamColor( "EvenStopColor", colorGrey50 ),ParamStyle("EvenStopStyle",styleLine|styleDashed|styleStaircase|styleThick|StyleHidden,maskAll));

// Plot ProfitStop Horizontal (ColorWhite)
x0 = Buybar ; y0 = ProfitStopPS ;
x1 = SellBar ; y1=y0;
Hline = LineArray(x0,y0,x1,y1,0);
Plot(HLine ,"ProfitStop",ParamColor( "ProfitStopColor", colorWhite ),ParamStyle("ProfitStopStyle",styleLine|styleStaircase|styleThick|StyleHidden,maskAll));

// Plot LossStop Horizontal (ColorRed)
x0 = Buybar ; y0 = MaxLossPS;
x1 = SellBar ; y1=y0;
Hline = LineArray(x0,y0,x1,y1,0);
Plot(HLine ,"StopLoss",ParamColor( "StopLossColor", colorRed ),ParamStyle("StopLossStyle",styleLine|styleStaircase|styleThick,maskAll));

}// End DisplayPlots

WorkingDays = SellBar - BuyBar+1;//(SellBar-BuyBar);
Maturestock = WorkingDays>=4;
Immaturestock = WorkingDays<4;


Totalbuyprice=TotalShare*BuyAt;
//CommisionX1=(Totalbuyprice*CommisionX1)/100;
FinalBuyValue=Totalbuyprice+CommisionX1;

procedure CreateTitleDetail(Sym)
{
// Create Title Detail
ssd = StrFormat("%.0f",DNUM[BuyBar]);
ssD = StrRight(ssD,6);
ssD = StrRight(ssD,2)+"-"+StrLeft(StrRight(ssD,4),2)+"-20"+StrLeft(ssD,2);

_N(BuyDate = ssD );
//_N(BuyDate = StrLeft(ssD,10));
//_N(BuyDate = StrFormat("%.0f",DNUM[BuyBar]));
_N(BuyTime = StrFormat("%.0f",TNUM[BuyBar]));
_N(SellDate = StrFormat("%.0f",DNUM[SellBar]));_N(SellTime = StrFormat("%.0f",TNUM[SellBar]));
_N(Title_1 = ""+

"\\c11 BuyDate: \\c11"+ BuyDate +//"/" + BuyTime +
//"\n\\c29 SellBar: \\c23"+ SellBar+"\\c29 SellDT: \\c23"+ SellDate + "/" + SellTime +

//"\n\\c38 Commision \\c38"+CommisionX1+
"\n\\c34 Entry Price: \\c34"+BuyAt+
//"\n\\c38 SellAt \\c01"+SellAt+
"\n\\c33 Share Quantity: \\c33"+TotalShare+
"\n\\c36 TotalBuyPrice: \\c36"+Totalbuyprice+
"\n"+EncodeColor(colorRose)+"-------------------------"
+

//"\n\\c21 BuyValue with Commission: \\c01: "+FinalBuyValue+
//"\n\\c21 LeftoverCash \\c01: "+LeftoverCash+
"\n\\c25 Current MarketValue \\c25: "+MarketValue/100+
"\n\\c54 Profit Gain \\c54: "+RawCashGain+
//"\n\\c21 CashReturned \\c01: "+ CashReturned +
//"\n\\c21 ReturnedTotalbuyprice \\c01: "+ReturnedTotalbuyprice+
"\n\\c48 Profit Percentage \\c48: "+TotalbuypriceGain+"%"+
"\n"+EncodeColor(colorRose)+"-------------------------"
+
//"\n\\c21 PSRequiredGain \\c01: "+PSRequiredGain+"%"+
//"\n\\c29 EvenStop : " + Prec(EvenStopPC,4) + "%, " + EvenStopPS +
"\n\\c44 ProfitTaking: " + ProfitStop + "%, " + ProfitStopPS +
"\n\\c07 StopLoss : " + StopLoss + "%, " + MaxLossPS +
"\n\\c51 TrailStop: \\c51" + TrailStop + "%, " + TrailStopValue +


//"\n\\c08 Working Days " +"\\c02@ \\c07" + WorkingDays+WriteIf(Maturestock," \\c08[Mature]"," ")+WriteIf(Immaturestock,"\\c04[Immature]"," ")+
"\n"+EncodeColor(colorRose)+"-------------------------"
+
//"\n\\c29 TrailVariance: \\c01" +TrailPercent + "% "+
"");
}// End CreateTitle

Totalbuyprice=TotalShare*BuyAt;
CommisionX1=(Totalbuyprice*CommisionX1)/100;
FinalBuyValue=Totalbuyprice+CommisionX1;

procedure LoadID(FileName)
{// Load ID
printf("loading: '"+FileName+"'\n");
fh = fopen( FileName, "r");
if( fh )
{// File open for read
TradeType = StrToNum(fgets( fh ));
TotalShare= StrToNum(fgets( fh ));
//StopLoss=StrToNum(fgets( fh ));
TimeFrame = StrToNum(fgets( fh ));
DBUY = StrToNum(fgets( fh ));
TBUY = StrToNum(fgets( fh ));
DSELL = StrToNum(fgets( fh ));
TSELL = StrToNum(fgets( fh ));
BuyAt = StrToNum(fgets( fh ));
SellAt = StrToNum(fgets( fh ));
HoldingsAdj = StrToNum(fgets( fh ));
ProfitStop = StrToNum(fgets( fh ));
StopLoss = StrToNum(fgets( fh ));
TrailStop = StrToNum(fgets( fh ));
Totalbuyprice = StrToNum(fgets( fh ));
CommisionX1= StrToNum(fgets( fh ));
AlertByte = StrToNum(fgets( fh ));
fclose( fh );
TitleS="ReadFile";
}// End file open for read
else
{// File not found
printf("File Not Found\n");
TitleS="Error";
}// End file not found
}// End Load ID

procedure SaveID(FileName)
{// Write ID
printf("saving: '"+FileName+"'\n");
fh = fopen( FileName, "w");
if( fh )
{// File open for write
fputs( StrFormat("%.00f\n",TradeType ), fh );
//fputs( StrFormat("%.00f\n",StopLoss ), fh );
fputs( StrFormat("%.00f\n",TotalShare), fh );
fputs( StrFormat("%.00f\n",TimeFrame ), fh );
fputs( StrFormat("%.00f\n",DBUY ), fh );
fputs( StrFormat("%.00f\n",TBUY ), fh );
fputs( StrFormat("%.00f\n",DSELL ), fh );
fputs( StrFormat("%.00f\n",TSELL ), fh );
fputs( StrFormat("%.02f\n",BuyAt ), fh );
fputs( StrFormat("%.02f\n",SellAt ), fh );
fputs( StrFormat("%.02f\n",HoldingsAdj ), fh );
fputs( StrFormat("%.02f\n",ProfitStop ), fh );
fputs( StrFormat("%.02f\n",StopLoss ), fh );
fputs( StrFormat("%.02f\n",TrailStop ), fh );
fputs( StrFormat("%.02f\n",Totalbuyprice ), fh );
fputs( StrFormat("%.02f\n",CommisionX1 ), fh );
fputs( StrFormat("%.00f\n",AlertByte ), fh );
fclose( fh );
TitleS = "SaveFile";
}// End File open for write
}// End WriteID
///////////////////////////////////////////////////////////////////////
// End Define Procedures/Functions
///////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////
// Start core section.
///////////////////////////////////////////////////////////////////////
{
if (OpenTrade == 1)
{// Open trade.
AlertIf( 1, "", "Open trade", 0,3 );
IDName = Name()+"-"+MultiTrade;
TrailName = DataPath + IDName;
LoadID(TrailName);
SellAt=0;DSELL=0;TSELL=0;
SaveID(TrailName);
}// End Open trade

if (CloseTrade == 1)
{// Close trade.
AlertIf( 1, "", "Close trade", 0,3 );
IDName = Name()+"-"+MultiTrade;
TrailName = DataPath + IDName;
LoadID(TrailName);
DSELL = DNUM[SelectedBar];TSELL = TNUM[SelectedBar];
SellAt=C[SelectedBar];
if (SellAtP != 0) {SellAt=SellAtP;}
SaveID(TrailName);
}// End Close trade

if (RemoveTrade == 1)
{// Remove Entry
AlertIf( 1, "", "Remove trade", 0,3 );
IDName = Name()+"-"+MultiTrade;
RemoveEntry(IDName);
}// End Remove Entry

if (CreateTrade == 1)
{// Write Data
AlertIf( 1, "", "Write trade", 0,3 );
// Set name & add to master index
IDName = Name()+"-"+MultiTrade;
RemoveEntry(IDName);
AddEntry(IDName);
TrailName = DataPath + IDName;
// Write data to file
DBUY = DNUM[BuyBar]; TBUY = TNUM[BuyBar];
DSELL = 0; TSELL = 0; SellAT = 0;
TotalEquity = 0;
SaveID(TrailName);
}// End Write data



// Calc & Display
IDName = Name()+"-"+MultiTrade;
printf("Current: "+IDName+"\n\n");

// Create Title Tally Header.
Title_2 = "-------------------------\n";//"\\c09 SYMBOLS- GAIN\n\n";

if (DisplayPlot == 0)
{// DisplayPlot
// Plot Price & Volume.

PlotForeign( GetBaseIndex(), GetBaseIndex(), colorAqua, styleLine | styleOwnScale);
//Plot( Volume, _DEFAULT_NAME(), colorBlueGrey , styleHistogram | styleOwnScale | styleThick );


if (StrFind(IDList,Name()) == 0)
{// Symbol not found in IDList, use selected.
TitleS="NoFile";
DoCalculation(Name());
DisplayPlots(Name(),"");
CreateTitleDetail(Name());
}// End Symbol not found
else
{// Symbol found in IDList.
if (StrFind(IDList,IDName) == 0)
{// Exact symbol not found in IDList, use selected.
TitleS="NoFile";
DoCalculation(Name());
DisplayPlots(Name(),"");
CreateTitleDetail(Name());
}// End Exact symbol not found
}// End Symbol found
}// End DisplayPlot
flagX = 0;
for( i = 0; ( sym = StrExtract( IDList, i ) ) != "<END>"; i++ )
{// Loop
TrailName = DataPath + sym;
symleft = StrLeft(sym, StrFind(sym,"-")-1); CurrentSym = Name();
symid = StrRight(sym, StrLen(sym)-StrFind(sym,"-"));
// printf("SymLeft: "+symleft+" Current: "+CurrentSym+"\n\n");

// Set Ticker/Trade Environment.
SetForeign(symleft);

// Load & Do Calculation
LoadID(TrailName);

TimeFrameSet(TimeFrame); // after load

//BuyBar = DBUY;
// Calc Buy & Sell Bar
// BuyBar = LastValue(DBUY)+LastValue(Cum((DBUY==DBUY) AND (DBUY<DBUY)));
//BuyBar = LastValue(DBUY,True);

BuyBar = LastValue(Cum(DNUM<DBUY))+LastValue(Cum((DNUM==DBUY) AND (TNUM<TBUY)));
SellBar = LastValue(Cum(DNUM<DSELL))+LastValue(Cum((DNUM==DSELL) AND (TNUM<TSELL)));
XBar = SellBar ;
// Overide Sell
//if ( (SelectedBar != BC) AND (sym == IDName ) AND (TitleS != "Error"))
{SellBar = SelectedBar; SellAt = Close[SellBar];Overide=" @ "+SellBar+" $"+SellAt;}

if (SellBar == 0) {SellBar=BC; SellAt = Close[SellBar];}

// Use loaded Sell Price
if (sym == IDName)
{// Exact match, Overide Sell Price.
if (SellAtP != 0) {SellAt = SellAtP;}
}// End Exact match

// Do the Trade Calcs
DoCalculation(sym); //Doesn't actualy use passed symbol.

// Determine Stops from LastBar/SelectedBar LongMode
ProfitStopFlag = IIf( C[SellBar] >= ProfitStopPS ,True,False);
EvenStopFlag = IIf( C[SellBar] >= EvenStopPS,True,False);
StopLossFlag = IIf( C[SellBar] <= MaxLossPS,True,False);
TrailStopFlag = IIf(TrailPercent >= TrailStop,True,False);

// Generate Alerts Strings for Display
PSD = WriteIf(ProfitStopFlag,"\\c15# ","\\c01. ");
ESD = WriteIf(EvenStopFlag,"\\c15# ","\\c01. ");
LSD = WriteIf(StopLossFlag,"\\c15# ","\\c01. ");
TSD = WriteIf(TrailStopFlag,"\\c15# ","\\c01. ");


WorkingDays = SellBar - BuyBar+1;
NDays = XBar - BuyBar+1;
BeforeEntry = DBUY > DNUM ;
WorkingDays = IIf(BeforeEntry,-1 * (WorkingDays -1),WorkingDays );
Maturestock = WorkingDays>=4;
BuyingDay = WorkingDays==1;
Immaturestock = WorkingDays<4 AND DBUY<=DNUM AND WorkingDays!=1;

MatureString ="\\c08 [Days" +"\\c02@\\c07" + WorkingDays+"] "+WriteIf(Maturestock," \\c08[Mature]","")+WriteIf(Immaturestock,"\\c04[Immature]","")+WriteIf(BuyingDay ,"\\c52[BuyingDay]","")+WriteIf(BeforeEntry ,"\\c04[BeforeEntry]","");

//MatureString =StrFormat(" %.0f ",DBUY)+ StrFormat(" %.0f ",SellBar )+"\\c08 [Days" +"\\c02@\\c07" + WorkingDays+"] "+WriteIf(Maturestock," \\c08[Mature]"," ")+WriteIf(Immaturestock,"\\c04[Immature]"," ")+WriteIf(BeforeEntry ,"\\c04[BeforeEntry]"," ");

if(flagX ==0){
nid = sym ;
}
if (sym == IDName)
{
flagX = 1;
nid = IDName;
en = BuyAt;
wd = StrToNum(StrFormat("%.0f",NDays ));
awd = StrToNum(StrFormat("%.0f",WorkingDays));
}





sss = StrFormat("%.0f",DBUY );
sss = StrRight(sss,6);
sss = StrRight(sss,2)+"-"+StrLeft(StrRight(sss,4),2)+"-20"+StrLeft(sss,2)+"] " + MatureString ;






// Create Title Tally Strings
ListAlerts = PSD + ESD + LSD + TSD; Tally = Tally + CashReturned;
Title_2 = Title_2 + " \\c02" + StrLeft(sym,StrLen(sym)-2) +
": [Buy " + sss + ""+
"\n\\c41 Entry @ "+BuyAt+
"\\c10 -- \\c33 NOS: \\c33"+TotalShare+
"\\c10 --\\c36 Value: \\c36"+Totalbuyprice+
"\n\\c44 Profit $" + StrFormat("%08.2f",CashReturned) + " \\c51 Percent: " + StrFormat("%+06.2f",TotalbuypriceGain) + "%\n"+
//"\\c44 ProfitTaking: " + ProfitStop + "%, " + ProfitStopPS + " \\c07 StopLoss : " + StopLoss + "%, " + MaxLossPS + " \\c51 TrailStop: \\c51" + TrailStop + "%, " + TrailStopValue +
//"\n"+
EncodeColor(colorRose)+"-------------------------\n";




if (sym == IDName)
{// Exact match, Create title.
CreateTitleDetail(sym);
}// End Exact match

// Select Plot Display
if (DisplayPlot == 1) {Plot(C,"Close:"+symleft,i+16,styleLine | styleOwnScale);}
if ((DisplayPlot == 0) AND (symleft == CurrentSym)) {DisplayPlots(sym,symid);}

// Cleanup
TimeFrameRestore();
RestorePriceArrays();
}// End loop
// End of Calc & Display


// Dynamic Title
TSpace = "";
for( i = 0; i<TitleSlide ; i++ ) {TSpace = TSpace + "\n";}


HighLowPercent_2 = (H - L)*100/H;
MAHighClosePercent = MA((H - C)*100/H,64);


Title_Header =Name()+ " "+ WriteVal( SelectedValue( DateTime() ), formatDateTime) + " Open - "+O + " High - "+ H + " Low - "+ L +" Close - "+C + StrFormat(" (%.1f%%) ", SelectedValue( ROC( C, 1 ) )) +
"\nVolume - " +V + " "+StrFormat("(%.1f%%) ", SelectedValue(ROC(V,1))) +" Average Volume(12) - " + MA(V,12) +
"\nHC : "+StrFormat("(%.1f%%) ", HighClosePercent ) +" AHC(64): "+StrFormat("(%.1f%%) ", MAHighClosePercent )+
" AHL(25): "+StrFormat("(%.1f%%) ", HighLowPercent )+ " H-L: "+StrFormat("(%.1f%%) ", HighLowPercent_2 )+ "\\c36";

Title_NetProfitLoss = "-------------------------\n"+"\\c45 Net Profit/Loss : " + Tally + " " +EncodeColor(colorRose)+"\n";
Title_1 = "";
if (TitleStyleT == "Detail")
{Title = Title_Header + Title_1;}
if (TitleStyleT == "Tally")
{Title = Title_Header + Title_2 + "\\c09 Tally:$" + Tally + " " ;}
if (TitleStyleT == "Detail/Tally")
{Title = Title_Header + Title_1+ "\n" + Title_NetProfitLoss + Title_2 ;}
if (TitleStyleT == "None")
{Title = Title_Header ;}
// End Dynamic Title

}

if(flagX ==0){
nid = sym ;
}
///////////////////////////////////////////////////////////////////////
// End Core Section.
///////////////////////////////////////////////////////////////////////

_SECTION_END();


nid = StrLeft(nid ,StrLen(nid )-2);
xid = Name();

if(nid == xid){
if(awd <0){
wd = wd+awd;
}
wd = wd*(-1);

for( i = 0; i<BarCount; i++ ){
local_C = C[wd];
}
for( i = wd; i<BarCount; i++ ){
local_C = C;
}
}
else{
nid = "";
}
z = BarIndex();
tz = StrFormat("%.0f",z);
zt = StrToNum(tz);


/*
MyATR=ATR(14);//Enter ATR Average or use the 14 Day Moving Average of ATR
MidRange=(H+L)/2;//Figure Used In Title for Middle of Trading Range
if(nid == xid){
Plot (local_C- (MyATR*2),"",IIf(z<=wd-2,colorBlack,colorWhite), styleLine);
Plot (local_C- (MyATR*1.5),"",IIf(z<=wd-2,colorBlack,colorWhite), styleLine);
Plot (local_C- (MyATR*3),"",IIf(z<=wd-2,colorBlack,colorWhite),styleLine);
}
*/


/*
_SECTION_BEGIN("Stop loss7");
lookbackPeriod7 = Param("Lookback period7", 20, 7, 30);
stoplossPercentage7 = 7;//Param("Stoploss Percentage7", 7, 7, 10);
if(nid == xid){
Plot(HHV(local_C,lookbackPeriod7) - HHV(local_C,lookbackPeriod7) * (stoplossPercentage7 / 100), "Trailing stoploss7", IIf(z<=wd-2,colorBlack,colorRed), styleDashed|styleThick,0,0,0);
}
_SECTION_END();

_SECTION_BEGIN("Stop loss5");
lookbackPeriod5 = Param("Lookback period5", 20, 5, 30);
stoplossPercentage5 = 5;//Param("Stoploss Percentage5", 5, 2, 10);
if(nid ==xid){
Plot(HHV(local_C,lookbackPeriod5) - HHV(local_C,lookbackPeriod5) * (stoplossPercentage5 / 100), "Trailing stoploss5", IIf(z<=wd-2,colorBlack,colorYellow), styleDashed|styleThick,0,0,0);
}
_SECTION_END();
*/

_SECTION_BEGIN("Stoploss Line");
if(nid == xid){
mf = Param("ATR multiplier",3,1,5,0.25);
ap=Param("ATR Period",10,5,30,1);
Lb=20;//Param("Lookback Period",20,10,40,1);
ps=1;//ParamToggle("Use last low pivot","Use,Dont",1);
//p1=ParamToggle("plot type","line,Dots",1);

t1=HHV(local_C,Lb);
t2=(mf*ATR(ap));
t3=Trough(local_C,2,1);
t4=t1-t2;
t5=Min(t4,t3);

if(ps)
{
t6 = t1-t2;
}
else
{
t6=t5;
}

initial=t6;
stop[ 0 ] = local_C[ 0 ];

for( i = 1 ; i < BarCount; i++)
{
if( local_C[ i ] > stop[ i - 1])
{
temp = t6[ i ];
if( temp > stop[ i - 1 ] ) stop[ i ] = temp;
else stop[ i ] = stop[ i - 1 ];
}
else
stop[ i ] = initial[ i ];

}

Plot(stop,"ATR Stop",IIf(z<=wd-2,colorBlack,ParamColor( "Color", colorLightYellow)),IIf(wd<0,styleNoDraw,styleLine|styleDots|styleNoTitle));
}
/////////////////here ATR ends////////////////////////////////////

_SECTION_END();
 

rajsumi121

Well-Known Member
#2
FOR AUTO PIVOT AND FIBB LEVELS

*/

_SECTION_BEGIN("INIT");
SetChartOptions(0,chartShowArrows|chartShowDates);
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
tchoice=Param("Title Selection ",2,1,2,1);
PlotCandle = ParamToggle("Plot Nifty Candle", "No,Yes", 0);
_SECTION_END();

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

_SECTION_BEGIN("Index_Compare");
IndexName = ParamList("IndexName ","^NSEI|^NSEBANK|^CNXIT|",0);
PlotForeign(IndexName,_DEFAULT_NAME(),colorBrightGreen , styleNoTitle | styleOwnScale | styleLine | styleThick );
_SECTION_END();

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

_SECTION_END();

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

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

x0 = Min(xSp0,xRp0)-Back;
x1 = (BarCount -1);
//////////////////////////////////////////////////////////////////
r236 = fib(0.236); r236I = LastValue (r236,1);
r382 = fib(0.382); r382I = LastValue (r382,1);
r050 = fib(0.50); r050I = LastValue (r050,1);
r618 = fib(0.618); r618I = LastValue (r618,1);
r786 = fib(0.786); r786I = LastValue (r786,1);
e127 = fib(1.27); e127I = LastValue (e127,1);
e162 = fib(1.62); e162I = LastValue (e162,1);
e200 = fib(2.00); e200I = LastValue (e200,1);
e262 = fib(2.62); e262I = LastValue (e262,1);
e424 = fib(4.24); e424I = LastValue (e424,1);
//////////////////////////////////////////////////////////////////
p00 = IIf(xSp0 > xRp0,ySp0,yRp0); p00I = LastValue (p00,1);
p100 = IIf(xSp0 < xRp0,ySp0,yRp0); p100I = LastValue (p100,1);
color00 =IIf(xSp0 > xRp0,colorLime,colorRed);
color100 =IIf(xSp0 < xRp0,colorLime,colorRed);
//////////////////////////////////////////////////////////////////
numbars = LastValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
//////////////////////////////////////////////////////////////////
if(fibs==1) {
Plot(LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back),"PR",32,styleThick | styleNoRescale | styleNoLabel | styleNoTitle,Null, Null,Fwd);
Plot(LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back),"PS",27, styleThick | styleNoRescale | styleNoLabel | styleNoTitle,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r236,x1,r236,Back),"",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r382,x1,r382,Back),"",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r050,x1,r050,Back),"",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r618,x1,r618,Back),"",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r786,x1,r786,Back),"",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e127,x1,e127,Back),"e127",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e162,x1,e162,Back),"e162",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e200,x1,e200,Back),"p200",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e262,x1,e262,Back),"p262",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e424,x1,e424,Back),"p424",colorBlack,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);

}
//////////////////////////////////////////////////////////////////
if(text==1) {
PlotText(" 0% = " + WriteVal(p00,fraction), LastValue(BarIndex())-(numbars/hts), p00I + 0.05, color00);
PlotText("23% = " + WriteVal(r236,fraction), LastValue(BarIndex())-(numbars/hts), r236I + 0.05, colorBlack);
PlotText("38% = " + WriteVal(r382,fraction), LastValue(BarIndex())-(numbars/hts), r382I + 0.05, colorBlack);
PlotText("50% = " + WriteVal(r050,fraction), LastValue(BarIndex())-(numbars/hts), r050I + 0.05, colorBlack);
PlotText("62% = " + WriteVal(r618,fraction), LastValue(BarIndex())-(numbars/hts), r618I + 0.05, colorBlack);
PlotText("78% = " + WriteVal(r786,fraction), LastValue(BarIndex())-(numbars/hts), r786I + 0.05, colorBlack);
PlotText("100% = " + WriteVal(p100,fraction), LastValue(BarIndex())-(numbars/hts),p100I + 0.05, color100);
PlotText("127% = " + WriteVal(e127,fraction), LastValue(BarIndex())-(numbars/hts),e127I + 0.05, colorBlack);
PlotText("162% = " + WriteVal(e162,fraction), LastValue(BarIndex())-(numbars/hts),e162I + 0.05, colorBlack);
PlotText("200% = " + WriteVal(e200,fraction), LastValue(BarIndex())-(numbars/hts),e200I + 0.05, colorBlack);
PlotText("262% = " + WriteVal(e262,fraction), LastValue(BarIndex())-(numbars/hts),e262I + 0.05, colorBlack);
PlotText("424% = " + WriteVal(e424,fraction), LastValue(BarIndex())-(numbars/hts),e424I + 0.05, colorBlack);
}
_SECTION_END();

_SECTION_BEGIN("Pivot");

YH = TimeFrameGetPrice("H", inDaily, -1); // yesterdays high
YL = TimeFrameGetPrice("L", inDaily, -1); // low
YC = TimeFrameGetPrice("C", inDaily, -1); // close
YO = TimeFrameGetPrice("O", inDaily); // current day open

//Normal Pivot
PP = (YH + YL + YC) / 3;
R1 = (2 * PP) - YL;
R2 = PP + (YH - YL);
R3 = YH + 2*(PP-YL);
S1 = (2 * PP) - YH;
S2 = PP - (YH - YL);
S3 = YL - 2*(YH - PP) ;

_SECTION_END();

_SECTION_BEGIN("TITLE");

//////////////////////////////////////////////////////////////////
if (tchoice==1 ) {
_N(Title = EncodeColor(colorWhite)+StrFormat(" {{NAME}} - {{INTERVAL}} {{DATE}} Open: %g, High: %g, Low: %g, Close: %g {{VALUES}}",O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
}
//////////////////////////////////////////////////////////////////WriteVal(HC ,fraction)

if (tchoice==2 ) {
Title = EncodeColor(colorBlack)+ Date() + " Close = " + EncodeColor(colorRed) +Close +
EncodeColor(colorBlack) + " Open = " + EncodeColor(colorBlack) + O +
EncodeColor(colorBlack) + " High = " + EncodeColor(5) + H +
EncodeColor(colorBlack) + " Low = " + EncodeColor(colorRed) + L +
EncodeColor(colorBlack) + " Volume = " + EncodeColor(colorBlack) + V + "\n\n"+
EncodeColor(colorBlack) + "Pivot Point= " + EncodeColor(colorBlack) + PP +
EncodeColor(colorBlack) + " Day's Open= " + EncodeColor(colorBlack) + YO +
EncodeColor(colorBlack) + " Nifty = " + EncodeColor(colorBlack) + Foreign("^NSEI","C") +"\n\n"+
EncodeColor(colorRed) + "R1= " + EncodeColor(colorBlack) + R1 +
EncodeColor(colorRed) + " R2= " + EncodeColor(colorBlack) + R2 +
EncodeColor(colorRed) + " R3= " + EncodeColor(colorBlack) + R3 +"\n"+
EncodeColor(colorGreen) + "S1= " + EncodeColor(colorBlack) + S1 +
EncodeColor(colorGreen) + " S2= " + EncodeColor(colorBlack) + S2 +
EncodeColor(colorGreen) + " S3= " + EncodeColor(colorBlack) + S3 +"\n"+
EncodeColor( colorBlack) +"_______________"+"\n"+
EncodeColor( colorBlack) + "424% = " + EncodeColor(25)+ e424 + " " +"\n"+
EncodeColor( colorBlack) + "262% = " + EncodeColor(47)+ e262 + " " +"\n"+
EncodeColor( colorBlack) + "200% = " + EncodeColor(47)+ e200 + " " +"\n"+
EncodeColor( colorBlack) + "162% = " + EncodeColor(47)+ e162 + " " +"\n"+
EncodeColor( colorBlack) + "127% = " + EncodeColor(47)+ e127 + " " +"\n"+
EncodeColor( colorRed) + "Res = " + EncodeColor(32)+ p100 + " "+"\n"+
EncodeColor( colorBlack) + "78% = " + EncodeColor(42)+ r786 + " " +"\n"+
EncodeColor( colorBlack) + "62% = " + EncodeColor(43)+ r618 + " "+"\n"+
EncodeColor( colorBlack) + "50% = " + EncodeColor(41)+ r050 + " "+"\n"+
EncodeColor( colorBlack) + "38% = " + EncodeColor(44)+ r382 + " "+"\n"+
EncodeColor( colorBlack) + "23% = " + EncodeColor(45)+ r236+ " " +"\n"+
EncodeColor( colorGreen) + "Sup = " + EncodeColor(34)+ p00 + " " ;

}

_SECTION_END();

_SECTION_BEGIN("Up Trend Line");
UTValue1=LastValue(Trough(L,1,2));
UTValue2=ySp0;
UTBar1=BarCount - 1 - LastValue(TroughBars(L,1,2));
price_utbar1=Close[UTBar1];
UTBar2=xSp0;
price_utbar2=Close[UTBar2];
UpTrendLine = LineArray( UTBar1, UTValue1, UTBar2,UTValue2, 1 );
UTLine = LineArray( UTBar1, UTValue1, UTBar2,UTValue2, 0 );
Plot( UpTrendLine , _DEFAULT_NAME(), colorGreen,styleDots | styleNoTitle | styleNoLabel);

Plot( UTLine , _DEFAULT_NAME(), colorGreen,styleDots | styleNoTitle | styleNoLabel);
_SECTION_END();


_SECTION_BEGIN("Down Trend Line");
DTValue1=LastValue(Peak(H,1,2));
DTValue2=yRp0;
DTBar1=BarCount - 1 - LastValue(PeakBars(H,1,2));
price_dtbar1=Close[DTBar1];
DTBar2=xRp0;
price_dtbar2=Close[DTBar2];
DownTrendLine = LineArray( DTBar1, DTValue1, DTBar2,DTValue2, 1 );
DTLine = LineArray( DTBar1, DTValue1, DTBar2,DTValue2, 0 );

Plot( DownTrendLine ,_DEFAULT_NAME(), colorRed,styleDots | styleNoTitle | styleNoLabel);
Plot( DTLine ,_DEFAULT_NAME(), colorRed,styleDots | styleNoTitle | styleNoLabel);

PlotOHLC( DownTrendLine , DownTrendLine , UpTrendLine , UpTrendLine , "", colorYellow, styleCloud | styleNoRescale);

DTLine = LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back);
UTLine = LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back);


CBuy = Cross(C,DownTrendLine );
CSell = Cross(UpTrendLine ,C);

baratcbuy = LastValue(ValueWhen(CBuy,BarIndex()));
baratcsell = LastValue(ValueWhen(CSell,BarIndex()));

CBuy = CBuy AND BarIndex() == baratcbuy ;
CSell = CSell AND BarIndex() == baratcsell ;

PlotShapes(shapeUpTriangle* CBuy ,colorBlue,O,L);
PlotShapes(shapeDownTriangle* CSell ,colorRed,O,H);

CBuy1 = Cross(C,DTLine );
CSell1 = Cross(UTLine ,C);

baratcbuy1 = LastValue(ValueWhen(CBuy1,BarIndex()));
baratcsell1 = LastValue(ValueWhen(CSell1,BarIndex()));

CBuy1 = CBuy1 AND BarIndex() == baratcbuy1 ;
CSell1 = CSell1 AND BarIndex() == baratcsell1 ;

PlotShapes(shapeHollowUpTriangle* CBuy1 ,colorBlue,O,L-1);
PlotShapes(shapeHollowDownTriangle* CSell1 ,colorRed,O,H-1);

_SECTION_END();


_SECTION_BEGIN("Auto");

ScanLookBack = Param("Scan Lookback", 1, 1, 25 );
Buy = ( CBuy OR CBuy1) AND ( (BarCount - baratcBuy )<=ScanLookBack OR (BarCount - baratcbuy1 )<=ScanLookBack);
Sell = ( CSell OR CSell1) AND ( (BarCount - baratcsell )<=ScanLookBack OR (BarCount - baratcsell1 )<=ScanLookBack ) ;

price = C[BarCount-1];

AlertIf(Buy,"","Buy @"+C+" Price @ Trigger="+price,1);
AlertIf(Sell,"","Sell @"+C+" Price @ Trigger="+price,2);

Filter = Buy OR Sell ;

Var = WriteIf(Buy,"BUY",WriteIf(Sell,"SELL",""));

AddTextColumn( Var , "Buy/Sell", 1.2 , colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));
AddColumn(price ,"Price",1.2,colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));
AddColumn(C ,"Price @ Trigger",1.2,colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));

stoploss = IIf(Buy, (price * (1-0.01)) , IIf(Sell, (price * (1+0.01)),0));
target1per = IIf(Buy, (price * (1+0.01)) , IIf(Sell, (price * (1-0.01)),0));
target15per = IIf(Buy, (price * (1+0.015)) , IIf(Sell, (price * (1-0.015)),0));
target2per = IIf(Buy, (price * (1+0.02)) , IIf(Sell, (price * (1-0.02)),0));

AddColumn(stoploss ,"Stop Loss",1.2,colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));
AddColumn(target1per ,"1% Target",1.2,colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));
AddColumn(target15per ,"1.5% Target",1.2,colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));
AddColumn(target2per ,"2% Target",1.2,colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));
AddColumn(V ,"Volume",1.2,colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));

_SECTION_END();

GraphXSpace = 10 ;
 

rajsumi121

Well-Known Member
#3
STOCHASTIC CROSSOVER BUY/SELL



_SECTION_BEGIN("PPO");
PPOShort = Param("PPO Short Period", 12, 1, 150, 1);
PPOLong = Param("PPO Long Period", 26, 1, 150, 1);
PPOsignal = Param("PPOsignal", 9, 1, 150, 1);
PPO = (EMA(C, PPOShort ) - EMA(C, PPOLong ))/ EMA(C, PPOLong );
PPOS = (EMA(ppo, PPOsignal ));
Val=ppo-PPOS ;
Plot( PPO , "ppo", colorGreen, styleLine| styleThick );
Plot ( PPOS ,"PPO Signal", colorOrange, styleLine| styleThick );
dynamic_color = IIf( Val> 0, colorGreen, colorRed );
Plot( Val, "PPO Histogram", dynamic_color, styleHistogram | styleThick );

Buy= Cross( ppo,ppos);
Sell= Cross( ppos, ppo);
PlotShapes(shapeUpArrow * Buy,colorGreen);
PlotShapes(shapeDownArrow * Sell,colorRed);
AlertIf( Buy , "SOUND C:\\Windows\\Media\\Ding.wav", "Audio alert", 2 );
AlertIf(Sell , "SOUND C:\\Windows\\Media\\Ding.wav", "Audio alert", 2 );









_SECTION_END();
 

rajsumi121

Well-Known Member
#4
SINGLE MOVING AVERAGE SYSTEM



_SECTION_BEGIN("MTF 60MA");
SetChartOptions(0,chartShowArrows|chartShowDates);
///////////////////////////////////////////////////////////////////////////////
SetChartBkColor(ParamColor("Outer panel color ",colorPaleBlue)); // color of outer border
SetChartBkGradientFill( ParamColor("Inner panel color upper half", colorAqua),ParamColor("Inner panel color lower half", colorPaleBlue)); // color of inner panel

SetChartOptions(0,chartShowArrows|chartShowDates);
// _N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );


//////////////// MA in different Time Frame ////////
MA60 = MA(C,60);


Plot(MA60,"MA60",colorBlack,styleLine|styleThick);


TimeFrameSet(in15Minute);
MA60_15Min=MA(Close,60);
// Col = IIf(MA60_15Min > Ref(MA60_15Min,-1), colorWhite,colorRed);
TimeFrameRestore();

Col15 = IIf(TimeFrameExpand(MA60_15Min,in15Minute) > TimeFrameExpand(Ref(MA60_15Min,-1),in15Minute), colorWhite,colorRed);

Plot(TimeFrameExpand(MA60_15Min,in15Minute), "MA15Mts",col15);

TimeFrameSet(inHourly);
MA60_60Min=MA(Close,60);
TimeFrameRestore();

Col60 = IIf(TimeFrameExpand(MA60_60Min,inHourly) > TimeFrameExpand(Ref(MA60_60Min,-1),inHourly), colorBlue,colorViolet);

Plot(TimeFrameExpand(MA60_60Min,inHourly), "MA60Mts",col60); // colorblue);

TimeFrameSet(4 * inHourly);
MA60_240Min=MA(Close,60);
TimeFrameRestore();

// Col240 = IIf(TimeFrameExpand(MA60_240Min,4 * inHourly) > TimeFrameExpand(Ref(MA60_240Min,-1),4 * inHourly), colorBrightGreen,colorLightGrey);

Plot(TimeFrameExpand(MA60_240Min,4 * inHourly), "MA240Mts",colorWhite);

///////////// Title //////////////////
Change=C-Ref(C,-1);
ROCVal = ROC(C,1);
Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}}" + " O: " + O + ", H:" + H + ", L:" +L+ ", C:"+ C
+" ("+NumToStr(Change,1.2)+" )" +" ("+NumToStr(ROCVal,1.2)+" %%)");
///////////// Title Over //////////////////


_SECTION_END();
 

rajsumi121

Well-Known Member
#5
CANDLESTICK SYSTEM WITH COMMENTARY



SetChartOptions(0,chartShowArrows|chartShowDates);

/*Body Colors*/
whiteBody=C>=O;
blackBody=O>C;

/*Body Size*/
smallBodyMaximum=0.0025;//less than 0.25%
LargeBodyMinimum=0.01;//greater than 1.0%
smallBody=(O>=C*(1-smallBodyMaximum) AND whiteBody) OR (C>=O*(1-smallBodyMaximum) AND blackBody);
largeBody=(C>=O*(1+largeBodyMinimum) AND whiteBody) OR C<=O*(1-largeBodyMinimum) AND blackBody;
mediumBody=NOT LargeBody AND NOT smallBody;
identicalBodies=abs(abs(Ref(O,-1)-Ref(C,-1))-abs(O-C)) < abs(O-C)*smallBodyMaximum;
realBodySize=abs(O-C);


/*Shadows*/
smallUpperShadow=(whiteBody AND H<=C*(1+smallBodyMaximum)) OR (blackBody AND H<=O*(1+smallBodyMaximum));
smallLowerShadow=(whiteBody AND L>=O*(1-smallBodyMaximum)) OR (blackBody AND L>=C*(1-smallBodyMaximum));
largeUpperShadow=(whiteBody AND H>=C*(1+largeBodyMinimum)) OR (blackBody AND H>=O*(1+largeBodyMinimum));
largeLowerShadow=(whiteBody AND L<=O*(1-largeBodyMinimum)) OR (blackBody AND L<=C*(1-largeBodyMinimum));

/*Gaps*/
upGap= IIf(Ref(blackBody,-1)AND whiteBody AND O>Ref(O,-1),1,
IIf(Ref(blackbody,-1) AND blackBody AND C>Ref(O,-1),1,
IIf(Ref(whiteBody,-1) AND whiteBody AND O>Ref(C,-1),1,
IIf(Ref(whiteBody,-1) AND blackBody AND C>Ref(C,-1),1,0))));

downGap=IIf(Ref(blackBody,-1)AND whiteBody AND C<Ref(C,-1),1,
IIf(Ref(blackbody,-1) AND blackBody AND O<Ref(C,-1),1,
IIf(Ref(whiteBody,-1) AND whiteBody AND C<Ref(O,-1),1,
IIf(Ref(whiteBody,-1) AND blackBody AND O<Ref(O,-1),1,0))));

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

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

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

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

/*DOJI definitions*/

/*Doji Today - (DT)*/
DT = abs(C-O) <= (C*smallBodyMaximum) OR (abs(O-C)<=((H-L)*0.1));

/* Doji Yesterday - (DY)*/
DY = abs(Ref ( C, -1)-Ref(O,-1)) <= Ref ( C, -1) *smallBodyMaximum OR abs (Ref ( O, -1)-Ref(C,-1)) <= (Ref ( H, -1 ) - Ref ( L, -1 ) )*0.1;


O1 = Ref(O,-1);O2 = Ref(O,-2);
H1 = Ref(H,-1);H2 = Ref(H,-2);
L1 = Ref(L,-1);L2 = Ref(L,-2);
C1 = Ref(C,-1);C2 = Ref(C,-2);
NearDoji = (abs(O-C)<= ((H-L)*0.1));
BlackCandle = (O>C);
LongBlackCandle = (O>C AND (O-C)/(0.001+H-L)>0.6);
SmallBlackCandle = ((O>C) AND ((H-L)>(3*(O-C))));
WhiteCandle = (C>O);
LongWhiteCandle = ((C>O) AND ((C-O)/(0.001+H-L)>0.6));
SmallWhiteCandle = ((C>O) AND ((H-L)>(3*(C-O))));
BlackMaubozu = (O>C AND H==O AND C==L);
WhiteMaubozu = (C>O AND H==C AND O==L);
BlackClosingMarubozu = (O>C AND C==L);
WhiteClosingMarubozu = (C>O AND C==H);
BlackOpeningMarubozu = (O>C AND O==H);
WhiteOpeningMarubozu = (C>O AND O==L);
HangingMan = (((H-L)>4*(O-C)) AND ((C-L)/(0.001+H-L)>= 0.75) AND ((O-L)/(0.001+H-L)>= 0.75));
Hammer = (((H-L)>3*(O-C)) AND ((C-L)/(0.001+H-L)>0.6) AND ((O-L)/(0.001+H-L)>0.6));
InvertedHammer = (((H-L)>3*(O-C)) AND ((H-C)/(0.001+H-L)>0.6) AND ((H-O)/(0.001+H-L)>0.6));
ShootingStar = (((H-L)>4*(O-C)) AND ((H-C)/(0.001+H-L)>= 0.75) AND ((H-O)/(0.001+H-L)>= 0.75));
BlackSpinningTop = ((O>C) AND ((H-L)>(3*(O-C))) AND (((H-O)/(0.001+H-L))<0.4) AND (((C-L)/(0.001+H-L))<0.4));
WhiteSpinningTop = ((C>O) AND ((H-L)>(3*(C-O))) AND (((H-C)/(0.001+H-L))<0.4) AND (((O-L)/(0.001+H-L))<0.4));
BearishAbandonedBaby = ((C1 == O1) AND (C2>O2) AND (O>C) AND (L1>H2) AND (L1>H));
BearishEveningDojiStar = ((C2>O2) AND ((C2-O2)/(0.001+H2-L2)>0.6) AND (C2<O1) AND (C1>O1) AND ((H1-L1)>(3*(C1-O1))) AND (O>C) AND (O<O1));
DarkCloudCover = (C1>O1 AND ((C1+O1)/2)>C AND O>C AND O>C1 AND C>O1 AND (O-C)/(0.001+(H-L)>0.6));
BearishEngulfing = ((C1>O1) AND (O>C) AND (O>= C1) AND (O1>= C) AND ((O-C)>(C1-O1)));
ThreeOutsideDownPattern = ((C2>O2) AND (O1>C1) AND (O1>= C2) AND (O2>= C1) AND ((O1-C1)>(C2-O2)) AND (O>C) AND (C<C1));
BullishAbandonedBaby = ((C1 == O1) AND (O2>C2) AND (C>O) AND (L2>H1) AND (L>H1));
BullishMorningDojiStar = ((O2>C2) AND ((O2-C2)/(0.001+H2-L2)>0.6) AND (C2>O1) AND (O1>C1) AND ((H1-L1)>(3*(C1-O1))) AND (C>O) AND (O>O1));
BullishEngulfing = ((O1>C1) AND (C>O) AND (C>= O1) AND (C1>= O) AND ((C-O)>(O1-C1)));
ThreeOutsideUpPattern = ((O2>C2) AND (C1>O1) AND (C1>= O2) AND (C2>= O1) AND ((C1-O1)>(O2-C2)) AND (C>O) AND (C>C1));
BullishHarami = ((O1>C1) AND (C>O) AND (C<= O1) AND (C1<= O) AND ((C-O)<(O1-C1)));
ThreeInsideUpPattern = ((O2>C2) AND (C1>O1) AND (C1<= O2) AND (C2<= O1) AND ((C1-O1)<(O2-C2)) AND (C>O) AND (C>C1) AND (O>O1));
PiercingLine = ((C1<O1) AND (((O1+C1)/2)<C) AND (O<C) AND (O<C1) AND (C<O1) AND ((C-O)/(0.001+(H-L))>0.6));
BearishHarami = ((C1>O1) AND (O>C) AND (O<= C1) AND (O1<= C) AND ((O-C)<(C1-O1)));
ThreeInsideDownPattern = ((C2>O2) AND (O1>C1) AND (O1<= C2) AND (O2<= C1) AND ((O1-C1)<(C2-O2)) AND (O>C) AND (C<C1) AND (O<O1));
ThreeWhiteSoldiers = (C>O*1.01) AND (C1>O1*1.01) AND (C2>O2*1.01) AND (C>C1) AND (C1>C2) AND (O<C1) AND (O>O1) AND (O1<C2) AND (O1>O2) AND (((H-C)/(H-L))<0.2) AND (((H1-C1)/(H1-L1))<0.2) AND (((H2-C2)/(H2-L2))<0.2);
DarkCloudCover = (C1>O1*1.01) AND (O>C) AND (O>H1) AND (C>O1) AND (((C1+O1)/2)>C) AND (C>O1) AND (MA(C,13)-Ref(MA(C,13),-4)>0);
ThreeBlackCrows = (O>C*1.01) AND (O1>C1*1.01) AND (O2>C2*1.01) AND (C<C1) AND (C1<C2) AND (O>C1) AND (O<O1) AND (O1>C2) AND (O1<O2) AND (((C-L)/(H-L))<0.2) AND (((C1-L1)/(H1-L1))<0.2) AND (((C2-L2)/(H2-L2))<0.2);
eveningStar=Ref(LargeBody,-2) AND Ref(whiteBody,-2) AND Ref(upGap,-1) AND NOT Ref(largeBody,-1) AND blackBody AND NOT smallBody AND (MHT OR MHY);
morningStar =Ref(largeBody,-2) AND Ref(blackBody,-2) AND Ref(downGap,-1) AND whiteBody AND LargeBody AND C>Ref(C,-2) AND MLY;
Doji = (O == C);
MATCHLOW = LLV(Low,8)==LLV(Low,2) AND Ref(Close,-1)<=Ref(Open,-1)*.99 AND abs(Close-Ref(Close,-1))<=Close*.0025 AND Open>Ref(Close,-1) AND Open<=(High-((High-Low)*.5));
GapUpx = GapUp();
GapDownx = GapDown();
BigGapUp = L>1.01*H1;
BigGapDown = H<0.99*L1;
HugeGapUp = L>1.02*H1;
HugeGapDown = H<0.98*L1;
DoubleGapUp = GapUp() AND Ref(GapUp(),-1);
DoubleGapDown = GapDown() AND Ref(GapDown(),-1);

c_Status =
WriteIf(HangingMan, "Hanging Man",
WriteIf(ShootingStar, "Shooting Star",
WriteIf(DarkCloudCover, "Dark Cloud Cover",
WriteIf(BearishEngulfing, "Bearish Engulfing",
WriteIf(BearishHarami, "Bearish Harami",
WriteIf(eveningStar, "Evening Star",
WriteIf(Hammer, "Hammer",
WriteIf(InvertedHammer, "Inverted Hammer",
WriteIf(PiercingLine, "Piercing Line",
WriteIf(BullishEngulfing, "Bullish Engulfing",
WriteIf(BullishHarami, "Bullish Harami",
WriteIf(morningStar, "Morning Star",
WriteIf(NearDoji, "Near Doji",
WriteIf(Doji, "Doji",
WriteIf(MATCHLOW,"MATCHING LOW",
"Zilch" )))))))))))))));
P_status =
WriteIf(GapUpx, "Gap Up",
WriteIf(GapDownx, "Gap Down",
WriteIf(BigGapUp, "Big Gap Up",
WriteIf(BigGapDown, "Big Gap Down",
WriteIf(HugeGapUp, "Huge Gap Up",
WriteIf(HugeGapDown, "Huge Gap Down",
WriteIf(DoubleGapUp, "Double Gap Up",
WriteIf(DoubleGapDown, "DoubleGapDown",
"Zilch" ))))))));
/*Tweezer Top*/
TweezerTop=abs(H-Ref(H,-1))<=H*0.0025 AND O >C AND (Ref(C,-1) > Ref(O,-1))AND (MHT OR MHY);

/*Tweezer Bottom*/
tweezerBottom= (abs(L-Ref(L,-1))/L<0.0025 OR
abs(L-Ref(L,-2))/L<0.0025) AND O < C AND (Ref( O,-1) > Ref(C,-1)) AND (MLT OR MLY);
PATTERN = WriteIf(tweezerTop, "Tweezer Top",
WriteIf(tweezerBottom, "Tweezer Bottom","Zilch" ));

Filter = tweezerTop OR tweezerBottom;
/*Body Colors*/
whiteBody=C>=O;
blackBody=O>C;

/*Body Size*/
smallBodyMaximum=0.0025;//less than 0.25%
LargeBodyMinimum=0.01;//greater than 1.0%
smallBody=(O>=C*(1-smallBodyMaximum) AND whiteBody) OR (C>=O*(1-smallBodyMaximum) AND blackBody);
largeBody=(C>=O*(1+largeBodyMinimum) AND whiteBody) OR C<=O*(1-largeBodyMinimum) AND blackBody;
mediumBody=NOT LargeBody AND NOT smallBody;
identicalBodies=abs(abs(Ref(O,-1)-Ref(C,-1))-abs(O-C)) < abs(O-C)*smallBodyMaximum;
realBodySize=abs(O-C);


/*Shadows*/
smallUpperShadow=(whiteBody AND H<=C*(1+smallBodyMaximum)) OR (blackBody AND H<=O*(1+smallBodyMaximum));
smallLowerShadow=(whiteBody AND L>=O*(1-smallBodyMaximum)) OR (blackBody AND L>=C*(1-smallBodyMaximum));
largeUpperShadow=(whiteBody AND H>=C*(1+largeBodyMinimum)) OR (blackBody AND H>=O*(1+largeBodyMinimum));
largeLowerShadow=(whiteBody AND L<=O*(1-largeBodyMinimum)) OR (blackBody AND L<=C*(1-largeBodyMinimum));

/*Gaps*/
upGap= IIf(Ref(blackBody,-1)AND whiteBody AND O>Ref(O,-1),1,
IIf(Ref(blackbody,-1) AND blackBody AND C>Ref(O,-1),1,
IIf(Ref(whiteBody,-1) AND whiteBody AND O>Ref(C,-1),1,
IIf(Ref(whiteBody,-1) AND blackBody AND C>Ref(C,-1),1,0))));

downGap=IIf(Ref(blackBody,-1)AND whiteBody AND C<Ref(C,-1),1,
IIf(Ref(blackbody,-1) AND blackBody AND O<Ref(C,-1),1,
IIf(Ref(whiteBody,-1) AND whiteBody AND C<Ref(O,-1),1,
IIf(Ref(whiteBody,-1) AND blackBody AND O<Ref(O,-1),1,0))));

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

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

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

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

/*DOJI definitions*/

/*Doji Today - (DT)*/
DT = abs(C-O) <= (C*smallBodyMaximum) OR (abs(O-C)<=((H-L)*0.1));

/* Doji Yesterday - (DY)*/
DY = abs(Ref ( C, -1)-Ref(O,-1)) <= Ref ( C, -1) *smallBodyMaximum OR abs (Ref ( O, -1)-Ref(C,-1)) <= (Ref ( H, -1 ) - Ref ( L, -1 ) )*0.1;


O1 = Ref(O,-1);O2 = Ref(O,-2);
H1 = Ref(H,-1);H2 = Ref(H,-2);
L1 = Ref(L,-1);L2 = Ref(L,-2);
C1 = Ref(C,-1);C2 = Ref(C,-2);
NearDoji = (abs(O-C)<= ((H-L)*0.1));
BlackCandle = (O>C);
LongBlackCandle = (O>C AND (O-C)/(0.001+H-L)>0.6);
SmallBlackCandle = ((O>C) AND ((H-L)>(3*(O-C))));
WhiteCandle = (C>O);
LongWhiteCandle = ((C>O) AND ((C-O)/(0.001+H-L)>0.6));
SmallWhiteCandle = ((C>O) AND ((H-L)>(3*(C-O))));
BlackMaubozu = (O>C AND H==O AND C==L);
WhiteMaubozu = (C>O AND H==C AND O==L);
BlackClosingMarubozu = (O>C AND C==L);
WhiteClosingMarubozu = (C>O AND C==H);
BlackOpeningMarubozu = (O>C AND O==H);
WhiteOpeningMarubozu = (C>O AND O==L);
HangingMan = (((H-L)>4*(O-C)) AND ((C-L)/(0.001+H-L)>= 0.75) AND ((O-L)/(0.001+H-L)>= 0.75));
Hammer = (((H-L)>3*(O-C)) AND ((C-L)/(0.001+H-L)>0.6) AND ((O-L)/(0.001+H-L)>0.6));
InvertedHammer = (((H-L)>3*(O-C)) AND ((H-C)/(0.001+H-L)>0.6) AND ((H-O)/(0.001+H-L)>0.6));
ShootingStar = (((H-L)>4*(O-C)) AND ((H-C)/(0.001+H-L)>= 0.75) AND ((H-O)/(0.001+H-L)>= 0.75));
BlackSpinningTop = ((O>C) AND ((H-L)>(3*(O-C))) AND (((H-O)/(0.001+H-L))<0.4) AND (((C-L)/(0.001+H-L))<0.4));
WhiteSpinningTop = ((C>O) AND ((H-L)>(3*(C-O))) AND (((H-C)/(0.001+H-L))<0.4) AND (((O-L)/(0.001+H-L))<0.4));
BearishAbandonedBaby = ((C1 == O1) AND (C2>O2) AND (O>C) AND (L1>H2) AND (L1>H));
BearishEveningDojiStar = ((C2>O2) AND ((C2-O2)/(0.001+H2-L2)>0.6) AND (C2<O1) AND (C1>O1) AND ((H1-L1)>(3*(C1-O1))) AND (O>C) AND (O<O1));
DarkCloudCover = (C1>O1 AND ((C1+O1)/2)>C AND O>C AND O>C1 AND C>O1 AND (O-C)/(0.001+(H-L)>0.6));
BearishEngulfing = ((C1>O1) AND (O>C) AND (O>= C1) AND (O1>= C) AND ((O-C)>(C1-O1)));
ThreeOutsideDownPattern = ((C2>O2) AND (O1>C1) AND (O1>= C2) AND (O2>= C1) AND ((O1-C1)>(C2-O2)) AND (O>C) AND (C<C1));
BullishAbandonedBaby = ((C1 == O1) AND (O2>C2) AND (C>O) AND (L2>H1) AND (L>H1));
BullishMorningDojiStar = ((O2>C2) AND ((O2-C2)/(0.001+H2-L2)>0.6) AND (C2>O1) AND (O1>C1) AND ((H1-L1)>(3*(C1-O1))) AND (C>O) AND (O>O1));
BullishEngulfing = ((O1>C1) AND (C>O) AND (C>= O1) AND (C1>= O) AND ((C-O)>(O1-C1)));
ThreeOutsideUpPattern = ((O2>C2) AND (C1>O1) AND (C1>= O2) AND (C2>= O1) AND ((C1-O1)>(O2-C2)) AND (C>O) AND (C>C1));
BullishHarami = ((O1>C1) AND (C>O) AND (C<= O1) AND (C1<= O) AND ((C-O)<(O1-C1)));
ThreeInsideUpPattern = ((O2>C2) AND (C1>O1) AND (C1<= O2) AND (C2<= O1) AND ((C1-O1)<(O2-C2)) AND (C>O) AND (C>C1) AND (O>O1));
PiercingLine = ((C1<O1) AND (((O1+C1)/2)<C) AND (O<C) AND (O<C1) AND (C<O1) AND ((C-O)/(0.001+(H-L))>0.6));
BearishHarami = ((C1>O1) AND (O>C) AND (O<= C1) AND (O1<= C) AND ((O-C)<(C1-O1)));
ThreeInsideDownPattern = ((C2>O2) AND (O1>C1) AND (O1<= C2) AND (O2<= C1) AND ((O1-C1)<(C2-O2)) AND (O>C) AND (C<C1) AND (O<O1));
ThreeWhiteSoldiers = (C>O*1.01) AND (C1>O1*1.01) AND (C2>O2*1.01) AND (C>C1) AND (C1>C2) AND (O<C1) AND (O>O1) AND (O1<C2) AND (O1>O2) AND (((H-C)/(H-L))<0.2) AND (((H1-C1)/(H1-L1))<0.2) AND (((H2-C2)/(H2-L2))<0.2);
DarkCloudCover = (C1>O1*1.01) AND (O>C) AND (O>H1) AND (C>O1) AND (((C1+O1)/2)>C) AND (C>O1) AND (MA(C,13)-Ref(MA(C,13),-4)>0);
ThreeBlackCrows = (O>C*1.01) AND (O1>C1*1.01) AND (O2>C2*1.01) AND (C<C1) AND (C1<C2) AND (O>C1) AND (O<O1) AND (O1>C2) AND (O1<O2) AND (((C-L)/(H-L))<0.2) AND (((C1-L1)/(H1-L1))<0.2) AND (((C2-L2)/(H2-L2))<0.2);
eveningStar=Ref(LargeBody,-2) AND Ref(whiteBody,-2) AND Ref(upGap,-1) AND NOT Ref(largeBody,-1) AND blackBody AND NOT smallBody AND (MHT OR MHY);
morningStar =Ref(largeBody,-2) AND Ref(blackBody,-2) AND Ref(downGap,-1) AND whiteBody AND LargeBody AND C>Ref(C,-2) AND MLY;
Doji = (O == C);
MATCHLOW = LLV(Low,8)==LLV(Low,2) AND Ref(Close,-1)<=Ref(Open,-1)*.99 AND abs(Close-Ref(Close,-1))<=Close*.0025 AND Open>Ref(Close,-1) AND Open<=(High-((High-Low)*.5));
GapUpx = GapUp();
GapDownx = GapDown();
BigGapUp = L>1.01*H1;
BigGapDown = H<0.99*L1;
HugeGapUp = L>1.02*H1;
HugeGapDown = H<0.98*L1;
DoubleGapUp = GapUp() AND Ref(GapUp(),-1);
DoubleGapDown = GapDown() AND Ref(GapDown(),-1);

c_Status =
WriteIf(HangingMan, "Hanging Man",
WriteIf(ShootingStar, "Shooting Star",
WriteIf(DarkCloudCover, "Dark Cloud Cover",
WriteIf(BearishEngulfing, "Bearish Engulfing",
WriteIf(BearishHarami, "Bearish Harami",
WriteIf(eveningStar, "Evening Star",
WriteIf(Hammer, "Hammer",
WriteIf(InvertedHammer, "Inverted Hammer",
WriteIf(PiercingLine, "Piercing Line",
WriteIf(BullishEngulfing, "Bullish Engulfing",
WriteIf(BullishHarami, "Bullish Harami",
WriteIf(morningStar, "Morning Star",
WriteIf(NearDoji, "Near Doji",
WriteIf(Doji, "Doji",
WriteIf(MATCHLOW,"MATCHING LOW",
"Zilch" )))))))))))))));
P_status =
WriteIf(GapUpx, "Gap Up",
WriteIf(GapDownx, "Gap Down",
WriteIf(BigGapUp, "Big Gap Up",
WriteIf(BigGapDown, "Big Gap Down",
WriteIf(HugeGapUp, "Huge Gap Up",
WriteIf(HugeGapDown, "Huge Gap Down",
WriteIf(DoubleGapUp, "Double Gap Up",
WriteIf(DoubleGapDown, "DoubleGapDown",
"Zilch" ))))))));
/*Tweezer Top*/
TweezerTop=abs(H-Ref(H,-1))<=H*0.0025 AND O >C AND (Ref(C,-1) > Ref(O,-1));

/*Tweezer Bottom*/
tweezerBottom= (abs(L-Ref(L,-1))/L<0.0025 OR
abs(L-Ref(L,-2))/L<0.0025) AND O < C AND (Ref( O,-1) > Ref(C,-1));
PATTERN = WriteIf(tweezerTop, "Tweezer Top",
WriteIf(tweezerBottom, "Tweezer Bottom","Zilch" ));

Filter = tweezerTop OR tweezerBottom;
//AddTextColumn(PATTERN, "Tweezer Pattern", 5.6, colorWhite, IIf(TweezerTop, colorRed,
//IIf(TweezerBottom, colorGreen, colorLightGrey)));

//AddTextColumn(C_Status, "Candle Pattern", 5.6, colorWhite, IIf(HangingMan OR ShootingStar OR DarkCloudCover OR BearishEngulfing OR BearishHarami OR eveningStar, colorRed,
//IIf(Hammer OR InvertedHammer OR PiercingLine OR BullishEngulfing OR BullishHarami OR morningStar OR MATCHLOW, colorGreen, IIf( NearDoji OR Doji, colorBlue, colorLightGrey))));
AddTextColumn(P_Status, "Price Pattern", 5.6, colorWhite, IIf(GapDownx OR BigGapDown OR HugeGapDown OR DoubleGapDown, colorRed,
IIf(GapUpx OR BigGapUp OR HugeGapUp OR DoubleGapUp, colorGreen, colorLightGrey)));
AddTextColumn(PATTERN + " And " + C_Status, "Tweezer Pattern" , 5.6, colorWhite, IIf(TweezerTop, colorRed,
IIf(TweezerBottom, colorGreen, colorLightGrey)));
AddColumn(C," CURRENT PRICE",1.2, IIf(C >Ref(C,-1),colorGreen,colorRed));
AddColumn(V," VOL TODAY ",1.2, IIf(V > MA(V,20),colorGreen, colorLightGrey));
/************************************************** *****
Candlestick Commentary
Load this file into the Commentary Option of the Analysis tab. Green arrows indicate bullish candles.
Red arrows indicate bearish candles. Scroll down the commentary for comments.
This is a work in progress. Thanks to all on this forum whose code I may have incorporated into this file. Comments are from Steve Nison "Japanese Candlestick Charting Techniques" and the LitWick web site.
************************************************** ********/

/*Body Colors*/
whiteBody=C>=O;
blackBody=O>C;

/*Body Size*/
smallBodyMaximum=0.0025;//less than 0.25%
LargeBodyMinimum=0.01;//greater than 1.0%
smallBody=(O>=C*(1-smallBodyMaximum) AND whiteBody)
OR (C>=O*(1-smallBodyMaximum) AND blackBody);
largeBody=(C>=O*(1+largeBodyMinimum) AND whiteBody)
OR C<=O*(1-largeBodyMinimum) AND blackBody;
mediumBody=NOT LargeBody AND NOT smallBody;
identicalBodies=abs(abs(Ref(O,-1)-Ref(C,-1))-abs(O-C)) <
abs(O-C)*smallBodyMaximum;
realBodySize=abs(O-C);


/*Shadows*/
smallUpperShadow=(whiteBody AND H<=C*(1+smallBodyMaximum))
OR (blackBody AND H<=O*(1+smallBodyMaximum));
smallLowerShadow=(whiteBody AND L>=O*(1-smallBodyMaximum))
OR (blackBody AND L>=C*(1-smallBodyMaximum));
largeUpperShadow=(whiteBody AND H>=C*(1+largeBodyMinimum))
OR (blackBody AND H>=O*(1+largeBodyMinimum));
largeLowerShadow=(whiteBody AND L<=O*(1-largeBodyMinimum))
OR (blackBody AND L<=C*(1-largeBodyMinimum));

/*Gaps*/
upGap= IIf(Ref(blackBody,-1)AND whiteBody AND O>Ref(O,-1),1,
IIf(Ref(blackbody,-1) AND blackBody AND C>Ref(O,-1),1,
IIf(Ref(whiteBody,-1) AND whiteBody AND O>Ref(C,-1),1,
IIf(Ref(whiteBody,-1) AND blackBody AND C>Ref(C,-1),1,0))));

downGap=IIf(Ref(blackBody,-1)AND whiteBody AND C<Ref(C,-1),1,
IIf(Ref(blackbody,-1) AND blackBody AND O<Ref(C,-1),1,
IIf(Ref(whiteBody,-1) AND whiteBody AND C<Ref(O,-1),1,
IIf(Ref(whiteBody,-1) AND blackBody AND O<Ref(O,-1),1,0))));


/*Candle Definitions*/
spinningTop=mediumBody;
doji=CdDoji(threshold=0.05);/*abs(C-O) <= (C*smallBodyMaximum) OR
(abs(O-C)<=((H-L)*0.1));*/
dojiStar=doji AND (upgap OR downgap)AND Ref(LargeBody,-1);
marabuzu=LargeBody AND smallUpperShadow AND smallLowerShadow;

shootingStar=/*(NOT largeBody AND smallLowerShadow AND LargeUpperShadow) OR*/
smallLowerShadow AND NOT doji AND
((blackBody AND abs(O-H)>2*realBodySize) OR
(whiteBody AND abs(H-C)>2*realBodySize));

Hammer=smallUpperShadow AND NOT doji AND
((blackBody AND abs(C-L)>2*realBodySize) OR
(whiteBody AND abs(L-O)>2*realBodySize));

tweezerTop=abs(H-Ref(H,-1))<=H*0.0025;
tweezerBottom=abs(L-Ref(L,-1))<=L*0.0025;
engulfing=
IIf(blackBody AND Ref(blackbody,-1) AND C<Ref(C,-1) AND O>Ref(O,-1),1,
IIf(blackBody AND Ref(whiteBody,-1) AND O>Ref(C,-1) AND C<Ref(O,-1),1,
IIf(whitebody AND Ref(whitebody,-1) AND C>Ref(C,-1) AND O<Ref(O,-1),1,
IIf(whiteBody AND Ref(blackBody,-1) AND C>Ref(O,-1)AND O<Ref(C,-1),1,0))));
Harami=
IIf(blackbody AND Ref(blackBody,-1) AND O<Ref(O,-1) AND C>Ref(C,-1),1,
IIf(blackBody AND Ref(whiteBody,-1) AND C>Ref(O,-1) AND O<Ref(C,-1),1,
IIf(whiteBody AND Ref(whiteBody,-1) AND C<Ref(C,-1) AND O>Ref(O,-1),1,
IIf(whiteBody AND Ref(blackBody,-1) AND O>Ref(C,-1) AND C<Ref(O,-1),1,0))));


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

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

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

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

/*DOJI definitions*/

/*Doji Today - (DT)*/
DT = abs(C-O) <= (C*smallBodyMaximum) OR
(abs(O-C)<=((H-L)*0.1));

/* Doji Yesterday - (DY)*/
DY = abs(Ref ( C, -1)-Ref(O,-1)) <= Ref ( C, -1) *smallBodyMaximum OR
abs (Ref ( O, -1)-Ref(C,-1)) <= (Ref ( H, -1 ) - Ref ( L, -1 ) )*0.1;

/**************************************************
BULLISH CANDLESTICKS
************************************************** * */

/* Abandoned Baby Bullish*/
abandonedBabybullish =Ref(largeBody,-2) AND Ref(blackBody,-2)//Large black candle
AND Ref(GapDown(),-1)
AND whiteBody AND LargeBody AND GapUp();//Large white candle

/* Belt Hold*///Bad formula
beltHoldBullish = largeBody AND smallLowerShadow AND whiteBody AND MLT;


/*BreakAway Bullish*/
breakAwayBullish=Ref(Largebody,-4) AND Ref(blackBody,-4)
AND Ref(blackBody,-3) AND Ref(O,-3)<Ref(C,-4)
AND Ref(smallbody,-2) AND Ref(C,-2)<Ref(C,-3)
AND Ref(C,-1)<Ref(C,-2)
AND LargeBody AND whiteBody AND C>Ref(O, -3)
AND C<Ref(C,-4);

/*Concealing Baby Swallow only one trade */
ConcealingBabySwallow=Ref(marabuzu,-3) AND Ref(blackbody,-3) AND
Ref(MArabuzu,-2) AND Ref(blackBody,-2) AND
Ref(blackBody,-1) AND Ref(downGap,-1) AND
Ref(H,-1)>Ref(C,-2)AND Ref(blackbody,-1)AND
blackBody AND engulfing;

/*Doji Star Bullish*/
dojiStarBullish=(dojiStar AND (MLT OR MLY))OR
(doji AND (C<Ref(C,-1) OR O<Ref(C,-1))AND Ref(blackBody,-1)
AND Ref(LargeBody,-1));

/*Engulfing Bullish*/
engulfingBullish =
engulfing AND largeBody AND whiteBody AND
(Ref(blackbody,-1) OR Ref(Doji,-1)) AND MLT;

/*Hammer Bullish*/
hammerBullish=Hammer AND (MLT OR MLY);

/*Dragonfly Doji Bullish*/
dragonflyDoji=smallBody AND LargeLowerShadow AND smallUpperShadow AND MLT;

/* Harami Bullish*/
haramiBullish = harami AND Ref (LargeBody,-1) AND Ref(blackBody,-1) AND
NOT LargeBody AND whiteBody;

/*Harami Cross*/
HaramiCross=harami AND Ref(LargeBody,-1) AND Ref(blackBody,-1) AND doji;

/* Homing Pigeon*/
homingPigeon = Ref(largeBody,-1) AND Ref(blackBody,-1) AND
H<= Ref ( O, -1 ) AND L>=Ref( C, -1) AND C<O AND MLY;

/*Inverted Hammer*/
invertedHammer=shootingStar AND (MLT OR MLY);

/* Meeting LinesBullish*/
meetingLinesbullish= Ref(LargeBody,-1) AND Ref(blackBody,-1) AND
LargeBody AND whiteBody AND
C>Ref(C,-1)*0.9975 AND C< Ref(C,-1)*1.0025;

/*Morning Doji Star*/
morningDojiStar= Ref(LargeBody,-2) AND Ref(blackBody,-2) AND
Ref(doji,-1) AND Ref(O,-1)<Ref(C,-2) AND
whiteBody AND C>Ref(C,-2) AND MLY;

/* Morning Star*/
morningStar =Ref(largeBody,-2) AND Ref(blackBody,-2)//Large black candle
AND Ref(downGap,-1)//Gap down yesterday
AND whiteBody AND LargeBody AND C>Ref(C,-2)//Large white candle today
AND MLY; //Yesterday was the low

/* Piercing Line*/
piercingLine= Ref(largeBody,-1) AND Ref(blackBody,-1)AND
O<Ref(L,-1) AND C>=(Ref(O,-1)+Ref(C,-1))/2 AND C<Ref(O,-1) AND MLT;

/* Stick Sandwich*/
stickSandwich=Ref(largeBody,-2) AND Ref(blackbody,-2) AND
Ref(largeBody,-1) AND Ref(whiteBody,-1) AND
Ref(O,-1)>=Ref(C,-2) AND O>=Ref(C,-1) AND
abs(C-Ref(C,-2))<=C*0.0025;

/*Three Inside Up harami confirming*/
threeInsideUp =Ref(Haramibullish,-1) AND whiteBody AND
largeBody AND C>Ref(C,-1);


/* Three Outside Up Engulfing confirmation*/
threeOutsideUp =Ref(engulfingBullish,-1) AND whiteBody AND C>Ref(C,-1);

/* Three Stars in the South*///Rewrite???
threeStarsInTheSouth=
Ref(LargeBody,-2) AND Ref(blackBody,-2) AND Ref(largelowerShadow,-2)
AND Ref(blackBody,-1) AND Ref(largeLowerShadow,-1) AND
Ref(L,-1)>Ref(L,-2) AND blackBody AND smallUpperShadow AND
smallLowerShadow AND L>Ref(L,-1) AND H<Ref(H,-1);

/* Tri-Star Bullish*/
triStarBullish=Ref(doji,-2) AND Ref(doji,-1) AND doji AND MLY AND
Ref(downgap,-1) AND upGap;

/* Three River Bottom Bad formula*/
threeriverBottom=Ref(largeBody,-2) AND Ref(blackBody,-2) AND
Ref(blackbody,-1) AND Ref(Largelowershadow,-1) AND
Ref(O,-1)<Ref(O,-2) AND Ref(C,-1)>Ref(C,-2) AND
whiteBody AND C<Ref(C,-1) AND MLY;

/* Mat Hold Bullish*/
MAtHoldBullish=Ref(LargeBody,-4) AND Ref(whiteBody,-4)//1st day
AND Ref(blackBody,-3) AND Ref(upGap,-3) AND NOT Ref(LargeBody,-3)
AND NOT Ref(LargeBody,-2) AND Ref(C,-2)<Ref(C,-3) AND Ref (O,-2)<Ref(O,-3) AND
Ref(C,-2)>Ref(O,-4) AND NOT Ref(LargeBody,-1) AND Ref(C,-1)<Ref(C,-2)
AND LargeBody AND whiteBody AND C>Ref(C,-4);

/*RisingThreeMethods*/
risingThreeMethods=Ref(LargeBody,-4) AND Ref(whiteBody,-4) AND NOT
Ref(LargeBody,-3) AND NOT Ref(LargeBody,-2)AND NOT Ref(LargeBody,-1) AND
Ref(C,-3)<Ref(C,-4) AND Ref(C,-2)<Ref(C,-3) AND Ref(C,-1)<Ref(C,-2) AND
LargeBody AND whitebody AND C>Ref(C,-4);

/* Seperating Lines Bullish*/
separatingLinesBullish=Ref(blackBody,-1) AND whiteBody AND LargeBody AND
smallLowerShadow AND MHT AND abs(O-Ref(O,-1))<=O*0.0025;

/*Side by Side White Lines*/
sideBySideWhiteLines=NOT Ref(smallBody,-2) AND Ref(whiteBody,-2)
AND Ref(upGap,-1) AND Ref(whitebody,-1)AND whiteBody AND
identicalBodies AND abs(O-Ref(O,-1))<O*0.0025;


/*Three White Soldiers*/
threeWhiteSoldiers=NOT Ref(smallbody,-2) AND Ref(whiteBody,-2) AND NOT
Ref(smallBody,-1) AND Ref(whiteBody,-1) AND NOT
smallBody AND whiteBody AND C>Ref(C,-1) AND Ref(C,-1)>Ref(C,-2) AND
Ref(O,-1)>Ref(O,-2) AND Ref(O,-1)<Ref(C,-2) AND O<Ref(C,-1) AND
O>Ref(O,-1) AND Ref(smallUpperShadow,-2) AND
Ref(smallUpperShadow,-1) AND smallUppershadow AND LLV(L,12)==Ref(L,-2);

/*Upside Gap Three Methods not very good*/
upsideGapThreeMethods=Ref(Largebody,-2) AND Ref(whiteBody,-2) AND
Ref(LargeBody,-1) AND Ref(whiteBody,-1) AND Ref(upGap,-1) AND
blackBody AND O>Ref(O,-1) AND C<Ref(C,-2)AND C>Ref(O,-2) AND
MHY;

/*Three Line Strike not good signals*/
threeLineStrike=NOT Ref(smallBody,-3) AND NOT Ref(smallBody,-2) AND
NOT Ref(smallBody,-1) AND Ref(whiteBody,-3) AND Ref(whiteBody,-2) AND
Ref(whiteBody,-1) AND Ref(C,-1)>Ref(C,-2) AND Ref(C,-2)>Ref(C,-3) AND
blackBody AND O>Ref(C,-1) AND C<Ref(O,-3);

/*Tweezer Bottom*/
tweezerBottom= (abs(L-Ref(L,-1))/L<0.0025 OR
abs(L-Ref(L,-2))/L<0.0025) AND O < C AND (Ref( O,-1) > Ref(C,-1));

/*Upside Tasuki Gap*/
upsideTasukiGap=Ref(largeBody,-2) AND Ref(largeBody,1) AND
Ref(whiteBody,-2) AND Ref(whiteBody,-1) AND Ref(upGap,-1) AND
blackBody AND O>Ref(O,-1) AND C<Ref(O,-1) AND C>Ref(C,-2) AND
identicalBodies AND O<Ref(C,-1);
//AND HHV(H,5)==Ref(H,-1); Do not use this line


/*****************************************
BEARISH CANDLESTICKS
******************************************/

/*Abandoned Baby Bearish*/
AbandonedBabyBearish=Ref(LargeBody,-2) AND Ref(whiteBody,-2) AND
Ref(smallBody,-1) AND Ref(GapUp(),-1) AND GapDown() AND
NOT smallBody AND blackBody AND MHY;

/*Advance Block Bearish*/
AdvanceBlockBearish=Ref(LargeBody,-2) AND Ref(whiteBody,-2)
AND Ref(whiteBody,-1) AND
whiteBody AND Ref(O,-1)>Ref(O,-2) AND Ref(O,-1)<Ref(C,-2) AND
Ref(C,-1)>Ref(C,-2) AND C>Ref(C,-1) AND
O<Ref(C,-1) AND O>Ref(O,-1) AND Ref(LargeUpperShadow,-1) AND LargeUpperShadow
AND C-O<Ref(C,-1)-Ref(O,-1) AND Ref(C,-1)-Ref(O,-1) < Ref(C,-2)-Ref(O,-2);

/*Belt Hold Bearish*/
beltHoldBearish=LargeBody AND BlackBody AND smalluppershadow AND MHT;

/*Breakaway Bearish*/
breakAwayBearish=Ref(LargeBody,-4) AND Ref(whiteBody,-4) AND
Ref(GapUp(),-3) AND Ref(whiteBody,-3) AND
Ref(smallbody,-2) AND Ref(smallBody,-1) AND
blackBody AND O>Ref(O,-3) AND C<Ref(C,-4);

/*Dark Cloud Cover*/
darkCloudCover=Ref(LargeBody,-1) AND Ref(whiteBody,-1) AND
blackBody AND O>Ref(H,-1) AND C>Ref(O,-1) AND C<(Ref(O,-1)+Ref(C,-1))/2
AND MHT;

/*Deliberation Bearish: needs confirmation*/
deliberationBearish=Ref(LargeBody,-2) AND Ref(whiteBody,-2) AND
Ref(LargeBody,-1) AND Ref(whiteBody,-1) AND Ref(C,-1)>Ref(C,-2) AND
smallbody AND upGap;

/*CounterAttackBearish*/
CounterAttackBearish=MHT AND LargeBody AND blackbody AND
Ref(largeBody,-1) AND Ref(whiteBody,-1) AND
C<Ref(C,-1)*1.0025 AND C>Ref(C,-1)*0.9975;;

/*Doji Star Bearish*/
dojiStarBearish=(dojiStar AND (MHT OR MHY))OR
(doji AND (C>Ref(C,-1) OR O>Ref(C,-1))AND Ref(whiteBody,-1)
AND Ref(LargeBody,-1));

/*Engulfing Bearish*/
engulfingBearish=engulfing AND largeBody AND blackBody AND
(Ref(whitebody,-1) OR Ref(Doji,-1))AND (MHT OR MHY);

/*Evening Doji Star check formula???*/
eveningDojiStar=Ref(LargeBody,-2) AND Ref(whiteBody,-2) AND
Ref(dojiStar,-1) AND Ref(GapUp(),-1) AND (MHY OR MHT);

/*Evening Star*/
eveningStar=Ref(LargeBody,-2) AND Ref(whiteBody,-2) AND
Ref(upGap,-1) AND NOT Ref(largeBody,-1) AND blackBody AND NOT smallBody AND
(MHT OR MHY);

/*Hammer Bearish*/
HammerBearish=Hammer AND HHV(H,8)==H;

/*hangingMan*/
HangingMan=NOT largeBody AND smallUpperShadow AND LargeLowerShadow AND MHT;

/*dragonfly Doji Bearish*/
dragonflyDojiBearish=doji AND smallUpperShadow AND LargeLowerShadow AND MHT;

/*Harami Bearish-*/
HaramiBearish=harami AND Ref(Largebody,-1) AND Ref(whiteBody,-1)AND blackBody
AND (MHY OR MHT);

/*HaramiCross Bearish*/
HaramiCrossBearish=harami AND doji AND Ref(whiteBody,-1) AND Ref(Largebody,-1);

/*Identical three black crows*/
idendicalThreeBlackCrows=Ref(blackBody,-2) AND Ref(blackBody,-1) AND blackBody AND
abs(Ref(C,-2)-Ref(O,-1))<Ref(C,-1)*0.0025 AND abs(Ref(C,-1)-O)<O*0.0025 AND
HHV(H,20)==Ref(H,-2) AND NOT Ref(doji,-2) AND NOT Ref(doji,-1) AND NOT doji AND
Ref(smallLowerShadow,-2) AND Ref(smallLowerShadow,-1) AND smallLowerShadow;

/*Kicking Bearish No trades*/
kickingBearish=Ref(whiteBody,-1) AND Ref(MArabuzu,-1) AND blackBody AND MArabuzu AND GapDown();

/*Meeting Lines Bearish*/
MeetingLinesBearish=Ref(LargeBody,-1) AND Ref(whiteBody,-1) AND
HHV(C,8)==Ref(C,-1) AND LargeBody AND blackBody AND
abs(C-Ref(C,-1))<C*0.0025;

/*ShootingStar*/
shootingStarGap=shootingStar AND GapUp() AND MHT;

/*Gravestone Doji*/
gravestoneDoji=doji AND largeUpperShadow AND smallLowerShadow AND GapUp()AND MHT;

/*Three Inside Down Bearish*/
threeInsideDownBearish=Ref(HaramiBearish,-1) AND blackBody AND C<Ref(C,-1)AND smallUpperShadow;

/*Three Outside Down Bearish*/
threeoutsideDownBearish=Ref(engulfingBearish,-1) AND blackBody AND C<Ref(C,-1)AND
NOT LargeUpperShadow;

/*Tri Star Bearish*/
triStarBearish=Ref(doji,-2) AND Ref(doji,-1) AND doji AND MHY AND Ref(upGap,-1)AND downGap;

/*Two Crows Bearish*/
twoCrows=Ref(whiteBody,-2) AND Ref(LargeBody,-2) //first day
AND Ref(blackBody,-1) AND Ref(upGap,-1)//Second Day
AND blackBody AND O<Ref(O,-1) AND O>Ref(C,-1)AND C<Ref(C,-2) AND
C>Ref(O,-2) AND MHY;//Third day

/*Upside Gap Two Crows*/
upsideGapTwoCrows= Ref(whiteBody,-2) AND Ref(LargeBody,-2)// first day
AND Ref(upGap,-1) AND Ref(blackBody,-1) // 2nd day
AND blackbody AND O>Ref(O,-1) AND C<Ref(C,-1) AND C>Ref(C,-2);

/*Doji Star Bearish needs confirmation
dojiStarBearish=Ref(LargeBody,-1) AND Ref(whiteBody,-1) // first day
AND doji AND upGap AND MHT;*/

/* Downside Gap Three Methods*/
downsideGapThreeMethods=
Ref(LargeBody,-2) AND Ref(blackBody,-2) AND Ref(downGap,-2) //first day
AND Ref(LargeBody,-1) AND Ref(blackBody,-1)//2nd day
AND whitebody AND O<Ref(O,-1) AND C>Ref(C,-2)
AND LLV(L,8)==Ref(L,-1);

/*Downside Tasuki Gap*/
downsideTasukiGap=
Ref(blackBody,-2)//first day
AND Ref(blackbody,-1) AND Ref(downgap,-1) //2nd day
AND whiteBody AND O<Ref(O,-1) AND O>Ref(C,-1) AND C>Ref(O,-1) AND C<Ref(C,-2)
AND Ref(identicalBodies,-1)
AND LLV(L,15)==Ref(L,-1);


/*Falling Three Meothods*/
fallingThreeMethods=Ref(LargeBody,-4) AND Ref(blackBody,-4) AND
/*Ref(doji,-3) AND Ref(doji,-2) AND Ref(doji,-1) AND*/ Ref(C,-1)>Ref(C,-2)
AND Ref(C,-2)>Ref(C,-3) AND LargeBody AND blackBody AND O>Ref(C,-4) AND
O<Ref(O,-4) AND C<Ref(O,-4)AND C<Ref(C,-4);

/*In Neck Bearish not good*/
inNeckBearish=Ref(LargeBody,-1) AND Ref(blackBody,-1) AND
whiteBody AND O<Ref(L,-1) AND C<Ref(C,-1)*1.0005 AND C>=Ref(C,-1);

/*On Neck Bearish not good*/
OnNeckBearish=Ref(LargeBody,-1) AND Ref(blackBody,-1) AND
whiteBody AND O<Ref(L,-1) AND C<Ref(L,-1)*1.0025 AND C>=Ref(L,-1)*0.9975;

/*separating Lines Bearish*/
separatingLinesBearish=Ref(LargeBody,-1) AND Ref(whiteBody,-1) AND
blackBody AND O>Ref(O,-1)*0.9975 AND O<=Ref(O,-1)*1.0025;

/*Side By Side White Lines Bearish*/
sideBySideWhiteLinesBearish=NOT Ref(smallBody,-2) AND Ref(blackBody,-2) AND
Ref(whiteBody,-1) AND whiteBody AND Ref(downGap,-1) AND identicalBodies
AND abs(C-Ref(C,-1)<C*0.0025);

/*Three Black Crows*/
threeBlackCrows=Ref(blackBody,-2) AND Ref(blackBody,-1) AND blackBody AND Ref(C,-1)<Ref(C,-2) AND C<Ref(C,-1) AND HHV(H,8)==Ref(H,-2) AND NOT Ref(doji,-2) AND NOT Ref(doji,-1) AND NOT doji;;

/*Three Line Strike no trades*/
threeLineStrike=threeBlackCrows AND whiteBody AND O<Ref(C,-1) AND C>Ref(O,-3);

/*Thrusting Bearish*/
thrustingBearish=Ref(blackBody,-1) AND Ref(LargeBody,-1) AND LargeBody AND
whitebody AND O<Ref(L,-1) AND C<(Ref(O,-1)+Ref(C,-1))/2 AND C>Ref(C,-1);

/*Tweezer Top*/
TweezerTop=abs(H-Ref(H,-1))<=H*0.0025 AND O >C AND (Ref(C,-1) > Ref(O,-1));




/* ***********************************************
Buy Rules
**************************************************/
Buy=
abandonedBabybullish OR
beltHoldBullish OR
breakAwayBullish OR
ConcealingBabySwallow OR
engulfingBullish OR
hammerBullish OR
dragonflyDoji OR
dojiStarBullish OR
haramiBullish OR
HaramiCross OR
homingPigeon OR
invertedHammer OR
meetingLinesbullish OR
morningDojiStar OR
morningStar OR
piercingLine OR
stickSandwich OR
threeInsideUp OR
threeOutsideUp OR
threeStarsInTheSouth OR
triStarBullish OR
threeriverBottom OR
MAtHoldBullish OR
risingThreeMethods OR
separatingLinesBullish OR
sideBySideWhiteLines OR
threeWhiteSoldiers OR
upsideGapThreeMethods OR
threeLineStrike OR
tweezerBottom OR
upsideTasukiGap;

/************************************
Sell Rules
*************************************/
Sell=
AbandonedBabyBearish OR
advanceBlockBearish OR
beltHoldBearish OR
breakAwayBearish OR
darkCloudCover OR
deliberationBearish OR
CounterAttackBearish OR
engulfingBearish OR
eveningDojiStar OR
eveningStar OR
HangingMan OR
dragonflyDojiBearish OR
HammerBearish OR
HaramiBearish OR
HaramiCrossBearish OR
idendicalThreeBlackCrows OR
kickingBearish OR
MeetingLinesBearish OR
shootingStarGap OR
gravestoneDoji OR
threeInsideDownBearish OR
threeoutsideDownBearish OR
triStarBearish OR
twoCrows OR
upsideGapTwoCrows OR
dojiStarBearish OR
downsideGapThreeMethods OR
downsideTasukiGap OR
fallingThreeMethods OR
inNeckBearish OR
OnNeckBearish OR
separatingLinesBearish OR
sideBySideWhiteLinesBearish OR
threeBlackCrows OR
threeLineStrike OR
thrustingBearish OR
tweezerTop;


/***************************************
Commentary
***************************************
Bullish Candles
****************************************/
C_sta =
WriteIf(abandonedBabybullish,"Abandoned Baby Bullish. A reversal pattern.\nLiWick reliability : High.",
WriteIf(beltHoldBullish,"Belt Hold Bullish. A reversal pattern.\nNison:The larger the candlestick, the more significant it is.\nLitWick Reliability: Low.",
WriteIf(breakAwayBullish,"Break Away Bullish. A reversal pattern.\nLitWick reliability: moderate.",
WriteIf(ConcealingBabySwallow,"Concealing Baby Swallow. A reversal pattern.\n LitWick reliability: high.",
WriteIf(dojiStarBullish,"Bullish doji Star. A reversal pattern.\nNison: Needs confirmation. Better at calling tops.\nLitWick reliability: moderate.",
WriteIf(engulfingBullish,"Bullish Engulfing. a reversal pattern.\nNison: Factors increasing the pattern's effectiveness are\n1) The first day has a small real body and the second day has a large real body.\n2) Pattern appears after protracted or very fast move.\n3) Heavy volume on second real body.\n4) The second day engulfs more than one real body.\nLitWick reliability: moderate",
WriteIf(hammerBullish,"Bullish Hammer. A reversal pattern.\nNison: The longer the lower shadow, the smaller the upper shadow, and the smaller the real body, the more significant the pattern.White real body more bullish than black body.\nLitWick reliability: low.",
WriteIf(dragonflyDoji,"Dragonfly Doji. LitWick reliability: moderate.",
WriteIf(haramiBullish, "Harami Bullish. A reversal pattern.\nNison: Less significant. Pattern needs confirmation.\nLitWick reliability: low.",
WriteIf(HaramiCross,"Harami Cross. A reversal pattern.\nNison: Better indicator than Harami. Better at calling tops than bottoms.\nLitWick reliability: low.",
WriteIf(homingPigeon,"Homing Pigeon. A reversal pattern.\nLitWick reliability: moderate.",
WriteIf(invertedHammer,"Inverted Hammer. A reversal pattern.\nNison:Needs bullish verification.\nLitWick reliability: low.",
WriteIf(meetingLinesbullish,"Meeting Lines bullish. A reversal pattern.\nLitWick reliability: moderate.",
WriteIf(morningDojiStar,"Morning Doji Star. A reversal pattern.\nImportant reversal signal.\nLitWick reliability: high.",
WriteIf(morningStar,"Morning Star. A reversal pattern.\nNison: The stronger the white third body the better.\nLitWick reliability: high.",
WriteIf(piercingLine,"Piercing Line. A reversal pattern.\nNison: A stron reversal pattern.\nLitWick reliability: moderate.",
WriteIf(stickSandwich,"Stick Sandwich. A reversal pattern.\nLitWick reliability: moderate.",
WriteIf(threeInsideUp,"3 Inside Up. A reversal pattern.\nLitWick reliability: high.",
WriteIf(threeOutsideUp,"3 Outside Up. A reversal pattern.\nLitWick reliability: high.",
WriteIf(threeStarsInTheSouth,"3 Stars in the South. A reversal pattern.\nLitWick reliability: moderate.",
WriteIf(triStarBullish,"Tri-Star Bullish. A reversal pattern.\nNison: Significant reversal pattern.\nLitWick reliability: moderate.",
WriteIf(threeriverBottom,"3 River Bottom. A reversal pattern.\nNison: Selling pressure drying up.\nLit Wick reliability: moderate.",
WriteIf(MAtHoldBullish,"Mat Hold Bullish. A continuation pattern.\nNison: May have 2-4 black candles.\nLitWick reliability: high. ",

WriteIf(risingThreeMethods,"Rising Three Methods. A continuation pattern>\nNison: Has more significance if volume of white candle sticks is greater than on black candlesticks.\nLitWick reliability: high.",
WriteIf(separatingLinesBullish,"Separating Lines Bullish. A continuation pattern.\nNison: \nLitWick reliability: low.",
WriteIf(sideBySideWhiteLines,"Side by Side White Lines. A continuation pattern.\nNison: If occurring during a downtrend may only be short covering.\nLitWick reliability: high.",
WriteIf(threeWhiteSoldiers,"3 White Soldiers. A continuation pattern.\nNison: Positive, but be aware of negative similar stalled pattern and advance block pattern.\nLitWick reliability: high.",
WriteIf(upsideGapThreeMethods,"Upside Gap 3 Methods. A continuation pattern.\nLitWick reliability: moderate.",
WriteIf(threeLineStrike,"3 Line Strike. A continuation pattern.\nLitWick reliability: low.",
WriteIf(tweezerBottom,"Tweezer Bottom.a reversal pattern. With other reversal candles it could indicate a support level.\nNison: Needs confirmation.",
WriteIf(upsideTasukiGap,"Upside Tasuki Gap. A continuation pattern.\nNison: the real bodies of the two candlesticks in the gap should be about the same size.\nLitWick reliability: moderate.",
"No Commentary..." )))))))))))))))))))))))))))))));

/***************************************
Bearish Candles
********************************************/
C_be =
WriteIf(AbandonedBabyBearish,"Abandoned Baby Bearish. A reversal pattern.\nNison: Extremely rare.\nLitWick reliability: high.",
WriteIf(advanceBlockBearish,"Advancing Block Bearish. A reversal pattern.\nNison: Rally is in trouble. Signs of weakening could be progressively smaller white read bodies or relatibvely long upper shadows on the last two white candlesticks.Not necessarily a reversal pattern.\nLitWick Reliability: moderate.",
WriteIf(beltHoldBearish,"Belt Hold Bearish. A reversal pattern.\nNison: The longer the height of the belt-hold candle the more significant the pattern.\nLitWick reliability: low.",
WriteIf(breakAwayBearish,"Break Away Bearish. A reversal pattern.\nLitWick reliability: moderate.",
WriteIf(darkCloudCover,"Dark Cloud Cover. A reversal pattern.\nNison: Factors indicating the importance of this signal are/n1)The greater the penetration of the first candle by the second.\n2)Both candles are marabozus.\n3)The second body opens above a major resistance level.\n4)High volume on the second day.\nLitWick Reliability: high.",
WriteIf(deliberationBearish,"Deliberation Bearish. A reversal pattern.\nNison: Not a reversal pattern, but a sign the rally is weakening.\nLitWick reliability: moderate.",
WriteIf(CounterAttackBearish,"Counter Attack Bearish.\nNison: A potential stalling of the rally.",
WriteIf(engulfingBearish,"Engulfing Bearish. A reversal pattern.\nNison: Major reversal signal. Factors increasing patterns importance are\n1) The first day has a very small real body and the second day a very large real body.\n2) The pattern apears after a protracted or very fast move.\n3) Heavy volume on the second day.\n4) The second day engulfs more than one real body.\nLitWick reliability: moderate.",
WriteIf(eveningDojiStar,"Evening Doji Star A reversal pattern.\nNison: Must be confirmed by long black candle.\nLit Wick reliability: high",
WriteIf(eveningStar,"Evening Star. a reversal pattern.\nNison: Gap between second and third bodies does not always occur.\nLitWick reliability: high.",
WriteIf(HammerBearish,"Bearish Hammer. a reversal pattern.\nNison: More bearish if hammer is black. Needs bearish confirmation. A large gap down on the following day would be a good confirmation.",
WriteIf(HangingMan,"Hanging Man. A reversal pattern.\nNison: Same as bearish hammer with a large gap down the following day.\nLitWick reliability: low.",
WriteIf(dragonflyDojiBearish,"Dragonfly Bearish. A reversal pattern.\nNison: Same as Hanging Man.\nLitWick reliability: moderate.",
WriteIf(HaramiBearish,"Harami Bearish. A reversal pattern.\nNison: Not as significant a reversal pattern as hanging man or engulfing.\nLitWick reliability: low.",
WriteIf(HaramiCrossBearish,"Harami Cross Bearish. A reversal pattern.\nNison: More significant reversal pattern than Harami. Second day can be white or black.\nLitWick reliability: moderate.",
WriteIf(idendicalThreeBlackCrows,"Identical 3 Black Crows. A reversal pattern in an uptrend.\nNison:Very bearish.\nLitWick reliability: high. ",
WriteIf(kickingBearish,"Kicking Bearish. A reversal pattern.\nLitWick reliability: high.",
WriteIf(MeetingLinesBearish,"Meeting Lines Bearish. A reversal pattern.\nNison: \nLitWick reliability: moderate, but not as strong as Dark cloud Cover.",
WriteIf(shootingStarGap,"Shooting Star. a reversal pattern.\nNison:Not major reversal signal as evening star. Ideally real body would gap away from previous body. Needs to appear after an uptrend.\nLitWick reliability: low.",
WriteIf(gravestoneDoji,"Gravestone Doji A reversal pattern.\nNison: more significant if it hits new high.\nLitWick reliability: moderate.",
WriteIf(threeInsideDownBearish,"3 Inside Down. A reversal pattern.\nNison: \nLitWick reliability: high.",
WriteIf(threeoutsideDownBearish,"3 Outside Down. A reversal pattern.\nLitWick reliability: high.",
WriteIf(triStarBearish,"Tri-Star Bearish. A reversal pattern.\nNison: Very significant reversal pattern.\nLitWick reliability: moderate.",
WriteIf(twoCrows,"2 Crows A reversal pattern.\nLitWick reliability: moderate.",
WriteIf(upsideGapTwoCrows,"Upside Gap 2 Crows. A reversal pattern.\nNison:Needs confirmation of a continued reversal on third day.\nLitWick reliability: high.",
WriteIf(dojiStarBearish,"Doji Star Bearish. A reversal pattern.\nNison: needs confirmation.\nLitWick reliability: moderate.",
WriteIf(downsideGapThreeMethods,"Downside Gap 3 Methods. A continuation pattern.\nNison: \nLitWick reliability: moderate.",
WriteIf(downsideTasukiGap,"Downside Tasuki Gap. A continuation method.\NNison: If last day closes window, continuation pattern is negated.\nLitWick reliability: moderate.",
WriteIf(fallingThreeMethods,"Falling 3 Methods. A continuation pattern.\nNison: \nLitWick reliability: high.",
WriteIf(inNeckBearish,"In Neck Bearish. A continuatin pattern.\nNison: Similar to piercing pattern but bearish because there is no penetration of second day.\nLitWick reliability: moderate.",
WriteIf(OnNeckBearish,"On Neck Bearish. A continuation pattern. Similar to piercing pattern but bearish beccause there is no penetration of the second day.\nLitWick reliability: moderate.",
WriteIf(separatingLinesBearish,"Separating Lines Bearish",
WriteIf(sideBySideWhiteLinesBearish,"Side by Side White Lines Bearish. A continuation pattern.\nNison: very rare.\nLitWick reliability: moderate.",
WriteIf(threeBlackCrows,"3 Black Crows. A reversal pattern.\nNison: Need to appear after a mature advance.\nLitWick reliability: high.",
WriteIf(threeLineStrike,"3 Line Strike. A continuation pattern.\nLitWick reliability: low.",
WriteIf(thrustingBearish,"Thrusting. A continuation pattern.\nNison: Not a reversal day because second day does not pierce midpoint of first day.\nLitWick reliability: low.",
WriteIf(tweezerTop,"Tweezer Top. A reversal pattern.\nNison: Needs confirmation.",
"No Commentary..." )))))))))))))))))))))))))))))))))))));


/***********************************************
End Commentary
************************************************/
Plot(C,"Price", IIf(C> Ref(C,-1),colorGreen,colorRed), styleCandle );
Title = EncodeColor(colorWhite)+ FullName()+"\n"+EncodeColor(colorGold)+ " Ngay:"+ Date() +StrFormat(" - Open %g, Hi %g, Lo %g, Close %g " , O,H,L,C )+"Volume : " + V +"\n"+ "_____ Candlestick Commentary _____" +"\n"+ "_ Bullish Candles:"+
EncodeColor(colorGreen)+
C_sta + "\n"+EncodeColor(colorGold)+"_ Bearish Candles :"+EncodeColor(colorRed)+
C_be +"\n"+EncodeColor(colorBrightGreen)+ "_____ praveen _____";
Plot(EMA(C,20)," ", colorGreen,1);
Plot(EMA(C,50)," ", colorYellow,1);
Plot(EMA(C,200)," ", colorRed,1);
Plot(EMA(C,100)," ", colorWhite,1);
//PlotVAPOverlay( Param("lines",300,10,1000,1), Param("width",10,1,99,1), ParamColor("color", colorDarkBlue), Param("style",0,0,7,1) );
//PlotVAPOverlayA( Param("Lines", 300, 100, 1000, 1 ), Param("Width", 80, 1, 200, 1 ), ParamColor("Color", colorGold ), ParamToggle("Side", "Left|Right" ) | 2 * ParamToggle("Style", "Fill|Lines", 0) | 4*ParamToggle("Z-order", "On top|Behind", 1 )) ;
//Plot(segments, "", colorLightGrey, styleHistogram | styleOwnScale );
PlotVAPOverlay( Param("lines",300,10,1000,1), Param("width",10,1,99,1), ParamColor("color", colorDarkBlue), Param("style",0,0,7,1) |4*ParamToggle("Z-order", "On top|Behind", 1 ));
_SECTION_BEGIN("Background text");

GfxSelectFont("Time news roman", Status("pxheight")/6 );
GfxSetTextAlign(6 );// center alignment
GfxSetOverlayMode(1 ) ;
//GfxSetTextColor( ColorRGB( 200, 200, 200 ) );
GfxSetTextColor( ColorHSB( 42, 42, 42 ) );
GfxSetBkMode(0); // transparent
GfxTextOut( Name(), Status("pxwidth")/2, Status("pxheight")/19 );
GfxSelectFont("Time news roman", Status("pxheight")/30 );
GfxTextOut(FullName(), Status("pxwidth")/2, Status("pxheight")/3.8 );
GfxSelectFont("Time news roman", Status("pxheight")/25 );
GfxTextOut("Market: " + MarketID(1), Status("pxwidth")/2, Status("pxheight")/3 );
_SECTION_BEGIN("Volume");
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorLavender ), styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick | styleNoLabel, maskHistogram ), 2 );
_SECTION_END();
 

rajsumi121

Well-Known Member
#6
3/60 MOVING AVERAGE CROSSOVER



_SECTION_BEGIN("Exact cross over");
// Plotting the Price;
Plot (C,"close",colorBlack ,styleCandle );
//Plotting Fast EMAs;
Plot(EMA(C,3) ,"3ema",colorBlue ,styleLine );
//Plotting Slow EMAs
Plot(EMA(C,60) ,"60ema",colorRed ,styleLine );
// calculation of crossover value;
g=(EMA(Close, 3) * (2 / 4 - 1)-EMA(Close, 60) * (2 / 61 - 1)) / (2 /4- 2 /61);
// explanation : 2/4 is actually 2/(Fast ema+1) and 2/61 is 2/(slow ema+1)
e=Ref(g,-1);
//buy or sell conditions;
Buy=Cross( EMA(C,3), EMA(C,60));
Sell=Cross( EMA(C,60), EMA(C,3));
// Plotting shapes;
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorBrightGreen, colorRed ),0, IIf( Buy, Low, High ) );
//displaying signals with crossover value;
GraphXSpace = 5;
dist = 1.5*ATR(5);
for( i = 0; i < BarCount; i++ )
{if( Buy ) PlotText( "Buy\n@" + e[ i ], i, L[ i ]-dist, colorBrightGreen );
if( Sell ) PlotText( "Sell\n@" + e[ i ], i, H[ i ]+dist,
colorRed);
}
//Title;
_N(Title = "{{NAME}} - {{INTERVAL}} {{DATE}}: "+" : {{OHLCX}} " +EncodeColor( colorRed) +" V "+WriteVal(V, 1)+" Lot Size "+WriteVal(RoundLotSize,1.0) +" Margin"+WriteVal( MarginDeposit, 1.0)+
"\n"+EncodeColor( colorDarkGreen) + " Next crossover value "+WriteVal(g, 1.2));
_SECTION_END();
 

rajsumi121

Well-Known Member
#7
ADX SYSTEM , USE WITH STOCHASTIC FOR BETTER RESULT



_SECTION_BEGIN("ADX + EMA + MACD");
// This combines three indicators into one timing Signal
//function ParamOptimize( description, default, minv, maxv, step )
// { return Optimize(description, Param(description,default, minv, maxv, step ), minv, maxv, step ); }
tgl = ParamToggle("Result", "AND logic|Compare");
// ema
emaPrice = ParamField("Ema Price field", 3);
PeriodShort = Param("Ema Short Periods", 5, 2, 20, 1);
PeriodLong = Param("Ema Long Periods", 15, 2, 100, 1);
pS = EMA(emaPrice , PeriodShort);
pL = EMA(emaPrice , PeriodLong);
upEma = IIf(pS > pL, 1, 0); // fast ema is above slow, long condition
// adx di lines
range = Param("ADX Periods", 10, 2, 200, 1 );
myPdi = PDI(range );
myMdi = MDI(range );
upAdx = IIf( myPdi > myMdi, 1, 0);
// macd
r1 = Param( "Macd Fast avg", 12, 2, 200, 1 );
r2 = Param( "Macd Slow avg", 26, 2, 200, 1 );
r3 = Param( "Macd Signal avg", 9, 2, 200, 1 );
myMacd = MACD(r1,r2);
mySignal = Signal(r1,r2,r3);
upMacd = IIf(myMacd > mySignal, 1, 0);
// switch test calculation and compare the results
if(tgl)
{
myBuy = upEma AND upAdx AND upMacd;
myShort = !upEma AND !upAdx AND !upMacd;
}
else
{
myBuy = IIf(pS > pL AND myMacd > mySignal AND myPdi > myMdi,1,0);
myShort = IIf(pS < pL AND myMacd < mySignal AND myPdi < myMdi,1,0);
}
Buy = Cover = ExRem(myBuy, myShort);
Short = Sell = ExRem(myShort, myBuy);
Plot( Buy * C, "ADX(" + NumToStr(range,1.0) + ") EMA(" + NumToStr(PeriodShort,1.0) + "," + NumToStr(PeriodLong,1.0) +
") MACD(" + NumToStr(r1,1.0) + "," + NumToStr(r2,1.0) + "," + NumToStr(r3,1.0) + ") - myBuy ", colorGreen); // a positive spike that indicates a buy or cover trade.
Plot( -Short * C , "myShort ", colorRed);
// exploration
Filter = Buy OR Short;
AddColumn(Close, "Close", 1.2);
AddColumn(Buy, "Buy", 1.0);
AddColumn(Short, "Short",1.0);
_SECTION_END();
 

rajsumi121

Well-Known Member
#8
7-34 SIGNAL .. LESS SIGNAL BUT GOOD ACCURACY


//Go Short/Long on Cross over with Stop loss of recent High/Low on 5 Minute Chart
_SECTION_BEGIN("Background_Setting");
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),
ParamColor("BgBottom", colorBlack),ParamColor("titleblock",colorWhite));
_SECTION_END();

_SECTION_BEGIN("734 cross");
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot(Close,"Price",colorWhite, styleCandle);
Plot(EMA(Close,7),"7EMA",colorGreen,style=styleThick);
Plot(EMA(Close,34),"34EMA",colorRed,style=styleThick);
Buy=Cross(EMA(Close,7),EMA(Close,34));
Sell=Cross(EMA(Close,34),EMA(Close,7));
Short=Sell;
Cover=Buy;
shape = Buy * shapeSmallUpTriangle + Sell * shapeSmallDownTriangle;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );
_SECTION_END();


_SECTION_BEGIN("Ribbon");
no=Param( "Swing", 10, 1, 55 );
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);
tsl=IIf(avn==1,sup,res);

Plot( 2, "Ribbon",IIf(C>tsl,colorGreen,colorRed),styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
_SECTION_END();
 

rajsumi121

Well-Known Member
#9
STOCHASTIC WITH SOME MODIFICATION



_SECTION_BEGIN("Fibosher");
SetBarsRequired(200, 0);

// Ehlers formulas modified by Danny Suwardhani 2008
// from Ehlers, John F. Cybernetic Analysis for Stocks and Futures. Wiley. 2004.
// Chapter 1, p. 1. Code on p. 7.

function InverseFisher(array)
{
e2y = exp(2 * array);
return (e2y - 1)/(e2y + 1);
}

function Normalize(array, arraylen)
// Figure 1.7 on p. 7
{
MaxH = HHV(array, arraylen);
MinL = LLV(array, arraylen);
Value1[0] = array[0]; // Initialize as array

for(i = 1; i < BarCount; i++)
{
Value1=.5*2*((array-MinL)/IIf(MaxH-MinL==0,1,MaxH-MinL)-.5)+.5*Value1[i-1];

if (Value1 > .9999) Value1 = .9999;
if (Value1 < -.9999) Value1 = -.9999;
}
return Value1;
}

function Fisher(array)
// Figure 1.7 on p. 7
{
F = array;
F = .25 * log((1+ array)/(1 - array)) + .5 * Ref(F, -1);
return F;
}

Med = (H+L)/2;
MidPoint=0;
// Fisher Transform
FisherXform = Fisher(Normalize(Med, 10));

FisherColor = colorYellow;
FisherColor = IIf(LinRegSlope(FisherXform,2) == 0,colorBlue,FisherColor );
FisherColor = IIf(LinRegSlope(FisherXform,2) < 0,colorRed,FisherColor );
Sell1 = LinRegSlope(FisherXform,2) <= 0 AND Ref(LinRegSlope(FisherXform,2),-1) > 0;
Buy1 = LinRegSlope(FisherXform,2) >= 0 AND Ref(LinRegSlope(FisherXform,2),-1) < 0;

Plot(FisherXform, "Fibosher", FisherColor , styleLine|styleThick);

barvisible = Status("barvisible");
maxr = LastValue( Highest( IIf( barvisible, FisherXform, 0 ) ) );
minr = LastValue( Lowest( IIf( barvisible, FisherXform, 100 ) ) );
ranr = maxr - minr;

Plot( maxr , "0%", colorGrey50 );
Plot( maxr - 0.236 * ranr, "-23.6%", colorPaleGreen );
Plot( maxr - 0.382 * ranr, "-38.2%", colorPaleBlue );
Plot( maxr - 0.50 * ranr, "-50.0%", colorOrange );
Plot( maxr - 0.618 * ranr, "-61.8%", colorPaleBlue );
Plot( maxr - 0.786 * ranr, "-78.6%", colorPaleGreen );
Plot( minr , "-100%", colorGrey50 );

GraphXSpace = 3;

_SECTION_END();
 

Similar threads