Simple Coding Help - No Promise.

ema5,ema8 cross over system

I require a AFL which
** plot Lines at crossover candle for EMA5>EMA8 BULL condition.
1) Draw Lines at HIGH and LOW of this Bull Crossover candle.
* Buy Condition 1 = Buy when the candle close above Bull High Line.
* Sell Condition 1 = Sell when the candle close below Bull Low Line.

** plot Lines at crossover candle for EMA5<EMA8 BEAR condition.
2) Draw Lines at HIGH and LOW of this Bear Crossover candle.
* Buy Condition2 = Buy when the candle close above Bear High Line.
* Sell Condition 2 = Sell when the candle close below Bear Low Line.

So, only one signal should be in live at any point of time. If Condition 1 active then past signal of Condition 2 should be inactive and vice verse.

Please Help.
 
Last edited:
hi everyone
I need help for a scan based on the following afl which will show name of the stocks with buy and sell signal and arrow

thanks in advance
_SECTION_BEGIN("zero lag macd");
p1 = Param("Short period", 12, 3, 50, 1);
p2 = Param("Long period", 26, 5, 100, 1);
p3 = Param("Signal period", 9, 3, 25, 1);

EMAshort = EMA(C, p1);
EMA2 = EMA( EMAshort, p1);
Diff = EMAshort - EMA2;
ZLEMAshort = EMAshort + Diff;

EMAlong = EMA(C, p2);
EMA2 = EMA(EMAlong, p2);
Diff = EMAlong - EMA2;
ZLEMAlong = EMAlong + Diff;

ZLMACD = ZLEMAshort - ZLEMAlong;

EMA1 = EMA(ZLMACD, p3);
EMA2 = EMA(EMA1, p3);
Diff = EMA1 - EMA2;
ZLSignal = EMA1 + Diff;

Plot(ZLMACD, "zero lag MACD", colorGreen);
Plot(ZLSignal, "zero lag Signal", colorRed);
_SECTION_END();
 

amitrandive

Well-Known Member
hi everyone
I need help for a scan based on the following afl which will show name of the stocks with buy and sell signal and arrow

thanks in advance
_SECTION_BEGIN("zero lag macd");
p1 = Param("Short period", 12, 3, 50, 1);
p2 = Param("Long period", 26, 5, 100, 1);
p3 = Param("Signal period", 9, 3, 25, 1);

EMAshort = EMA(C, p1);
EMA2 = EMA( EMAshort, p1);
Diff = EMAshort - EMA2;
ZLEMAshort = EMAshort + Diff;

EMAlong = EMA(C, p2);
EMA2 = EMA(EMAlong, p2);
Diff = EMAlong - EMA2;
ZLEMAlong = EMAlong + Diff;

ZLMACD = ZLEMAshort - ZLEMAlong;

EMA1 = EMA(ZLMACD, p3);
EMA2 = EMA(EMA1, p3);
Diff = EMA1 - EMA2;
ZLSignal = EMA1 + Diff;

Plot(ZLMACD, "zero lag MACD", colorGreen);
Plot(ZLSignal, "zero lag Signal", colorRed);
_SECTION_END();
Added arrows and scan

Code:
_SECTION_BEGIN("zero lag macd");
p1 = Param("Short period", 12, 3, 50, 1);
p2 = Param("Long period", 26, 5, 100, 1);
p3 = Param("Signal period", 9, 3, 25, 1);

EMAshort = EMA(C, p1);
EMA2 = EMA( EMAshort, p1);
Diff = EMAshort - EMA2;
ZLEMAshort = EMAshort + Diff;

EMAlong = EMA(C, p2);
EMA2 = EMA(EMAlong, p2);
Diff = EMAlong - EMA2;
ZLEMAlong = EMAlong + Diff;

ZLMACD = ZLEMAshort - ZLEMAlong;

EMA1 = EMA(ZLMACD, p3);
EMA2 = EMA(EMA1, p3);
Diff = EMA1 - EMA2;
ZLSignal = EMA1 + Diff;

Plot(ZLMACD, "zero lag MACD", colorGreen);
Plot(ZLSignal, "zero lag Signal", colorRed);
_SECTION_END();
_SECTION_BEGIN("Buy Sell Arrows");
shapesSignalswitch = ParamToggle("Cross Signal Arrows","On,Off");
UPcolor = ParamColor( "UP Color", colorGreen );
DOWNcolor = ParamColor( "Down Color", colorRed );
Buy=Cross( ZLMACD, ZLSignal );
Sell=Cross( ZLSignal, ZLMACD );
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( IIf(shapesSignalswitch,-1e10,shape), IIf( Buy, UPcolor, DOWNcolor ));
_SECTION_END();
Filter = Buy OR Sell ;
AddColumn(IIf(Buy, BuyPrice, 0),  "Buy", 6.2);
AddColumn(IIf(Sell, SellPrice, 0),  "Sell", 6.2);
AddColumn(Close,"Close",1.2);
 

amitrandive

Well-Known Member
Hi my dear friends;
I need to add exploring for this wonderful afl.exploring sell buy.i am waiting for your kindness
Scan added.

Code:
//ELLIOT Fractals
_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 ), styleCandle
| ParamStyle("Style") | GetPriceStyle() );
// Paste the code below to your price chart somewhere and green ribbon means both
// both MACD and ADX trending up so if the red ribbon shows up the MACD and the ADX
// are both trending down.

_SECTION_BEGIN("trending ribbon");
uptrend=PDI()>MDI()AND Signal()<MACD();
downtrend=MDI()>PDI()AND Signal()>MACD();


Plot( 2, /* defines the height of the ribbon in percent of pane width */"ribbon",
IIf( uptrend, colorGreen, IIf( downtrend, colorRed, 0 )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

_SECTION_END();

_SECTION_END();

_SECTION_BEGIN("LEMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 20, 2, 200, 1, 10 );
lema = EMA (Close,Periods)+ EMA((Close-EMA(Close,Periods)),Periods);
Plot( lEMA, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ),
ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("ELLIOTT Fractals");
/*
The basic definition of an 'up' fractal is a bar high that is both higher than the two bars immediately preceding it
and higher than the two bars immediately following it.
The lows of the bars are NOT considered in determining the up fractal progression.

If two bars in the progression have equal highs followed by two consecutive bars with lower highs,
then a total of six bars rather than the usual five bars will make up the progression.
The first High becomes the counting fractal. Reverse for 'down' fractals.

The 5 bar formation works best on Daily or longer time frame charts.For intraday data charts we often use 9 bar, 13 bar and 21 bar formations for fractal counting
*/
Up5BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND Ref(H,1) < H AND Ref(H,2) < H;
Up6BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND (H == Ref(H,1)) AND Ref(H,2) < H AND Ref(H,3) < H;
Down5BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND Ref(L,1) > L AND Ref(L,2) > L;
Down6BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND (L == Ref(L,1)) AND Ref(L,2) > L AND Ref(L,3) > L;

//TODO: More filtering: Show only troughs that are around atrough in trix(9).

PlotShapes( IIf(Down5BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);
PlotShapes( IIf(Down6BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);

PlotShapes( IIf(Up5BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);
PlotShapes( IIf(Up6BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);

Up = (Up5BarFractal OR Up6BarFractal);
Down = (Down5BarFractal OR Down6BarFractal);
//Removing false fractals:
DownSignal = Flip(Ref(Up,-1), Ref(Down,-1));
UpSignal = Flip(Ref(Down,-1), Ref(Up,-1));

LastHigh[0] = H[0];
LastLow[0] = L[0];

LastLowIndex = 0;
LastHighIndex = 0;
Valid = 0;
for (i=1; i < BarCount; i++)
{

LastHigh[i] = LastHigh[i-1];
LastLow[i] = LastLow[i-1];
if (Up[i])
{
Valid[i] = True;
if (DownSignal[i])
{
//Sequence of 2 Up Fractals. Validate only the higher one.
Valid[i] = H[i] >= H[LastHighIndex];
Valid[LastHighIndex] = H[LastHighIndex] > H[i];
}
LastHigh[i] = Max(H[i], H[LastHighIndex ]);
LastHighIndex = i;
}

if (Down[i])
{
Valid[i] = True;
if (UpSignal[i])
{
//Sequence of 2 Down Fractals. Validate only the lower one.
Valid[i] = L[i] <= L[LastLowIndex];
Valid[LastLowIndex] = L[LastLowIndex] < L[i];
}

LastLow[i] = Min(L[i], L[LastLowIndex]);
LastLowIndex = i;
}
}

TrixN = Trix(9);
TroughLow = Ref(TrixN, -3) > TrixN AND Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN AND Ref(TrixN, 3) > TrixN;
TroughHigh = Ref(TrixN, -3) < TrixN AND Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN AND Ref(TrixN, 3) < TrixN;
//TroughLow = Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN;
//TroughHigh = Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN;
ZeroValid = Cross(TrixN, 0) OR Cross(0, TrixN) OR Ref(Cross(TrixN, 0),1) OR Ref(Cross(0, TrixN),1);
ValidLow = TroughLow OR Ref(TroughLow, 1) OR Ref(TroughLow, 2) OR Ref(TroughLow, 3) OR Ref(TroughLow, 4);// OR Ref(TroughLow, 5));
ValidHigh = TroughHigh OR Ref(TroughHigh, 1) OR Ref(TroughHigh, 2) OR Ref(TroughHigh, 3) OR Ref(TroughHigh, 4);// OR Ref(TroughHigh, 5));

//Plot(LastHigh-10 ,"LastHigh", colorBlue, styleLine);
//Plot(LastLow-10 ,"LastLow ", colorRed, styleLine);
//Plot(Valid*5 + 10 ,"LastLow ", colorGreen, styleLine | styleThick);

//PlotShapes( IIf(Down AND Valid,shapeSmallCircle,0) ,colorGreen, 0, L,-12);
//PlotShapes( IIf(Up AND Valid,shapeSmallCircle,0) ,colorYellow, 0, H,-12);
Maxi = Up AND (ValidHigh OR ZeroValid);
Mini = Down AND (ValidLow OR ZeroValid);
PlotShapes( IIf(Down AND (ValidLow OR ZeroValid),shapeSmallUpTriangle,0) ,colorBlue, 0, L,-12);
PlotShapes( IIf(Up AND (ValidHigh OR ZeroValid),shapeSmallDownTriangle,0) ,colorOrange, 0, H,-12);
Buy=Cover=IIf(Down AND (ValidLow OR ZeroValid),1,0);
Sell=Short=IIf(Up AND (ValidHigh OR ZeroValid),1,0);
//Plot(UpSignal*3+5,"UpSignal", colorBlue, styleLine| styleThick);
//Plot(DownSignal*3 ,"DownSignal", colorRed, styleLine| styleThick);

/*
LastMaxi = 0;
LastMini = 0;
ElliotLines = 0;
State = 0;
for (i=1; i < BarCount; i++)
{
State[i] = State[i-1];
if (Maxi[i])
{
State[i] = 1;//down
}

if (Mini[i])
{
State[i] = 2;
}

}

PlotShapes(IIf(State > 0, shapeSmallCircle, 0), IIf(State == 1, colorRed, colorBlue), 0, IIf(State == 1, H, L), -5);
*/
//Line = LineArray( x0, y0, x1, y1, 1 );
//Plot( Line, "Trend line", colorBlue );

/*
Wave B
Usually 50% of Wave A
Should not exceed 75% of Wave A
Wave C
either 1 x Wave A
or 1.62 x Wave A
or 2.62 x Wave A
*/
function CorrectiveRatios(StartPrice, A, B, C, RatioDelta, Delta)
{

ALength = abs(startPrice - A); BLength = abs(A-B);
CLength = abs(B-C);

Ratio1 = BLength / CLength ;
Cond1 = Ration1 >= 0.5 - RatioDelta AND ratio1 <= 0.75 + RatioDelta;
Cond2 = abs(Clength - ALength) < Delta OR abs(Clength - 1.62 * ALength) < Delta OR abs(CLength - 2.62 * ALength) < Delta;

return Cond1 AND Cond2;
}

function ImpulseRules(StartPrice, One, Two, Three, Four, Five)
{
//Wave 2 should be beneath wave 1 start:
Cond1 = Two > StartPrice AND Two < One;
//Wave 4 - the same:
Cond2 = Four > Two AND Four < Three;
//Wave 5 should be <= wave 3
Cond3 = abs(Three-Two) >= abs(Five - Four);
//Wave 1 should be smaller than wave five, making wave 3 the biggest:
Cond4 = abs(StartPrice - One) < abs(Five - Four);
return Cond1 AND Cond2 AND Cond3 AND Cond4;
}
_SECTION_END(); 
Filter = Buy OR Sell ;
AddColumn(IIf(Buy, BuyPrice, 0),  "Buy", 6.2);
AddColumn(IIf(Sell, SellPrice, 0),  "Sell", 6.2);
AddColumn(Close,"Close",1.2);
 

amitrandive

Well-Known Member
Request

I have AFL (not mine), for Maximum and Minimum high / low marking for 4 (candle) days..

_SECTION_BEGIN("4hl method");
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle |

_SECTION_END();

I request and require

1st Condition......110 candle Maximum high / Minimum low marking / deduction....

2nd Condition.....if the next candle close is below Maxium High (1st Condition) candle low...we should have marking or sell Singal.....vis versa if the next candle close is above the Minimum Low (1st Condition) Candle high...we should have marking or Buy Signal...

Can anybody help in this......

Tried this , check whether it works,scanner only , no plotting.If logic works , we can add buy sell arrows later.That is easy


Code:
TimeFrameSet(inDaily);
EMAH110 = EMA( H, 110 ); 
EMAL110 = EMA( L, 110 ); 
TimeFrameRestore();
TOUCH110=H > EMAH110 AND L < EMAL110;
Buy=TOUCH110 AND C>EMAH110;
Sell=TOUCH110 AND C<EMAH110;
 
Last edited:
I require a AFL which
** plot Lines at crossover candle for EMA5>EMA8 BULL condition.
1) Draw Lines at HIGH and LOW of this Bull Crossover candle.
* Buy Condition 1 = Buy when the candle close above Bull High Line.
* Sell Condition 1 = Sell when the candle close below Bull Low Line.

** plot Lines at crossover candle for EMA5<EMA8 BEAR condition.
2) Draw Lines at HIGH and LOW of this Bear Crossover candle.
* Buy Condition 2 = Buy when the candle close above Bear High Line.
* Sell Condition 2 = Sell when the candle close below Bear Low Line.

So, only one signal should be in live at any point of time. If Condition 1 active then past signal of Condition 2 should be inactive and vice verse.

Please Help.
 

Rish

Well-Known Member

Tried this , check whether it works,scanner only , no plotting.If logic works , we can add buy sell arrows later.That is easy


Code:
TimeFrameSet(inDaily);
EMAH110 = EMA( H, 110 ); 
EMAL110 = EMA( L, 110 ); 
TimeFrameRestore();
TOUCH110=H > EMAH110 AND L < EMAL110;
Buy=TOUCH110 AND C>EMAH110;
Sell=TOUCH110 AND C<EMAH110;
Thanks Amit..i got some idea based on your code and i made some changes and drawn lines and 15 minutes is working good now. I will make for all time frame.. Once, i freeze and fix other logics..i will send the code to check at your end.

Once Again Thanks a lot...

 

amitrandive

Well-Known Member
Hello amit ji & friends,

Need small help for plotting exploration..

Conditions -

1) Price </> then 5 SMA

2) Stochastic Crossover 5'3

3) cci above/Below 100/-100


Thanx's in advance
I assume your conditions as below ,correct if they are wrong

For Buy
Price > 5 SMA
Stochastic(5,3,3) Bullish crossover
CCI>0
All above conditions to be satisfied for a buy.
For Sell
Price <5 SMA
Stochastic (5,3,3)Bearish crossover
CCI<0
All above conditions to be satisfied for a sell.
 
I assume your conditions as below ,correct if they are wrong

ice > 5 SMA
Stochastic(5,3,3) Bullish crossover
CCI>0
All above conditions to be satisfied for a buyFor Buy
Pr.
For Sell
Price <5 SMA
Stochastic (5,3,3)Bearish crossover
CCI<0
All above conditions to be satisfied for a sell.

HTML:
For Buy 

Price > 5 SMA
Stochastic(5,3,3) Bullish crossover
CCI>100

All above conditions to be satisfied for a buy.

For Sell 

Price <5 SMA
Stochastic (5,3,3)Bearish crossover
CCI<-100

All above conditions to be satisfied for a sell.
(Only change was CCI value rest all perfect)
Thanx you
 

Similar threads