I need AFL

#1
Hola,
Yo trabajo con EMA 34.
Necesito que cuando su pendiente este entre -15 y +15 el color de la misma sea negro.
Cuando su pendiente sea mayor de 15 su color sea blanco y cuando sea menor de 15 el color sea verde claro. Puede alguien ayudarme. Gracias

Saludos,

Hello,
I work with EMA 34.
I need that when their slope this between -15 and +15 color of the same is black.
When their slope is greater of 15 their color is white and when he is smaller of -15 the color is pale green. Somebody can help me. Thanks

Greetings,
 

vinodkiyer

Well-Known Member
#2
_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", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("EMA1");
P = ParamField("Price field",-1);
_SECTION_END();



// Angle variables

PI = atan(1.00) * 4;
periods = 34;
HighHigh = HHV(H, periods);
LowLow = LLV(L, periods);
range = 25 / (HighHigh - LowLow) * LowLow;

// EMA34 Angle

EMA34 = EMA(C,34);
x1_EMA34 = 0;
x2_EMA34 = 1;
y1_EMA34 = 0;
y2_EMA34 = (Ref(EMA34, -1) - EMA34) / Avg * range;
c_EMA34 = sqrt((x2_EMA34 - x1_EMA34)*(x2_EMA34 - x1_EMA34) + (y2_EMA34 - y1_EMA34)*(y2_EMA34 - y1_EMA34));
angle_EMA34 = round(180 * acos((x2_EMA34 - x1_EMA34)/c_EMA34) / PI);
angle_EMA34 = IIf(y2_EMA34 > 0, - angle_EMA34, angle_EMA34);

Col=IIf(angle_EMA34 >15,colorWhite,IIf(angle_EMA34 <(-15),colorPaleGreen,colorBlack));

Plot( EMA( P, 34 ), _DEFAULT_NAME(), Col, ParamStyle("Style") );
 

colion

Active Member
#4
Hello,
I work with EMA 34.
I need that when their slope this between -15 and +15 color of the same is black.
When their slope is greater of 15 their color is white and when he is smaller of -15 the color is pale green. Somebody can help me. Thanks


Greetings,

Specifying +/- 15 degrees is not necessarily enough to define what you want. The slope will depend on how many bars are included in the calculation. So how many bars do you want to include? A simple way of proceeding that gives you control over the number of bars (and therefore the angle) is to use the function LinRegSlope() and simply convert slope to angle with arctan(slope).


The actual code can take many forms and here is one way of proceeding:

period = param("slope period", 13, 3, 34, 1);
slope = linregslope(c, period);
angle = atan(slope);
plot(angle, "angle", iif( angle > 15, colorwhite, iif(angle < -15,colorpalegreen, colorred));
 
#6
hi
yes ema 34 is very imp factor in intraday. thanks for coding it for the benifi of memberes.
i have two requests to add to this code only. code masters pl help.

1. exploration for all the stocks when the price crosses 34 ema with alert sound.same for sell.

2.arrows of buy and sell on price tends to move above/below this 34 ema.

3. simply cross overs with angle i dont think will speed up the price , add volume factor to identify the trades in our exploration/ scan in intraday.

can any one help?


ravi
 

singhboy

Active Member
#7
hi
yes ema 34 is very imp factor in intraday. thanks for coding it for the benifi of memberes.
i have two requests to add to this code only. code masters pl help.

1. exploration for all the stocks when the price crosses 34 ema with alert sound.same for sell.

2.arrows of buy and sell on price tends to move above/below this 34 ema.

3. simply cross overs with angle i dont think will speed up the price , add volume factor to identify the trades in our exploration/ scan in intraday.

can any one help?
I cant add to this afl, i hav sumthing similar to ur query, see if this helps
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
}
_SECTION_END();

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

_SECTION_BEGIN("Mid EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 45, 2, 300, 1 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") | styleNoRescale );
_SECTION_END();

_SECTION_BEGIN("Long EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 100, 2, 400, 1 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") | styleNoRescale );
_SECTION_END();

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

_SECTION_BEGIN("Volume");
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorLavender ), styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick | styleNoLabel, maskHistogram ), 2 );
_SECTION_END();

_SECTION_BEGIN("Price Interpretation");
movshort = ParamField("Short Time MA", 8 );
movmed = ParamField("Mid Time MA", 9 );
movlong = ParamField("Long Time MA", 10 );
btop = ParamField("BBTop", 11 );
bbot = ParamField("BBBottom", 12 );
if( Status("action") == actionCommentary )
{
width = btop - bbot;
lslop = LinRegSlope( C, 30 ) + 100;
lslo = LLV( lslop, 90 );
lshi = HHV( lslop, 90 );
lswidth = lshi - lslo;
trend = 100*( lslop - lslo )/lswidth;

mawidth = MA( width, 100 );
relwidth = 100*(width - mawidth)/mawidth;

_N( tname = Name()+"("+FullName()+")" );

printf("Price and moving averages:\n");
printf( tname + " has closed " + WriteIf( C > movshort, "above" , "below" ) + " its Short time moving average. ");

printf("\nShort time moving average is currently " + WriteIf( movshort > movmed, "above", "below") + " mid-time, AND " + WriteIf( movshort > movlong, "above", "below" ) + " long time moving averages.");

printf("\nThe relationship between price and moving averages is: "+
WriteIf( C > movshort AND movshort > movmed, "bullish",
WriteIf( C < movshort AND movshort < movmed, "bearish", "neutral" ) ) + " in short-term, and "+
WriteIf( movshort > movmed AND movmed > movlong , "bullish",
WriteIf( movshort < movmed AND movmed < movlong, "bearish", "neutral" ) ) + " in mid-long term. ");

printf("\n\nBollinger Bands:\n");
printf(tname+ " has closed " +
WriteIf( C < bbot, "below the lower band by " +
WriteVal( 100 *( bbot-C )/ width, 1.1 ) + "%%. " +
WriteIf( trend < 30, " This combined with the steep downtrend can suggest that the downward trend in prices has a good chance of continuing. However, a short-term pull-back inside the bands is likely.",
WriteIf( trend > 30 AND trend < 70, "Although prices have broken the lower band and a downside breakout is possible, the most likely scenario for "+tname+" is to continue within current trading range.", "" ) ), "" ) +

WriteIf( C > btop, "above the upper band by " +
WriteVal( 100 *( C- btop )/ width, 1.1 ) + "%%. " +
WriteIf( trend > 70, " This combined with the steep uptrend suggests that the upward trend in prices has a good chance of continuing. However, a short-term pull-back inside the bands is likely.",
WriteIf( trend > 30 AND trend < 70, "Although prices have broken the upper band and a upside breakout is possible, the most likely scenario for "+tname+" is to continue within current trading range.", "" ) ), "" ) +

WriteIf( C < btop AND ( ( btop - C ) / width ) < 0.5,
"below upper band by " +
WriteVal( 100 *( btop - C )/ width, 1.1 ) + "%%. ",
WriteIf( C < btop AND C > bbot , "above bottom band by " +
WriteVal( 100 *( C - bbot )/ width, 1.1 ) + "%%. ", "" ) ));

printf("\n"+
WriteIf( ( trend > 30 AND trend < 70 AND ( C > btop OR C < bbot ) ) AND abs(relwidth) > 40,
"This picture becomes somewhat unclear due to the fact that Bollinger Bands are currently",
"Bollinger Bands are " )+
WriteVal( abs( relwidth ), 1.1 ) + "%% " +
WriteIf( relwidth > 0, "wider" , "narrower" ) +
" than normal.");

printf("\n");

printf(
WriteIf( abs( relwidth ) < 40, "The current width of the bands (alone) does not suggest anything conclusive about the future volatility or movement of prices.","")+
WriteIf( relwidth < -40, "The narrow width of the bands suggests low volatility as compared to " + tname + "'s normal range. Therefore, the probability of volatility increasing with a sharp price move has increased for the near-term. "+
"The bands have been in this narrow range for " + WriteVal(BarsSince(Cross(-40,relwidth)),1.0) + " bars. The probability of a significant price move increases the longer the bands remain in this narrow range." ,"")+
WriteIf( relwidth > 40, "The large width of the bands suggest high volatility as compared to " + tname + "'s normal range. Therefore, the probability of volatility decreasing and prices entering (or remaining in) a trading range has increased for the near-term. "+
"The bands have been in this wide range for " + WriteVal(BarsSince(Cross(relwidth,40)),1.0) + " bars.The probability of prices consolidating into a less volatile trading range increases the longer the bands remain in this wide range." ,""));

printf("\n\nThis commentary is not a recommendation to buy or sell. Use at your own risk.");
}
_SECTION_END();
x = EMA(Close,34);
y = Close;

Buy=Cross(y,x)


;
Sell= Cross(x,y)

;

AddColumn(Close,"Close",1.4);
AddColumn(Buy,"buy",1.2);
AddColumn(Sell,"sell",1.2);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,Graph1);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,Graph1);
_SECTION_END();
 

singhboy

Active Member
#8
and u can use this for exploration
x = EMA(Close,34);
y = Close;

Buy=Cross(y,x)
AND Close > EMA( Close , 34 )
AND (
( StochK( 5, 3)>StochD( 5, 3, 3 ))
AND StochK( 5, 3 ) < 80
);
Sell=Cross(x,y)
AND Close > EMA( Close , 34 )
AND (
( StochK( 5, 3)<StochD( 5, 3, 3 ))
AND StochK( 5, 3 ) > 20
);

Filter=(Volume>50000) AND (Buy ) AND (Close>200);
AddColumn(Close,"Close",1.4);
AddColumn(Buy,"buy",1.2);
 

THE LORD

Active Member
#9
Specifying +/- 15 degrees is not necessarily enough to define what you want. The slope will depend on how many bars are included in the calculation. So how many bars do you want to include? A simple way of proceeding that gives you control over the number of bars (and therefore the angle) is to use the function LinRegSlope() and simply convert slope to angle with arctan(slope).


The actual code can take many forms and here is one way of proceeding:

period = param("slope period", 13, 3, 34, 1);
slope = linregslope(c, period);
angle = atan(slope);
plot(angle, "angle", iif( angle > 15, colorwhite, iif(angle < -15,colorpalegreen, colorred));
could you put the full afl
 

Similar threads