Simple Coding Help - No Promise.

shri_r3

Active Member
Hello friends,

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

When viewing intraday charts say hourly of 15 mins for ex rate of change is calculated with respect to immediate previous bar.
How to code it to show net % change wrt previous day closing even for intraday timeframe.
Thank you
 

trash

Well-Known Member
Hello friends,

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

When viewing intraday charts say hourly of 15 mins for ex rate of change is calculated with respect to immediate previous bar.
How to code it to show net % change wrt previous day closing even for intraday timeframe.
Thank you
Time frame functions.

Code:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

tmfrm = inDaily;
TimeFrameSet( tmfrm );
myvar = ROC(C, 1);
TimeFrameRestore();
myvar = TimeFrameExpand( myvar, tmfrm, expandFirst );

_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open = %g , Hi = %g , Lo = %g , Close = %g ( daily: %.1f%% ) {{VALUES}}",
                       O, H, L, C, SelectedValue( myvar ) ) );
_SECTION_END();
 

VJAY

Well-Known Member
I want arrows in my stoch afl....red arrow when K crosses below D abv 80 & Blue arrow when K crosses abv D below 20 .if possible sound alert too when arrow creates..please help to code it... ...For testing purpose

_SECTION_BEGIN("Stochastic %D");
periods = Param( "Periods", 15, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
Plot( StochD( periods , Ksmooth, DSmooth ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("Stochastic %K");
periods = Param( "Periods", 15, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Plot( StochK( periods , Ksmooth), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
 

amitrandive

Well-Known Member
I want arrows in my stoch afl....red arrow when K crosses below D abv 80 & Blue arrow when K crosses abv D below 20 .if possible sound alert too when arrow creates..please help to code it... ...For testing purpose
This should work

Code:
_SECTION_BEGIN(" Stoch KD Cloud");
periods = Param( "Periods", 15, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
a = StochK( periods , Ksmooth);
Plot( a, _DEFAULT_NAME(), ParamColor( "Color", colorBrightGreen ), ParamStyle("Style") );
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
b = StochD( periods , Ksmooth, DSmooth );
Plot( b, _DEFAULT_NAME(), ParamColor( "Color", colorRed ), ParamStyle("Style") );
 
PlotOHLC( a,a,b,a,"", IIf(a>b, colorBrightGreen, colorRed), styleCloud);
 
Overbought= 80; Oversold= 20;
Plot(Overbought,"OB",colorRed);
Plot(Oversold,"OS",colorGreen);
 
Buy = Cross( a, b );
Sell = Cross( b, a );
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone) ,colorBlue);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);
AlertIf( Buy, "SOUND C:\\Windows\\Media\\Ding.wav", "Audio alert", 1 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\Ding.wav", "Audio alert", 2 );
_SECTION_END();
 

VJAY

Well-Known Member
This should work

Code:
_SECTION_BEGIN(" Stoch KD Cloud");
periods = Param( "Periods", 15, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
a = StochK( periods , Ksmooth);
Plot( a, _DEFAULT_NAME(), ParamColor( "Color", colorBrightGreen ), ParamStyle("Style") );
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
b = StochD( periods , Ksmooth, DSmooth );
Plot( b, _DEFAULT_NAME(), ParamColor( "Color", colorRed ), ParamStyle("Style") );
 
PlotOHLC( a,a,b,a,"", IIf(a>b, colorBrightGreen, colorRed), styleCloud);
 
Overbought= 80; Oversold= 20;
Plot(Overbought,"OB",colorRed);
Plot(Oversold,"OS",colorGreen);
 
Buy = Cross( a, b );
Sell = Cross( b, a );
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone) ,colorBlue);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);
AlertIf( Buy, "SOUND C:\\Windows\\Media\\Ding.wav", "Audio alert", 1 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\Ding.wav", "Audio alert", 2 );
_SECTION_END();
Thanks a lot amit bhai...its gr8
 

hmp

Well-Known Member
Hi
I would like to have afl for following strategy.
Ema 5,34,& 200 crossover.
Scanning the stocks for buy/sell when 5/200 crossover occurs,along with red/green arrows.
Thanks & regards.
 

msa5678

Well-Known Member
I need to display the last 4 signals in a box on the chart, the AFL is pasted below. Getting the current signal details are already coded in the AFL, But I need the previous signal details also displayed. Running automatic analysis everytime to get the past signals is time consuming, if they are displayed on the chart it will be very helpful.

Code:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, V, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
SetChartBkGradientFill( ParamColor("Inner panel upper",colorWhite),ParamColor("Inner panel lower",colorLightYellow));

_SECTION_END();

_SECTION_BEGIN("Auto Trading System");
acc = Param("Acceleration", 0.019, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.019, 0, 1, 0.001 );
Trds = Param("Number of Trades", 123, 0, 5000, 1);
Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorYellow ),
ParamStyle("Style", styleLine | styleLine, maskDefault | styleLine | styleLine )
);

Val = SAR( acc, accm );
Diff = (Val - C) ;

Buy = Cross(Open,  SAR(acc,accm));
Sell = Cross(SAR(acc,accm), Open );
Short=Sell;
Cover=Buy;
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy ); 
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone), colorBlack, 0, Low, Offset=-15);
PlotShapes(IIf(Sell, shapeDownArrow,shapeNone), colorBlue, 0, High,
Offset=-15);
dist = 5*ATR(2);
for( i = 0; i < BarCount; i++ )
{
if( Buy[i] ) PlotText( "" + C[ i ], i, H[ i ]+dist[i], colorBlue ); 
if( Sell[i] ) PlotText( "" + C[ i ], i, L[ i ]-dist[i], colorBlack ); 
}

t1= Flip(Buy,Sell);
t2= Flip(Sell,Buy);
BPrice=ValueWhen(t1 AND Ref(t1,-1)==0,C,1);
SPrice=ValueWhen(t2 AND Ref(t2,-1)==0,C,1);



Filter = Buy OR Sell;

AddColumn( Buy, "Buy", 1);
AddColumn( Sell, "Sell", 1);



GfxSetBkMode(1);
GfxSelectPen( colorBlack, 1, 0) ;
GfxSelectSolidBrush( colorPink ); 
GfxRoundRect( 92, 160, 175, 85, 9, 9 ) ;


entry = 0;
sig = "none";
for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1)
{
sig = "Prcd";
entry = C[i];
 
bars = i;
i = 0;
}
if(Sell[i] == 1)
{
sig = "Sold";
entry = C[i];
 
bars = i;
i = 0;
}
}


GfxSetBkMode(1);
GfxSelectPen( colorBlack, 1, 0) ;
GfxSelectSolidBrush( colorPink ); 
GfxSelectFont("romans", 15, 700 ); 
GfxTextOut( ""+Val, 95, 85);
GfxSelectFont("romans", 9, 700 );
GfxTextOut( ""+acc+"    "+accm, 98, 105);
GfxSelectFont("romans", 9, 700 );
GfxTextOut( ""+sig+" @ "+entry, 95, 140);
GfxTextOut( "   "+Diff, 95, 118);
GfxTextOut( "     Trds   "+Trds, 89, 130);
_SECTION_END();
 

amitrandive

Well-Known Member
Hi
I would like to have afl for following strategy.
Ema 5,34,& 200 crossover.
Scanning the stocks for buy/sell when 5/200 crossover occurs,along with red/green arrows.
Thanks & regards.

Try this

Code:
 Plot(Close,"Price",colorBlack, styleCandle);
 Plot(EMA(Close,5),"5EMA",colorBlue,style=styleThick);
 Plot(EMA(Close,34),"34EMA",colorRed,style=styleThick);
 Plot(EMA(Close,200),"200EMA",colorYellow,style=styleThick);

 Buy=Cross(EMA(Close,5),EMA(Close,200));
 Sell=Cross(EMA(Close,200),EMA(Close,5)); 
Short=Sell; Cover=Buy; shape = Buy * shapeUpArrow + Sell * shapeDownArrow; PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );
 _SECTION_END(); _SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",30,11,100,1); 
GfxSelectFont("Times New Roman", FS, 700, True ); 
GfxSetBkMode( colorWhite ); GfxSetTextColor( ParamColor("Color",colorBlack) );
 Hor=Param("Horizontal Position",600,1,1200,1);
 Ver=Param("Vertical Position",1,1,830,1); GfxTextOut(""+C, Hor , Ver );
 YC=TimeFrameGetPrice("C",inDaily,-1); DD=Prec(C-YC,2); xx=Prec((DD/YC)*100,2); 
GfxSelectFont("Times New Roman", 11, 700, True ); GfxSetBkMode( colorWhite );
 GfxSetTextColor(ParamColor("Color",colorBlack) ); 
GfxTextOut(""+DD+" ("+xx+"%)", Hor , Ver+45 );
Filter=Buy OR Sell; 
 
AddColumn(IIf(Buy,BuyPrice,Null)," Buy Signal ", 6.2,1.2,colorGreen); 
AddColumn(IIf(Sell,SellPrice,Null)," Sell Signal ",6.2,1.2,colorOrange); 
AddColumn(C,"LTP",6.2,1.2);
 _SECTION_END();
 

msa5678

Well-Known Member
I need to display the last 4 signals in a box on the chart, the AFL is pasted below. Getting the current signal details are already coded in the AFL, But I need the previous signal details also displayed. Running automatic analysis everytime to get the past signals is time consuming, if they are displayed on the chart it will be very helpful.

Code:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, V, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
SetChartBkGradientFill( ParamColor("Inner panel upper",colorWhite),ParamColor("Inner panel lower",colorLightYellow));

_SECTION_END();

_SECTION_BEGIN("Auto Trading System");
acc = Param("Acceleration", 0.019, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.019, 0, 1, 0.001 );
Trds = Param("Number of Trades", 123, 0, 5000, 1);
Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorYellow ),
ParamStyle("Style", styleLine | styleLine, maskDefault | styleLine | styleLine )
);

Val = SAR( acc, accm );
Diff = (Val - C) ;

Buy = Cross(Open,  SAR(acc,accm));
Sell = Cross(SAR(acc,accm), Open );
Short=Sell;
Cover=Buy;
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy ); 
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone), colorBlack, 0, Low, Offset=-15);
PlotShapes(IIf(Sell, shapeDownArrow,shapeNone), colorBlue, 0, High,
Offset=-15);
dist = 5*ATR(2);
for( i = 0; i < BarCount; i++ )
{
if( Buy[i] ) PlotText( "" + C[ i ], i, H[ i ]+dist[i], colorBlue ); 
if( Sell[i] ) PlotText( "" + C[ i ], i, L[ i ]-dist[i], colorBlack ); 
}

t1= Flip(Buy,Sell);
t2= Flip(Sell,Buy);
BPrice=ValueWhen(t1 AND Ref(t1,-1)==0,C,1);
SPrice=ValueWhen(t2 AND Ref(t2,-1)==0,C,1);



Filter = Buy OR Sell;

AddColumn( Buy, "Buy", 1);
AddColumn( Sell, "Sell", 1);



GfxSetBkMode(1);
GfxSelectPen( colorBlack, 1, 0) ;
GfxSelectSolidBrush( colorPink ); 
GfxRoundRect( 92, 160, 175, 85, 9, 9 ) ;


entry = 0;
sig = "none";
for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1)
{
sig = "Prcd";
entry = C[i];
 
bars = i;
i = 0;
}
if(Sell[i] == 1)
{
sig = "Sold";
entry = C[i];
 
bars = i;
i = 0;
}
}


GfxSetBkMode(1);
GfxSelectPen( colorBlack, 1, 0) ;
GfxSelectSolidBrush( colorPink ); 
GfxSelectFont("romans", 15, 700 ); 
GfxTextOut( ""+Val, 95, 85);
GfxSelectFont("romans", 9, 700 );
GfxTextOut( ""+acc+"    "+accm, 98, 105);
GfxSelectFont("romans", 9, 700 );
GfxTextOut( ""+sig+" @ "+entry, 95, 140);
GfxTextOut( "   "+Diff, 95, 118);
GfxTextOut( "     Trds   "+Trds, 89, 130);
_SECTION_END();
Dear Amit,

Please look into the above request.

Regards
 

Similar threads