Simple Coding Help - No Promise.

Riskyman

Well-Known Member
Replace following lines... this will scan and plot arrows when your conditions are true [ green - red candle ]
Excellent!. Thanks a ton for your kind help. Appreciate it man. I checked and it shows all the scrips switching colors. Just wondering what below equation means.

PlotShapes(Buy*1,5,0,HaLow,-15);
PlotShapes(SELL*2,4,0,HaHigh,-15);
 
Folks

Continuing on the holy grail quest of KRA ....

discovered yet another Indicator/Oscillator that claims to show the trend without any lag (in other words, lag is compensated for). Testing and expert opinion welcome...

First Clue was present in TJ itself here

Digging further revealed this site

Code is

Code:
r = Param( "TSI period Length:", 25, 1, 100, 1 );
s = Param( "TSI period Smoothing:", 13, 1, 100, 1 );
sig = Param( "TSI Signal Length:", 7, 1, 100, 1 );
 
Mtm = C - Ref ( C, -1 );
AbsMtm = abs(Mtm);

numT = EMA ( EMA ( Mtm, r ), s );
DenT = EMA ( EMA ( AbsMtm, r ), s );

TSI = 100 * Nz ( numT / DenT );
Plot( TSI, "TSI("+r+","+s+")", colorRed, styleLine);
Plot(EMA(TSI,sig), "", colorLightBlue, styleLine);
Plot(0,"", colorBlack, styleDashed);




Similar RSI afl mastermind with Signal.

HTML:
// volume spike ( check stocks whose volume for the day is at least 10% greater than its 30 day ave volume )
Volume_to = Sum(Volume, 51);
Volume_to = Volume_to - Volume;
Volume50 = Volume_to / 50;
percentage = ( abs( Volume50 - Volume ) ) / Volume50;
percentage = percentage * 100;

AddColumn(O,"Open", 1.4);
AddColumn(H,"High", 1.4);
AddColumn(L,"Low", 1.4);
AddColumn(C,"Close", 1.4);
AddColumn(Volume50,"Ave 50 days Volume", 1, colorBlue);
AddColumn(Volume,"Volume Today", 1, colorBlue);
AddColumn(Percentage," % Increase", 1.2, colorBlue);

Filter = Volume > Volume50 AND percentage > 10;
// volume spike

_SECTION_BEGIN("RSI EMA");

Plot (EMA(RSI(34),9), "Smoothed RSI-5", colorGreen , styleNoLabel | styleThick);
Plot (EMA(RSI(34),20), "Smoothed RSI-14", colorRed , styleNoLabel | styleThick);
GfxSetTextAlign(6 );// center alignment 
GfxSetOverlayMode(1 ) ; 
GfxSetTextColor( colorGold ); 
GfxSetBkMode(0); // transparent 
GfxSelectFont("Time news roman", Status("pxheight")/10 ); 
GfxTextOut("Stock Market Pilipinas " , Status("pxwidth")/2, Status("pxheight")/3 ); 

Buy = Cross(EMA (RSI(14),5), EMA (RSI(14), 20));
Sell = Cross(EMA (RSI(14),20), EMA (RSI(14), 5));


PlotShapes(IIf(Buy,shapeUpArrow,shapeNone) ,colorBrightGreen);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);

_SECTION_END();

Check it
 

amitrandive

Well-Known Member
Similar RSI afl mastermind with Signal.

HTML:
// volume spike ( check stocks whose volume for the day is at least 10% greater than its 30 day ave volume )
Volume_to = Sum(Volume, 51);
Volume_to = Volume_to - Volume;
Volume50 = Volume_to / 50;
percentage = ( abs( Volume50 - Volume ) ) / Volume50;
percentage = percentage * 100;

AddColumn(O,"Open", 1.4);
AddColumn(H,"High", 1.4);
AddColumn(L,"Low", 1.4);
AddColumn(C,"Close", 1.4);
AddColumn(Volume50,"Ave 50 days Volume", 1, colorBlue);
AddColumn(Volume,"Volume Today", 1, colorBlue);
AddColumn(Percentage," % Increase", 1.2, colorBlue);

Filter = Volume > Volume50 AND percentage > 10;
// volume spike

_SECTION_BEGIN("RSI EMA");

Plot (EMA(RSI(34),9), "Smoothed RSI-5", colorGreen , styleNoLabel | styleThick);
Plot (EMA(RSI(34),20), "Smoothed RSI-14", colorRed , styleNoLabel | styleThick);
GfxSetTextAlign(6 );// center alignment 
GfxSetOverlayMode(1 ) ; 
GfxSetTextColor( colorGold ); 
GfxSetBkMode(0); // transparent 
GfxSelectFont("Time news roman", Status("pxheight")/10 ); 
GfxTextOut("Stock Market Pilipinas " , Status("pxwidth")/2, Status("pxheight")/3 ); 

Buy = Cross(EMA (RSI(14),5), EMA (RSI(14), 20));
Sell = Cross(EMA (RSI(14),20), EMA (RSI(14), 5));


PlotShapes(IIf(Buy,shapeUpArrow,shapeNone) ,colorBrightGreen);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);

_SECTION_END();

Check it
Shruti

Only below code is enough.Rest is not needed in the code


Code:
_SECTION_BEGIN("RSI EMA");
 
Plot (EMA(RSI(34),9), "Smoothed RSI-5", colorGreen , styleNoLabel | styleThick);
Plot (EMA(RSI(34),20), "Smoothed RSI-14", colorRed , styleNoLabel | styleThick);

Buy = Cross(EMA (RSI(14),5), EMA (RSI(14), 20));
Sell = Cross(EMA (RSI(14),20), EMA (RSI(14), 5));
  
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone) ,colorBrightGreen);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);
 
_SECTION_END();
 

Riskyman

Well-Known Member
Code:
//CalcTrendProcedure=ParamToggle("CalcTrendProcedure","ON|OFF");

_SECTION_BEGIN("CalcTrendProcedure");

Length=25;//Param("Length",25, 2); 
Deviation=2;//Param("Deviation",2);
MoneyRisk=1;//Param("Money Risk", 1);
LineStyle=0;//ParamToggle("Display line mode", "No|Yes", 0); 
cUpTrendLine =18;// ParamColor("UpTrendLine", colorGold);
cDnTrendLine = 18;//ParamColor("DownTrendLine", colorGold);

TurnedUp=Nz(StaticVarGet("TurnedUp"));
TurnedDown=Nz(StaticVarGet("TurnedDown"));
SoundON = ParamToggle("Sound","Off|On",1);


// remove appropriate comment /* & */ ie consider code between /* */

// for eg. condition for buy sell

//1. option

/*
period = 20; // number of averaging periods 
m = MA( Close, period ); // simple moving average
Buy = Cross( Close, m ); // buy when close crosses ABOVE moving average
Sell = Cross( m, Close ); // sell when closes crosses BELOW moving average
*/

//---------------
// 2. option

/*
period = 20; // number of averaging periods 
m = EMA( Close, period ); // exponential moving average
Buy = Cross( Close, m ); // buy when close crosses ABOVE moving average
Sell = Cross( m, Close ); // sell when closes crosses BELOW moving average
*/


procedure CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown){
	global UpTrendLine;
	global DownTrendLine;
	global smax;
	global smin;

	UpTrendLine=Null;
	DownTrendLine=Null;
	smax=Null;
	smin=Null;
	trend=0;

	for (i=Length+1; i<BarCount; i++){ 
		smax[i]=bbtop[i];
		smin[i]=bbbot[i];
		
		if (C[i]>smax[i-1]) trend=1;
		if (C[i]<smin[i-1]) trend=-1;
		if(trend>0 && smin[i]<smin[i-1]) smin[i]=smin[i-1];
		if(trend<0 && smax[i]>smax[i-1]) smax[i]=smax[i-1];
		
		bsmax[i]=smax[i]+0.5*(MoneyRisk-1)*(smax[i]-smin[i]);
		bsmin[i]=smin[i]-0.5*(MoneyRisk-1)*(smax[i]-smin[i]);
		
		if(trend>0 && bsmin[i]<bsmin[i-1]) bsmin[i]=bsmin[i-1];
		if(trend<0 && bsmax[i]>bsmax[i-1]) bsmax[i]=bsmax[i-1];
		
		if (Buy[i]) { 
			UpTrendLine[i]=bsmin[i];
			if (SoundON==True && !TurnedUp && i==BarCount-1){// && IsEmpty(UpTrendLine[i-1])) { 
				Say("attention please, Market Going, UP");
				PopupWindow(Date()+ "\n  > " +  Name() + "\n  > Buy : " + L[ i ] + "\n  > Target : " +(L[i]*1.005) +"\n  > Stop Loss : " +(L[i]*0.9975),"Buy alert", 100, 640*mtRandom(), 480*mtRandom());				TurnedUp=StaticVarSet("TurnedUp",1);
				TurnedDown=StaticVarSet("TurnedDown",0);

			} 
		} 
	
	 
		if (Sell[i]) 	{ 
			DownTrendLine[i]=bsmax[i];
			if (SoundON==True && !TurnedDown && i==BarCount-1){// && IsEmpty(DownTrendLine[i-1])) {
				Say("attention please, Market Going, DOWN");
				PopupWindow( Date()+ "\n  > " + Name() + "\n  > Sell : " + H[i] + "\n  > Target : " + (H[i]*0.995)+"\n  > Stop Loss : " +(H[i]*1.0025),"Sell alert", 100, 640*mtRandom(), 480*mtRandom());
				TurnedUp=StaticVarSet("TurnedUp",0);
				TurnedDown=StaticVarSet("TurnedDown",1);
			} 
		} 
	} 
} 
	bbtop=BBandTop(C,Length,Deviation);
	bbbot=BBandBot(C,Length,Deviation);
//if(CalcTrendProcedure){
	CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown);
//}	
	UpTrendSigNal=UpTrendLine aND IsEmpty(Ref(UpTrendLine,-1));
	DownTrendSigNal=DownTrendLine aND IsEmpty(Ref(DownTrendLine,-1));

//}
/*
dist = 0.8*aTR(10);
dist1 = 2*aTR(10);
for( i = 0; i < BarCount; i++ ) { 
	if( UpTrendSignal[i] ) {
		PlotText( "\nBuy:" + L[ i ] + "\nT= " + (L[i]*1.005) + "\nSL= " + (L[i]*0.9975), i, L[ i ]-dist[i], colorGreen, colorWhite );
	 }
	 if( DownTrendSignal[i] ) {
		PlotText( "Sell:" + H[ i ] + "\nT= " + (H[i]*0.995) + "\nSL= " + (H[i]*1.0025), i, H[ i ]+dist1[i], colorRed, colorWhite ); 
	 }
}
*/
 
I am trying to generate code for automatic buy and sell.. Facing a typical problem... If the buy and sell are on the same bar - sell is not being generated... eg. If price crosses My trigger level and does my financial target on same bar, system generates a bar arrow on cross of trigger but does not generate a sell arrow when price+tgt is achieved in same bar... It does work If the target gets achieved in any of the subsequent bars... Can anybody help/guide?
Can anybody guide pl?
 

hmp

Well-Known Member
Folks

Continuing on the holy grail quest of KRA ....

discovered yet another Indicator/Oscillator that claims to show the trend without any lag (in other words, lag is compensated for). Testing and expert opinion welcome...

First Clue was present in TJ itself here

Digging further revealed this site

Code is

Code:
r = Param( "TSI period Length:", 25, 1, 100, 1 );
s = Param( "TSI period Smoothing:", 13, 1, 100, 1 );
sig = Param( "TSI Signal Length:", 7, 1, 100, 1 );
 
Mtm = C - Ref ( C, -1 );
AbsMtm = abs(Mtm);

numT = EMA ( EMA ( Mtm, r ), s );
DenT = EMA ( EMA ( AbsMtm, r ), s );

TSI = 100 * Nz ( numT / DenT );
Plot( TSI, "TSI("+r+","+s+")", colorRed, styleLine);
Plot(EMA(TSI,sig), "", colorLightBlue, styleLine);
Plot(0,"", colorBlack, styleDashed);
Yes!
Its almost a holy grail provided one can add buy sell signals with proper scanning facility.Really excellent code.
Thanks & regards.
 

Nehal_s143

Well-Known Member
Yes!
Its almost a holy grail provided one can add buy sell signals with proper scanning facility.Really excellent code.
Thanks & regards.
code with arrows and explore :)

Code:
_SECTION_BEGIN("TSI");
r = Param( "TSI period Length:", 25, 1, 100, 1 );
s = Param( "TSI period Smoothing:", 13, 1, 100, 1 );
sig = Param( "TSI Signal Length:", 7, 1, 100, 1 );
 
Mtm = C - Ref ( C, -1 );
AbsMtm = abs(Mtm);

numT = EMA ( EMA ( Mtm, r ), s );
DenT = EMA ( EMA ( AbsMtm, r ), s );

TSI = 100 * Nz ( numT / DenT );
Plot( TSI, "TSI("+r+","+s+")", colorRed, styleLine);
Plot(EMA(TSI,sig), "", colorLightBlue, styleLine);
sige=EMA(TSI,sig);
Plot(0,"", colorGold, styleDashed);


myc2=IIf(Tsi>0 AND Tsi>sige,colorBlue,
      IIf(Tsi>0 AND Tsi<sige,colorSkyblue,
       IIf(Tsi<0 AND Tsi>sige,colorPink,
        IIf(Tsi<0 AND Tsi<sige,colorRed,31))));

Plot(6, "ribbon", myc2, styleOwnScale| styleArea|styleNoLabel,-0.5,100);

Buy =   Tsi>sige;
Sell =  Tsi<sige;
Short = Tsi<sige;
Cover = Tsi>sige;

Buy=ExRem(Buy,Sell);
Short=ExRem(Short,Cover);
Sell=ExRem(Sell,Buy);
Cover=ExRem(Cover,Short);
  
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone) ,colorBrightGreen);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);

Filter = Buy OR Sell OR Short OR Cover;
AddColumn(IIf(Buy, BuyPrice, 0),  "Buy", 6.2);
AddColumn(IIf(Sell, SellPrice, 0),  "Sell", 6.2);
AddColumn(IIf(Short, ShortPrice, 0),  "Short", 6.2);
AddColumn(IIf(Cover, CoverPrice, 0),  "Cover", 6.2);
AddColumn(Close,"Close",1.2);
 
_SECTION_END();
 
code with arrows and explore :)

Code:
_SECTION_BEGIN("TSI");
r = Param( "TSI period Length:", 25, 1, 100, 1 );
s = Param( "TSI period Smoothing:", 13, 1, 100, 1 );
sig = Param( "TSI Signal Length:", 7, 1, 100, 1 );
 
Mtm = C - Ref ( C, -1 );
AbsMtm = abs(Mtm);

numT = EMA ( EMA ( Mtm, r ), s );
DenT = EMA ( EMA ( AbsMtm, r ), s );

TSI = 100 * Nz ( numT / DenT );
Plot( TSI, "TSI("+r+","+s+")", colorRed, styleLine);
Plot(EMA(TSI,sig), "", colorLightBlue, styleLine);
sige=EMA(TSI,sig);
Plot(0,"", colorGold, styleDashed);


myc2=IIf(Tsi>0 AND Tsi>sige,colorBlue,
      IIf(Tsi>0 AND Tsi<sige,colorSkyblue,
       IIf(Tsi<0 AND Tsi>sige,colorPink,
        IIf(Tsi<0 AND Tsi<sige,colorRed,31))));

Plot(6, "ribbon", myc2, styleOwnScale| styleArea|styleNoLabel,-0.5,100);

Buy =  Tsi>sige;
Sell =  Tsi<sige;
Short = Tsi<sige;
Cover = Tsi>sige;

Buy=ExRem(Buy,Sell);
Short=ExRem(Short,Cover);
Sell=ExRem(Sell,Buy);
Cover=ExRem(Cover,Short);
  
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone) ,colorBrightGreen);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);

Filter = Buy OR Sell OR Short OR Cover;
AddColumn(IIf(Buy, BuyPrice, 0),  "Buy", 6.2);
AddColumn(IIf(Sell, SellPrice, 0),  "Sell", 6.2);
AddColumn(IIf(Short, ShortPrice, 0),  "Short", 6.2);
AddColumn(IIf(Cover, CoverPrice, 0),  "Cover", 6.2);
AddColumn(Close,"Close",1.2);
 
_SECTION_END();
Nehal

Nice addition .... Hope hmp can start scanning now ...

Overall, my recommendation would be to not plot the ribbon because zero line is important part of this TSI indcator and the ribbon (with its height of 6) almost totally dominates the zero line... Of course, if you must have ribbon, do it such that it gets plotted without shifting the zero line of TSI.

Go thru the stockcharts website for tutorial and interpretation...
 
Last edited:

Rish

Well-Known Member
code with arrows and explore :)

Code:
_SECTION_BEGIN("TSI");
r = Param( "TSI period Length:", 25, 1, 100, 1 );
s = Param( "TSI period Smoothing:", 13, 1, 100, 1 );
sig = Param( "TSI Signal Length:", 7, 1, 100, 1 );
 
Mtm = C - Ref ( C, -1 );
AbsMtm = abs(Mtm);

numT = EMA ( EMA ( Mtm, r ), s );
DenT = EMA ( EMA ( AbsMtm, r ), s );

TSI = 100 * Nz ( numT / DenT );
Plot( TSI, "TSI("+r+","+s+")", colorRed, styleLine);
Plot(EMA(TSI,sig), "", colorLightBlue, styleLine);
sige=EMA(TSI,sig);
Plot(0,"", colorGold, styleDashed);


myc2=IIf(Tsi>0 AND Tsi>sige,colorBlue,
      IIf(Tsi>0 AND Tsi<sige,colorSkyblue,
       IIf(Tsi<0 AND Tsi>sige,colorPink,
        IIf(Tsi<0 AND Tsi<sige,colorRed,31))));

Plot(6, "ribbon", myc2, styleOwnScale| styleArea|styleNoLabel,-0.5,100);

Buy =   Tsi>sige;
Sell =  Tsi<sige;
Short = Tsi<sige;
Cover = Tsi>sige;

Buy=ExRem(Buy,Sell);
Short=ExRem(Short,Cover);
Sell=ExRem(Sell,Buy);
Cover=ExRem(Cover,Short);
  
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone) ,colorBrightGreen);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);

Filter = Buy OR Sell OR Short OR Cover;
AddColumn(IIf(Buy, BuyPrice, 0),  "Buy", 6.2);
AddColumn(IIf(Sell, SellPrice, 0),  "Sell", 6.2);
AddColumn(IIf(Short, ShortPrice, 0),  "Short", 6.2);
AddColumn(IIf(Cover, CoverPrice, 0),  "Cover", 6.2);
AddColumn(Close,"Close",1.2);
 
_SECTION_END();
Can u please post with some chart...which will be best entry point....

I feel zero line crossover will avoid noises...in hourly time frame..

your view please..
 

Similar threads