Simple Coding Help - No Promise.

cloudTrader

Well-Known Member
Found the below code on another forum and the query asked was also very interesting. Can it be done by the experts without having to invest much time. If yes, plz. do look into the code and the condition required.

The below code shows the 3 Day Highest High & Lowest Low levels. If the Opening Price of the Day for any scrip opens above the highest high level or the lowest low level then can an alert or a signal be generated ?

I used to follow this system but looking just one scrip was not so fruitful and the code for scanning many stocks was not available to me. Now after getting this code I am excited if it could be achieved.

_SECTION_BEGIN("3 Days Highest High Lowest Low method");
Plot( C, "Close", ParamColor("Color", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
DC=TimeFrameGetPrice( "C", inDaily, 0);
DC1=TimeFrameGetPrice( "C", inDaily, -1);
dh=TimeFrameGetPrice( "H", inDaily, 0);
dh1=TimeFrameGetPrice( "H", inDaily, -1);
dh2=TimeFrameGetPrice( "H", inDaily, -2);
dh3=TimeFrameGetPrice( "H", inDaily, -3);

DL=TimeFrameGetPrice( "L", inDaily, 0);
dl1=TimeFrameGetPrice( "l", inDaily, -1);
dl2=TimeFrameGetPrice( "l", inDaily, -2);
dl3=TimeFrameGetPrice( "l", inDaily, -3);

do1=TimeFrameGetPrice( "O", inDaily, -1);
doo=TimeFrameGetPrice( "O", inDaily, 0);
Maxh1=Max(dh1,dh2);
Maxh2=Max(dh2,dh3);
Maxh=Max(Maxh1,Maxh2);
Plot(Maxh,"maxh",colorBrown,styleLine);

Minl1=Min(dl1,dl2);
Minl2=Min(dl2,dl3);
Minl=Min(Minl1,Minl2);
Plot(Minl,"minl",colorYellow,styleLine);
Buy = Cross(Close , Maxh);
Sell = Cross( Minl,Close);
PlotShapes(Sell*shapeDownArrow,colorRed);
PlotShapes(Buy*shapeUpArrow,colorGreen);
Title = EncodeColor(colorWhite)+ Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+" 3dh= "+WriteVal(Maxh)+" 3dL= "+WriteVal(Minl);

Filter=(Buy OR Sell) ;
NumColumns = 0;
AddColumn(Close,"CMP", 1.2);
AddColumn( IIf( Buy, 66, 83 ), "Signal" , formatChar,2,4 );
AddColumn(doo,"open", 1.2);
AddColumn(dH,"HIGH", 1.2);
AddColumn(dL,"low", 1.2);
AddColumn(dC,"close", 1.2);
AddColumn(Maxh,"buy value", 1.2);
AddColumn(Minl,"sell value", 1.2);

_SECTION_END();
 
help to add buy sell signal arrows in this afl
thise are 3 ma crossing with smooth stochastic
1)LWMA,price field- close, 21periods,skye blue colour
2)EMA,price field-LWMA(21),3periods,yellow colour,style dasshed
3)EMA1,pricefield-close,50periods,blue,thick style

buy=1lwma cross ema3from below and this above 3rd ema at same time double stochastic bullish cross below 25 means at oversold region and heiken ashi bullished candle form
sell=1lwma cross ema3 below and this below 3rd ema at same time double stochastic bearish cross above 90 means in overbrought regionand heiken ashi bearish candle form
i send afl
1)heiken ashi candle
2)lwma
3)ema3
4)ema 50
5)double stochastic it has buy sell arrows please remove that
thanks in advance
traderji.jpg

1)_SECTION_BEGIN("henicane ashi");
SetChartOptions(0,chartShowArrows | chartShowDates);

HaClose = (O + H + L + C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
xDiff = (HaHigh - Halow) * 10000;
barcolor = IIf(HaClose >= HaOpen,colorGreen,colorRed);
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", barcolor, styleCandle );
_SECTION_END();

2)_SECTION_BEGIN("lwma");
function LWMA( P, per )
{
s=0;
pa=0;

for( i = 0; i < per; i++ )
{
s=s+(Ref(P,-i)*(per-i));
pa=pa+(per-i);
}
return (s/pa);
}

P = ParamField("Price field");
Periods = Param("Periods", 21 );

Plot(LWMA( P, Periods ), "LWMA("+Periods +")", ParamColor( "LWMA Color", colorCycle ), ParamStyle("LWMA Style") );
_SECTION_END();

3)_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 3 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

4)_SECTION_BEGIN("EMA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 50 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

5)_SECTION_BEGIN("DoubleStochastic");
R = ((HHV(H,60) - C) /(HHV (H,60) -LLV (L,60))) *-100;
Period = 6;
EMA1 = EMA(R,Period);
EMA2 = EMA(EMA1,2);
se = EMA1 - EMA2;
ni = EMA1 + se;
PR = 0-abs(ni);
ra = MA(PR,2);
na = PR>=ra AND PR>=Ref(PR,-1) ;
tu = (PR < ra) OR PR>= ra AND PR< Ref(PR,-1) ;
barcolor = IIf( tu,colorRed, IIf( na, colorBrightGreen, 7));
Graph0 = PR;
Graph1 = ra;


pds = 10; /*Periods */
/*pds = Optimize("pds",13,2,20,1); */

slw = 13; /*Slowing for Full Stoch%K*/
/*slw = Optimize("slw",3,1,14,1); */



slwd = 5; /*Slowing for Full Stoch%D*/
/*slwd = Optimize("slwd",3,1,14,1); */
ob = 90; /*Overbought */
/*ob = Optimize("ob",83,65,88,1); */
os = 25; /*Oversold */
/*os = Optimize("os",24,20,50,1); */


FSK = 100*(C-LLV(L,pds))/(HHV(H,pds)-LLV(L,pds)); // FASTSTOCHK

FLSK = EMA( FSK, slw ); // FULLSTOCHK




DSK = ((FLSK-LLV(FLSK,pds))/(HHV(FLSK,pds)-LLV(FLSK,pds))) * 100;

DLSK = EMA( DSK, slwd ); // FULLSTOCHD



Buy = Cross (DSK ,DLSK);
Sell = Cross (DLSK ,DSK);
PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow, IIf( Buy, colorGreen, colorRed ) );
Graph0BarColor = ValueWhen( barcolor != 0, barcolor );

AlertIf( Buy , "SOUND C:\\Windows\\Media\\chimes.wav", "Audio alert", 2 );
AlertIf( Sell , "SOUND C:\\Windows\\Media\\alert.wav", "Audio alert", 2 );






Plot( MA( DLSK, 4 ), "MA-3"+_PARAM_VALUES(),ParamColor("ColorD" , colorRed ));

Plot( DLSK, "Stochastic %D"+_PARAM_VALUES(),ParamColor("ColorK" , colorBlue ), styleLine);

Plot(Ob,"Overbought Level",colorRed, styleLine);
Plot(Os,"Oversold Level",colorGreen, styleLine);

_SECTION_BEGIN("Candle Identification");
O1 = Ref(O,-1);O2 = Ref(O,-2);
H1 = Ref(H,-1);H2 = Ref(H,-2);
L1 = Ref(L,-1);L2 = Ref(L,-2);
C1 = Ref(C,-1);C2 = Ref(C,-2);
function CandlePattern(P)
{
global PatternName;
if(P == 0) { PatternName = "NearDoji"; Pv = (abs(O-C)<= ((H-L)*0.1)); }
else if(P == 1) { PatternName = "BlackCandle"; Pv = (O>C); }
else if(P == 2) { PatternName = "LongBlackCandle"; Pv = (O>C AND
(O-C)/(.001+H-L)>.6); }
else if(P == 3) { PatternName = "SmallBlackCandle"; Pv = ((O>C) AND
((H-L)>(3*(O-C)))); }
else if(P == 4) { PatternName = "WhiteCandle"; Pv = (C>O); }
else if(P == 5) { PatternName = "LongWhiteCandle"; Pv = ((C>O) AND
((C-O)/(.001+H-L)>.6)); }
else if(P == 6) { PatternName = "SmallWhiteCandle"; Pv = ((C>O) AND
((H-L)>(3*(C-O)))); }
else if(P == 7) { PatternName = "BlackMaubozu"; Pv = (O>C AND H==O AND
C==L); }
else if(P == 8) { PatternName = "WhiteMaubozu"; Pv = (C>O AND H==C AND
O==L); }
else if(P == 9) { PatternName = "BlackClosingMarubozu"; Pv = (O>C AND
C==L); }
else if(P == 10) { PatternName = "WhiteClosingMarubozu"; Pv = (C>O AND
C==H); }
else if(P == 11) { PatternName = "BlackOpeningMarubozu"; Pv = (O>C AND
O==H); }
else if(P == 12) { PatternName = "WhiteOpeningMarubozu"; Pv = (C>O AND
O==L); }
else if(P == 13) { PatternName = "HangingMan"; Pv = (((H-L)>4*(O-C)) AND
((C-L)/(.001+H-L)>= 0.75) AND ((O-L)/(.001+H-L)>= 0.75)); }
else if(P == 14) { PatternName = "Hammer"; Pv = (((H-L)>3*(O-C)) AND
((C-L)/(.001+H-L)>0.6) AND ((O-L)/(.001+H-L)>0.6)); }
else if(P == 15) { PatternName = "InvertedHammer"; Pv = (((H-L)>3*(O-C))
AND ((H-C)/(.001+H-L)>0.6) AND ((H-O)/(.001+H-L)>0.6)); }
else if(P == 16) { PatternName = "ShootingStar"; Pv = (((H-L)>4*(O-C))
AND ((H-C)/(.001+H-L)>= 0.75) AND ((H-O)/(.001+H-L)>= 0.75)); }
else if(P == 17) { PatternName = "BlackSpinningTop"; Pv = ((O>C) AND
((H-L)>(3*(O-C))) AND (((H-O)/(.001+H-L))<.4) AND
(((C-L)/(.001+H-L))<.4)); }
else if(P == 18) { PatternName = "WhiteSpinningTop"; Pv = ((C>O) AND
((H-L)>(3*(C-O))) AND (((H-C)/(.001+H-L))<.4) AND
(((O-L)/(.001+H-L))<.4)); }
else if(P == 19) { PatternName = "BearishAbandonedBaby"; Pv = ((C1 == O1)
AND (C2>O2) AND (O>C) AND (L1>H2) AND (L1>H)); }
else if(P == 20) { PatternName = "BearishEveningDojiStar"; Pv = ((C2>O2)
AND ((C2-O2)/(.001+H2-L2)>.6) AND (C2<O1) AND (C1>O1) AND
((H1-L1)>(3*(C1-O1))) AND (O>C) AND (O<O1)); }
else if(P == 21) { PatternName = "DarkCloudCover"; Pv = (C1>O1 AND
((C1+O1)/2)>C AND O>C AND O>C1 AND C>O1 AND (O-C)/(.001+(H-L)>0.6)); }
else if(P == 22) { PatternName = "BearishEngulfing"; Pv = ((C1>O1) AND
(O>C) AND (O>= C1) AND (O1>= C) AND ((O-C)>(C1-O1))); }
else if(P == 23) { PatternName = "ThreeOutsideDownPattern"; Pv = ((C2>O2)
AND (O1>C1) AND (O1>= C2) AND (O2>= C1) AND ((O1-C1)>(C2-O2)) AND (O>C) AND
(C<C1)); }
else if(P == 24) { PatternName = "BullishAbandonedBaby"; Pv = ((C1 == O1)
AND (O2>C2) AND (C>O) AND (L2>H1) AND (L>H1)); }
else if(P == 25) { PatternName = "BullishMorningDojiStar"; Pv = ((O2>C2)
AND ((O2-C2)/(.001+H2-L2)>.6) AND (C2>O1) AND (O1>C1) AND
((H1-L1)>(3*(C1-O1))) AND (C>O) AND (O>O1)); }
else if(P == 26) { PatternName = "BullishEngulfing"; Pv = ((O1>C1) AND
(C>O) AND (C>= O1) AND (C1>= O) AND ((C-O)>(O1-C1))); }
else if(P == 27) { PatternName = "ThreeOutsideUpPattern"; Pv = ((O2>C2)
AND (C1>O1) AND (C1>= O2) AND (C2>= O1) AND ((C1-O1)>(O2-C2)) AND (C>O) AND
(C>C1)); }
else if(P == 28) { PatternName = "BullishHarami"; Pv = ((O1>C1) AND (C>O)
AND (C<= O1) AND (C1<= O) AND ((C-O)<(O1-C1))); }
else if(P == 29) { PatternName = "ThreeInsideUpPattern"; Pv = ((O2>C2)
AND (C1>O1) AND (C1<= O2) AND (C2<= O1) AND ((C1-O1)<(O2-C2)) AND (C>O) AND
(C>C1) AND (O>O1)); }
else if(P == 30) { PatternName = "PiercingLine"; Pv = ((C1<O1) AND
(((O1+C1)/2)<C) AND (O<C) AND (O<C1) AND (C<O1) AND
((C-O)/(.001+(H-L))>0.6)); }
else if(P == 31) { PatternName = "BearishHarami"; Pv = ((C1>O1) AND (O>C)
AND (O<= C1) AND (O1<= C) AND ((O-C)<(C1-O1))); }
else if(P == 32) { PatternName = "ThreeInsideDownPattern"; Pv = ((C2>O2)
AND (O1>C1) AND (O1<= C2) AND (O2<= C1) AND ((O1-C1)<(C2-O2)) AND (O>C) AND
(C<C1) AND (O<O1)); }
else if(P == 33) { PatternName = "ThreeWhiteSoldiers"; Pv = (C>O*1.01)
AND (C1>O1*1.01) AND (C2>O2*1.01) AND (C>C1) AND (C1>C2) AND (O<C1) AND
(O>O1) AND (O1<C2) AND (O1>O2) AND (((H-C)/(H-L))<.2) AND
(((H1-C1)/(H1-L1))<.2) AND (((H2-C2)/(H2-L2))<.2); }
else if(P == 34) { PatternName = "DarkCloudCover"; Pv = (C1>O1*1.01) AND
(O>C) AND (O>H1) AND (C>O1) AND (((C1+O1)/2)>C) AND (C>O1) AND
(MA(C,13)-Ref(MA(C,13),-4)>0); }
else if(P == 35) { PatternName = "ThreeBlackCrows"; Pv = (O>C*1.01) AND
(O1>C1*1.01) AND (O2>C2*1.01) AND (C<C1) AND (C1<C2) AND (O>C1) AND (O<O1)
AND (O1>C2) AND (O1<O2) AND (((C-L)/(H-L))<.2) AND (((C1-L1)/(H1-L1))<.2)
AND (((C2-L2)/(H2-L2))<.2); }
else if(P == 36) { PatternName = "doji"; Pv = (O == C); }
else if(P == 37) { PatternName = "GapUp"; Pv = GapUp(); }
else if(P == 38) { PatternName = "GapDown"; Pv = GapDown(); }
else if(P == 39) { PatternName = "BigGapUp"; Pv = L>1.01*H1; }
else if(P == 40) { PatternName = "BigGapDown"; Pv = H<0.99*L1; }
else if(P == 41) { PatternName = "HugeGapUp"; Pv = L>1.02*H1; }
else if(P == 42) { PatternName = "HugeGapDown"; Pv = H<0.98*L1; }
else if(P == 43) { PatternName = "DoubleGapUp"; Pv = GapUp() AND
Ref(GapUp(),-1); }
else if(P == 44) { PatternName = "DoubleGapDown"; Pv = GapDown() AND
Ref(GapDown(),-1); }
return Pv;
}

PatternNameList = "";
for(Cp=0; Cp<=44; Cp++)
{
VarSet("Pattern"+NumToStr(Cp,1.0),CandlePattern(cP));
PatternNameList = PatternNameList +PatternName+",";
}

BI = BarIndex();
SelectedBar = SelectedValue(BI) -BI[0];
//Selectedbar = Status("lastvisiblebar")-1;
PStr="";
for(Cp=0; Cp<=44; Cp++)
{
Temp = VarGet("Pattern"+NumToStr(Cp,1.0));
if(temp[SelectedBar]) Pstr=Pstr+"#"+NumToStr(Cp,1.0)+" - "+StrExtract(PatternNameList,Cp)+"\n";
}


FS=Param("Font Size",11,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorWhite) );
Hor=Param("Horizontal Position",237,1,1200,1);
Ver=Param("Vertical Position",50,1,830,1);
GfxTextOut("Candle Reader= "+Pstr, Hor , Ver );





_SECTION_END();
 

ocil

Well-Known Member
HI, can any one help me to plot stop loss on today chart using yesterday candle middle point?

prevMP = (prevL + prevH) / 2; how to convert this to no ? so i can backtest. (Buy price - MP) stoploss for today buy call.

Pls help friend
 

Romeo1998

Well-Known Member
Dear friend,
use this code :)

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

//get High price of previous day
dh=TimeFrameGetPrice("H",inDaily,-1);

//get Low price of previous day
dl=TimeFrameGetPrice("L",inDaily,-1);

//add them
mid =( dl+dh)/2;

//Plot it
Plot(mid,"mid",colorBlue,styleDots|styleLine);
 

ocil

Well-Known Member
Many Thanks, friend .
Dear friend,
use this code :)

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

//get High price of previous day
dh=TimeFrameGetPrice("H",inDaily,-1);

//get Low price of previous day
dl=TimeFrameGetPrice("L",inDaily,-1);

//add them
mid =( dl+dh)/2;

//Plot it
Plot(mid,"mid",colorBlue,styleDots|styleLine);
 

toocool

Well-Known Member
is it possible to have multi time frame emas also but with buttons to show whichever tf we chose at that moment

for example we put 1 minute charts and want to see 5 minute ema 5 different ema all for 5 minutes tf , but later on same chart now we want to see 15 minute ema , and then we need to see 1 hour ema , and 2 hour and 4 hour .

now for this we need a visible button on top of chart , we click the timeframe button having all these buttons 1 minute , 5 minute , 15 minute , 1 hour , 2 hour , 4 hour .....................and as an when we click button of different tf , the ema on 1 minute chart change accordingly :)
 
Nice u have posted here , didnt want to hijack varun's thread

Buttons not sure...As MB has replied, it may come in next versions
Anyways use toggle for now

_SECTION_BEGIN("MTF EMA");
_SECTION_BEGIN("EMA 5 MIN");
EM5=ParamToggle("EMA5","Off|On",1);

if(EM5)
{
TimeFrameSet(in5Minute);
m5= EMA(Close,5) ;
Plot(TimeFrameExpand(m5, in5Minute), "", ParamColor( "5 Min Color", colorRed ), styleLine|styleThick);
TimeFrameRestore();
}
_SECTION_END();

_SECTION_BEGIN("EMA 15 MIN");
EM15=ParamToggle("EMA15","Off|On",1);

if(EM15)
{
TimeFrameSet(in15Minute);
m15= EMA(Close,5) ;
Plot(TimeFrameExpand(m15, in15Minute), "", ParamColor( "15 Min Color", colorBlue ),styleLine|styleThick);
TimeFrameRestore();
}
_SECTION_END();

_SECTION_BEGIN("EMA Hourly");
EMH=ParamToggle("EMAH","Off|On",1);

if(EMH)
{
TimeFrameSet(inHourly);
mH= EMA(Close,5) ;
Plot(TimeFrameExpand(mH, inHourly), "", ParamColor( "Hourly Color", colorGreen ),styleLine|styleThick);
TimeFrameRestore();
}
_SECTION_END();

_SECTION_BEGIN("EMA 2Hourly");
EM2H=ParamToggle("EMA2H","Off|On",1);

if(EM2H)
{
TimeFrameSet(inHourly*2);
m2H= EMA(Close,5) ;
Plot(TimeFrameExpand(m2H, inHourly*2), "", ParamColor( "2Hour Color", colorYellow ),styleLine|styleThick);
TimeFrameRestore();
}
_SECTION_END();

_SECTION_BEGIN("EMA 4Hourly");
EM4H=ParamToggle("EMA4H","Off|On",1);

if(EM4H)
{
TimeFrameSet(inHourly*4);
m4H= EMA(Close,5) ;
Plot(TimeFrameExpand(m4H, inHourly*4), "", ParamColor( "4Hour Color", colorOrange ),styleStaircase|styleThick);
TimeFrameRestore();
}
_SECTION_END();
_SECTION_END();
 

Similar threads