Simple Coding Help - No Promise.

Hello,

I have a simple MA afl. Only one line code. Here it is :

Sell=Cross(Ref(MA(C,20),-1),Ref(C,-1)) AND Ref(C,-2)>(Ref(MA(C,20),-2));

I have written this afl assuming that I will be having the signals after completion of current bar ( Whatever time frame chosen in intraday for eg. hourly.)

So when I scan the list, it gives me the scrips which have crossed the MA(20) in previous bar, from upside and previous to previous bar's close must be greater than the previous to previous MA(20).

Now the issue is that, whenever I scan, the signal gives me the current market price as signal price. Where as It has to be close of previous bar.

Please help

Regards
Avinash
You will need to use Explorer to fulfill your needs


Filter = Sell;

And then add a line to add column for price you want.
 

amitrandive

Well-Known Member
Hello,

I have a simple MA afl. Only one line code. Here it is :

Sell=Cross(Ref(MA(C,20),-1),Ref(C,-1)) AND Ref(C,-2)>(Ref(MA(C,20),-2));

I have written this afl assuming that I will be having the signals after completion of current bar ( Whatever time frame chosen in intraday for eg. hourly.)

So when I scan the list, it gives me the scrips which have crossed the MA(20) in previous bar, from upside and previous to previous bar's close must be greater than the previous to previous MA(20).

Now the issue is that, whenever I scan, the signal gives me the current market price as signal price. Where as It has to be close of previous bar.

Please help

Regards
Avinash
You can try adding this

SellPrice=ValueWhen(Sell,C);
 
Similar AFL.Enjoy :D


Code:
_SECTION_BEGIN("YPF");
EntrySignal = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) );
ExitSignal = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) );
Color = IIf( EntrySignal, colorAqua, IIf( ExitSignal, colorOrange, colorGrey50 ));
TrailStop = HHV( C - 2 * ATR(10), 15 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10);
/* plot price chart and stops */
Plot( C, "Price", Color, styleCandle | styleThick );
/* plot color ribbon */
Plot( 1, "", Color, styleArea | styleOwnScale | styleNoLabel, -0.1, 50 );
BanlanceSignal = ( LLV( L, 20 ) + 2 * ATR( 10 ) );
TYP=(High + Low + 2*Close)/4;
CI=(TYP-MA(TYP,14))/(0.015*StDev(TYP,14));
EM2=EMA(CI,5);

// Sigma
Var1=EMA((Close-Ref(Close,-5))/Ref(Close,-5),5);
Var2=EMA((Close-Ref(Close,-20))/Ref(Close,-20),3);
Var3=EMA((Close-Ref(Close,-30))/Ref(Close,-30),3);

G1= EMA(Var1,5);
G2= EMA(Var2,20);
G3= EMA(Var3,30);

Buy=EM2<-80 AND EM2>Ref(EM2,-1) AND Ref(EM2,-1)<=Ref(EM2,-2)AND G1>Ref(G1,-1);
PlotShapes( IIf( Buy, shapeDigit0, shapeNone ), colorBrightGreen ,layer = 0, yposition = C, offset = -20 );
Sell=IIf( EntrySignal, colorAqua, IIf( ExitSignal, colorOrange, colorGrey50 ));
_SECTION_END();



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

Thank you very much for your above AFL
But there is no Buy Sell signals in it. If possible please add

PriyaRamesh
 

trash

Well-Known Member
Very kind, thank you!!

However the rules are not exactly what I meant.

- Uptrend starts when RSI(14) crosses 70 upward (ribbon green) and ends when RSI(14) crosses 40 downward. Then trend is sideways (ribbon grey)

- Downtrend starts when RSI(14) crosses 30 downward (ribbon red) and ends when RSI(14) crosses 60 upwards. Then trend is sideways (ribbon grey).

This is based upon Cardwell's interpretation of RSI with bull-support and bear-resistance.

I will also try to code this into an afl and will post it when I succeed.

Thanks again for your effort and time.:thumb:
Is the one below the RSI ribbon you are looking for?
See ribbon color and compare with RSI value in picture.
If that's the correct one then all you have to use is Cross(...) and LowestSince(...) for uptrend and HighestSince(..) for downtrend.

 

amitrandive

Well-Known Member
Amitrandiveji,

Thank you very much for your above AFL
But there is no Buy Sell signals in it. If possible please add

PriyaRamesh
Code:
_SECTION_BEGIN("YPF");
EntrySignal = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) );
ExitSignal = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) );
Color = IIf( EntrySignal, colorAqua, IIf( ExitSignal, colorOrange, colorGrey50 ));
TrailStop = HHV( C - 2 * ATR(10), 15 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10);
/* plot price chart and stops */
Plot( C, "Price", Color, styleCandle | styleThick );
/* plot color ribbon */
Plot( 1, "", Color, styleArea | styleOwnScale | styleNoLabel, -0.1, 50 );
BanlanceSignal = ( LLV( L, 20 ) + 2 * ATR( 10 ) );
TYP=(High + Low + 2*Close)/4;
CI=(TYP-MA(TYP,14))/(0.015*StDev(TYP,14));
EM2=EMA(CI,5);

// Sigma
Var1=EMA((Close-Ref(Close,-5))/Ref(Close,-5),5);
Var2=EMA((Close-Ref(Close,-20))/Ref(Close,-20),3);
Var3=EMA((Close-Ref(Close,-30))/Ref(Close,-30),3);

G1= EMA(Var1,5);
G2= EMA(Var2,20);
G3= EMA(Var3,30);

Buy=EM2<-80 AND EM2>Ref(EM2,-1) AND Ref(EM2,-1)<=Ref(EM2,-2)AND G1>Ref(G1,-1);
Sell=EM2>-80 AND EM2<Ref(EM2,-1) AND Ref(EM2,-1)>=Ref(EM2,-2)AND G1<Ref(G1,-1);
//Sell=IIf( EntrySignal, colorAqua, IIf( ExitSignal, colorOrange, colorGrey50 ));
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy ); 
PlotShapes (IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,Graph0,-15);
PlotShapes (IIf(Sell,shapeDownArrow,shapeNone),colorCustom12,0,Graph0,-15);

_SECTION_END();



_SECTION_BEGIN("Price1");
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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
 
Many thanks for your help trash!

I'm trying to code the afl but I get stuck in probably wrong logic.
Code:
_SECTION_BEGIN("RSI in ribbon color");

MyRSI = RSI(14);

UpFlag = Cross(myRSI, 70);
Trendup = IIf(LowestSince(UpFlag,C,1)>=40,1,0);

DownFlag = Cross(30, myRSI);
Trenddown = IIf(HighestSince(Downflag,C,1) <=60, 1, 0);
 
  Plot( 2,"",IIf(Trendup,colorGreen, IIf(Trenddown,colorRed, 0)),styleOwnScale|styleArea|styleNoLabel, -.5, 100);
_SECTION_END();
Where am I going wrong..?
 
Last edited:
i've downloaded an AFL for harmonics pattern but the projection start from the tip of the wick which is the high price, i need a pattern detection that starts the projection from the closing price of the candle, can you please help me.
thank you.
 

trash

Well-Known Member
Many thanks for your help trash!

I'm trying to code the afl but I get stuck in probably wrong logic.

_SECTION_BEGIN("RSI in ribbon color");

MyRSI = RSI(14);

UpFlag = Cross(myRSI, 70);
Trendup = IIf(LowestSince(UpFlag,C,1)>=40,1,0);

DownFlag = Cross(30, myRSI);
Trenddown = IIf(HighestSince(Downflag,C,1) <=60, 1, 0);

Plot( 2,"",IIf(Trendup,colorGreen, IIf(Trenddown,colorRed, 0)),styleOwnScale|styleArea|styleNoLabel, -.5, 100);
_SECTION_END();

Where am I going wrong..?
You have it almost.
It's not C you are looking for but your RSI.
Also you don't need to use Iif if you are just looking for true/false.

So

Code:
EDIT: Code removed by trash since requester understood what was the problem
BTW, next time please use code tags. Thanks!
 
Last edited:
Thanks a lot for your help trash! This was exactly what I was looking for.
Indeed it had to be myRSI instead of C...:annoyed:

Now I will implement this afl in a multiple timeframe sheet so I can keep track of different trend stages in one sheet.

Sorry by the way not using the code-brackets. I corrected it ;)
 

Similar threads