I have southwind Breeze and super trend Buy-Sell signal dash board for 5Min-15Min-60Min and the codes are as follows.I need your help to write similar dash board based on Southwind Breeze Signals. It will be an amazing indicator for safe trading:
Southwind Breeze AFL:
_SECTION_BEGIN("CandleStick Analysis");
/*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;
/*(NOT largeBody AND smallLowerShadow AND LargeUpperShadow) OR*/
shootingStar=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 (MLT OR MLY);
/*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 OR
abs(H-Ref(H,-2))/H<0.0025)
AND (MHT OR MHY);
/* ***********************************************
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
****************************************/
WriteIf(Buy,"Bullish\n=======\n","")+
WriteIf(abandonedBabybullish,"Abandoned Baby Bullish. \nA reversal pattern.\n\\c16LiWick reliability : High.","")+
WriteIf(beltHoldBullish,"Belt Hold Bullish. \nA reversal pattern.\nNison:The larger the candlestick, the more significant it is.\nLitWick Reliability: Low.","")+
WriteIf(breakAwayBullish,"Break Away Bullish. \nA reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(ConcealingBabySwallow,"Concealing Baby Swallow. \nA 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. \nA 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. \nA 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. \nLitWick reliability: moderate.","")+
WriteIf(haramiBullish, "Harami Bullish. \nA reversal pattern.\nNison: Less significant. Pattern needs confirmation.\nLitWick reliability: low.","")+
WriteIf(HaramiCross,"Harami Cross. \nA reversal pattern.\nNison: Better indicator than Harami. Better at calling tops than bottoms.\nLitWick reliability: low.","")+
WriteIf(homingPigeon,"Homing Pigeon. \nA reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(invertedHammer,"Inverted Hammer. \nA reversal pattern.\nNison:Needs bullish verification.\nLitWick reliability: low.","")+
WriteIf(meetingLinesbullish,"Meeting Lines bullish. \nA reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(morningDojiStar,"Morning Doji Star. \nA reversal pattern.\nImportant reversal signal.\nLitWick reliability: high.","")+
WriteIf(morningStar,"Morning Star. \nA reversal pattern.\nNison: The stronger the white third body the better.\nLitWick reliability: high.","")+
WriteIf(piercingLine,"Piercing Line. \nA reversal pattern.\nNison: A stron reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(stickSandwich,"Stick Sandwich. \nA reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(threeInsideUp,"3 Inside Up. \nA reversal pattern.\nLitWick reliability: high.","")+
WriteIf(threeOutsideUp,"3 Outside Up. \nA reversal pattern.\nLitWick reliability: high.","")+
WriteIf(threeStarsInTheSouth,"3 Stars in the South. \nA reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(triStarBullish,"Tri-Star Bullish. \nA reversal pattern.\nNison: Significant reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(threeriverBottom,"3 River Bottom. \nA reversal pattern.\nNison: Selling pressure drying up.\nLit Wick reliability: moderate.","")+
WriteIf(MAtHoldBullish,"Mat Hold Bullish. \nA continuation pattern.\nNison: May have 2-4 black candles.\nLitWick reliability: high. ","")+
WriteIf(risingThreeMethods,"Rising Three Methods. \nA 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. \nA continuation pattern.\nNison: \nLitWick reliability: low.","")+
WriteIf(sideBySideWhiteLines,"Side by Side White Lines. \nA continuation pattern.\nNison: If occurring during a downtrend may only be short covering.\nLitWick reliability: high.","")+
WriteIf(threeWhiteSoldiers,"3 White Soldiers. \nA 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. \nA continuation pattern.\nLitWick reliability: moderate.","")+
WriteIf(threeLineStrike,"3 Line Strike. \nA continuation pattern.\nLitWick reliability: low.","")+
WriteIf(tweezerBottom,"Tweezer Bottom.\nA reversal pattern. With other reversal candles it could indicate a support level.\nNison: Needs confirmation.","")+
WriteIf(upsideTasukiGap,"Upside Tasuki Gap. \nA continuation pattern.\nNison: the real bodies of the two candlesticks in the gap should be about the same size.\nLitWick reliability: moderate.","")+
WriteIf(Buy,"\n-------------------------------------------","");; /***************************************
Bearish Candles
********************************************/
WriteIf(Sell,"Bearish\n=======\n","")+
WriteIf(AbandonedBabyBearish,"Abandoned Baby Bearish. \nA reversal pattern.\nNison: Extremely rare.\nLitWick reliability: high.","")+
WriteIf(advanceBlockBearish,"Advancing Block Bearish. \nA 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. \nA 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. \nA reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(darkCloudCover,"Dark Cloud Cover. \nA 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. \nA 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. \nA 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 \nA reversal pattern.\nNison: Must be confirmed by long black candle.\nLit Wick reliability: high","")+
WriteIf(eveningStar,"Evening Star. \nA reversal pattern.\nNison: Gap between Second AND third bodies does NOT always occur.\nLitWick reliability: High.","")+
WriteIf(HammerBearish,"Bearish Hammer. \nA 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. \nA reversal pattern.\nNison: Same as bearish hammer with a large gap down the following day.\nLitWick reliability: low.","")+
WriteIf(dragonflyDojiBearish,"Dragonfly Bearish. \nA reversal pattern.\nNison: Same as Hanging Man.\nLitWick reliability: moderate.","")+
WriteIf(HaramiBearish,"Harami Bearish. \nA reversal pattern.\nNison: Not as significant a reversal pattern as hanging man or engulfing.\nLitWick reliability: low.","")+
WriteIf(HaramiCrossBearish,"Harami Cross Bearish. \nA 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. \nA reversal pattern in an uptrend.\nNison:Very bearish.\nLitWick reliability: high. ","")+
WriteIf(kickingBearish,"Kicking Bearish. \nA reversal pattern.\nLitWick reliability: high.","")+
WriteIf(MeetingLinesBearish,"Meeting Lines Bearish. \nA reversal pattern.\nNison: \nLitWick reliability: moderate, but not as strong as Dark cloud Cover.","")+
WriteIf(shootingStarGap,"Shooting Star. \nA 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. \nA reversal pattern.\nNison: more significant if it hits new high.\nLitWick reliability: moderate.","")+
WriteIf(threeInsideDownBearish,"3 Inside Down. \nA reversal pattern.\nNison: \nLitWick reliability: high.","")+
WriteIf(threeoutsideDownBearish,"3 Outside Down. \nA reversal pattern.\nLitWick reliability: high.","")+
WriteIf(triStarBearish,"Tri-Star Bearish. \nA reversal pattern.\nNison: Very significant reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(twoCrows,"2 Crows. \nA reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(upsideGapTwoCrows,"Upside Gap 2 Crows. \nA reversal pattern.\nNison:Needs confirmation of a continued reversal on third day.\nLitWick reliability: high.","")+
WriteIf(dojiStarBearish,"Doji Star Bearish. \nA 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. \nA continuation method.\nNison: If last day closes window, continuation pattern is negated.\nLitWick reliability: moderate.","")+
WriteIf(fallingThreeMethods,"Falling 3 Methods. \nA 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. \nA 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. \nA continuation pattern.\nNison: very rare.\nLitWick reliability: moderate.","")+
WriteIf(threeBlackCrows,"3 Black Crows. \nA reversal pattern.\nNison: Need to appear after a mature advance.\nLitWick reliability: high.","")+
WriteIf(threeLineStrike,"3 Line Strike. \nA continuation pattern.\nLitWick reliability: low.","")+
WriteIf(thrustingBearish,"Thrusting. \nA continuation pattern.\nNison: Not a reversal day because second day does not pierce midpoint of first day.\nLitWick reliability: low.","")+
WriteIf(tweezerTop,"Tweezer Top. \nA reversal pattern.\nNison: Needs confirmation.","")+
WriteIf(Sell,"\n---------------------------------------------------","");
/***********************************************
End Commentary
************************************************/
_SECTION_END();
_SECTION_BEGIN("Signal Panel");
sp = ParamToggle("Signal Panel","Show|Hide",1);
showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);
no=6;
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
s5d=IIf(avn==1,sup,res);
ColorSL = IIf(avn==1,colorBrightGreen,colorRed);
if (showsl == 1) Plot(s5d,"Stop Loss",ColorSL,styleDots);
exitlong = Cross(s5d, H);
exitshort = Cross(L, s5d);
Buy = exitshort;
Sell = exitlong;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
PlotShapes(exitlong * shapeDownArrow, colorRed,0,H,-10);
PlotShapes(exitshort * shapeUpArrow, colorLime,0,L,-15);
AlertIf( Buy, "", "BUY @ " + C, 1 );
AlertIf( Sell, "", "SELL @ " + C, 2 );
for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";
sl = s5d;
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);
bars = i;
i = 0;
}
if(Sell == 1)
{
sig = "SELL";
entry = C;
sl = s5d;
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, s5d[BarCount-1], Ref(s5d, -1));
sl = ssl[BarCount-1];
if (sp == 1 )
{
Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorDarkRed, styleLine|styleLine, Null, Null, Offset);
Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorGreen, styleLine|styleLine, Null, Null, Offset);
for (i=bars; i <BarCount;i++)
{
PlotText(""+sig+"@"+entry, BarCount-2,entry,Null,colorBlue);
PlotText("T1@"+tar1,BarCount,tar1,Null,Clr);
PlotText("T2@"+tar2,BarCount,tar2,Null,Clr);
PlotText ("T3@"+tar3,BarCount,tar3,Null,Clr);
}
printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago");
printf("\n" + sig + " @ : " + entry + "\nStop Loss : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"+ "\nTarget_1 : " + tar1 + "\nTarget_2 : " + tar2 + "\nTarget_3 : " + tar3);
printf("\nCurrent P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2));
}
_SECTION_END();
_SECTION_BEGIN("VSA");
DTL=Param("Linear regression period",60,10,100,10);
wbf=Param("WRB factor",1.5,1.3,2.5,.1);
nbf=Param("NRB factor",0.7,0.3,0.9,0.1);
TL=LinRegSlope(MA(C, DTL),2);
Vlp=Param("Volume lookback period",30,20,300,10);
Vrg=MA(V,Vlp);
St = StDev(Vrg,Vlp);
Vp3 = Vrg + 3*st;
Vp2 = Vrg + 2*st;;
Vp1 = Vrg + 1*st;;
Vn1 = Vrg -1*st;
Vn2 = Vrg -2*st;
rg=(H-L);
arg=Wilders(rg,30);
wrb=rg>(wbf*arg);
nrb=rg<(nbf*arg);
Vl=V<Ref(V,-1) AND V<Ref(V,-2);
upbar=C>Ref(C,-1);
dnbar=C<Ref(C,-1);
Vh=V>Ref(V,-1) AND Ref(V,-1)>Ref(V,-2);
Cloc=C-L;
x=rg/Cloc;
x1=IIf(Cloc==0,arg,x);
Vb=V>Vrg OR V>Ref(V,-1);
ucls=x1<2;
dcls=x1>2;
mcls=x1<2.2 AND x1>1.8 ;
Vlcls=x1>4;
Vhcls=x1<1.35;
j=MA(C,5);
TLL=LinRegSlope(j,40) ;
Tlm=LinRegSlope(j,15) ;
tls=LinRegSlope(j,5);
mp=(H+L)/2;
Pp1=Param("NumberOfDays",30,1,200,1);
Pp2=Param("VolOfDays",15,1,200,1);
numDays = Pp1;
dwWideSpread = 1.8;
dwNarrowSpread = 0.8;
dwSpreadMiddle = 0.5;
dwHighClose = 0.7;
dwLowClose = 0.3;
volNumDays = Pp2;
dwUltraHighVol = 2;
dwVeryHighVol = 1.75; // was 1.8
dwHighVol = 1.75; // was 1.8
dwmoderateVol = 1.10; // was 1.8
dwLowVol = 0.75; // was 0.8
////////////////////////////////////////////////////////////////////////////////////
// Classify each bar...
///////////////////////////////////////////////////////////////////////////////////
upBar = C > Ref(C,-1);
downBar = C < Ref(C,-1);
spread = H-L;
avgRange = Sum(spread, numDays) / numDays;
wideRange = spread >= (dwWideSpread * avgRange);
narrowRange = spread <= (dwNarrowSpread * avgRange);
testHighClose = L + (spread * dwHighClose);
testLowClose = L + (spread * dwLowClose);
testCloseMiddle = L + (spread * dwSpreadMiddle);
upClose = C > testHighClose;
downClose = C < testLowClose;
middleClose = C >= testLowClose AND C <= testHighClose;
avgVolume = EMA(V, volNumDays);
highVolume = V > (avgVolume * dwHighVol);
moderateVol= V > (avgVolume * dwmoderateVol);
veryHighVolume = V > (avgVolume * dwVeryHighVol);
ultraHighVolume = V > (avgVolume * dwUltraHighVol);
LowVolume = V < (avgVolume * dwLowVol);
////////////////////////////////////////////////////////////////////////////////////
// direction and title
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
//
// Basic patterns...
//
////////////////////////////////////////////////////////////////////////////////////
upThrustBar = downClose AND H > Ref(H,-1) AND (C == L) AND downClose AND (NOT narrowRange);
noDemandBar = narrowRange AND LowVolume AND upBar AND (NOT upClose);
//noDemandBar = narrowRange AND LowVolume AND upBar AND (V < Ref(V,-1)) AND (V < Ref(V,-2));
noSupplyBar = narrowRange AND LowVolume AND downBar AND (V < Ref(V,-1)) AND (V < Ref(V,-2));
absorption = Ref(downbar, -1) AND Ref(highVolume, -1) AND upBar;
support = Ref(downBar,-1) AND (NOT Ref(downClose,-1)) AND Ref(highVolume,-1) AND upBar;
stoppingVolume = Ref(downBar,-1) AND Ref(highVolume,-1) AND C > testCloseMiddle AND (NOT downBar);
bullishsign=moderateVol+UpThrustBar;//OR moderateVol+upBar;
//rallyEnd = (Ref(highVolume,-1) AND Ref(upBar,-1) AND wideRange AND downBar) OR
// (narrowRange AND highVolume AND H > Ref(HHV(H, 250), -1));
////////////////////////////////////////////////////////////////////////////////////
//
// Strength and Weakness
//
////////////////////////////////////////////////////////////////////////////////////
weakness = upThrustBar OR noDemandBar OR (narrowRange AND (H > Ref(H,-1)) AND highVolume) OR (Ref(highVolume,-1) AND Ref(upBar,-1) AND downBar AND (H < Ref(H,-1)));
/////////////////////////////////////////////////////////////////////////////////////////////
C1 = Ref(C, -1);
uc = C > C1; dc = C <= C1;
ud = C > O; dd = C <= O;
green = 1; blue = 2; yellow = 3; red = 4; white = 5;
VType = IIf(ud, IIf(uc, green, yellow), IIf(dd,IIf(dc, red, blue), white));
/* green volume: up-day and up-close*/
gv = IIf(VType == green, V, 0);
/* yellow volume: up-day but down-close */
yv = IIf(VType == yellow, V, 0);
/* red volume: down-day and down-close */
rv = IIf(VType == red, V, 0);
/* blue volume: down-day but up-close */
bv = IIf(VType == blue, V, 0);
uv = gv + bv; uv1 = Ref(uv, -1); /* up volume */
dv = rv + yv; dv1 = Ref(dv, -1); /* down volume */
/* create moving average period parameters */
VolPer = Param("Adjust Vol. MA per.", 34, 1, 255, 1);
ConvPer = Param("Adjust Conv. MA per.", 9, 1, 255, 1);
/* create triple exponential moving avearges of separate up and down volume
moving averages */
MAuv = TEMA(uv, VolPer ); mauv1 = Ref(mauv, -1);
MAdv = TEMA(dv, VolPer ); madv1 = Ref(madv, -1);
MAtv = TEMA(V, VolPer );//total volume
/* Switch for Horizontal lines indicating current level of positive and
negative volume for ease in comparing to past highs/lows - toggle via
parmameter window */
OscillatorOnly = Param("Show Oscillator Only", 0, 0, 1, 1);
CompareBullVolume = Param("Show Bull Level", 1, 0, 1, 1);
if(CompareBullvolume AND !OscillatorOnly){
//Plot(SelectedValue(MAuv), "", colorGreen, styleLine);
}
CompareBearVolume = Param("Show Bear Level", 1, 0, 1, 1);
if(CompareBearVolume AND !OscillatorOnly){
//Plot(SelectedValue(MAdv), "", colorRed, styleLine);
}
/* Volume Segment Switches - toggle via parameter window */
bullvolume = Param("Show Bull Volume", 1, 0, 1, 1);
bearvolume = Param("Show Bear Volume", 1, 0, 1, 1);
totalvolume = Param("Show Total Volume", 1, 0, 1, 1);
/* plot volume lines and histograms if toggled on: */
bearToFront = Param("Show Bear Vol in Front", 0, 0, 1, 1);
if(bearToFront AND !OscillatorOnly){
//Plot(MAdv, "", colorRed, styleHistogram|styleNoLabel);
}
if(bullvolume AND !OscillatorOnly){
//Plot(MAuv, "Average Bull Volume", colorGreen, styleHistogram|styleNoLabel);
}
if(bearvolume AND !OscillatorOnly){
//Plot(MAdv, "Average Bear Volume", colorRed, styleHistogram|styleNoLabel);
}
if(totalVolume AND !OscillatorOnly){
//Plot(MAtv, "Total Volume", colorWhite, styleHistogram|styleNoLabel);
//Plot(MAtv, "", colorWhite, styleLine);
}
if(bullvolume AND !OscillatorOnly){
//Plot(MAuv, "", colorGreen, styleLine);
}
if(bearvolume AND !OscillatorOnly){
//Plot(MAdv, "", colorRed, styleLine);
}
/* better visibility of zero line: */
//Plot(0, "", colorBlue, 1);
/* Rise/Fall Convergence variables: */
Converge = (TEMA(MAuv - MAdv, ConvPer));
Converge1 = Ref(Converge, -1);
ConvergeUp = Converge > Converge1;
ConvergeOver = Converge > 0;
rising = ConvergeUp AND ConvergeOver;
falling = !ConvergeUp AND ConvergeOver;
/* Rise/Fall Convergence Oscillator Switch - toggle via parameter window - (provides a better view of resulting combination of battling bull/bear volume forces) */
convergenceOscillator = Param("Show Oscillator", 0, 0, 1, 1);
if(convergenceOscillator OR OscillatorOnly){
//Plot(Converge, "Bull/Bear Volume Convergence/Divergence", colorViolet,1|styleLeftAxisScale|styleNoLabel|styleThick);
//Plot(0,"", colorYellow, 1|styleLeftAxisScale|styleNoLabel);
}
/********************************************************
Convergence Rise/Fall Shadows:
(provides a more easily visible display of rising and falling bull/bear volume convergence) - toggle via parameter window
-posiitive Volume exceeding negative Volume: Light shadow
-negative volume exceeding positive volume: dark shadow
-if you use standard gray background - best shadows are:
-my greys: 14 = (216, 216, 216); 15 = (168, 168, 168));
-best substitute? using AB color constants?
-light: colorpalegreen; dark: colorRose;?
-(depends on your color scheme - customize to your tastes)
**********************************************************/
/* uncomment if you use my custom color greys: */
riseFallColor = IIf(rising, 14,15); //my custom shadow greys
/* comment out if you use my custom color gray shadows: */
/* riseFallColor = IIf(rising, colorPaleGreen,colorRose); */
/* Rise/Fall Convergence Plot Switch - toggle via parameter window */
riseFallShadows = Param("Show RiseFallShadows", 0, 0, 1, 1);
if(riseFallShadows){
//Plot(IIf(rising OR falling, 1, 0), "", riseFallColor,styleHistogram|styleArea|styleOwnScale|styleNoLabel);
}
_SECTION_END();
_SECTION_BEGIN("Pivot Finder");
/***********************************
Code to automatically identify pivots
***********************************/
// -- what will be our lookback range for the hh and ll?
farback=Param("How Far back to go",100,50,5000,10);
nBars = Param("Number of bars", 12, 5, 40);
//"BIdxJJJ = " + BarIndex() + "\n" + "OGGGGGGGGGGG = " + O + "\n"+"H = "+ H + "\n"+"L = " + L + "\n"+"C " ;
GraphXSpace=7;
// -- Create 0-initialized arrays the size of barcount
aHPivs = H - H;
aLPivs = L - L;
// -- More for future use, not necessary for basic plotting
aHPivHighs = H - H;
aLPivLows = L - L;
aHPivIdxs = H - H;
aLPivIdxs = L - L;
nHPivs = 0;
nLPivs = 0;
lastHPIdx = 0;
lastLPIdx = 0;
lastHPH = 0;
lastLPL = 0;
curPivBarIdx = 0;
aHHVBars = HHVBars(H, nBars);
aLLVBars = LLVBars(L, nBars);
aHHV = HHV(H, nBars);
aLLV = LLV(L, nBars);
aVisBars = Status("barvisible");
nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));
_TRACE("Last visible bar: " + nLastVisBar);
// -- Initialize value of curTrend
curBar = (BarCount-1);
curTrend = "";
if (aLLVBars[curBar] <
aHHVBars[curBar]) {
curTrend = "D";
}
else {
curTrend = "U";
}
if (BarCount > farback)
{
for (i=0; i<farback; i++) {
curBar = (BarCount - 1) - i;
// -- Have we identified a pivot? If trend is down...
if (aLLVBars[curBar] < aHHVBars[curBar]) {
// ... and had been up, this is a trend change
if (curTrend == "U") {
curTrend = "D";
// -- Capture pivot information
curPivBarIdx = curBar - aLLVBars[curBar];
aLPivs[curPivBarIdx] = 1;
aLPivLows[nLPivs] = L[curPivBarIdx];
aLPivIdxs[nLPivs] = curPivBarIdx;
nLPivs++;
}
// -- or current trend is up
} else {
if (curTrend == "D") {
curTrend = "U";
curPivBarIdx = curBar - aHHVBars[curBar];
aHPivs[curPivBarIdx] = 1;
aHPivHighs[nHPivs] = H[curPivBarIdx];
aHPivIdxs[nHPivs] = curPivBarIdx;
nHPivs++;
}
// -- If curTrend is up...else...
}
// -- loop through bars
}
}
curBar = (BarCount-1);
candIdx = 0;
candPrc = 0;
lastLPIdx = aLPivIdxs[0];
lastLPL = aLPivLows[0];
lastHPIdx = aHPivIdxs[0];
lastHPH = aHPivHighs[0];
if (lastLPIdx > lastHPIdx) {
// -- Bar and price info for candidate pivot
candIdx = curBar - aHHVBars[curBar];
candPrc = aHHV[curBar];
if (
lastHPH < candPrc AND
candIdx > lastLPIdx AND
candIdx < curBar) {
// -- OK, we'll add this as a pivot...
aHPivs[candIdx] = 1;
// ...and then rearrange elements in the
// pivot information arrays
for (j=0; j<nHPivs; j++) {
aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-
(j+1)];
aHPivIdxs[nHPivs-j] = aHPivIdxs[nHPivs-(j+1)];
}
aHPivHighs[0] = candPrc ;
aHPivIdxs[0] = candIdx;
nHPivs++;
}
} else {
// -- Bar and price info for candidate pivot
candIdx = curBar - aLLVBars[curBar];
candPrc = aLLV[curBar];
if (
lastLPL > candPrc AND
candIdx > lastHPIdx AND
candIdx < curBar) {
// -- OK, we'll add this as a pivot...
aLPivs[candIdx] = 1;
for (j=0; j<nLPivs; j++) {
aLPivLows[nLPivs-j] = aLPivLows[nLPivs-(j+1)];
aLPivIdxs[nLPivs-j] = aLPivIdxs[nLPivs-(j+1)];
}
aLPivLows[0] = candPrc;
aLPivIdxs[0] = candIdx;
nLPivs++;
}
}
//PlotShapes(IIf(aHPivs==1,shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-15);
//PlotShapes(IIf(aLPivs==1,shapeUpArrow , shapeNone), ColorRGB(168,255,0), 0, Low, Offset=-15);
//printf("\n Buuuy pivotss %g", aLPivs);
//printf("\n Seel pivotss %g \n",aHPivs);
IIf( (aHPivs==1 AND aLPivs==0),PIVOT_SELL = 5, PIVOT_SELL = 0 );
IIf( aLPivs==1 AND aHPivs==0, PIVOT_BUY = 0, PIVOT_BUY = 5 );
PIVOT_BUY = IIf(aLPivs==1, 5, 0);
PIVOT_SELL = IIf(aHPivs==1, 5, 0);
//printf("\n Buy pivots %g", PIVOT_BUY);
//printf("\n Sell pivots %g \n",PIVOT_SELL);
PIVOT_status = WriteIf(PIVOT_BUY,"Buy["+PIVOT_BUY+"]",WriteIf(PIVOT_SELL,"Sell["+PIVOT_SELL+"]","NA"));
PIVOT_col = IIf (PIVOT_BUY,colorGreen, IIf (PIVOT_SELL,colorRed,colorLightGrey));
_SECTION_END();
/**********************************************************
/ADX
***********************************************************/
range = Param("Range",14,3,60,1);
px = PDI(range);
nx = MDI(range);
ax = ADX(range);
Line_Control = 20;
up_adx = Ref(ADX(range),-1) < ADX(range);
dw_adx = Ref(ADX(range),-1) > ADX(range);
// ADX Trends
Notrend = ADX(range) < 20;
ModerateTrend = ADX(range) >= 20 AND ADX(range) < 40 AND up_adx ;
StrongTrend = ADX(range) >= 40 AND ADX(range) < 60 AND up_adx ;
VeryStrongTrend = ADX(range) >= 60 AND ADX(range) < 80 AND up_adx ;
ExtremelyStrongTrend = ADX(range) >= 80 AND up_adx ;
// Buy Conditions
bcon1 = Cross(px,ax) AND nx < px AND ax > Ref(ax,-1);
scon1 = Cross(nx,ax) AND px < nx AND ax > Ref(ax,-1);
adbuy = ax < 20 AND ax > Ref(ax,-1) AND ( Cross(px,nx) OR nx < px) ;
adsell = ax < 20 AND ax > Ref(ax,-1) AND ( Cross(nx,px) OR nx > px) ;
adbuy1 = Cross(px,ax) AND nx < px AND ax > Ref(ax,-1) AND px > ax;
adsell1 = Cross(nx,ax) AND nx > px AND ax > Ref(ax,-1) AND nx > ax;
BUY_ADX = bcon1 + adbuy + adbuy1;
SELL_ADX = scon1 + adsell + adsell1;
ADX_status = WriteIf(BUY_ADX,"Buy["+BUY_ADX+"]",WriteIf(SELL_ADX,"Sell["+SELL_ADX+"]","NA"));
ADX_col = IIf (BUY_ADX,colorGreen, IIf (SELL_ADX,colorRed,colorLightGrey));
/**********************************************************
/MACD Cross
***********************************************************/
_SECTION_BEGIN("MACD");
MACD_TOGGLE = ParamToggle("Plot MACD","Off|On",0);
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
m1 = MACD(r1, r2);
s1 = Signal(r1,r2,r3);
difference = m1-s1;
mycolor=IIf(m1<0 AND m1>s1,51,IIf(m1>0 AND m1>s1,colorBrightGreen,IIf(m1>0 AND m1<s1,colorLightOrange,colorRed)));
// **********************
//MACD crossing zero
B_MACD_0 = Cross(MACD(r1, r2),0);
S_MACD_0 = Cross(0,MACD(r1, r2));
// **********************
//Bullish - Bearish MACD crossing signal above zero or below zero plane
BULL_CROSS_ABOVE_ZERO = Cross (MACD(r1, r2),Signal(r1,r2,r3)) AND MACD(r1, r2) > 0;
BEAR_CROSS_ABOVE_ZERO = Cross (Signal(r1,r2,r3),MACD(r1, r2)) AND MACD(r1, r2) > 0;
// **********************
//bELOW ZERO Bullish - Bearish MACD crossing signal above zero or below zero plane
BULL_CROSS_BELOW_ZERO = Cross (MACD(r1, r2),Signal(r1,r2,r3)) AND MACD(r1, r2)<0;
BEAR_CROSS_BELOW_ZERO = Cross(Signal(r1,r2,r3),MACD(r1, r2)) AND MACD(r1, r2)<0;
// **********************
//Zero line reject ZLR
BEAR_ZLR = BarsSince(B_MACD_0);
BEAR_ZLR1 = (BEAR_ZLR < 6) AND (S_MACD_0);
BULL_ZLR = BarsSince(S_MACD_0);
BULL_ZLR1 = (BULL_ZLR < 6) AND (B_MACD_0);
// **********************
//HOOKS
BULL_HOOK1 = BarsSince(BEAR_CROSS_ABOVE_ZERO);
BULL_HOOK = (BULL_HOOK1<6) AND BULL_CROSS_ABOVE_ZERO ;
BEAR_HOOK1 = BarsSince(BULL_CROSS_ABOVE_ZERO);
BEAR_HOOK = (BEAR_HOOK1<6) AND BEAR_CROSS_ABOVE_ZERO ;
BUY_MACD = B_MACD_0 + BULL_CROSS_ABOVE_ZERO + BULL_CROSS_BELOW_ZERO + BULL_ZLR1 + BULL_HOOK;
SELL_MACD = S_MACD_0 + BEAR_CROSS_ABOVE_ZERO + BEAR_CROSS_BELOW_ZERO + BEAR_ZLR1 + BEAR_HOOK;
_SECTION_END();
BUY_MACD = B_MACD_0 + BULL_CROSS_ABOVE_ZERO + BULL_CROSS_BELOW_ZERO + BULL_ZLR1 + BULL_HOOK ;
SELL_MACD = S_MACD_0 + BEAR_CROSS_ABOVE_ZERO + BEAR_CROSS_BELOW_ZERO + BEAR_ZLR1 + BEAR_HOOK ;
MACD_status = WriteIf(BUY_MACD,"Buy["+BUY_MACD+"]",WriteIf(SELL_MACD,"Sell["+SELL_MACD+"]","NA"));
MACD_col = IIf (BUY_MACD,colorGreen, IIf (SELL_MACD,colorRed,colorLightGrey));
/**************************************************
Stochastics
***************************************************/
_SECTION_BEGIN("STOCHASTICS");
STOC_TOGGLE = ParamToggle("Plot STOCHASTICS","Off|On",0);
SP = Param( "Periods", 10, 1, 200, 1 );
Ksmooth = Param( "%K avg", 5, 1, 200, 1 );
Dsmooth = Param( "%D avg", 5, 1, 200, 1 );
StochDval = StochD( SP , Ksmooth, DSmooth );
StochKval = StochK( SP , Ksmooth);
Overbought = 80;
Oversold = 20;
/*
if(STOC_TOGGLE==1)
{
GraphX = 5;
Plot( StochD( SP , Ksmooth, DSmooth), _DEFAULT_NAME(), ParamColor( "ColorD", colorTurquoise ), ParamStyle("Style") );
Plot( StochK( SP , Ksmooth), _DEFAULT_NAME(), ParamColor( "ColorK", colorPaleGreen ), ParamStyle("Style") );
Plot(Overbought,"Overbought Level",colorRed);
Plot(Oversold,"Oversold Level",colorGreen);
}
*/
StochBuy = Cross(StochK(SP,Ksmooth), StochD(SP,Ksmooth, DSmooth)) AND (StochD(SP,Ksmooth, DSmooth) > 20) AND (StochK(SP,Ksmooth) > 20) AND (StochD(SP,Ksmooth, DSmooth) < 80) AND (StochK(SP,Ksmooth) < 80);
StochSell = Cross (StochD(SP,Ksmooth, DSmooth), StochK(SP,Ksmooth)) AND (StochD(SP,Ksmooth, DSmooth) > 20) AND (StochK(SP,Ksmooth) > 20) AND (StochD(SP,Ksmooth, DSmooth) < 80) AND (StochK(SP,Ksmooth) < 80);
StochStrongBuy = Cross(StochK(SP,Ksmooth),StochD(SP,Ksmooth, DSmooth)) AND (StochD(SP,Ksmooth, DSmooth) < 20) AND (StochK(SP,Ksmooth) < 20) ;
StochStrongSell = Cross (StochD(SP,Ksmooth,DSmooth), StochK(SP , Ksmooth)) AND (StochD(SP,Ksmooth, DSmooth) > 80) AND (StochK(SP,Ksmooth) > 80);
BUY_STOCH = StochBuy + StochStrongBuy;
SELL_STOCH = StochSell + StochStrongSell;
printf("Sto %g",BUY_STOCH);
_SECTION_END();
STOCH_status = WriteIf(BUY_STOCH,"Buy["+BUY_STOCH+"]",WriteIf(SELL_STOCH,"Sell["+SELL_STOCH+"]","NA"));
STOCH_col = IIf (BUY_STOCH,colorGreen, IIf (SELL_STOCH,colorRed,colorLightGrey));
/**************************************************
TREND DETECTOR
***************************************************/
_SECTION_BEGIN("Trend Detector");
TREND_TOGGLE = ParamToggle("Plot Trend","Off|On",0);
A = (H+C+L)/3;
B=MA(A,5)-EMA(A,34);
D = EMA(A,34)-MA(A,5);
Bcolor=IIf(B>D,25,39);
Dcolor=IIf(D<B,25,39);
Up = B > D;
down = B < D;
TREND_B = Cross(B,D);
TREND_S = Cross(D,B);
if(TREND_TOGGLE==1)
{
Plot(B,"B ",Bcolor,styleLine|styleThick);
Plot(D,"D ",Dcolor,styleLine|styleThick);
Plot(B,"",Bcolor,styleHistogram|styleThick);
Plot(D,"",Dcolor,styleHistogram|styleThick);
Plot(0,"",colorWhite,styleLine);
PlotShapes(IIf(TREND_S, shapeHollowDownArrow , shapeNone), colorRed,0,0,-8);
PlotShapes(IIf(TREND_B, shapeHollowUpArrow , shapeNone), colorGreen,0,0,-8);
}
_SECTION_END();
TREND_status = WriteIf(TREND_B,"Buy",WriteIf(TREND_S ,"Sell","NA"));
TREND_col = IIf (TREND_B,colorGreen, IIf (TREND_S ,colorRed,colorLightGrey));
/**************************************************
RSI
***************************************************/
_SECTION_BEGIN("RSI");
Rperiods = Param( "Periods", 14, 1, 200, 1 );
OB = Param("OverBrought Line",70,70,100,1);
OS = Param("OverSold Line",30,20,40,1);
CentreRSI = 50;
Overbought = OB;
Oversold = OS;
RSI_PERIODS = Prec(RSI( Rperiods),1);
//******* RSI Cross 30 or 70**//
B_RSI = RSI_CROSS_30 = Cross(RSI_PERIODS,OS);
S_RSI = RSI_CROSS_70 = Cross(OB,RSI_PERIODS);
//******* RSI < 30 or > 70**//
RSI_BELOW_30 = RSI_PERIODS < OS ;
RSI_ABOVE_70 = RSI_PERIODS > OB ;
//******* RSI > OR < IN LAST 14 DAYS***//
RSI_14_GREATEST = RSI_PERIODS>=HHV( RSI_PERIODS, 14);
RSI_14_LOWEST = RSI_PERIODS<=LLV( RSI_PERIODS, 14);
//******* RSI DIVERGENCE***//
RSI_BEAR_DIV = Close >= HHV( Close, 14 ) AND RSI_PERIODS < HHV( RSI_PERIODS, 14 );
RSI_BULL_DIV = RSI_PERIODS >= HHV( RSI_PERIODS, 14 ) AND Close < HHV( Close, 14 );
RSI_BULL_DIV1 = Close <= LLV( Close, 14 ) AND RSI_PERIODS > LLV(RSI_PERIODS, 14 );
RSI_BEAR_DIV1 = RSI_PERIODS <= LLV( RSI_PERIODS, 14) AND Close > LLV(Close,14);
/*****/////////
RSI_BUY = B_RSI ;
RSI_SELL =S_RSI ;
_SECTION_END();
RSI_status = WriteIf(RSI_BUY,"Buy["+RSI_BUY+"]",WriteIf(RSI_SELL,"Sell["+RSI_SELL+"]","NA"));
RSI_col = IIf (RSI_BUY,colorGreen, IIf (RSI_SELL,colorRed,colorLightGrey));
/**************************************************
OBV
***************************************************/
_SECTION_BEGIN("OBV");
MA_OBV_Period = Param("OBV_MA Period",10,10,21,1);
/***********OBV CROSS MA************/
OBV_BUY = Cross(OBV(),MA(OBV(),MA_OBV_Period));
OBV_SELL = Cross(MA(OBV(),MA_OBV_Period),OBV());
_SECTION_END();
OBV_status = WriteIf(OBV_BUY,"Buy",WriteIf(OBV_SELL,"Sell","NA"));
OBV_col = IIf (OBV_BUY,colorGreen, IIf (OBV_SELL,colorRed,colorLightGrey));
/**************************************************
TSV = SIMILAR TO WORDEN
***************************************************/
_SECTION_BEGIN("TSV");
Period = Param("Period for FVE", 22, 5, 80, 1 );
Coeff = Param("Coeff for Cutoff", 0.1, 0, 2, 0.01 );
intra=log(H)-log(L);
Vintra = StDev(intra, period );
inter = log(Avg)-log(Ref(Avg,-1));
Vinter = StDev(inter,period);
Cutoff = Coeff * (Vinter+Vintra)*C;
MF = C- (H+L)/2 + Avg - Ref( Avg, -1 );
VC = IIf( MF > Cutoff, V,
IIf( MF < -Cutoff, -V, 0 ));
FVE = 100 * Sum( VC, Period )/(MA( V, Period ) * Period );
// Momemtum Indicator by William Blau
TSI = 100 * ( EMA( EMA( C - Ref( C, -1 ) ,25 ) ,13)
/ EMA( EMA( abs( C - Ref( C, -1) ),25 ), 13 ) );
TSI_BUY = Cross(TSI,EMA(TSI,7));
TSI_SELL = Cross(EMA(TSI,7),TSI);
_SECTION_END();
TSI_status = WriteIf(TSI_BUY,"Buy",WriteIf(TSI_SELL,"Sell","NA"));
TSI_col = IIf (TSI_BUY,colorGreen, IIf (TSI_SELL,colorRed,colorLightGrey));
/**************************************************
TRIX
***************************************************/
_SECTION_BEGIN("TRIX");
// TRIX - 15 Periods, 9 Signal Periods
tPeriods = Param("Periods", 15, 2, 100, 1 );
tSig = Param("Signal", 9, 2, 100, 1);
Zero = 0;
TRIX_VAL = Trix(tPeriods);
SIG_TRIX = EMA(Trix(tPeriods),tSig);
/***********TRIX & Signal Line cross ************/
TRIX_SIGNAL_BUY = Cross(TRIX_VAL, SIG_TRIX) AND TRIX_VAL < 0;
TRIX_SIGNAL_SELL = Cross(SIG_TRIX, TRIX_VAL)AND TRIX_VAL > 0;
/***********TRIX & Zero Line cross ************/
TRIX_ZERO_BUY = Cross(TRIX_VAL, Zero);
TRIX_ZERO_SELL = Cross(Zero, TRIX_VAL);
TRIX_BUY = TRIX_SIGNAL_BUY + TRIX_ZERO_BUY;
TRIX_SELL = TRIX_SIGNAL_SELL + TRIX_ZERO_SELL;
_SECTION_END();
TRIX_status = WriteIf(TRIX_BUY,"Buy",WriteIf(TRIX_SELL,"Sell","NA"));
TRIX_col = IIf (TRIX_BUY,colorGreen, IIf (TRIX_SELL,colorRed,colorLightGrey));
/************************************************
Gap
*************************************************/
GAP_UP = GapUp();
GAP_DW = GapDown();
GAP_status = WriteIf(GAP_UP,"Buy",WriteIf(GAP_DW ,"Sell","NA"));
GAP_col = IIf (GAP_UP,colorGreen, IIf (GAP_DW ,colorRed,colorLightGrey));
/************************************************
Total of Bullish/Bearish
*************************************************/
Total_Buy = PIVOT_BUY + BUY_ADX + BUY_MACD + BUY_STOCH+ TREND_B + GAP_UP + RSI_BUY + OBV_BUY + TSI_BUY + TRIX_BUY;
Total_Sell = PIVOT_SELL + SELL_ADX + SELL_MACD + SELL_STOCH + TREND_S + GAP_DW + RSI_SELL + OBV_SELL +TSI_SELL+TRIX_SELL;
printf("B OIVOTS %g\n",PIVOT_BUY);
printf("SELL PIVOTS %g\n",PIVOT_SELL);
printf("BUY GAP %g\n",TREND_B);
printf("BUY TREND %g\n",GAP_UP);
printf("BUY RSI %g\n",B_RSI + RSI_14_GREATEST + RSI_BULL_DIV1 + RSI_BULL_DIV);
_SECTION_BEGIN("Chart Settings");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(ParamColor("Outer Panel",colorPaleBlue));
SetChartBkGradientFill(ParamColor("Upper Chart",colorDarkGrey),ParamColor("Lower Chart",colorDarkGrey));
GraphXSpace=Param("GraphXSpace",10,0,100,1);
dec = (Param("Decimals",2,0,7,1)/10)+1;
bi = BarIndex();
Lbi = LastValue(BarIndex());
sbi = SelectedValue(bi);
x1= BarCount-1;
Title = EncodeColor(55)+ Name() + " " + EncodeColor(32) + Date() + " " + EncodeColor(5) + "{{INTERVAL}} " +
EncodeColor(55)+ " Open = "+ EncodeColor(52)+ WriteVal(O,dec) +
EncodeColor(55)+ " High = "+ EncodeColor(5) + WriteVal(H,dec) +
EncodeColor(55)+ " Low = "+ EncodeColor(32)+ WriteVal(L,dec) +
EncodeColor(55)+ " Close = "+ EncodeColor(52)+ WriteVal(C,dec)+
EncodeColor(55)+ " Volume = "+ EncodeColor(52)+ WriteVal(V,1) +
"\n" + EncodeColor(colorYellow) + "----------------------------------------"
+ "\n"+EncodeColor(colorGold)+ " Analysis "
+"\n"+EncodeColor(colorYellow) +"----------------------------------------"
///// PIVOTS
+ "\n"
+EncodeColor(colorWhite)+"PIVOTS = " +
WriteIf (aLPivs,EncodeColor(ColorRGB(168,255,0))+" BUY("+PIVOT_BUY+")",WriteIf (aHPivs,EncodeColor(colorRed)+ " SELL("+PIVOT_SELL+")","Neutral"))
///// ADX
+ "\n"+EncodeColor(colorWhite)+"ADX = " +
WriteIf (BUY_ADX,EncodeColor(ColorRGB(168,255,0))+"BUY("+BUY_ADX+")",WriteIf (SELL_ADX,EncodeColor(colorRed)+ " SELL("+SELL_ADX+")","Neutral"))
///// MACD
+ "\n" +EncodeColor(colorWhite)+"MACD "+"["+r1+"]"+" " +"["+r2+"]"+" " +"["+r3+"] = " +
WriteIf (BUY_MACD,EncodeColor(ColorRGB(168,255,0))+"BUY("+BUY_MACD+")",WriteIf (SELL_MACD,EncodeColor(colorRed)+ "SELL("+SELL_MACD+")","Neutral"))
///// STOChASTICS
+"\n"+EncodeColor(colorWhite)+"Stochastics = "
+ WriteIf(BUY_STOCH,EncodeColor(ColorRGB(168,255,0))+"BUY ("+BUY_STOCH+")",WriteIf(SELL_STOCH,EncodeColor(colorRed)+"SELL("+SELL_STOCH+")","Neutral"))
///// RSI
+"\n" + EncodeColor(colorWhite)+"RSI"+"("+Rperiods+") = "
+WriteIf(B_RSI,EncodeColor(ColorRGB(168,255,0))+"BUY("+RSI_BUY+")",WriteIf (S_RSI,EncodeColor(colorRed)+"SELL("+RSI_SELL+")","Neutral"))
///// OBV
+"\n" +EncodeColor(colorWhite)+"OBV = "+
WriteIf(OBV_BUY,EncodeColor(ColorRGB(168,255,0))+"BUY(1)",WriteIf(OBV_SELL,EncodeColor(colorRed)+"SELL(1)",""))+
WriteIf(NOT OBV_BUY AND NOT OBV_SELL,"No Cross","")
///// TSV
+"\n"
+EncodeColor(colorWhite)+"TSV = " +
WriteIf(TSI_BUY,EncodeColor(ColorRGB(168,255,0))+"BUY(1)",
WriteIf(TSI_SELL,EncodeColor(colorRed)+"SELL(1)",""))+
WriteIf(NOT TSI_BUY AND NOT TSI_SELL,EncodeColor(colorAqua)+"NA","")
///// TRIX
+"\n"
+EncodeColor(colorWhite)+"TRIX "+ "("+tPeriods+") "+"(" +tSig+ ") = "
+EncodeColor(ColorRGB(168,255,0))+
WriteIf (TRIX_BUY, "BUY ("+TRIX_BUY+")","")
+EncodeColor(colorRed)+
WriteIf (TRIX_SELL, "SELL("+TRIX_SELL+")","")
+EncodeColor(colorAqua)+
WriteIf (NOT TRIX_SELL AND NOT TRIX_BUY, "No Cross","")
///// TREND
+"\n" +EncodeColor(colorWhite)+"Trend = "
+WriteIf(Up AND NOT TREND_B,EncodeColor(ColorRGB(168,255,0))+"Up ",WriteIf(Up AND TREND_B,EncodeColor(colorBrightGreen)+ "BUY(1)",
WriteIf(Down AND NOT TREND_S,EncodeColor(colorRed)+"Down",WriteIf(Down AND TREND_S,EncodeColor(colorRed)+"SELL(1)","."))))
///// GAPS
+"\n"+EncodeColor(colorWhite)+"GAP = "
+WriteIf(GAP_UP,EncodeColor(ColorRGB(168,255,0))+"UP (1)",WriteIf(GAP_DW,EncodeColor(colorRed)+"DOWN (1)", EncodeColor(colorAqua)+"Neutral"))
+"\n"+EncodeColor(colorPink) +"======================="
+"\n"+EncodeColor((ColorRGB(242,157,255)))+"BUY = "+EncodeColor(colorYellow)+Total_Buy
+"\n"+EncodeColor((ColorRGB(242,157,255)))+"SELL = "+EncodeColor(colorYellow)+Total_Sell
+"\n"+EncodeColor(colorPink) +"----------------------------------------"
+"\n"+EncodeColor(07)+"Volume: "+WriteIf(V>Vp2,EncodeColor(colorLime)+"Very High",WriteIf(V>Vp1,EncodeColor(colorLime)+" High",WriteIf(V>Vrg,EncodeColor(colorLime)+"Above Average",
WriteIf(V<Vrg AND V>Vn1,EncodeColor(colorRed)+"Less than Average",WriteIf(V<Vn1,EncodeColor(colorRed)+"Low","")))))
+"\n"+EncodeColor(colorYellow)+"Spread: "+WriteIf(rg >(arg*2),EncodeColor(colorLime)+" Wide",WriteIf(rg>arg,EncodeColor(colorLime)+" Above Average",EncodeColor(colorRed)+" Narrow"))
+"\n"+(EncodeColor(colorYellow)+"Close: ")+WriteIf(Vhcls,EncodeColor(colorLime)+"Very High",WriteIf(ucls,EncodeColor(colorLime)+"High",WriteIf(mcls,EncodeColor(colorYellow)+"Mid",
WriteIf(dcls,EncodeColor(colorRed)+"Down","Very Low"))))
+"\n"+EncodeColor(colorYellow) + "Zone : " +WriteIf(rising , EncodeColor(colorBrightGreen) + "Accumulation",WriteIf(falling , EncodeColor(colorCustom12) + "Distirbution",EncodeColor(colorAqua) + "Flat")) + " "
+"\n"+EncodeColor(colorYellow) + "Status : " +
WriteIf(Weakness , EncodeColor(colorRed) + "Weak",
WriteIf(stoppingVolume , EncodeColor(colorCustom12) + "StoppingVol",
WriteIf(noSupplyBar , EncodeColor(colorLightOrange) + "NoSupply",
WriteIf(support , EncodeColor(colorLightBlue) + "SupportVol",
WriteIf(noDemandBar , EncodeColor(colorPink) + "NoDemand",
WriteIf(absorption, EncodeColor(colorSkyblue) + "Absorption",
WriteIf(upThrustBar, EncodeColor(colorBlue) + "Upthrust",
WriteIf(bullishsign, EncodeColor(colorPaleGreen) + "STRONG",
EncodeColor(colorTan) + "Neutral")))))))) + " "
+"\n"+EncodeColor(colorPink)+"----------------------------------------";
_SECTION_END();
//========================================================================
SetChartOptions(2,chartShowArrows|chartShowDates|chartWrapTitle);
SetChartOptions(0,chartShowArrows|chartShowDates);
//GfxGradientRect( 180, 30, 1759, 735, ColorRGB(40,40,40), ColorRGB(0,0,40) );
GfxSetOverlayMode(1);
//GfxSelectPen( ColorRGB(150,0,0), 1 );
GfxSelectSolidBrush( ColorRGB(0,0,40) );
//GfxRectangle=( 0,750, 1807, 35 );
//GfxSelectPen( ColorRGB(150,0,0), 2 );
GfxSelectSolidBrush( ColorRGB(65,65,65) );
//GfxPolygon(250,200,200,250,250,20,200,50);
//GfxSelectPen( ColorRGB(125,0,0), 1 );
//GfxSelectSolidBrush( ColorRGB(0,0,40) );
//GfxRectangle( 10,100, 190, 160 );
//GfxSelectPen=( ColorRGB(0,0,0) ,1 );
GfxSelectSolidBrush( ColorRGB(0,0,0) );
//GfxSetTextAlign( 250 );// center alignment
GfxSetOverlayMode(1);
//GfxSelectFont=("Times New Roman", 30, 400, True );
GfxSetTextColor( ColorRGB( 105, 105, 105 ) );
GfxSetBkMode(0); // transparent
//GfxTextOut=("Pathfinder", 15 , 35 );
_SECTION_BEGIN("Flower");
si=Param("Zoom/In Out",5,-50,100,1);
GraphXSpace=si;
r1 = Param( "ColorFast avg", 5, 2, 200, 1 );
r2 = Param( "ColorSlow avg", 10, 2, 200, 1 );
r3 = Param( "ColorSignal avg", 5, 2, 200, 1 );
m1=MACD(r1,r2);
s1=Signal(r1,r2,r3);
mycolor=IIf(m1<0 AND m1>s1, ColorRGB(155,155,155),IIf(m1>0 AND m1>s1,ColorRGB(0,125,0),IIf(m1>0 AND m1<s1,ColorRGB(180,30,160),ColorRGB(100,0,0))));
Prd1=Param("ATR Period",4,1,20,1);
Prd2=Param("Look Back",7,1,20,1);
green = HHV(LLV(L,Prd1)+ATR(Prd1),Prd2);
red = LLV(HHV(H,Prd1)-ATR(Prd1),Prd2);
flowerClose = EMA((Open+High+Low+Close)/4,3) ;
flowerOpen = EMA((Ref(Open,-1) + Ref(flowerClose,-1))/2,3);
Temp = Max(High, flowerOpen);
flowerHigh = EMA(Max(Temp, flowerClose),3);
Temp = Min(Low,flowerOpen);
flowerLow = EMA(Min(Temp, flowerClose),3);
barColor=IIf(Close>Open,ColorRGB(0,245,0),ColorRGB(255,0,0));
Ctmpl = E_TSKPCOLORTMPL(Open,High,Low,Close,Volume);
total = 0;
total = total + IIf(tskp_colortmplcnd0 > 0, 1, -1);
total = total + IIf(tskp_colortmplcnd1 > 0, 1, -1);
total = total + IIf(tskp_colortmplcnd2 > 0, 1, -1);
total = total + IIf(tskp_colortmplcnd3 > 0, 1, -1);
total = total + IIf(tskp_colortmplcnd4 > 0, 1, -1);
total = total + IIf(tskp_colortmplcnd5 > 0, 1, -1);
total = total + IIf(tskp_colortmplcnd6 > 0, 1, -1);
total = total + IIf(tskp_colortmplcnd7 > 0, 1, -1);
total = total + IIf(tskp_colortmplcnd8 > 0, 1, -1);
for( i = 0; i < BarCount; i++ )
{
if( total >= 5 )
Color = colorLime;
else if( total <= -5 )
Color = colorRed;
else
Color = colorWhite;
}
Candle=ParamList("Candle","Modified Candlestick,Modified Heikin Ashi,Normal Candlestick",1);
if(Candle=="Modified Candlestick")
{
ColorHighliter = myColor;
SetBarFillColor( ColorHighliter );
Plot (Close,"- Modified Candlestick", Color,ParamStyle( "Style", styleCandle|styleLine | styleThick, maskAll));
}
if(Candle=="Modified Heikin Ashi")
{
ColorHighliter = myColor;
SetBarFillColor( ColorHighliter );
PlotOHLC( IIf(flowerOpen<flowerClose, flowerOpen, flowerClose),flowerHigh,flowerLow,IIf(flowerOpen<flowerClose, flowerClose, flowerOpen), "Modified Heikin Ashi", Color, styleCandle|styleLine);
}
if(Candle=="Normal Candlestick")
{
//ColorHighliter = myColor;
//SetBarFillColor( ColorHighliter );
PlotOHLC(O,H,L,C,"Normal Candlestick",barcolor,styleCandle|styleLine);
}
_SECTION_END();
_SECTION_BEGIN("TSKPPIVOT");
if(Candle=="Modified Heikin Ashi")
{
CHiPr = 0;
CLoPr = 9999999;
blsLong = 0;
PrevCOBar = 0;
NumBars = 0;
PrePP = 0;
PrevLowVal = 9999999;
BuySig = 0;
blsShort = 0;
PrevHiVal = 0;
blsNewCO = 0;
BarDif = 0;
KPA900Val = E_TSKPA900(Close);
KPAutoStopVal = E_TSKPAUTOSTOP(High,Low,Close);
// -- Create 0-initialized arrays the size of barcount
aHPivs = flowerHigh - flowerHigh;
aLPivs = flowerLow - flowerLow;
aHiVal = flowerHigh - flowerHigh;
aLoVal = flowerLow - flowerLow;
Ctmpl = E_TSKPCOLORTMPL(Open,High,Low,Close,Volume);
sctotal = 0;
sctotal = sctotal + IIf(tskp_colortmplcnd0 > 0, 1, -1);
sctotal = sctotal + IIf(tskp_colortmplcnd1 > 0, 1, -1);
sctotal = sctotal + IIf(tskp_colortmplcnd2 > 0, 1, -1);
sctotal = sctotal + IIf(tskp_colortmplcnd3 > 0, 1, -1);
sctotal = sctotal + IIf(tskp_colortmplcnd4 > 0, 1, -1);
sctotal = sctotal + IIf(tskp_colortmplcnd5 > 0, 1, -1);
sctotal = sctotal + IIf(tskp_colortmplcnd6 > 0, 1, -1);
sctotal = sctotal + IIf(tskp_colortmplcnd7 > 0, 1, -1);
sctotal = sctotal + IIf(tskp_colortmplcnd8 > 0, 1, -1);
for (curBar=0; curBar < BarCount-1; curBar++)
{
if ( curBar == 0 )
{
CHiPr = flowerHigh[curBar];
CHiBar = curBar;
CLoPr = flowerLow[curBar];
CLoBar = curBar;
blsLong = 0;
blsShort = 0;
blsNewCO = 0;
PrePP = 0;
PrevCOBar = 0;
PrevHiVal = flowerHigh[curBar];
PrevLowVal = flowerLow[curBar];
BuySig = 0;
SellSig = 0;
blsLL = 0;
}
if (flowerHigh[CurBar] >= CHiPr) {
CHiPr = flowerHigh[CurBar];
ChiBar = CurBar;
}
if (flowerLow[CurBar] <= CLoPr) {
CLoPr = flowerLow[CurBar];
CLoBar = CurBar;
}
if ( (KPA900Val[curBar] >= KPAutoStopVal[curbar]) AND (PrePP != -1) AND (blsLong != 1) ){
BarDif = CurBar - PrevCOBar;
if (BarDif >= NumBars) {
blsLong = 1;
blsShort = 0;
blsNewCO = 1;
PrevCOBar = CurBar;
}
}
if ( (KPA900Val[curBar] <= KPAutoStopVal[curbar]) AND (PrePP != 1) AND (blsShort != 1) ){
BarDif = CurBar - PrevCOBar;
if (BarDif >= NumBars) {
blsLong = 0;
blsShort = 1;
blsNewCO = 1;
PrevCOBar = CurBar;
}
}
if ( (blsNewCO == 1) AND (sctotal[CurBar] >= 5) AND (blsLong == 1) ) {
LVal = CurBar - CLoBar;
for (j= CLoBar-1; j <= CLoBar+1; j++)
{
if (j >=0) {
aLPivs[j] = 1;
aLoVal[j] = CLoPr;
}
}
PrePP = -1;
blsNewCO = 0;
CHiPr = flowerHigh[CurBar];
CHiBar = CurBar;
CLoPr = flowerLow[Curbar];
CLoBar = CurBar;
}
else if ((blsNewCO == 1) AND (sctotal[CurBar] <= -5) AND (blsShort == 1) ) {
HVal = CurBar - CHiBar;
for (j= CHiBar-1; j <= CHiBar+1; j++)
{
if (j >=0) {
aHPivs[j] = 1;
aHiVal[j] = CHiPr;
}
}
PrePP = 1;
blsNewCO = 0;
CHiPr = flowerHigh[CurBar];
CHiBar = CurBar;
CLoPr = flowerLow[Curbar];
CLoBar = CurBar;
}
}
PlotShapes(IIf(aHPivs == 1, 21,shapeNone), ColorRGB(255,0,145),0, aHiVal,Offset = 20);
PlotShapes(IIf(aHPivs == 1, 15,shapeNone), ColorRGB(200,50,75),0, aHiVal,Offset = 20);
PlotShapes(IIf(aLPivs == 1, 21,shapeNone), ColorRGB(0,125,225),0, aLoVal, Offset = -20);
PlotShapes(IIf(aLPivs == 1, 15,shapeNone), ColorRGB(0,125,255),0, aLoVal, Offset = -20);
}
_SECTION_END();
_SECTION_BEGIN("Resistance");
supres=ParamToggle("Sup_Res","No|Yes",1);
if(supres)
{
Prd1=Param("Res_Period1",2,0,200,1);
test = TEMA ( High , Prd1 ) ;
PK = test > Ref(test,-1) AND Ref(test,1) < High;//Peak
PKV0 = ValueWhen(PK,flowerHigh,0);//PeakValue0
PKV1 = ValueWhen(PK,flowerHigh,1);//PeakValue1
PKV2 = ValueWhen(PK,flowerHigh,2);//PeakValue2
MPK = PKV2 < PKV1 AND PKV1 > PKV0 ;//MajorPeak
RsColor=ParamColor("ResistColor",ColorRGB(225,0,0));
BrCount=Param("ResistBarLength",8,1,500,1);
for (i=0;i<BarCount-BrCount;i++) //hide the line except most recent 10 bars
{
RsColor = colorBlack;
}
MPKV = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,1); //MajorPeakValue
MPKD = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),1); //MajorPeakDate
SD = IIf(DateNum() < LastValue(MPKD,lastmode = True ), Null, LastValue(MPKV,Lastmode = True));//SelectedDate
Plot(SD, "Resist1", ColorRGB(200,0,0),ParamStyle("ResStyle1",styleDashed|styleNoTitle,maskAll));
RsColor2=ParamColor("Resist2Color",ColorRGB(225,0,0));
BrCount=Param("Resist2BarLength",8,1,500,1);
for (i=0;i<BarCount-BrCount;i++) //hide the line except most recent 10 bars
{
RsColor2 = colorBlack;
}
MPKV2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,2); //MajorPeakValue
MPKD2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),2); //MajorPeakDate
SD2 = IIf(DateNum() < LastValue(MPKD2,lastmode = True ), Null, LastValue(MPKV2,Lastmode = True));//SelectedDate
Plot(SD2, "Resist2", RsColor2,ParamStyle("ResStyle2",styleDashed|styleNoTitle,maskAll));
RsColor3=ParamColor("Resist3Color",ColorRGB(225,0,0));
BrCount=Param("Resist3BarLength",8,1,500,1);
for (i=0;i<BarCount-BrCount;i++) //hide the line except most recent 10 bars
{
RsColor3 = colorBlack;
}
MPKV3 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,3); //MajorPeakValue
MPKD3 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),3); //MajorPeakDate
SD3 = IIf(DateNum() < LastValue(MPKD3,lastmode = True ), Null, LastValue(MPKV3,Lastmode = True));//SelectedDate
Plot(SD3, "Resist3", RsColor3,ParamStyle("ResStyle3",styleThick|styleDots|styleNoTitle,maskAll));
_SECTION_END();
_SECTION_BEGIN("Support");
Prd2=Param("Sup_Period1",2,0,200,1);
test2 = TEMA ( Low , Prd2 ) ;
SP = Ref(test2,1) > Low AND test2 < Ref(test2,-1);//Peak
SPV0 = ValueWhen(SP,flowerLow,0);//PeakValue0
SPV1 = ValueWhen(SP,flowerLow,1);//PeakValue1
SPV2 = ValueWhen(SP,flowerLow,2);//PeakValue2
MSP = SPV2 > SPV1 AND SPV1 < SPV0 ;//MajorPeak
SpColor=ParamColor("SupColor",ColorRGB(0,225,0));
BrCount=Param("SupBarLength",8,1,500,1);
for (i=0;i<BarCount-BrCount;i++) //hide the line except most recent 10 bars
{
SpColor = colorBlack;
}
MSPV = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,1);
MSPD = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),1);
SD = IIf(DateNum() < LastValue(MSPD,lastmode = True ), Null, LastValue(MSPV,Lastmode = True));
Plot(SD,"Support1",SpColor,ParamStyle("SupportLine1",styleDashed|styleNoTitle,maskAll));
SpColor2=ParamColor("SupColor2",ColorRGB(0,200,0));
BrCount=Param("Sup2BarLength",8,1,500,1);
for (i=0;i<BarCount-BrCount;i++) //hide the line except most recent 10 bars
{
SpColor2 = colorBlack;
}
MSPV2 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,2);
MSPD2 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),2);
SD2 = IIf(DateNum() < LastValue(MSPD2,lastmode = True ), Null, LastValue(MSPV2,Lastmode = True));
Plot(SD2,"Support2",Spcolor2,ParamStyle("SupportLine2",styleDashed|styleNoTitle,maskAll));
SpColor3=ParamColor("SupColor3",ColorRGB(0,175,0));
BrCount=Param("Sup3BarLength",8,1,500,1);
for (i=0;i<BarCount-BrCount;i++) //hide the line except most recent 10 bars
{
SpColor3 = colorBlack;
}
MSPV3 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,3);
MSPD3 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),3);
SD3 = IIf(DateNum() < LastValue(MSPD3,lastmode = True ), Null, LastValue(MSPV3,Lastmode = True));
Plot(SD3,"Support3",SpColor3,ParamStyle("SupportLine3",styleThick|styleDots|styleNoTitle,maskAll));
}
_SECTION_END();
_SECTION_BEGIN("20EMA High");
Ph = ParamField("Price field",1);
Periods1 = Param("Periods", 20, 2, 400, 1 );
bbt=MA( Ph, Periods1 );
//Plot( bbt, "20EMA(H)", ParamColor( "Color", colorAqua ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale );
_SECTION_END();
_SECTION_BEGIN("20EMA Low");
Pl = ParamField("Price field",2);
Periods2 = Param("Periods", 20, 2, 400, 1 );
bbb=MA( Pl, Periods2 );
//Plot( bbb, "20EMA(L)", ParamColor( "Color", colorAqua ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale );
_SECTION_END();
_SECTION_END();
_SECTION_BEGIN("Supertrend");
procedure calcTrend_proc(ATR_Period,tr,ATR_Multiplier,TrendMode,CalcPrice)
{
global buffer_line_down;
global buffer_line_up;
buffer_line_down = Null;
buffer_line_up = Null;
PHASE_NONE = 0;
PHASE_BUY = 1;
PHASE_SELL = -1;
phase=PHASE_NONE;
band_upper = 0;band_lower = 0;
for(i = ATR_Period + 1; i < BarCount; i++)
{
band_upper = CalcPrice + ATR_Multiplier * tr;
band_lower = CalcPrice - ATR_Multiplier * tr;
if(phase==PHASE_NONE)
{
buffer_line_up = CalcPrice;
buffer_line_down = CalcPrice;
}
if(phase!=PHASE_BUY && Close>buffer_line_down[i-1] && !IsEmpty(buffer_line_down[i-1]))
{
phase = PHASE_BUY;
buffer_line_up = band_lower;
buffer_line_up[i-1] = buffer_line_down[i-1];
}
if(phase!=PHASE_SELL && Close<buffer_line_up[i-1] && !IsEmpty(buffer_line_up[i-1]))
{
phase = PHASE_SELL;
buffer_line_down = band_upper;
buffer_line_down[i-1] = buffer_line_up[i-1];
}
if(phase==PHASE_BUY && ((TrendMode==0 && !IsEmpty(buffer_line_up[i-2])) || TrendMode==1) )
{
if(band_lower>buffer_line_up[i-1])
{
buffer_line_up = band_lower;
}
else
{
buffer_line_up = buffer_line_up[i-1];
}
}
if(phase==PHASE_SELL && ((TrendMode==0 && !IsEmpty(buffer_line_down[i-2])) || TrendMode==1) )
{
if(band_upper<buffer_line_down[i-1])
{
buffer_line_down = band_upper;
}
else
{
buffer_line_down = buffer_line_down[i-1];
}
}
}
}
TrendMode = ParamToggle("TrendMode","Off|On",1);
ATR_Multiplier = Param("ATR_Multiplier",2,0.1,10,0.1);
ATR_Period = Param( "ATR_Period",5,1,20,1);
tr = ATR(ATR_Period);
CalcPrice = (H+L)/2;
calcTrend_proc(ATR_Period,tr,ATR_Multiplier,TrendMode,CalcPrice);
st = ParamToggle("Supertrend","Show|Hide",0);
if(st==1) {
Plot(buffer_line_up,"\nUP Trend",ColorRGB(28,134,238),styleThick);
Plot(buffer_line_down,"\nDOWN Trend",ColorRGB(205,51,51),styleThick);
}
_SECTION_END();
_SECTION_BEGIN("Beta Adjusted Trailing Stops");
/*Concept from Bulkowski’s Stop Placement
Mr. Bulkowski has extensively researched the Trailing Stop problem and found that the best multiplier to be 2 when the lookback period was 22 bars (one month).
The average high-low volatility measure (HL) performs better than the average true range (ATR, which includes gaps, whereas the HL method does not)
AND better than standard deviation. Standard deviation performed the worst of the three methods in nearly all of the tests.
The stop is only raised (or lowered) only if a previous high (or low) is exceeded over the past 22 bar period.
The results are excellent when a trending market is in progress and the stop usually gets you out with less that a 8% loss if things go against you.
*/
dif=Ref(High,0)-Ref(Low,0);
dif1=Ref(High,-1)-Ref(Low,-1);
dif2=Ref(High,-2)-Ref(Low,-2);
dif3=Ref(High,-3)-Ref(Low,-3);
dif4=Ref(High,-4)-Ref(Low,-4);
dif5=Ref(High,-5)-Ref(Low,-5);
dif6=Ref(High,-6)-Ref(Low,-6);
dif7=Ref(High,-7)-Ref(Low,-7);
dif8=Ref(High,-8)-Ref(Low,-8);
dif9=Ref(High,-9)-Ref(Low,-9);
dif10=Ref(High,-10)-Ref(Low,-10);
dif11=Ref(High,-11)-Ref(Low,-11);
dif12=Ref(High,-12)-Ref(Low,-12);
dif13=Ref(High,-13)-Ref(Low,-13);
dif14=Ref(High,-14)-Ref(Low,-14);
dif15=Ref(High,-15)-Ref(Low,-15);
dif16=Ref(High,-16)-Ref(Low,-16);
dif17=Ref(High,-17)-Ref(Low,-17);
dif18=Ref(High,-18)-Ref(Low,-18);
dif19=Ref(High,-19)-Ref(Low,-19);
dif20=Ref(High,-20)-Ref(Low,-20);
dif21=Ref(High,-21)-Ref(Low,-21);
Sumdif=(dif+dif1+dif2+dif3+dif4+dif5+dif6+dif7+dif8+dif9+dif10+dif11+dif12+dif13+dif14+dif15+dif16+dif17+dif18+dif19+dif20+dif21)/22;
mp = Param("Multiplier",2,0.25,5,0.25);
Sumdifml=(Sumdif*mp);
Betastops=HHV(C,21) - Sumdifml; // Fibonacci Period used
ColorBATS = IIf(Betastops>C,colorTurquoise,colorGold);
Plot(Betastops, "BATS", colorBATS,ParamStyle("Style1",styleThick,maskAll));
_SECTION_END();
_SECTION_BEGIN("HAS MTF");
/*
Created by chandrakant
Modified on 120309..credit goes to of Karthik sir
1. Here are some observations to keep in mind that will help assure
you are in a good trending move which is detrimental to the success
of the trade moving higher before the inevitable over exhausted trend.
2 Consider only going long on the 5M if the 30M (two rows above) is also blue.
3 Consider the 1hr row as well being blue since it has an effect too.
4 The 15M row has to be blue with NO exceptions
5 The 30M row if blue has less effect on the trade as compared to the 15M row
but keep this in mind. The 30M row being blue helps the 15M row continue to stay blue.
6 The 1hr row has even less effect OR importance but it too keeps the 30M
from weakening to some minor degree.
*/
// Define label bar (x) position location
blankRightBars = 5; //insert actual blank right bars specified in Preferences
barsInView = Status("lastvisiblebarindex") - Status("firstvisiblebarindex") - blankRightBars;
Offset = Param("Offset Bar", 0.95, 0, 1, 0.01);
textOffset = BarCount - (Offset * barsInView);
//// Default TF of the Chart ( Bottom Ribbon )
HaClose =EMA((O+H+L+C)/4,3);
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
//PlotText("HAS MTF :"+Interval(2), textoffset, 41.01, colorYellow);
Color = IIf( Haopen > Haclose,4, IIf( Haopen == Haclose,colorYellow, 6));
Plot(2,"", Color, styleHistogram+styleThick|styleOwnScale|styleNoLabel, 0, 100 );
Plot( 3,"",colorDarkGrey,styleOwnScale|styleArea|styleNoLabel,0, 100 );
//// 3 X TF Plot ( 2nd Ribbon from Bottom )
Compress2= Param("Compression",3,1,3,1);
TimeFrameSet(Compress2* Interval());
HaClose2 =EMA((O+H+L+C)/4,3);
HaOpen2 = AMA( Ref( HaClose2, -1 ), 0.5 );
HaHigh2 = Max( H, Max( HaClose2, HaOpen2 ) );
HaLow2 = Min( L, Min( HaClose2, HaOpen2 ) );
//PlotText("HAS MTF :"+Interval(2), textoffset, 41.055, colorYellow);
TimeFrameRestore();
HAopen2f=TimeFrameExpand( Haopen2, Compress2* Interval());
Haclose2f=TimeFrameExpand( Haclose2, Compress2* Interval());
HaHigh2f=TimeFrameExpand( Hahigh2, Compress2* Interval());
HaLow2f=TimeFrameExpand( Halow2, Compress2* Interval());
Color2 = IIf( Haopen2f > Haclose2f,4, IIf(Haopen2f == Haclose2f,colorYellow, 6));
Plot(5,"", Color2, styleHistogram+styleThick|styleOwnScale|styleNoLabel, 0, 100 );
Plot( 6,"",colorDarkGrey,styleOwnScale|styleArea|styleNoLabel,0, 100 );
//// 6 X TF Plot ( 3rd Ribbon from Bottom )
Compress3= Param("Compression3",6,2,6,1);
TimeFrameSet(Compress3* Interval());
HaClose3 =EMA((O+H+L+C)/4,3);
HaOpen3 = AMA( Ref( HaClose3, -1 ), 0.5 );
HaHigh3 = Max( H, Max( HaClose3, HaOpen3 ) );
HaLow3 = Min( L, Min( HaClose3, HaOpen3 ) );
//PlotText("HAS MTF :"+Interval(2), textoffset,41.10, colorYellow);
TimeFrameRestore();
HAopen3f=TimeFrameExpand( Haopen3, Compress3* Interval());
Haclose3f=TimeFrameExpand( Haclose3, Compress3* Interval());
HaHigh3f=TimeFrameExpand( Hahigh3, Compress3* Interval());
HaLow3f=TimeFrameExpand( Halow3, Compress3* Interval());
color3 = IIf( Haopen3f > Haclose3f,4, IIf( Haopen3f == Haclose3f,colorYellow,6));
Plot(8,"", Color3, styleHistogram+styleThick|styleOwnScale|styleNoLabel, 0, 100 );
Plot(9,"",colorDarkGrey,styleOwnScale|styleArea|styleNoLabel,0, 100 );
//// 12 X TF Plot ( 4th Ribbon from Bottom )
Compress4= Param("Compression4",12,2,12,1);
TimeFrameSet(Compress4* Interval());
HaClose4 =EMA((O+H+L+C)/4,3);
HaOpen4 = AMA( Ref( HaClose4, -1 ), 0.5 );
HaHigh4 = Max( H, Max( HaClose4, HaOpen4 ) );
HaLow4 = Min( L, Min( HaClose4, HaOpen4 ) );
//PlotText("HAS MTF :"+Interval(2), textoffset, 41.14, colorYellow);
TimeFrameRestore();
HAopen4f=TimeFrameExpand( Haopen4, Compress4* Interval());
Haclose4f=TimeFrameExpand( Haclose4, Compress4* Interval());
HaHigh4f=TimeFrameExpand( Hahigh4, Compress4* Interval());
HaLow4f=TimeFrameExpand( Halow4, Compress4* Interval());
Color4 = IIf( Haopen4f > Haclose4f,4, IIf( Haopen4f == Haclose4f ,colorYellow, 6));
Plot(11,"", Color4, styleHistogram+styleThick|styleOwnScale|styleNoLabel, 0, 100 );
Plot( 12,"",colorDarkGrey,styleOwnScale|styleArea|styleNoLabel,0, 100 );
_SECTION_END();
Super Trend Dash Board:
/* Done by Rajandran R */
_SECTION_BEGIN("SuperTrend 5min");
_N(Title = "MultiTimeframe Signal DashBoard");
TimeFrameSet(in5Minute);
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));
GfxSetBkMode(0);
GfxSetOverlayMode(1);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
//Plot(C,"\nPrice",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);
SetTradeDelays(1,1,1,1);
PositionSize=100000;
symbol = Name();
Factor=Optimize("Factor",4,2,10,1);
Pd=Optimize("ATR Period",10,3,20,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;
for (i = 1; i <BarCount; i++) {
TrendUp = Null;
TrendDown = Null;
trend=1;
if (Close>Up[i-1]) {
trend=1;
if (trend[i-1] == -1) changeOfTrend = 1;
}
else if (Close<Dn[i-1]) {
trend=-1;
if (trend[i-1] == 1) changeOfTrend = 1;
}
else if (trend[i-1]==1) {
trend=1;
changeOfTrend = 0;
}
else if (trend[i-1]==-1) {
trend=-1;
changeOfTrend = 0;
}
if (trend<0 && trend[i-1]>0) {
flag=1;
}
else {
flag=0;
}
if (trend>0 && trend[i-1]<0) {
flagh=1;
}
else {
flagh=0;
}
if (trend>0 && Dn<Dn[i-1]){
Dn=Dn[i-1];
}
if (trend<0 && Up>Up[i-1])
{ Up=Up[i-1];
}
if (flag==1)
{ Up=(H+L)/2+(Factor*iATR);;
}
if (flagh==1)
{ Dn=(H+L)/2-(Factor*iATR);;
}
if (trend==1) {
TrendUp=Dn;
if (changeOfTrend == 1) {
TrendUp[i-1] = TrendDown[i-1];
changeOfTrend = 0;
}
}
else if (trend==-1) {
TrendDown=Up;
if (changeOfTrend == 1) {
TrendDown[i-1] = TrendUp[i-1];
changeOfTrend = 0;
}
}
}
Buy = trend==1;
Sell=trend==-1;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=Sell;
Cover=Buy;
BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);
TrendSL=IIf(trend==1,TrendUp,TrendDown);
for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";
sl = TrendSL;
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);
bars = i;
i = 0;
}
if(Sell == 1)
{
sig = "SELL";
entry = C;
sl = TrendSL;
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, TrendSL[BarCount-1], Ref(TrendSL, -1));
sl = ssl[BarCount-1];
messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );
if ( sig =="BUY")
{
GfxSelectSolidBrush( colorBlue ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 5;
x2 = 290;
y = pxHeight;
GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 98, x2, y , 7, 7 ) ;
GfxTextOut( ( "Marketcalls - Supertrend 5min"),13,y-100);
GfxTextOut( (" "),27,y-100);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-80) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-60);
GfxTextOut( ("Trailing SL : " + Ref(TrendSL,-1) + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 13, y-40);
/*GfxTextOut( ("TGT:1 : " + tar1), 13, y -80);
GfxTextOut( ("TGT:2 : " + tar2), 13,y-60);
GfxTextOut( ("TGT:3 : " + tar3), 13,y-40);*/
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 13, y-22);;
}
TimeFrameRestore();
_SECTION_END();
_SECTION_BEGIN("SuperTrend 15min");
TimeFrameSet(in5Minute*3);
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));
GfxSetBkMode(0);
GfxSetOverlayMode(1);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
//Plot(C,"\nPrice",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);
SetTradeDelays(1,1,1,1);
PositionSize=100000;
symbol = Name();
Factor=Optimize("Factor",4,2,10,1);
Pd=Optimize("ATR Period",10,3,20,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;
for (i = 1; i <BarCount; i++) {
TrendUp = Null;
TrendDown = Null;
trend=1;
if (Close>Up[i-1]) {
trend=1;
if (trend[i-1] == -1) changeOfTrend = 1;
}
else if (Close<Dn[i-1]) {
trend=-1;
if (trend[i-1] == 1) changeOfTrend = 1;
}
else if (trend[i-1]==1) {
trend=1;
changeOfTrend = 0;
}
else if (trend[i-1]==-1) {
trend=-1;
changeOfTrend = 0;
}
if (trend<0 && trend[i-1]>0) {
flag=1;
}
else {
flag=0;
}
if (trend>0 && trend[i-1]<0) {
flagh=1;
}
else {
flagh=0;
}
if (trend>0 && Dn<Dn[i-1]){
Dn=Dn[i-1];
}
if (trend<0 && Up>Up[i-1])
{ Up=Up[i-1];
}
if (flag==1)
{ Up=(H+L)/2+(Factor*iATR);;
}
if (flagh==1)
{ Dn=(H+L)/2-(Factor*iATR);;
}
if (trend==1) {
TrendUp=Dn;
if (changeOfTrend == 1) {
TrendUp[i-1] = TrendDown[i-1];
changeOfTrend = 0;
}
}
else if (trend==-1) {
TrendDown=Up;
if (changeOfTrend == 1) {
TrendDown[i-1] = TrendUp[i-1];
changeOfTrend = 0;
}
}
}
Buy = trend==1;
Sell=trend==-1;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=Sell;
Cover=Buy;
BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);
TrendSL=IIf(trend==1,TrendUp,TrendDown);
for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";
sl = TrendSL;
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);
bars = i;
i = 0;
}
if(Sell == 1)
{
sig = "SELL";
entry = C;
sl = TrendSL;
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, TrendSL[BarCount-1], Ref(TrendSL, -1));
sl = ssl[BarCount-1];
messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );
if ( sig =="BUY")
{
GfxSelectSolidBrush( colorBlue ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 305;
x2 = 590;
y = pxHeight;
GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 98, x2, y , 7, 7 ) ;
GfxTextOut( ( "Marketcalls - Supertrend 15min"),313,y-100);
GfxTextOut( (" "),327,y-100);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 313, y-80) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 313, y-60);
GfxTextOut( ("Trailing SL : " + Ref(TrendSL,-1) + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 313, y-40);
/*GfxTextOut( ("TGT:1 : " + tar1), 13, y -80);
GfxTextOut( ("TGT:2 : " + tar2), 13,y-60);
GfxTextOut( ("TGT:3 : " + tar3), 13,y-40);*/
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 313, y-22);;
}
TimeFrameRestore();
_SECTION_END();
_SECTION_BEGIN("SuperTrend Hourly");
TimeFrameSet(inHourly);
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));
GfxSetBkMode(0);
GfxSetOverlayMode(1);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
//Plot(C,"\nPrice",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);
SetTradeDelays(1,1,1,1);
PositionSize=100000;
symbol = Name();
Factor=Optimize("Factor",4,2,10,1);
Pd=Optimize("ATR Period",10,3,20,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;
for (i = 1; i <BarCount; i++) {
TrendUp = Null;
TrendDown = Null;
trend=1;
if (Close>Up[i-1]) {
trend=1;
if (trend[i-1] == -1) changeOfTrend = 1;
}
else if (Close<Dn[i-1]) {
trend=-1;
if (trend[i-1] == 1) changeOfTrend = 1;
}
else if (trend[i-1]==1) {
trend=1;
changeOfTrend = 0;
}
else if (trend[i-1]==-1) {
trend=-1;
changeOfTrend = 0;
}
if (trend<0 && trend[i-1]>0) {
flag=1;
}
else {
flag=0;
}
if (trend>0 && trend[i-1]<0) {
flagh=1;
}
else {
flagh=0;
}
if (trend>0 && Dn<Dn[i-1]){
Dn=Dn[i-1];
}
if (trend<0 && Up>Up[i-1])
{ Up=Up[i-1];
}
if (flag==1)
{ Up=(H+L)/2+(Factor*iATR);;
}
if (flagh==1)
{ Dn=(H+L)/2-(Factor*iATR);;
}
if (trend==1) {
TrendUp=Dn;
if (changeOfTrend == 1) {
TrendUp[i-1] = TrendDown[i-1];
changeOfTrend = 0;
}
}
else if (trend==-1) {
TrendDown=Up;
if (changeOfTrend == 1) {
TrendDown[i-1] = TrendUp[i-1];
changeOfTrend = 0;
}
}
}
Buy = trend==1;
Sell=trend==-1;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=Sell;
Cover=Buy;
BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);
TrendSL=IIf(trend==1,TrendUp,TrendDown);
for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";
sl = TrendSL;
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);
bars = i;
i = 0;
}
if(Sell == 1)
{
sig = "SELL";
entry = C;
sl = TrendSL;
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, TrendSL[BarCount-1], Ref(TrendSL, -1));
sl = ssl[BarCount-1];
messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );
if ( sig =="BUY")
{
GfxSelectSolidBrush( colorBlue ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 605;
x2 = 890;
y = pxHeight;
GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 98, x2, y , 7, 7 ) ;
GfxTextOut( ( "Marketcalls - Supertrend Hourly"),613,y-100);
GfxTextOut( (" "),327,y-100);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 613, y-80) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 613, y-60);
GfxTextOut( ("Trailing SL : " + Ref(TrendSL,-1) + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 613, y-40);
/*GfxTextOut( ("TGT:1 : " + tar1), 13, y -80);
GfxTextOut( ("TGT:2 : " + tar2), 13,y-60);
GfxTextOut( ("TGT:3 : " + tar3), 13,y-40);*/
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 613, y-22);;
}
TimeFrameRestore();
_SECTION_END();
Southwind Breeze AFL:
_SECTION_BEGIN("CandleStick Analysis");
/*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;
/*(NOT largeBody AND smallLowerShadow AND LargeUpperShadow) OR*/
shootingStar=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 (MLT OR MLY);
/*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 OR
abs(H-Ref(H,-2))/H<0.0025)
AND (MHT OR MHY);
/* ***********************************************
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
****************************************/
WriteIf(Buy,"Bullish\n=======\n","")+
WriteIf(abandonedBabybullish,"Abandoned Baby Bullish. \nA reversal pattern.\n\\c16LiWick reliability : High.","")+
WriteIf(beltHoldBullish,"Belt Hold Bullish. \nA reversal pattern.\nNison:The larger the candlestick, the more significant it is.\nLitWick Reliability: Low.","")+
WriteIf(breakAwayBullish,"Break Away Bullish. \nA reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(ConcealingBabySwallow,"Concealing Baby Swallow. \nA 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. \nA 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. \nA 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. \nLitWick reliability: moderate.","")+
WriteIf(haramiBullish, "Harami Bullish. \nA reversal pattern.\nNison: Less significant. Pattern needs confirmation.\nLitWick reliability: low.","")+
WriteIf(HaramiCross,"Harami Cross. \nA reversal pattern.\nNison: Better indicator than Harami. Better at calling tops than bottoms.\nLitWick reliability: low.","")+
WriteIf(homingPigeon,"Homing Pigeon. \nA reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(invertedHammer,"Inverted Hammer. \nA reversal pattern.\nNison:Needs bullish verification.\nLitWick reliability: low.","")+
WriteIf(meetingLinesbullish,"Meeting Lines bullish. \nA reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(morningDojiStar,"Morning Doji Star. \nA reversal pattern.\nImportant reversal signal.\nLitWick reliability: high.","")+
WriteIf(morningStar,"Morning Star. \nA reversal pattern.\nNison: The stronger the white third body the better.\nLitWick reliability: high.","")+
WriteIf(piercingLine,"Piercing Line. \nA reversal pattern.\nNison: A stron reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(stickSandwich,"Stick Sandwich. \nA reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(threeInsideUp,"3 Inside Up. \nA reversal pattern.\nLitWick reliability: high.","")+
WriteIf(threeOutsideUp,"3 Outside Up. \nA reversal pattern.\nLitWick reliability: high.","")+
WriteIf(threeStarsInTheSouth,"3 Stars in the South. \nA reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(triStarBullish,"Tri-Star Bullish. \nA reversal pattern.\nNison: Significant reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(threeriverBottom,"3 River Bottom. \nA reversal pattern.\nNison: Selling pressure drying up.\nLit Wick reliability: moderate.","")+
WriteIf(MAtHoldBullish,"Mat Hold Bullish. \nA continuation pattern.\nNison: May have 2-4 black candles.\nLitWick reliability: high. ","")+
WriteIf(risingThreeMethods,"Rising Three Methods. \nA 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. \nA continuation pattern.\nNison: \nLitWick reliability: low.","")+
WriteIf(sideBySideWhiteLines,"Side by Side White Lines. \nA continuation pattern.\nNison: If occurring during a downtrend may only be short covering.\nLitWick reliability: high.","")+
WriteIf(threeWhiteSoldiers,"3 White Soldiers. \nA 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. \nA continuation pattern.\nLitWick reliability: moderate.","")+
WriteIf(threeLineStrike,"3 Line Strike. \nA continuation pattern.\nLitWick reliability: low.","")+
WriteIf(tweezerBottom,"Tweezer Bottom.\nA reversal pattern. With other reversal candles it could indicate a support level.\nNison: Needs confirmation.","")+
WriteIf(upsideTasukiGap,"Upside Tasuki Gap. \nA continuation pattern.\nNison: the real bodies of the two candlesticks in the gap should be about the same size.\nLitWick reliability: moderate.","")+
WriteIf(Buy,"\n-------------------------------------------","");; /***************************************
Bearish Candles
********************************************/
WriteIf(Sell,"Bearish\n=======\n","")+
WriteIf(AbandonedBabyBearish,"Abandoned Baby Bearish. \nA reversal pattern.\nNison: Extremely rare.\nLitWick reliability: high.","")+
WriteIf(advanceBlockBearish,"Advancing Block Bearish. \nA 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. \nA 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. \nA reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(darkCloudCover,"Dark Cloud Cover. \nA 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. \nA 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. \nA 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 \nA reversal pattern.\nNison: Must be confirmed by long black candle.\nLit Wick reliability: high","")+
WriteIf(eveningStar,"Evening Star. \nA reversal pattern.\nNison: Gap between Second AND third bodies does NOT always occur.\nLitWick reliability: High.","")+
WriteIf(HammerBearish,"Bearish Hammer. \nA 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. \nA reversal pattern.\nNison: Same as bearish hammer with a large gap down the following day.\nLitWick reliability: low.","")+
WriteIf(dragonflyDojiBearish,"Dragonfly Bearish. \nA reversal pattern.\nNison: Same as Hanging Man.\nLitWick reliability: moderate.","")+
WriteIf(HaramiBearish,"Harami Bearish. \nA reversal pattern.\nNison: Not as significant a reversal pattern as hanging man or engulfing.\nLitWick reliability: low.","")+
WriteIf(HaramiCrossBearish,"Harami Cross Bearish. \nA 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. \nA reversal pattern in an uptrend.\nNison:Very bearish.\nLitWick reliability: high. ","")+
WriteIf(kickingBearish,"Kicking Bearish. \nA reversal pattern.\nLitWick reliability: high.","")+
WriteIf(MeetingLinesBearish,"Meeting Lines Bearish. \nA reversal pattern.\nNison: \nLitWick reliability: moderate, but not as strong as Dark cloud Cover.","")+
WriteIf(shootingStarGap,"Shooting Star. \nA 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. \nA reversal pattern.\nNison: more significant if it hits new high.\nLitWick reliability: moderate.","")+
WriteIf(threeInsideDownBearish,"3 Inside Down. \nA reversal pattern.\nNison: \nLitWick reliability: high.","")+
WriteIf(threeoutsideDownBearish,"3 Outside Down. \nA reversal pattern.\nLitWick reliability: high.","")+
WriteIf(triStarBearish,"Tri-Star Bearish. \nA reversal pattern.\nNison: Very significant reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(twoCrows,"2 Crows. \nA reversal pattern.\nLitWick reliability: moderate.","")+
WriteIf(upsideGapTwoCrows,"Upside Gap 2 Crows. \nA reversal pattern.\nNison:Needs confirmation of a continued reversal on third day.\nLitWick reliability: high.","")+
WriteIf(dojiStarBearish,"Doji Star Bearish. \nA 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. \nA continuation method.\nNison: If last day closes window, continuation pattern is negated.\nLitWick reliability: moderate.","")+
WriteIf(fallingThreeMethods,"Falling 3 Methods. \nA 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. \nA 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. \nA continuation pattern.\nNison: very rare.\nLitWick reliability: moderate.","")+
WriteIf(threeBlackCrows,"3 Black Crows. \nA reversal pattern.\nNison: Need to appear after a mature advance.\nLitWick reliability: high.","")+
WriteIf(threeLineStrike,"3 Line Strike. \nA continuation pattern.\nLitWick reliability: low.","")+
WriteIf(thrustingBearish,"Thrusting. \nA continuation pattern.\nNison: Not a reversal day because second day does not pierce midpoint of first day.\nLitWick reliability: low.","")+
WriteIf(tweezerTop,"Tweezer Top. \nA reversal pattern.\nNison: Needs confirmation.","")+
WriteIf(Sell,"\n---------------------------------------------------","");
/***********************************************
End Commentary
************************************************/
_SECTION_END();
_SECTION_BEGIN("Signal Panel");
sp = ParamToggle("Signal Panel","Show|Hide",1);
showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);
no=6;
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
s5d=IIf(avn==1,sup,res);
ColorSL = IIf(avn==1,colorBrightGreen,colorRed);
if (showsl == 1) Plot(s5d,"Stop Loss",ColorSL,styleDots);
exitlong = Cross(s5d, H);
exitshort = Cross(L, s5d);
Buy = exitshort;
Sell = exitlong;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
PlotShapes(exitlong * shapeDownArrow, colorRed,0,H,-10);
PlotShapes(exitshort * shapeUpArrow, colorLime,0,L,-15);
AlertIf( Buy, "", "BUY @ " + C, 1 );
AlertIf( Sell, "", "SELL @ " + C, 2 );
for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";
sl = s5d;
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);
bars = i;
i = 0;
}
if(Sell == 1)
{
sig = "SELL";
entry = C;
sl = s5d;
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, s5d[BarCount-1], Ref(s5d, -1));
sl = ssl[BarCount-1];
if (sp == 1 )
{
Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorDarkRed, styleLine|styleLine, Null, Null, Offset);
Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorGreen, styleLine|styleLine, Null, Null, Offset);
for (i=bars; i <BarCount;i++)
{
PlotText(""+sig+"@"+entry, BarCount-2,entry,Null,colorBlue);
PlotText("T1@"+tar1,BarCount,tar1,Null,Clr);
PlotText("T2@"+tar2,BarCount,tar2,Null,Clr);
PlotText ("T3@"+tar3,BarCount,tar3,Null,Clr);
}
printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago");
printf("\n" + sig + " @ : " + entry + "\nStop Loss : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"+ "\nTarget_1 : " + tar1 + "\nTarget_2 : " + tar2 + "\nTarget_3 : " + tar3);
printf("\nCurrent P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2));
}
_SECTION_END();
_SECTION_BEGIN("VSA");
DTL=Param("Linear regression period",60,10,100,10);
wbf=Param("WRB factor",1.5,1.3,2.5,.1);
nbf=Param("NRB factor",0.7,0.3,0.9,0.1);
TL=LinRegSlope(MA(C, DTL),2);
Vlp=Param("Volume lookback period",30,20,300,10);
Vrg=MA(V,Vlp);
St = StDev(Vrg,Vlp);
Vp3 = Vrg + 3*st;
Vp2 = Vrg + 2*st;;
Vp1 = Vrg + 1*st;;
Vn1 = Vrg -1*st;
Vn2 = Vrg -2*st;
rg=(H-L);
arg=Wilders(rg,30);
wrb=rg>(wbf*arg);
nrb=rg<(nbf*arg);
Vl=V<Ref(V,-1) AND V<Ref(V,-2);
upbar=C>Ref(C,-1);
dnbar=C<Ref(C,-1);
Vh=V>Ref(V,-1) AND Ref(V,-1)>Ref(V,-2);
Cloc=C-L;
x=rg/Cloc;
x1=IIf(Cloc==0,arg,x);
Vb=V>Vrg OR V>Ref(V,-1);
ucls=x1<2;
dcls=x1>2;
mcls=x1<2.2 AND x1>1.8 ;
Vlcls=x1>4;
Vhcls=x1<1.35;
j=MA(C,5);
TLL=LinRegSlope(j,40) ;
Tlm=LinRegSlope(j,15) ;
tls=LinRegSlope(j,5);
mp=(H+L)/2;
Pp1=Param("NumberOfDays",30,1,200,1);
Pp2=Param("VolOfDays",15,1,200,1);
numDays = Pp1;
dwWideSpread = 1.8;
dwNarrowSpread = 0.8;
dwSpreadMiddle = 0.5;
dwHighClose = 0.7;
dwLowClose = 0.3;
volNumDays = Pp2;
dwUltraHighVol = 2;
dwVeryHighVol = 1.75; // was 1.8
dwHighVol = 1.75; // was 1.8
dwmoderateVol = 1.10; // was 1.8
dwLowVol = 0.75; // was 0.8
////////////////////////////////////////////////////////////////////////////////////
// Classify each bar...
///////////////////////////////////////////////////////////////////////////////////
upBar = C > Ref(C,-1);
downBar = C < Ref(C,-1);
spread = H-L;
avgRange = Sum(spread, numDays) / numDays;
wideRange = spread >= (dwWideSpread * avgRange);
narrowRange = spread <= (dwNarrowSpread * avgRange);
testHighClose = L + (spread * dwHighClose);
testLowClose = L + (spread * dwLowClose);
testCloseMiddle = L + (spread * dwSpreadMiddle);
upClose = C > testHighClose;
downClose = C < testLowClose;
middleClose = C >= testLowClose AND C <= testHighClose;
avgVolume = EMA(V, volNumDays);
highVolume = V > (avgVolume * dwHighVol);
moderateVol= V > (avgVolume * dwmoderateVol);
veryHighVolume = V > (avgVolume * dwVeryHighVol);
ultraHighVolume = V > (avgVolume * dwUltraHighVol);
LowVolume = V < (avgVolume * dwLowVol);
////////////////////////////////////////////////////////////////////////////////////
// direction and title
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
//
// Basic patterns...
//
////////////////////////////////////////////////////////////////////////////////////
upThrustBar = downClose AND H > Ref(H,-1) AND (C == L) AND downClose AND (NOT narrowRange);
noDemandBar = narrowRange AND LowVolume AND upBar AND (NOT upClose);
//noDemandBar = narrowRange AND LowVolume AND upBar AND (V < Ref(V,-1)) AND (V < Ref(V,-2));
noSupplyBar = narrowRange AND LowVolume AND downBar AND (V < Ref(V,-1)) AND (V < Ref(V,-2));
absorption = Ref(downbar, -1) AND Ref(highVolume, -1) AND upBar;
support = Ref(downBar,-1) AND (NOT Ref(downClose,-1)) AND Ref(highVolume,-1) AND upBar;
stoppingVolume = Ref(downBar,-1) AND Ref(highVolume,-1) AND C > testCloseMiddle AND (NOT downBar);
bullishsign=moderateVol+UpThrustBar;//OR moderateVol+upBar;
//rallyEnd = (Ref(highVolume,-1) AND Ref(upBar,-1) AND wideRange AND downBar) OR
// (narrowRange AND highVolume AND H > Ref(HHV(H, 250), -1));
////////////////////////////////////////////////////////////////////////////////////
//
// Strength and Weakness
//
////////////////////////////////////////////////////////////////////////////////////
weakness = upThrustBar OR noDemandBar OR (narrowRange AND (H > Ref(H,-1)) AND highVolume) OR (Ref(highVolume,-1) AND Ref(upBar,-1) AND downBar AND (H < Ref(H,-1)));
/////////////////////////////////////////////////////////////////////////////////////////////
C1 = Ref(C, -1);
uc = C > C1; dc = C <= C1;
ud = C > O; dd = C <= O;
green = 1; blue = 2; yellow = 3; red = 4; white = 5;
VType = IIf(ud, IIf(uc, green, yellow), IIf(dd,IIf(dc, red, blue), white));
/* green volume: up-day and up-close*/
gv = IIf(VType == green, V, 0);
/* yellow volume: up-day but down-close */
yv = IIf(VType == yellow, V, 0);
/* red volume: down-day and down-close */
rv = IIf(VType == red, V, 0);
/* blue volume: down-day but up-close */
bv = IIf(VType == blue, V, 0);
uv = gv + bv; uv1 = Ref(uv, -1); /* up volume */
dv = rv + yv; dv1 = Ref(dv, -1); /* down volume */
/* create moving average period parameters */
VolPer = Param("Adjust Vol. MA per.", 34, 1, 255, 1);
ConvPer = Param("Adjust Conv. MA per.", 9, 1, 255, 1);
/* create triple exponential moving avearges of separate up and down volume
moving averages */
MAuv = TEMA(uv, VolPer ); mauv1 = Ref(mauv, -1);
MAdv = TEMA(dv, VolPer ); madv1 = Ref(madv, -1);
MAtv = TEMA(V, VolPer );//total volume
/* Switch for Horizontal lines indicating current level of positive and
negative volume for ease in comparing to past highs/lows - toggle via
parmameter window */
OscillatorOnly = Param("Show Oscillator Only", 0, 0, 1, 1);
CompareBullVolume = Param("Show Bull Level", 1, 0, 1, 1);
if(CompareBullvolume AND !OscillatorOnly){
//Plot(SelectedValue(MAuv), "", colorGreen, styleLine);
}
CompareBearVolume = Param("Show Bear Level", 1, 0, 1, 1);
if(CompareBearVolume AND !OscillatorOnly){
//Plot(SelectedValue(MAdv), "", colorRed, styleLine);
}
/* Volume Segment Switches - toggle via parameter window */
bullvolume = Param("Show Bull Volume", 1, 0, 1, 1);
bearvolume = Param("Show Bear Volume", 1, 0, 1, 1);
totalvolume = Param("Show Total Volume", 1, 0, 1, 1);
/* plot volume lines and histograms if toggled on: */
bearToFront = Param("Show Bear Vol in Front", 0, 0, 1, 1);
if(bearToFront AND !OscillatorOnly){
//Plot(MAdv, "", colorRed, styleHistogram|styleNoLabel);
}
if(bullvolume AND !OscillatorOnly){
//Plot(MAuv, "Average Bull Volume", colorGreen, styleHistogram|styleNoLabel);
}
if(bearvolume AND !OscillatorOnly){
//Plot(MAdv, "Average Bear Volume", colorRed, styleHistogram|styleNoLabel);
}
if(totalVolume AND !OscillatorOnly){
//Plot(MAtv, "Total Volume", colorWhite, styleHistogram|styleNoLabel);
//Plot(MAtv, "", colorWhite, styleLine);
}
if(bullvolume AND !OscillatorOnly){
//Plot(MAuv, "", colorGreen, styleLine);
}
if(bearvolume AND !OscillatorOnly){
//Plot(MAdv, "", colorRed, styleLine);
}
/* better visibility of zero line: */
//Plot(0, "", colorBlue, 1);
/* Rise/Fall Convergence variables: */
Converge = (TEMA(MAuv - MAdv, ConvPer));
Converge1 = Ref(Converge, -1);
ConvergeUp = Converge > Converge1;
ConvergeOver = Converge > 0;
rising = ConvergeUp AND ConvergeOver;
falling = !ConvergeUp AND ConvergeOver;
/* Rise/Fall Convergence Oscillator Switch - toggle via parameter window - (provides a better view of resulting combination of battling bull/bear volume forces) */
convergenceOscillator = Param("Show Oscillator", 0, 0, 1, 1);
if(convergenceOscillator OR OscillatorOnly){
//Plot(Converge, "Bull/Bear Volume Convergence/Divergence", colorViolet,1|styleLeftAxisScale|styleNoLabel|styleThick);
//Plot(0,"", colorYellow, 1|styleLeftAxisScale|styleNoLabel);
}
/********************************************************
Convergence Rise/Fall Shadows:
(provides a more easily visible display of rising and falling bull/bear volume convergence) - toggle via parameter window
-posiitive Volume exceeding negative Volume: Light shadow
-negative volume exceeding positive volume: dark shadow
-if you use standard gray background - best shadows are:
-my greys: 14 = (216, 216, 216); 15 = (168, 168, 168));
-best substitute? using AB color constants?
-light: colorpalegreen; dark: colorRose;?
-(depends on your color scheme - customize to your tastes)
**********************************************************/
/* uncomment if you use my custom color greys: */
riseFallColor = IIf(rising, 14,15); //my custom shadow greys
/* comment out if you use my custom color gray shadows: */
/* riseFallColor = IIf(rising, colorPaleGreen,colorRose); */
/* Rise/Fall Convergence Plot Switch - toggle via parameter window */
riseFallShadows = Param("Show RiseFallShadows", 0, 0, 1, 1);
if(riseFallShadows){
//Plot(IIf(rising OR falling, 1, 0), "", riseFallColor,styleHistogram|styleArea|styleOwnScale|styleNoLabel);
}
_SECTION_END();
_SECTION_BEGIN("Pivot Finder");
/***********************************
Code to automatically identify pivots
***********************************/
// -- what will be our lookback range for the hh and ll?
farback=Param("How Far back to go",100,50,5000,10);
nBars = Param("Number of bars", 12, 5, 40);
//"BIdxJJJ = " + BarIndex() + "\n" + "OGGGGGGGGGGG = " + O + "\n"+"H = "+ H + "\n"+"L = " + L + "\n"+"C " ;
GraphXSpace=7;
// -- Create 0-initialized arrays the size of barcount
aHPivs = H - H;
aLPivs = L - L;
// -- More for future use, not necessary for basic plotting
aHPivHighs = H - H;
aLPivLows = L - L;
aHPivIdxs = H - H;
aLPivIdxs = L - L;
nHPivs = 0;
nLPivs = 0;
lastHPIdx = 0;
lastLPIdx = 0;
lastHPH = 0;
lastLPL = 0;
curPivBarIdx = 0;
aHHVBars = HHVBars(H, nBars);
aLLVBars = LLVBars(L, nBars);
aHHV = HHV(H, nBars);
aLLV = LLV(L, nBars);
aVisBars = Status("barvisible");
nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));
_TRACE("Last visible bar: " + nLastVisBar);
// -- Initialize value of curTrend
curBar = (BarCount-1);
curTrend = "";
if (aLLVBars[curBar] <
aHHVBars[curBar]) {
curTrend = "D";
}
else {
curTrend = "U";
}
if (BarCount > farback)
{
for (i=0; i<farback; i++) {
curBar = (BarCount - 1) - i;
// -- Have we identified a pivot? If trend is down...
if (aLLVBars[curBar] < aHHVBars[curBar]) {
// ... and had been up, this is a trend change
if (curTrend == "U") {
curTrend = "D";
// -- Capture pivot information
curPivBarIdx = curBar - aLLVBars[curBar];
aLPivs[curPivBarIdx] = 1;
aLPivLows[nLPivs] = L[curPivBarIdx];
aLPivIdxs[nLPivs] = curPivBarIdx;
nLPivs++;
}
// -- or current trend is up
} else {
if (curTrend == "D") {
curTrend = "U";
curPivBarIdx = curBar - aHHVBars[curBar];
aHPivs[curPivBarIdx] = 1;
aHPivHighs[nHPivs] = H[curPivBarIdx];
aHPivIdxs[nHPivs] = curPivBarIdx;
nHPivs++;
}
// -- If curTrend is up...else...
}
// -- loop through bars
}
}
curBar = (BarCount-1);
candIdx = 0;
candPrc = 0;
lastLPIdx = aLPivIdxs[0];
lastLPL = aLPivLows[0];
lastHPIdx = aHPivIdxs[0];
lastHPH = aHPivHighs[0];
if (lastLPIdx > lastHPIdx) {
// -- Bar and price info for candidate pivot
candIdx = curBar - aHHVBars[curBar];
candPrc = aHHV[curBar];
if (
lastHPH < candPrc AND
candIdx > lastLPIdx AND
candIdx < curBar) {
// -- OK, we'll add this as a pivot...
aHPivs[candIdx] = 1;
// ...and then rearrange elements in the
// pivot information arrays
for (j=0; j<nHPivs; j++) {
aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-
(j+1)];
aHPivIdxs[nHPivs-j] = aHPivIdxs[nHPivs-(j+1)];
}
aHPivHighs[0] = candPrc ;
aHPivIdxs[0] = candIdx;
nHPivs++;
}
} else {
// -- Bar and price info for candidate pivot
candIdx = curBar - aLLVBars[curBar];
candPrc = aLLV[curBar];
if (
lastLPL > candPrc AND
candIdx > lastHPIdx AND
candIdx < curBar) {
// -- OK, we'll add this as a pivot...
aLPivs[candIdx] = 1;
for (j=0; j<nLPivs; j++) {
aLPivLows[nLPivs-j] = aLPivLows[nLPivs-(j+1)];
aLPivIdxs[nLPivs-j] = aLPivIdxs[nLPivs-(j+1)];
}
aLPivLows[0] = candPrc;
aLPivIdxs[0] = candIdx;
nLPivs++;
}
}
//PlotShapes(IIf(aHPivs==1,shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-15);
//PlotShapes(IIf(aLPivs==1,shapeUpArrow , shapeNone), ColorRGB(168,255,0), 0, Low, Offset=-15);
//printf("\n Buuuy pivotss %g", aLPivs);
//printf("\n Seel pivotss %g \n",aHPivs);
IIf( (aHPivs==1 AND aLPivs==0),PIVOT_SELL = 5, PIVOT_SELL = 0 );
IIf( aLPivs==1 AND aHPivs==0, PIVOT_BUY = 0, PIVOT_BUY = 5 );
PIVOT_BUY = IIf(aLPivs==1, 5, 0);
PIVOT_SELL = IIf(aHPivs==1, 5, 0);
//printf("\n Buy pivots %g", PIVOT_BUY);
//printf("\n Sell pivots %g \n",PIVOT_SELL);
PIVOT_status = WriteIf(PIVOT_BUY,"Buy["+PIVOT_BUY+"]",WriteIf(PIVOT_SELL,"Sell["+PIVOT_SELL+"]","NA"));
PIVOT_col = IIf (PIVOT_BUY,colorGreen, IIf (PIVOT_SELL,colorRed,colorLightGrey));
_SECTION_END();
/**********************************************************
/ADX
***********************************************************/
range = Param("Range",14,3,60,1);
px = PDI(range);
nx = MDI(range);
ax = ADX(range);
Line_Control = 20;
up_adx = Ref(ADX(range),-1) < ADX(range);
dw_adx = Ref(ADX(range),-1) > ADX(range);
// ADX Trends
Notrend = ADX(range) < 20;
ModerateTrend = ADX(range) >= 20 AND ADX(range) < 40 AND up_adx ;
StrongTrend = ADX(range) >= 40 AND ADX(range) < 60 AND up_adx ;
VeryStrongTrend = ADX(range) >= 60 AND ADX(range) < 80 AND up_adx ;
ExtremelyStrongTrend = ADX(range) >= 80 AND up_adx ;
// Buy Conditions
bcon1 = Cross(px,ax) AND nx < px AND ax > Ref(ax,-1);
scon1 = Cross(nx,ax) AND px < nx AND ax > Ref(ax,-1);
adbuy = ax < 20 AND ax > Ref(ax,-1) AND ( Cross(px,nx) OR nx < px) ;
adsell = ax < 20 AND ax > Ref(ax,-1) AND ( Cross(nx,px) OR nx > px) ;
adbuy1 = Cross(px,ax) AND nx < px AND ax > Ref(ax,-1) AND px > ax;
adsell1 = Cross(nx,ax) AND nx > px AND ax > Ref(ax,-1) AND nx > ax;
BUY_ADX = bcon1 + adbuy + adbuy1;
SELL_ADX = scon1 + adsell + adsell1;
ADX_status = WriteIf(BUY_ADX,"Buy["+BUY_ADX+"]",WriteIf(SELL_ADX,"Sell["+SELL_ADX+"]","NA"));
ADX_col = IIf (BUY_ADX,colorGreen, IIf (SELL_ADX,colorRed,colorLightGrey));
/**********************************************************
/MACD Cross
***********************************************************/
_SECTION_BEGIN("MACD");
MACD_TOGGLE = ParamToggle("Plot MACD","Off|On",0);
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
m1 = MACD(r1, r2);
s1 = Signal(r1,r2,r3);
difference = m1-s1;
mycolor=IIf(m1<0 AND m1>s1,51,IIf(m1>0 AND m1>s1,colorBrightGreen,IIf(m1>0 AND m1<s1,colorLightOrange,colorRed)));
// **********************
//MACD crossing zero
B_MACD_0 = Cross(MACD(r1, r2),0);
S_MACD_0 = Cross(0,MACD(r1, r2));
// **********************
//Bullish - Bearish MACD crossing signal above zero or below zero plane
BULL_CROSS_ABOVE_ZERO = Cross (MACD(r1, r2),Signal(r1,r2,r3)) AND MACD(r1, r2) > 0;
BEAR_CROSS_ABOVE_ZERO = Cross (Signal(r1,r2,r3),MACD(r1, r2)) AND MACD(r1, r2) > 0;
// **********************
//bELOW ZERO Bullish - Bearish MACD crossing signal above zero or below zero plane
BULL_CROSS_BELOW_ZERO = Cross (MACD(r1, r2),Signal(r1,r2,r3)) AND MACD(r1, r2)<0;
BEAR_CROSS_BELOW_ZERO = Cross(Signal(r1,r2,r3),MACD(r1, r2)) AND MACD(r1, r2)<0;
// **********************
//Zero line reject ZLR
BEAR_ZLR = BarsSince(B_MACD_0);
BEAR_ZLR1 = (BEAR_ZLR < 6) AND (S_MACD_0);
BULL_ZLR = BarsSince(S_MACD_0);
BULL_ZLR1 = (BULL_ZLR < 6) AND (B_MACD_0);
// **********************
//HOOKS
BULL_HOOK1 = BarsSince(BEAR_CROSS_ABOVE_ZERO);
BULL_HOOK = (BULL_HOOK1<6) AND BULL_CROSS_ABOVE_ZERO ;
BEAR_HOOK1 = BarsSince(BULL_CROSS_ABOVE_ZERO);
BEAR_HOOK = (BEAR_HOOK1<6) AND BEAR_CROSS_ABOVE_ZERO ;
BUY_MACD = B_MACD_0 + BULL_CROSS_ABOVE_ZERO + BULL_CROSS_BELOW_ZERO + BULL_ZLR1 + BULL_HOOK;
SELL_MACD = S_MACD_0 + BEAR_CROSS_ABOVE_ZERO + BEAR_CROSS_BELOW_ZERO + BEAR_ZLR1 + BEAR_HOOK;
_SECTION_END();
BUY_MACD = B_MACD_0 + BULL_CROSS_ABOVE_ZERO + BULL_CROSS_BELOW_ZERO + BULL_ZLR1 + BULL_HOOK ;
SELL_MACD = S_MACD_0 + BEAR_CROSS_ABOVE_ZERO + BEAR_CROSS_BELOW_ZERO + BEAR_ZLR1 + BEAR_HOOK ;
MACD_status = WriteIf(BUY_MACD,"Buy["+BUY_MACD+"]",WriteIf(SELL_MACD,"Sell["+SELL_MACD+"]","NA"));
MACD_col = IIf (BUY_MACD,colorGreen, IIf (SELL_MACD,colorRed,colorLightGrey));
/**************************************************
Stochastics
***************************************************/
_SECTION_BEGIN("STOCHASTICS");
STOC_TOGGLE = ParamToggle("Plot STOCHASTICS","Off|On",0);
SP = Param( "Periods", 10, 1, 200, 1 );
Ksmooth = Param( "%K avg", 5, 1, 200, 1 );
Dsmooth = Param( "%D avg", 5, 1, 200, 1 );
StochDval = StochD( SP , Ksmooth, DSmooth );
StochKval = StochK( SP , Ksmooth);
Overbought = 80;
Oversold = 20;
/*
if(STOC_TOGGLE==1)
{
GraphX = 5;
Plot( StochD( SP , Ksmooth, DSmooth), _DEFAULT_NAME(), ParamColor( "ColorD", colorTurquoise ), ParamStyle("Style") );
Plot( StochK( SP , Ksmooth), _DEFAULT_NAME(), ParamColor( "ColorK", colorPaleGreen ), ParamStyle("Style") );
Plot(Overbought,"Overbought Level",colorRed);
Plot(Oversold,"Oversold Level",colorGreen);
}
*/
StochBuy = Cross(StochK(SP,Ksmooth), StochD(SP,Ksmooth, DSmooth)) AND (StochD(SP,Ksmooth, DSmooth) > 20) AND (StochK(SP,Ksmooth) > 20) AND (StochD(SP,Ksmooth, DSmooth) < 80) AND (StochK(SP,Ksmooth) < 80);
StochSell = Cross (StochD(SP,Ksmooth, DSmooth), StochK(SP,Ksmooth)) AND (StochD(SP,Ksmooth, DSmooth) > 20) AND (StochK(SP,Ksmooth) > 20) AND (StochD(SP,Ksmooth, DSmooth) < 80) AND (StochK(SP,Ksmooth) < 80);
StochStrongBuy = Cross(StochK(SP,Ksmooth),StochD(SP,Ksmooth, DSmooth)) AND (StochD(SP,Ksmooth, DSmooth) < 20) AND (StochK(SP,Ksmooth) < 20) ;
StochStrongSell = Cross (StochD(SP,Ksmooth,DSmooth), StochK(SP , Ksmooth)) AND (StochD(SP,Ksmooth, DSmooth) > 80) AND (StochK(SP,Ksmooth) > 80);
BUY_STOCH = StochBuy + StochStrongBuy;
SELL_STOCH = StochSell + StochStrongSell;
printf("Sto %g",BUY_STOCH);
_SECTION_END();
STOCH_status = WriteIf(BUY_STOCH,"Buy["+BUY_STOCH+"]",WriteIf(SELL_STOCH,"Sell["+SELL_STOCH+"]","NA"));
STOCH_col = IIf (BUY_STOCH,colorGreen, IIf (SELL_STOCH,colorRed,colorLightGrey));
/**************************************************
TREND DETECTOR
***************************************************/
_SECTION_BEGIN("Trend Detector");
TREND_TOGGLE = ParamToggle("Plot Trend","Off|On",0);
A = (H+C+L)/3;
B=MA(A,5)-EMA(A,34);
D = EMA(A,34)-MA(A,5);
Bcolor=IIf(B>D,25,39);
Dcolor=IIf(D<B,25,39);
Up = B > D;
down = B < D;
TREND_B = Cross(B,D);
TREND_S = Cross(D,B);
if(TREND_TOGGLE==1)
{
Plot(B,"B ",Bcolor,styleLine|styleThick);
Plot(D,"D ",Dcolor,styleLine|styleThick);
Plot(B,"",Bcolor,styleHistogram|styleThick);
Plot(D,"",Dcolor,styleHistogram|styleThick);
Plot(0,"",colorWhite,styleLine);
PlotShapes(IIf(TREND_S, shapeHollowDownArrow , shapeNone), colorRed,0,0,-8);
PlotShapes(IIf(TREND_B, shapeHollowUpArrow , shapeNone), colorGreen,0,0,-8);
}
_SECTION_END();
TREND_status = WriteIf(TREND_B,"Buy",WriteIf(TREND_S ,"Sell","NA"));
TREND_col = IIf (TREND_B,colorGreen, IIf (TREND_S ,colorRed,colorLightGrey));
/**************************************************
RSI
***************************************************/
_SECTION_BEGIN("RSI");
Rperiods = Param( "Periods", 14, 1, 200, 1 );
OB = Param("OverBrought Line",70,70,100,1);
OS = Param("OverSold Line",30,20,40,1);
CentreRSI = 50;
Overbought = OB;
Oversold = OS;
RSI_PERIODS = Prec(RSI( Rperiods),1);
//******* RSI Cross 30 or 70**//
B_RSI = RSI_CROSS_30 = Cross(RSI_PERIODS,OS);
S_RSI = RSI_CROSS_70 = Cross(OB,RSI_PERIODS);
//******* RSI < 30 or > 70**//
RSI_BELOW_30 = RSI_PERIODS < OS ;
RSI_ABOVE_70 = RSI_PERIODS > OB ;
//******* RSI > OR < IN LAST 14 DAYS***//
RSI_14_GREATEST = RSI_PERIODS>=HHV( RSI_PERIODS, 14);
RSI_14_LOWEST = RSI_PERIODS<=LLV( RSI_PERIODS, 14);
//******* RSI DIVERGENCE***//
RSI_BEAR_DIV = Close >= HHV( Close, 14 ) AND RSI_PERIODS < HHV( RSI_PERIODS, 14 );
RSI_BULL_DIV = RSI_PERIODS >= HHV( RSI_PERIODS, 14 ) AND Close < HHV( Close, 14 );
RSI_BULL_DIV1 = Close <= LLV( Close, 14 ) AND RSI_PERIODS > LLV(RSI_PERIODS, 14 );
RSI_BEAR_DIV1 = RSI_PERIODS <= LLV( RSI_PERIODS, 14) AND Close > LLV(Close,14);
/*****/////////
RSI_BUY = B_RSI ;
RSI_SELL =S_RSI ;
_SECTION_END();
RSI_status = WriteIf(RSI_BUY,"Buy["+RSI_BUY+"]",WriteIf(RSI_SELL,"Sell["+RSI_SELL+"]","NA"));
RSI_col = IIf (RSI_BUY,colorGreen, IIf (RSI_SELL,colorRed,colorLightGrey));
/**************************************************
OBV
***************************************************/
_SECTION_BEGIN("OBV");
MA_OBV_Period = Param("OBV_MA Period",10,10,21,1);
/***********OBV CROSS MA************/
OBV_BUY = Cross(OBV(),MA(OBV(),MA_OBV_Period));
OBV_SELL = Cross(MA(OBV(),MA_OBV_Period),OBV());
_SECTION_END();
OBV_status = WriteIf(OBV_BUY,"Buy",WriteIf(OBV_SELL,"Sell","NA"));
OBV_col = IIf (OBV_BUY,colorGreen, IIf (OBV_SELL,colorRed,colorLightGrey));
/**************************************************
TSV = SIMILAR TO WORDEN
***************************************************/
_SECTION_BEGIN("TSV");
Period = Param("Period for FVE", 22, 5, 80, 1 );
Coeff = Param("Coeff for Cutoff", 0.1, 0, 2, 0.01 );
intra=log(H)-log(L);
Vintra = StDev(intra, period );
inter = log(Avg)-log(Ref(Avg,-1));
Vinter = StDev(inter,period);
Cutoff = Coeff * (Vinter+Vintra)*C;
MF = C- (H+L)/2 + Avg - Ref( Avg, -1 );
VC = IIf( MF > Cutoff, V,
IIf( MF < -Cutoff, -V, 0 ));
FVE = 100 * Sum( VC, Period )/(MA( V, Period ) * Period );
// Momemtum Indicator by William Blau
TSI = 100 * ( EMA( EMA( C - Ref( C, -1 ) ,25 ) ,13)
/ EMA( EMA( abs( C - Ref( C, -1) ),25 ), 13 ) );
TSI_BUY = Cross(TSI,EMA(TSI,7));
TSI_SELL = Cross(EMA(TSI,7),TSI);
_SECTION_END();
TSI_status = WriteIf(TSI_BUY,"Buy",WriteIf(TSI_SELL,"Sell","NA"));
TSI_col = IIf (TSI_BUY,colorGreen, IIf (TSI_SELL,colorRed,colorLightGrey));
/**************************************************
TRIX
***************************************************/
_SECTION_BEGIN("TRIX");
// TRIX - 15 Periods, 9 Signal Periods
tPeriods = Param("Periods", 15, 2, 100, 1 );
tSig = Param("Signal", 9, 2, 100, 1);
Zero = 0;
TRIX_VAL = Trix(tPeriods);
SIG_TRIX = EMA(Trix(tPeriods),tSig);
/***********TRIX & Signal Line cross ************/
TRIX_SIGNAL_BUY = Cross(TRIX_VAL, SIG_TRIX) AND TRIX_VAL < 0;
TRIX_SIGNAL_SELL = Cross(SIG_TRIX, TRIX_VAL)AND TRIX_VAL > 0;
/***********TRIX & Zero Line cross ************/
TRIX_ZERO_BUY = Cross(TRIX_VAL, Zero);
TRIX_ZERO_SELL = Cross(Zero, TRIX_VAL);
TRIX_BUY = TRIX_SIGNAL_BUY + TRIX_ZERO_BUY;
TRIX_SELL = TRIX_SIGNAL_SELL + TRIX_ZERO_SELL;
_SECTION_END();
TRIX_status = WriteIf(TRIX_BUY,"Buy",WriteIf(TRIX_SELL,"Sell","NA"));
TRIX_col = IIf (TRIX_BUY,colorGreen, IIf (TRIX_SELL,colorRed,colorLightGrey));
/************************************************
Gap
*************************************************/
GAP_UP = GapUp();
GAP_DW = GapDown();
GAP_status = WriteIf(GAP_UP,"Buy",WriteIf(GAP_DW ,"Sell","NA"));
GAP_col = IIf (GAP_UP,colorGreen, IIf (GAP_DW ,colorRed,colorLightGrey));
/************************************************
Total of Bullish/Bearish
*************************************************/
Total_Buy = PIVOT_BUY + BUY_ADX + BUY_MACD + BUY_STOCH+ TREND_B + GAP_UP + RSI_BUY + OBV_BUY + TSI_BUY + TRIX_BUY;
Total_Sell = PIVOT_SELL + SELL_ADX + SELL_MACD + SELL_STOCH + TREND_S + GAP_DW + RSI_SELL + OBV_SELL +TSI_SELL+TRIX_SELL;
printf("B OIVOTS %g\n",PIVOT_BUY);
printf("SELL PIVOTS %g\n",PIVOT_SELL);
printf("BUY GAP %g\n",TREND_B);
printf("BUY TREND %g\n",GAP_UP);
printf("BUY RSI %g\n",B_RSI + RSI_14_GREATEST + RSI_BULL_DIV1 + RSI_BULL_DIV);
_SECTION_BEGIN("Chart Settings");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(ParamColor("Outer Panel",colorPaleBlue));
SetChartBkGradientFill(ParamColor("Upper Chart",colorDarkGrey),ParamColor("Lower Chart",colorDarkGrey));
GraphXSpace=Param("GraphXSpace",10,0,100,1);
dec = (Param("Decimals",2,0,7,1)/10)+1;
bi = BarIndex();
Lbi = LastValue(BarIndex());
sbi = SelectedValue(bi);
x1= BarCount-1;
Title = EncodeColor(55)+ Name() + " " + EncodeColor(32) + Date() + " " + EncodeColor(5) + "{{INTERVAL}} " +
EncodeColor(55)+ " Open = "+ EncodeColor(52)+ WriteVal(O,dec) +
EncodeColor(55)+ " High = "+ EncodeColor(5) + WriteVal(H,dec) +
EncodeColor(55)+ " Low = "+ EncodeColor(32)+ WriteVal(L,dec) +
EncodeColor(55)+ " Close = "+ EncodeColor(52)+ WriteVal(C,dec)+
EncodeColor(55)+ " Volume = "+ EncodeColor(52)+ WriteVal(V,1) +
"\n" + EncodeColor(colorYellow) + "----------------------------------------"
+ "\n"+EncodeColor(colorGold)+ " Analysis "
+"\n"+EncodeColor(colorYellow) +"----------------------------------------"
///// PIVOTS
+ "\n"
+EncodeColor(colorWhite)+"PIVOTS = " +
WriteIf (aLPivs,EncodeColor(ColorRGB(168,255,0))+" BUY("+PIVOT_BUY+")",WriteIf (aHPivs,EncodeColor(colorRed)+ " SELL("+PIVOT_SELL+")","Neutral"))
///// ADX
+ "\n"+EncodeColor(colorWhite)+"ADX = " +
WriteIf (BUY_ADX,EncodeColor(ColorRGB(168,255,0))+"BUY("+BUY_ADX+")",WriteIf (SELL_ADX,EncodeColor(colorRed)+ " SELL("+SELL_ADX+")","Neutral"))
///// MACD
+ "\n" +EncodeColor(colorWhite)+"MACD "+"["+r1+"]"+" " +"["+r2+"]"+" " +"["+r3+"] = " +
WriteIf (BUY_MACD,EncodeColor(ColorRGB(168,255,0))+"BUY("+BUY_MACD+")",WriteIf (SELL_MACD,EncodeColor(colorRed)+ "SELL("+SELL_MACD+")","Neutral"))
///// STOChASTICS
+"\n"+EncodeColor(colorWhite)+"Stochastics = "
+ WriteIf(BUY_STOCH,EncodeColor(ColorRGB(168,255,0))+"BUY ("+BUY_STOCH+")",WriteIf(SELL_STOCH,EncodeColor(colorRed)+"SELL("+SELL_STOCH+")","Neutral"))
///// RSI
+"\n" + EncodeColor(colorWhite)+"RSI"+"("+Rperiods+") = "
+WriteIf(B_RSI,EncodeColor(ColorRGB(168,255,0))+"BUY("+RSI_BUY+")",WriteIf (S_RSI,EncodeColor(colorRed)+"SELL("+RSI_SELL+")","Neutral"))
///// OBV
+"\n" +EncodeColor(colorWhite)+"OBV = "+
WriteIf(OBV_BUY,EncodeColor(ColorRGB(168,255,0))+"BUY(1)",WriteIf(OBV_SELL,EncodeColor(colorRed)+"SELL(1)",""))+
WriteIf(NOT OBV_BUY AND NOT OBV_SELL,"No Cross","")
///// TSV
+"\n"
+EncodeColor(colorWhite)+"TSV = " +
WriteIf(TSI_BUY,EncodeColor(ColorRGB(168,255,0))+"BUY(1)",
WriteIf(TSI_SELL,EncodeColor(colorRed)+"SELL(1)",""))+
WriteIf(NOT TSI_BUY AND NOT TSI_SELL,EncodeColor(colorAqua)+"NA","")
///// TRIX
+"\n"
+EncodeColor(colorWhite)+"TRIX "+ "("+tPeriods+") "+"(" +tSig+ ") = "
+EncodeColor(ColorRGB(168,255,0))+
WriteIf (TRIX_BUY, "BUY ("+TRIX_BUY+")","")
+EncodeColor(colorRed)+
WriteIf (TRIX_SELL, "SELL("+TRIX_SELL+")","")
+EncodeColor(colorAqua)+
WriteIf (NOT TRIX_SELL AND NOT TRIX_BUY, "No Cross","")
///// TREND
+"\n" +EncodeColor(colorWhite)+"Trend = "
+WriteIf(Up AND NOT TREND_B,EncodeColor(ColorRGB(168,255,0))+"Up ",WriteIf(Up AND TREND_B,EncodeColor(colorBrightGreen)+ "BUY(1)",
WriteIf(Down AND NOT TREND_S,EncodeColor(colorRed)+"Down",WriteIf(Down AND TREND_S,EncodeColor(colorRed)+"SELL(1)","."))))
///// GAPS
+"\n"+EncodeColor(colorWhite)+"GAP = "
+WriteIf(GAP_UP,EncodeColor(ColorRGB(168,255,0))+"UP (1)",WriteIf(GAP_DW,EncodeColor(colorRed)+"DOWN (1)", EncodeColor(colorAqua)+"Neutral"))
+"\n"+EncodeColor(colorPink) +"======================="
+"\n"+EncodeColor((ColorRGB(242,157,255)))+"BUY = "+EncodeColor(colorYellow)+Total_Buy
+"\n"+EncodeColor((ColorRGB(242,157,255)))+"SELL = "+EncodeColor(colorYellow)+Total_Sell
+"\n"+EncodeColor(colorPink) +"----------------------------------------"
+"\n"+EncodeColor(07)+"Volume: "+WriteIf(V>Vp2,EncodeColor(colorLime)+"Very High",WriteIf(V>Vp1,EncodeColor(colorLime)+" High",WriteIf(V>Vrg,EncodeColor(colorLime)+"Above Average",
WriteIf(V<Vrg AND V>Vn1,EncodeColor(colorRed)+"Less than Average",WriteIf(V<Vn1,EncodeColor(colorRed)+"Low","")))))
+"\n"+EncodeColor(colorYellow)+"Spread: "+WriteIf(rg >(arg*2),EncodeColor(colorLime)+" Wide",WriteIf(rg>arg,EncodeColor(colorLime)+" Above Average",EncodeColor(colorRed)+" Narrow"))
+"\n"+(EncodeColor(colorYellow)+"Close: ")+WriteIf(Vhcls,EncodeColor(colorLime)+"Very High",WriteIf(ucls,EncodeColor(colorLime)+"High",WriteIf(mcls,EncodeColor(colorYellow)+"Mid",
WriteIf(dcls,EncodeColor(colorRed)+"Down","Very Low"))))
+"\n"+EncodeColor(colorYellow) + "Zone : " +WriteIf(rising , EncodeColor(colorBrightGreen) + "Accumulation",WriteIf(falling , EncodeColor(colorCustom12) + "Distirbution",EncodeColor(colorAqua) + "Flat")) + " "
+"\n"+EncodeColor(colorYellow) + "Status : " +
WriteIf(Weakness , EncodeColor(colorRed) + "Weak",
WriteIf(stoppingVolume , EncodeColor(colorCustom12) + "StoppingVol",
WriteIf(noSupplyBar , EncodeColor(colorLightOrange) + "NoSupply",
WriteIf(support , EncodeColor(colorLightBlue) + "SupportVol",
WriteIf(noDemandBar , EncodeColor(colorPink) + "NoDemand",
WriteIf(absorption, EncodeColor(colorSkyblue) + "Absorption",
WriteIf(upThrustBar, EncodeColor(colorBlue) + "Upthrust",
WriteIf(bullishsign, EncodeColor(colorPaleGreen) + "STRONG",
EncodeColor(colorTan) + "Neutral")))))))) + " "
+"\n"+EncodeColor(colorPink)+"----------------------------------------";
_SECTION_END();
//========================================================================
SetChartOptions(2,chartShowArrows|chartShowDates|chartWrapTitle);
SetChartOptions(0,chartShowArrows|chartShowDates);
//GfxGradientRect( 180, 30, 1759, 735, ColorRGB(40,40,40), ColorRGB(0,0,40) );
GfxSetOverlayMode(1);
//GfxSelectPen( ColorRGB(150,0,0), 1 );
GfxSelectSolidBrush( ColorRGB(0,0,40) );
//GfxRectangle=( 0,750, 1807, 35 );
//GfxSelectPen( ColorRGB(150,0,0), 2 );
GfxSelectSolidBrush( ColorRGB(65,65,65) );
//GfxPolygon(250,200,200,250,250,20,200,50);
//GfxSelectPen( ColorRGB(125,0,0), 1 );
//GfxSelectSolidBrush( ColorRGB(0,0,40) );
//GfxRectangle( 10,100, 190, 160 );
//GfxSelectPen=( ColorRGB(0,0,0) ,1 );
GfxSelectSolidBrush( ColorRGB(0,0,0) );
//GfxSetTextAlign( 250 );// center alignment
GfxSetOverlayMode(1);
//GfxSelectFont=("Times New Roman", 30, 400, True );
GfxSetTextColor( ColorRGB( 105, 105, 105 ) );
GfxSetBkMode(0); // transparent
//GfxTextOut=("Pathfinder", 15 , 35 );
_SECTION_BEGIN("Flower");
si=Param("Zoom/In Out",5,-50,100,1);
GraphXSpace=si;
r1 = Param( "ColorFast avg", 5, 2, 200, 1 );
r2 = Param( "ColorSlow avg", 10, 2, 200, 1 );
r3 = Param( "ColorSignal avg", 5, 2, 200, 1 );
m1=MACD(r1,r2);
s1=Signal(r1,r2,r3);
mycolor=IIf(m1<0 AND m1>s1, ColorRGB(155,155,155),IIf(m1>0 AND m1>s1,ColorRGB(0,125,0),IIf(m1>0 AND m1<s1,ColorRGB(180,30,160),ColorRGB(100,0,0))));
Prd1=Param("ATR Period",4,1,20,1);
Prd2=Param("Look Back",7,1,20,1);
green = HHV(LLV(L,Prd1)+ATR(Prd1),Prd2);
red = LLV(HHV(H,Prd1)-ATR(Prd1),Prd2);
flowerClose = EMA((Open+High+Low+Close)/4,3) ;
flowerOpen = EMA((Ref(Open,-1) + Ref(flowerClose,-1))/2,3);
Temp = Max(High, flowerOpen);
flowerHigh = EMA(Max(Temp, flowerClose),3);
Temp = Min(Low,flowerOpen);
flowerLow = EMA(Min(Temp, flowerClose),3);
barColor=IIf(Close>Open,ColorRGB(0,245,0),ColorRGB(255,0,0));
Ctmpl = E_TSKPCOLORTMPL(Open,High,Low,Close,Volume);
total = 0;
total = total + IIf(tskp_colortmplcnd0 > 0, 1, -1);
total = total + IIf(tskp_colortmplcnd1 > 0, 1, -1);
total = total + IIf(tskp_colortmplcnd2 > 0, 1, -1);
total = total + IIf(tskp_colortmplcnd3 > 0, 1, -1);
total = total + IIf(tskp_colortmplcnd4 > 0, 1, -1);
total = total + IIf(tskp_colortmplcnd5 > 0, 1, -1);
total = total + IIf(tskp_colortmplcnd6 > 0, 1, -1);
total = total + IIf(tskp_colortmplcnd7 > 0, 1, -1);
total = total + IIf(tskp_colortmplcnd8 > 0, 1, -1);
for( i = 0; i < BarCount; i++ )
{
if( total >= 5 )
Color = colorLime;
else if( total <= -5 )
Color = colorRed;
else
Color = colorWhite;
}
Candle=ParamList("Candle","Modified Candlestick,Modified Heikin Ashi,Normal Candlestick",1);
if(Candle=="Modified Candlestick")
{
ColorHighliter = myColor;
SetBarFillColor( ColorHighliter );
Plot (Close,"- Modified Candlestick", Color,ParamStyle( "Style", styleCandle|styleLine | styleThick, maskAll));
}
if(Candle=="Modified Heikin Ashi")
{
ColorHighliter = myColor;
SetBarFillColor( ColorHighliter );
PlotOHLC( IIf(flowerOpen<flowerClose, flowerOpen, flowerClose),flowerHigh,flowerLow,IIf(flowerOpen<flowerClose, flowerClose, flowerOpen), "Modified Heikin Ashi", Color, styleCandle|styleLine);
}
if(Candle=="Normal Candlestick")
{
//ColorHighliter = myColor;
//SetBarFillColor( ColorHighliter );
PlotOHLC(O,H,L,C,"Normal Candlestick",barcolor,styleCandle|styleLine);
}
_SECTION_END();
_SECTION_BEGIN("TSKPPIVOT");
if(Candle=="Modified Heikin Ashi")
{
CHiPr = 0;
CLoPr = 9999999;
blsLong = 0;
PrevCOBar = 0;
NumBars = 0;
PrePP = 0;
PrevLowVal = 9999999;
BuySig = 0;
blsShort = 0;
PrevHiVal = 0;
blsNewCO = 0;
BarDif = 0;
KPA900Val = E_TSKPA900(Close);
KPAutoStopVal = E_TSKPAUTOSTOP(High,Low,Close);
// -- Create 0-initialized arrays the size of barcount
aHPivs = flowerHigh - flowerHigh;
aLPivs = flowerLow - flowerLow;
aHiVal = flowerHigh - flowerHigh;
aLoVal = flowerLow - flowerLow;
Ctmpl = E_TSKPCOLORTMPL(Open,High,Low,Close,Volume);
sctotal = 0;
sctotal = sctotal + IIf(tskp_colortmplcnd0 > 0, 1, -1);
sctotal = sctotal + IIf(tskp_colortmplcnd1 > 0, 1, -1);
sctotal = sctotal + IIf(tskp_colortmplcnd2 > 0, 1, -1);
sctotal = sctotal + IIf(tskp_colortmplcnd3 > 0, 1, -1);
sctotal = sctotal + IIf(tskp_colortmplcnd4 > 0, 1, -1);
sctotal = sctotal + IIf(tskp_colortmplcnd5 > 0, 1, -1);
sctotal = sctotal + IIf(tskp_colortmplcnd6 > 0, 1, -1);
sctotal = sctotal + IIf(tskp_colortmplcnd7 > 0, 1, -1);
sctotal = sctotal + IIf(tskp_colortmplcnd8 > 0, 1, -1);
for (curBar=0; curBar < BarCount-1; curBar++)
{
if ( curBar == 0 )
{
CHiPr = flowerHigh[curBar];
CHiBar = curBar;
CLoPr = flowerLow[curBar];
CLoBar = curBar;
blsLong = 0;
blsShort = 0;
blsNewCO = 0;
PrePP = 0;
PrevCOBar = 0;
PrevHiVal = flowerHigh[curBar];
PrevLowVal = flowerLow[curBar];
BuySig = 0;
SellSig = 0;
blsLL = 0;
}
if (flowerHigh[CurBar] >= CHiPr) {
CHiPr = flowerHigh[CurBar];
ChiBar = CurBar;
}
if (flowerLow[CurBar] <= CLoPr) {
CLoPr = flowerLow[CurBar];
CLoBar = CurBar;
}
if ( (KPA900Val[curBar] >= KPAutoStopVal[curbar]) AND (PrePP != -1) AND (blsLong != 1) ){
BarDif = CurBar - PrevCOBar;
if (BarDif >= NumBars) {
blsLong = 1;
blsShort = 0;
blsNewCO = 1;
PrevCOBar = CurBar;
}
}
if ( (KPA900Val[curBar] <= KPAutoStopVal[curbar]) AND (PrePP != 1) AND (blsShort != 1) ){
BarDif = CurBar - PrevCOBar;
if (BarDif >= NumBars) {
blsLong = 0;
blsShort = 1;
blsNewCO = 1;
PrevCOBar = CurBar;
}
}
if ( (blsNewCO == 1) AND (sctotal[CurBar] >= 5) AND (blsLong == 1) ) {
LVal = CurBar - CLoBar;
for (j= CLoBar-1; j <= CLoBar+1; j++)
{
if (j >=0) {
aLPivs[j] = 1;
aLoVal[j] = CLoPr;
}
}
PrePP = -1;
blsNewCO = 0;
CHiPr = flowerHigh[CurBar];
CHiBar = CurBar;
CLoPr = flowerLow[Curbar];
CLoBar = CurBar;
}
else if ((blsNewCO == 1) AND (sctotal[CurBar] <= -5) AND (blsShort == 1) ) {
HVal = CurBar - CHiBar;
for (j= CHiBar-1; j <= CHiBar+1; j++)
{
if (j >=0) {
aHPivs[j] = 1;
aHiVal[j] = CHiPr;
}
}
PrePP = 1;
blsNewCO = 0;
CHiPr = flowerHigh[CurBar];
CHiBar = CurBar;
CLoPr = flowerLow[Curbar];
CLoBar = CurBar;
}
}
PlotShapes(IIf(aHPivs == 1, 21,shapeNone), ColorRGB(255,0,145),0, aHiVal,Offset = 20);
PlotShapes(IIf(aHPivs == 1, 15,shapeNone), ColorRGB(200,50,75),0, aHiVal,Offset = 20);
PlotShapes(IIf(aLPivs == 1, 21,shapeNone), ColorRGB(0,125,225),0, aLoVal, Offset = -20);
PlotShapes(IIf(aLPivs == 1, 15,shapeNone), ColorRGB(0,125,255),0, aLoVal, Offset = -20);
}
_SECTION_END();
_SECTION_BEGIN("Resistance");
supres=ParamToggle("Sup_Res","No|Yes",1);
if(supres)
{
Prd1=Param("Res_Period1",2,0,200,1);
test = TEMA ( High , Prd1 ) ;
PK = test > Ref(test,-1) AND Ref(test,1) < High;//Peak
PKV0 = ValueWhen(PK,flowerHigh,0);//PeakValue0
PKV1 = ValueWhen(PK,flowerHigh,1);//PeakValue1
PKV2 = ValueWhen(PK,flowerHigh,2);//PeakValue2
MPK = PKV2 < PKV1 AND PKV1 > PKV0 ;//MajorPeak
RsColor=ParamColor("ResistColor",ColorRGB(225,0,0));
BrCount=Param("ResistBarLength",8,1,500,1);
for (i=0;i<BarCount-BrCount;i++) //hide the line except most recent 10 bars
{
RsColor = colorBlack;
}
MPKV = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,1); //MajorPeakValue
MPKD = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),1); //MajorPeakDate
SD = IIf(DateNum() < LastValue(MPKD,lastmode = True ), Null, LastValue(MPKV,Lastmode = True));//SelectedDate
Plot(SD, "Resist1", ColorRGB(200,0,0),ParamStyle("ResStyle1",styleDashed|styleNoTitle,maskAll));
RsColor2=ParamColor("Resist2Color",ColorRGB(225,0,0));
BrCount=Param("Resist2BarLength",8,1,500,1);
for (i=0;i<BarCount-BrCount;i++) //hide the line except most recent 10 bars
{
RsColor2 = colorBlack;
}
MPKV2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,2); //MajorPeakValue
MPKD2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),2); //MajorPeakDate
SD2 = IIf(DateNum() < LastValue(MPKD2,lastmode = True ), Null, LastValue(MPKV2,Lastmode = True));//SelectedDate
Plot(SD2, "Resist2", RsColor2,ParamStyle("ResStyle2",styleDashed|styleNoTitle,maskAll));
RsColor3=ParamColor("Resist3Color",ColorRGB(225,0,0));
BrCount=Param("Resist3BarLength",8,1,500,1);
for (i=0;i<BarCount-BrCount;i++) //hide the line except most recent 10 bars
{
RsColor3 = colorBlack;
}
MPKV3 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,3); //MajorPeakValue
MPKD3 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),3); //MajorPeakDate
SD3 = IIf(DateNum() < LastValue(MPKD3,lastmode = True ), Null, LastValue(MPKV3,Lastmode = True));//SelectedDate
Plot(SD3, "Resist3", RsColor3,ParamStyle("ResStyle3",styleThick|styleDots|styleNoTitle,maskAll));
_SECTION_END();
_SECTION_BEGIN("Support");
Prd2=Param("Sup_Period1",2,0,200,1);
test2 = TEMA ( Low , Prd2 ) ;
SP = Ref(test2,1) > Low AND test2 < Ref(test2,-1);//Peak
SPV0 = ValueWhen(SP,flowerLow,0);//PeakValue0
SPV1 = ValueWhen(SP,flowerLow,1);//PeakValue1
SPV2 = ValueWhen(SP,flowerLow,2);//PeakValue2
MSP = SPV2 > SPV1 AND SPV1 < SPV0 ;//MajorPeak
SpColor=ParamColor("SupColor",ColorRGB(0,225,0));
BrCount=Param("SupBarLength",8,1,500,1);
for (i=0;i<BarCount-BrCount;i++) //hide the line except most recent 10 bars
{
SpColor = colorBlack;
}
MSPV = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,1);
MSPD = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),1);
SD = IIf(DateNum() < LastValue(MSPD,lastmode = True ), Null, LastValue(MSPV,Lastmode = True));
Plot(SD,"Support1",SpColor,ParamStyle("SupportLine1",styleDashed|styleNoTitle,maskAll));
SpColor2=ParamColor("SupColor2",ColorRGB(0,200,0));
BrCount=Param("Sup2BarLength",8,1,500,1);
for (i=0;i<BarCount-BrCount;i++) //hide the line except most recent 10 bars
{
SpColor2 = colorBlack;
}
MSPV2 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,2);
MSPD2 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),2);
SD2 = IIf(DateNum() < LastValue(MSPD2,lastmode = True ), Null, LastValue(MSPV2,Lastmode = True));
Plot(SD2,"Support2",Spcolor2,ParamStyle("SupportLine2",styleDashed|styleNoTitle,maskAll));
SpColor3=ParamColor("SupColor3",ColorRGB(0,175,0));
BrCount=Param("Sup3BarLength",8,1,500,1);
for (i=0;i<BarCount-BrCount;i++) //hide the line except most recent 10 bars
{
SpColor3 = colorBlack;
}
MSPV3 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,3);
MSPD3 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),3);
SD3 = IIf(DateNum() < LastValue(MSPD3,lastmode = True ), Null, LastValue(MSPV3,Lastmode = True));
Plot(SD3,"Support3",SpColor3,ParamStyle("SupportLine3",styleThick|styleDots|styleNoTitle,maskAll));
}
_SECTION_END();
_SECTION_BEGIN("20EMA High");
Ph = ParamField("Price field",1);
Periods1 = Param("Periods", 20, 2, 400, 1 );
bbt=MA( Ph, Periods1 );
//Plot( bbt, "20EMA(H)", ParamColor( "Color", colorAqua ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale );
_SECTION_END();
_SECTION_BEGIN("20EMA Low");
Pl = ParamField("Price field",2);
Periods2 = Param("Periods", 20, 2, 400, 1 );
bbb=MA( Pl, Periods2 );
//Plot( bbb, "20EMA(L)", ParamColor( "Color", colorAqua ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale );
_SECTION_END();
_SECTION_END();
_SECTION_BEGIN("Supertrend");
procedure calcTrend_proc(ATR_Period,tr,ATR_Multiplier,TrendMode,CalcPrice)
{
global buffer_line_down;
global buffer_line_up;
buffer_line_down = Null;
buffer_line_up = Null;
PHASE_NONE = 0;
PHASE_BUY = 1;
PHASE_SELL = -1;
phase=PHASE_NONE;
band_upper = 0;band_lower = 0;
for(i = ATR_Period + 1; i < BarCount; i++)
{
band_upper = CalcPrice + ATR_Multiplier * tr;
band_lower = CalcPrice - ATR_Multiplier * tr;
if(phase==PHASE_NONE)
{
buffer_line_up = CalcPrice;
buffer_line_down = CalcPrice;
}
if(phase!=PHASE_BUY && Close>buffer_line_down[i-1] && !IsEmpty(buffer_line_down[i-1]))
{
phase = PHASE_BUY;
buffer_line_up = band_lower;
buffer_line_up[i-1] = buffer_line_down[i-1];
}
if(phase!=PHASE_SELL && Close<buffer_line_up[i-1] && !IsEmpty(buffer_line_up[i-1]))
{
phase = PHASE_SELL;
buffer_line_down = band_upper;
buffer_line_down[i-1] = buffer_line_up[i-1];
}
if(phase==PHASE_BUY && ((TrendMode==0 && !IsEmpty(buffer_line_up[i-2])) || TrendMode==1) )
{
if(band_lower>buffer_line_up[i-1])
{
buffer_line_up = band_lower;
}
else
{
buffer_line_up = buffer_line_up[i-1];
}
}
if(phase==PHASE_SELL && ((TrendMode==0 && !IsEmpty(buffer_line_down[i-2])) || TrendMode==1) )
{
if(band_upper<buffer_line_down[i-1])
{
buffer_line_down = band_upper;
}
else
{
buffer_line_down = buffer_line_down[i-1];
}
}
}
}
TrendMode = ParamToggle("TrendMode","Off|On",1);
ATR_Multiplier = Param("ATR_Multiplier",2,0.1,10,0.1);
ATR_Period = Param( "ATR_Period",5,1,20,1);
tr = ATR(ATR_Period);
CalcPrice = (H+L)/2;
calcTrend_proc(ATR_Period,tr,ATR_Multiplier,TrendMode,CalcPrice);
st = ParamToggle("Supertrend","Show|Hide",0);
if(st==1) {
Plot(buffer_line_up,"\nUP Trend",ColorRGB(28,134,238),styleThick);
Plot(buffer_line_down,"\nDOWN Trend",ColorRGB(205,51,51),styleThick);
}
_SECTION_END();
_SECTION_BEGIN("Beta Adjusted Trailing Stops");
/*Concept from Bulkowski’s Stop Placement
Mr. Bulkowski has extensively researched the Trailing Stop problem and found that the best multiplier to be 2 when the lookback period was 22 bars (one month).
The average high-low volatility measure (HL) performs better than the average true range (ATR, which includes gaps, whereas the HL method does not)
AND better than standard deviation. Standard deviation performed the worst of the three methods in nearly all of the tests.
The stop is only raised (or lowered) only if a previous high (or low) is exceeded over the past 22 bar period.
The results are excellent when a trending market is in progress and the stop usually gets you out with less that a 8% loss if things go against you.
*/
dif=Ref(High,0)-Ref(Low,0);
dif1=Ref(High,-1)-Ref(Low,-1);
dif2=Ref(High,-2)-Ref(Low,-2);
dif3=Ref(High,-3)-Ref(Low,-3);
dif4=Ref(High,-4)-Ref(Low,-4);
dif5=Ref(High,-5)-Ref(Low,-5);
dif6=Ref(High,-6)-Ref(Low,-6);
dif7=Ref(High,-7)-Ref(Low,-7);
dif8=Ref(High,-8)-Ref(Low,-8);
dif9=Ref(High,-9)-Ref(Low,-9);
dif10=Ref(High,-10)-Ref(Low,-10);
dif11=Ref(High,-11)-Ref(Low,-11);
dif12=Ref(High,-12)-Ref(Low,-12);
dif13=Ref(High,-13)-Ref(Low,-13);
dif14=Ref(High,-14)-Ref(Low,-14);
dif15=Ref(High,-15)-Ref(Low,-15);
dif16=Ref(High,-16)-Ref(Low,-16);
dif17=Ref(High,-17)-Ref(Low,-17);
dif18=Ref(High,-18)-Ref(Low,-18);
dif19=Ref(High,-19)-Ref(Low,-19);
dif20=Ref(High,-20)-Ref(Low,-20);
dif21=Ref(High,-21)-Ref(Low,-21);
Sumdif=(dif+dif1+dif2+dif3+dif4+dif5+dif6+dif7+dif8+dif9+dif10+dif11+dif12+dif13+dif14+dif15+dif16+dif17+dif18+dif19+dif20+dif21)/22;
mp = Param("Multiplier",2,0.25,5,0.25);
Sumdifml=(Sumdif*mp);
Betastops=HHV(C,21) - Sumdifml; // Fibonacci Period used
ColorBATS = IIf(Betastops>C,colorTurquoise,colorGold);
Plot(Betastops, "BATS", colorBATS,ParamStyle("Style1",styleThick,maskAll));
_SECTION_END();
_SECTION_BEGIN("HAS MTF");
/*
Created by chandrakant
Modified on 120309..credit goes to of Karthik sir
1. Here are some observations to keep in mind that will help assure
you are in a good trending move which is detrimental to the success
of the trade moving higher before the inevitable over exhausted trend.
2 Consider only going long on the 5M if the 30M (two rows above) is also blue.
3 Consider the 1hr row as well being blue since it has an effect too.
4 The 15M row has to be blue with NO exceptions
5 The 30M row if blue has less effect on the trade as compared to the 15M row
but keep this in mind. The 30M row being blue helps the 15M row continue to stay blue.
6 The 1hr row has even less effect OR importance but it too keeps the 30M
from weakening to some minor degree.
*/
// Define label bar (x) position location
blankRightBars = 5; //insert actual blank right bars specified in Preferences
barsInView = Status("lastvisiblebarindex") - Status("firstvisiblebarindex") - blankRightBars;
Offset = Param("Offset Bar", 0.95, 0, 1, 0.01);
textOffset = BarCount - (Offset * barsInView);
//// Default TF of the Chart ( Bottom Ribbon )
HaClose =EMA((O+H+L+C)/4,3);
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
//PlotText("HAS MTF :"+Interval(2), textoffset, 41.01, colorYellow);
Color = IIf( Haopen > Haclose,4, IIf( Haopen == Haclose,colorYellow, 6));
Plot(2,"", Color, styleHistogram+styleThick|styleOwnScale|styleNoLabel, 0, 100 );
Plot( 3,"",colorDarkGrey,styleOwnScale|styleArea|styleNoLabel,0, 100 );
//// 3 X TF Plot ( 2nd Ribbon from Bottom )
Compress2= Param("Compression",3,1,3,1);
TimeFrameSet(Compress2* Interval());
HaClose2 =EMA((O+H+L+C)/4,3);
HaOpen2 = AMA( Ref( HaClose2, -1 ), 0.5 );
HaHigh2 = Max( H, Max( HaClose2, HaOpen2 ) );
HaLow2 = Min( L, Min( HaClose2, HaOpen2 ) );
//PlotText("HAS MTF :"+Interval(2), textoffset, 41.055, colorYellow);
TimeFrameRestore();
HAopen2f=TimeFrameExpand( Haopen2, Compress2* Interval());
Haclose2f=TimeFrameExpand( Haclose2, Compress2* Interval());
HaHigh2f=TimeFrameExpand( Hahigh2, Compress2* Interval());
HaLow2f=TimeFrameExpand( Halow2, Compress2* Interval());
Color2 = IIf( Haopen2f > Haclose2f,4, IIf(Haopen2f == Haclose2f,colorYellow, 6));
Plot(5,"", Color2, styleHistogram+styleThick|styleOwnScale|styleNoLabel, 0, 100 );
Plot( 6,"",colorDarkGrey,styleOwnScale|styleArea|styleNoLabel,0, 100 );
//// 6 X TF Plot ( 3rd Ribbon from Bottom )
Compress3= Param("Compression3",6,2,6,1);
TimeFrameSet(Compress3* Interval());
HaClose3 =EMA((O+H+L+C)/4,3);
HaOpen3 = AMA( Ref( HaClose3, -1 ), 0.5 );
HaHigh3 = Max( H, Max( HaClose3, HaOpen3 ) );
HaLow3 = Min( L, Min( HaClose3, HaOpen3 ) );
//PlotText("HAS MTF :"+Interval(2), textoffset,41.10, colorYellow);
TimeFrameRestore();
HAopen3f=TimeFrameExpand( Haopen3, Compress3* Interval());
Haclose3f=TimeFrameExpand( Haclose3, Compress3* Interval());
HaHigh3f=TimeFrameExpand( Hahigh3, Compress3* Interval());
HaLow3f=TimeFrameExpand( Halow3, Compress3* Interval());
color3 = IIf( Haopen3f > Haclose3f,4, IIf( Haopen3f == Haclose3f,colorYellow,6));
Plot(8,"", Color3, styleHistogram+styleThick|styleOwnScale|styleNoLabel, 0, 100 );
Plot(9,"",colorDarkGrey,styleOwnScale|styleArea|styleNoLabel,0, 100 );
//// 12 X TF Plot ( 4th Ribbon from Bottom )
Compress4= Param("Compression4",12,2,12,1);
TimeFrameSet(Compress4* Interval());
HaClose4 =EMA((O+H+L+C)/4,3);
HaOpen4 = AMA( Ref( HaClose4, -1 ), 0.5 );
HaHigh4 = Max( H, Max( HaClose4, HaOpen4 ) );
HaLow4 = Min( L, Min( HaClose4, HaOpen4 ) );
//PlotText("HAS MTF :"+Interval(2), textoffset, 41.14, colorYellow);
TimeFrameRestore();
HAopen4f=TimeFrameExpand( Haopen4, Compress4* Interval());
Haclose4f=TimeFrameExpand( Haclose4, Compress4* Interval());
HaHigh4f=TimeFrameExpand( Hahigh4, Compress4* Interval());
HaLow4f=TimeFrameExpand( Halow4, Compress4* Interval());
Color4 = IIf( Haopen4f > Haclose4f,4, IIf( Haopen4f == Haclose4f ,colorYellow, 6));
Plot(11,"", Color4, styleHistogram+styleThick|styleOwnScale|styleNoLabel, 0, 100 );
Plot( 12,"",colorDarkGrey,styleOwnScale|styleArea|styleNoLabel,0, 100 );
_SECTION_END();
Super Trend Dash Board:
/* Done by Rajandran R */
_SECTION_BEGIN("SuperTrend 5min");
_N(Title = "MultiTimeframe Signal DashBoard");
TimeFrameSet(in5Minute);
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));
GfxSetBkMode(0);
GfxSetOverlayMode(1);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
//Plot(C,"\nPrice",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);
SetTradeDelays(1,1,1,1);
PositionSize=100000;
symbol = Name();
Factor=Optimize("Factor",4,2,10,1);
Pd=Optimize("ATR Period",10,3,20,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;
for (i = 1; i <BarCount; i++) {
TrendUp = Null;
TrendDown = Null;
trend=1;
if (Close>Up[i-1]) {
trend=1;
if (trend[i-1] == -1) changeOfTrend = 1;
}
else if (Close<Dn[i-1]) {
trend=-1;
if (trend[i-1] == 1) changeOfTrend = 1;
}
else if (trend[i-1]==1) {
trend=1;
changeOfTrend = 0;
}
else if (trend[i-1]==-1) {
trend=-1;
changeOfTrend = 0;
}
if (trend<0 && trend[i-1]>0) {
flag=1;
}
else {
flag=0;
}
if (trend>0 && trend[i-1]<0) {
flagh=1;
}
else {
flagh=0;
}
if (trend>0 && Dn<Dn[i-1]){
Dn=Dn[i-1];
}
if (trend<0 && Up>Up[i-1])
{ Up=Up[i-1];
}
if (flag==1)
{ Up=(H+L)/2+(Factor*iATR);;
}
if (flagh==1)
{ Dn=(H+L)/2-(Factor*iATR);;
}
if (trend==1) {
TrendUp=Dn;
if (changeOfTrend == 1) {
TrendUp[i-1] = TrendDown[i-1];
changeOfTrend = 0;
}
}
else if (trend==-1) {
TrendDown=Up;
if (changeOfTrend == 1) {
TrendDown[i-1] = TrendUp[i-1];
changeOfTrend = 0;
}
}
}
Buy = trend==1;
Sell=trend==-1;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=Sell;
Cover=Buy;
BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);
TrendSL=IIf(trend==1,TrendUp,TrendDown);
for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";
sl = TrendSL;
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);
bars = i;
i = 0;
}
if(Sell == 1)
{
sig = "SELL";
entry = C;
sl = TrendSL;
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, TrendSL[BarCount-1], Ref(TrendSL, -1));
sl = ssl[BarCount-1];
messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );
if ( sig =="BUY")
{
GfxSelectSolidBrush( colorBlue ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 5;
x2 = 290;
y = pxHeight;
GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 98, x2, y , 7, 7 ) ;
GfxTextOut( ( "Marketcalls - Supertrend 5min"),13,y-100);
GfxTextOut( (" "),27,y-100);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-80) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-60);
GfxTextOut( ("Trailing SL : " + Ref(TrendSL,-1) + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 13, y-40);
/*GfxTextOut( ("TGT:1 : " + tar1), 13, y -80);
GfxTextOut( ("TGT:2 : " + tar2), 13,y-60);
GfxTextOut( ("TGT:3 : " + tar3), 13,y-40);*/
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 13, y-22);;
}
TimeFrameRestore();
_SECTION_END();
_SECTION_BEGIN("SuperTrend 15min");
TimeFrameSet(in5Minute*3);
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));
GfxSetBkMode(0);
GfxSetOverlayMode(1);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
//Plot(C,"\nPrice",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);
SetTradeDelays(1,1,1,1);
PositionSize=100000;
symbol = Name();
Factor=Optimize("Factor",4,2,10,1);
Pd=Optimize("ATR Period",10,3,20,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;
for (i = 1; i <BarCount; i++) {
TrendUp = Null;
TrendDown = Null;
trend=1;
if (Close>Up[i-1]) {
trend=1;
if (trend[i-1] == -1) changeOfTrend = 1;
}
else if (Close<Dn[i-1]) {
trend=-1;
if (trend[i-1] == 1) changeOfTrend = 1;
}
else if (trend[i-1]==1) {
trend=1;
changeOfTrend = 0;
}
else if (trend[i-1]==-1) {
trend=-1;
changeOfTrend = 0;
}
if (trend<0 && trend[i-1]>0) {
flag=1;
}
else {
flag=0;
}
if (trend>0 && trend[i-1]<0) {
flagh=1;
}
else {
flagh=0;
}
if (trend>0 && Dn<Dn[i-1]){
Dn=Dn[i-1];
}
if (trend<0 && Up>Up[i-1])
{ Up=Up[i-1];
}
if (flag==1)
{ Up=(H+L)/2+(Factor*iATR);;
}
if (flagh==1)
{ Dn=(H+L)/2-(Factor*iATR);;
}
if (trend==1) {
TrendUp=Dn;
if (changeOfTrend == 1) {
TrendUp[i-1] = TrendDown[i-1];
changeOfTrend = 0;
}
}
else if (trend==-1) {
TrendDown=Up;
if (changeOfTrend == 1) {
TrendDown[i-1] = TrendUp[i-1];
changeOfTrend = 0;
}
}
}
Buy = trend==1;
Sell=trend==-1;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=Sell;
Cover=Buy;
BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);
TrendSL=IIf(trend==1,TrendUp,TrendDown);
for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";
sl = TrendSL;
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);
bars = i;
i = 0;
}
if(Sell == 1)
{
sig = "SELL";
entry = C;
sl = TrendSL;
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, TrendSL[BarCount-1], Ref(TrendSL, -1));
sl = ssl[BarCount-1];
messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );
if ( sig =="BUY")
{
GfxSelectSolidBrush( colorBlue ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 305;
x2 = 590;
y = pxHeight;
GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 98, x2, y , 7, 7 ) ;
GfxTextOut( ( "Marketcalls - Supertrend 15min"),313,y-100);
GfxTextOut( (" "),327,y-100);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 313, y-80) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 313, y-60);
GfxTextOut( ("Trailing SL : " + Ref(TrendSL,-1) + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 313, y-40);
/*GfxTextOut( ("TGT:1 : " + tar1), 13, y -80);
GfxTextOut( ("TGT:2 : " + tar2), 13,y-60);
GfxTextOut( ("TGT:3 : " + tar3), 13,y-40);*/
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 313, y-22);;
}
TimeFrameRestore();
_SECTION_END();
_SECTION_BEGIN("SuperTrend Hourly");
TimeFrameSet(inHourly);
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));
GfxSetBkMode(0);
GfxSetOverlayMode(1);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
//Plot(C,"\nPrice",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);
SetTradeDelays(1,1,1,1);
PositionSize=100000;
symbol = Name();
Factor=Optimize("Factor",4,2,10,1);
Pd=Optimize("ATR Period",10,3,20,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;
for (i = 1; i <BarCount; i++) {
TrendUp = Null;
TrendDown = Null;
trend=1;
if (Close>Up[i-1]) {
trend=1;
if (trend[i-1] == -1) changeOfTrend = 1;
}
else if (Close<Dn[i-1]) {
trend=-1;
if (trend[i-1] == 1) changeOfTrend = 1;
}
else if (trend[i-1]==1) {
trend=1;
changeOfTrend = 0;
}
else if (trend[i-1]==-1) {
trend=-1;
changeOfTrend = 0;
}
if (trend<0 && trend[i-1]>0) {
flag=1;
}
else {
flag=0;
}
if (trend>0 && trend[i-1]<0) {
flagh=1;
}
else {
flagh=0;
}
if (trend>0 && Dn<Dn[i-1]){
Dn=Dn[i-1];
}
if (trend<0 && Up>Up[i-1])
{ Up=Up[i-1];
}
if (flag==1)
{ Up=(H+L)/2+(Factor*iATR);;
}
if (flagh==1)
{ Dn=(H+L)/2-(Factor*iATR);;
}
if (trend==1) {
TrendUp=Dn;
if (changeOfTrend == 1) {
TrendUp[i-1] = TrendDown[i-1];
changeOfTrend = 0;
}
}
else if (trend==-1) {
TrendDown=Up;
if (changeOfTrend == 1) {
TrendDown[i-1] = TrendUp[i-1];
changeOfTrend = 0;
}
}
}
Buy = trend==1;
Sell=trend==-1;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=Sell;
Cover=Buy;
BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);
TrendSL=IIf(trend==1,TrendUp,TrendDown);
for(i=BarCount-1;i>1;i--)
{
if(Buy == 1)
{
entry = C;
sig = "BUY";
sl = TrendSL;
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);
bars = i;
i = 0;
}
if(Sell == 1)
{
sig = "SELL";
entry = C;
sl = TrendSL;
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, TrendSL[BarCount-1], Ref(TrendSL, -1));
sl = ssl[BarCount-1];
messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );
if ( sig =="BUY")
{
GfxSelectSolidBrush( colorBlue ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 605;
x2 = 890;
y = pxHeight;
GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 98, x2, y , 7, 7 ) ;
GfxTextOut( ( "Marketcalls - Supertrend Hourly"),613,y-100);
GfxTextOut( (" "),327,y-100);
GfxTextOut( ("Last " + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 613, y-80) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 613, y-60);
GfxTextOut( ("Trailing SL : " + Ref(TrendSL,-1) + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 613, y-40);
/*GfxTextOut( ("TGT:1 : " + tar1), 13, y -80);
GfxTextOut( ("TGT:2 : " + tar2), 13,y-60);
GfxTextOut( ("TGT:3 : " + tar3), 13,y-40);*/
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 613, y-22);;
}
TimeFrameRestore();
_SECTION_END();