Simple Coding Help - No Promise.

Friends

I need Exponential crossover (3,15 EMA) method with buy and sell arrows and need it for Auto trade.

Please share the AFL.

Cheers
:thumb:
If you simply search EMA crossover you will get many AFL in google.
Anyway below sample code for EMA crossover copied from wisestocktrader. Change the parameter as per ur requirement.
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();
 
 
_SECTION_BEGIN("ema_crossover");
x = EMA(Close,3);
y = EMA(Close,8);
Plot(EMA(Close,3),"",colorRed,styleLine);
Plot(EMA(Close,8),"",colorDarkGreen,styleLine);
 
Buy=Cross(x,y);
PlotShapes(shapeUpArrow*Buy,colorGreen);
XR=(EMA(Close,3) * (2 / 6 - 1) - EMA(Close,8) * (2 / 11 - 1)) / (2 / 6 - 2 / 11);
Title = Name() + " " + Date()+" " + EncodeColor( colorBlue ) +"3/8 EMA " +EncodeColor( colorRed )
+ " O " + O + " H " + H + " L " + L + " C "+ C + "\n";
 
Sell=Cross(y,x);
PlotShapes(shapeDownArrow*Sell,colorRed);
AlertIf( Sell, "SOUND C:\\Windows\\Media\\chord.wav", "Audio alert", 2 );
XR=(EMA(Close,8) * (2 / 6 - 1) - EMA(Close,3) * (2 / 11 - 1)) / (2 / 6 - 2 / 11);
Title = Name() + " " + Date()+" " + EncodeColor( colorBlue ) +"3/8 EMA " +EncodeColor( colorRed )
+ " O " + O + " H " + H + " L " + L + " C "+ C + "\n";
 
_SECTION_END();
 
Try this

Code:
Buyc   = C > Ref(LSA, -P3) AND C > Ref( LSB, -P3) AND CL > BL;
Shortc = C < Ref(LSA, -P3) AND C < Ref( LSB, -P3) AND CL < BL;

Buy  = Cover = Ref(Buyc, -1) ==1; 
Sell = Short = Ref(Shortc,-1)==1;

Buy  = ExRem(Buy,Sell);		Short = ExRem(Short,Cover);
Sell = ExRem(Sell,Buy);		Cover = ExRem(Cover,Short);

Profit = 1.6;		Loss   = 0.5;
ApplyStop(stopTypeProfit, stopModePercent,Profit,ExitAtStop=1);
ApplyStop(stopTypeLoss, stopModePercent,Loss,ExitAtStop=1);

Happy :)
Hi Happy ji, Sorry about very delayed reply, I wasn't available these days. I checked this code just by copy&paste working fine..yet to check on trade by trade basis. Anyway Thank you so much :)
 
Hello,
I'm looking for multi dimensional examples.. In context of time,price ..

for two dimensional varset/varget [][]
matrix also used
of course two loop will be there, for two [][]

it seems matrix is easy,it's intial topic in mathematics, i'm pretty much familiar with inverse of it and all.. but how to use it in trading way .. example: time and price



I wanna see few examples ..
that contain atleast [][]
let me know , i can make two loops for that example .
 
I want to code scanner to scan stock but the tricky thing is I am having one huge code which gives actual buy sell signal on chart, but i want to use this signal from 1st afl and write a code in 2nd AFL using signals from 1st afl any help will be appreciated this would be a breakthrough in building a successful scanner
 
Hi
Can anyone share the code where can I scan/explore all stocks
which gap up from yesterday hiigh/ gapdown below yesterday low
thanks
Scanner
Code:
Buy = TimeFrameGetPrice("O",inDaily,0) > TimeFrameGetPrice("H",inDaily, -1);
Short=TimeFrameGetPrice("O",inDaily,0) < TimeFrameGetPrice("L",inDaily, -1);
Sell = Cover = 0;
Explorer
Code:
Filter = (TimeFrameGetPrice("O",inDaily,0) > TimeFrameGetPrice("H",inDaily, -1)) OR 
(TimeFrameGetPrice("O",inDaily,0) < TimeFrameGetPrice("L",inDaily, -1));

// Add as many AddColumns as you want ...
 
hi , can anyone fix this afl to show multi time frame please , i want to see daily weekly monthly but i dont know how to code , please fix for me , thanks


_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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 200, 1 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale );
Buy = Cross( MA( Close, 15 ), MA( Close, 45 ) );
Sell = Cross( MA( Close, 45 ), MA( Close, 15 ) );
PlotShapes(IIf(Sell==1, shapeDownArrow, shapeNone), colorYellow, 0,High, Offset=-15);
PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorYellow, 0,Low, Offset=-15);
_SECTION_END();

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

_SECTION_BEGIN("Long MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 100, 2, 400, 1 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale );
Buy = Cross( MA( Close, 15 ), MA( Close, 100 ) );
Sell = Cross( MA( Close, 100 ), MA( Close, 15 ) );
PlotShapes(IIf(Sell==1, shapeDownArrow, shapeNone), colorCustom11, 0,High, Offset=-15);
PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorCustom11, 0,Low, Offset=-15);

_SECTION_END();

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

_SECTION_BEGIN("BBands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 100, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorLightGrey );
Color = ColorBlend( Color, GetChartBkColor(), 0.5 );
Style = ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale;;
Plot( bbt = BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style );
Plot( bbb = BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style );
PlotOHLC( bbt, bbt, bbb, bbb, "", ColorBlend( Color, GetChartBkColor(), 0.7 ), styleNoLabel | styleCloud | styleNoRescale, Null, Null, Null, -1 );
_SECTION_END();

_SECTION_BEGIN("Volume");
Color = ParamColor("Color", ColorRGB( 128, 128, 192 ) );
Plot( Volume, _DEFAULT_NAME(), ColorBlend( Color, GetChartBkColor(), 0.5 ), 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();

_SECTION_BEGIN("SAR");
acc = Param("Acceleration", 0.02, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.2, 0, 1, 0.001 );
Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) );
_SECTION_END();
 

mt4trader

Well-Known Member
AUTOTRADE LINE
i want following features
1 it will generate buy or sell signal by crossing a line drawn manually by user
2 it can be selected buy or sell
above are the basic function needed.
additional features are optional.
1 there must be time delay for signal generation with user delay input
 
VPCI - Volume Price confirmation indicator

Dear Programers & all members,
It show error in the last line. Could anybody else please correct.

VCPI CODE
Code:
// volume weighted MA
function VWMA( array, period )
{
  return Sum( array * V, period ) / Sum( V, period );
}
// Volume Price Confirmation Indicator
function VPCI( speriod, Lperiod )
{
  Vw = VWMA( C, lperiod );
  Vpc = Vw - MA( C, lperiod );
 
  Vpr = VWMA( C, speriod ) / MA( C, speriod );
  Vm = MA( V, speriod ) / MA( V, Lperiod );
  return Vpc * Vpr * Vm;
}
// plot VPCI
speriod = Param("Short period", 5, 1, 50, 1 );
lperiod = Param("Long period", 20, 1, 100, 1 );
Vp = VPCI( speriod, Lperiod );
Plot( Vp, "VPCI"+ _PARAM_VALUES(), colorRed );
// and VPCI smoothed
aperiod = Param("Smoothing period", 20, 1, 30, 1 );
Vps = MA( Vp, aperiod);
Plot( Vps, "MA("+aperiod+")", colorBlue );
// simple trading system follows
Buy = Vp > Vps AND
      ADX( 7 ) > 10 AND
      MACD( 12, 26 ) > Signal( 12, 26, 9 );
Sell = Vps < Vp
 
Last edited by a moderator:

amitrandive

Well-Known Member
VPCI - Volume Price confirmation indicator

Dear Programers & all members,
It show error in the last line. Could anybody else please correct.

VCPI CODE
Code:
// volume weighted MA
function VWMA( array, period )
{
  return Sum( array * V, period ) / Sum( V, period );
}
// Volume Price Confirmation Indicator
function VPCI( speriod, Lperiod )
{
  Vw = VWMA( C, lperiod );
  Vpc = Vw - MA( C, lperiod );
 
  Vpr = VWMA( C, speriod ) / MA( C, speriod );
  Vm = MA( V, speriod ) / MA( V, Lperiod );
  return Vpc * Vpr * Vm;
}
// plot VPCI
speriod = Param("Short period", 5, 1, 50, 1 );
lperiod = Param("Long period", 20, 1, 100, 1 );
Vp = VPCI( speriod, Lperiod );
Plot( Vp, "VPCI"+ _PARAM_VALUES(), colorRed );
// and VPCI smoothed
aperiod = Param("Smoothing period", 20, 1, 30, 1 );
Vps = MA( Vp, aperiod);
Plot( Vps, "MA("+aperiod+")", colorBlue );
// simple trading system follows
Buy = Vp > Vps AND
      ADX( 7 ) > 10 AND
      MACD( 12, 26 ) > Signal( 12, 26, 9 );
Sell = Vps < Vp
Modify last line as(add semicolon at the end)
Code:
Sell = Vps < Vp;
 

Similar threads