Simple Coding Help - No Promise.

mastermind007

Well-Known Member
Dear happy singh ji,
i want the close line in this afl to be blue when it is above heiken ashi and red when it is below heiken ashi price

_SECTION_BEGIN("Heiken Ashi");
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack),ParamColor("Titleblock",colorLightGrey ));
SetChartOptions(0,chartShowArrows|chartShowDates);
GraphXSpace=5;

p=Param("Period",6,2,40,1);
Om=MA(O,p);
hm=MA(H,p);
lm=MA(L,p);
Cm=MA(C,p);


HACLOSE=(Om+Hm+Lm+Cm)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( Hm, Max( HaClose, HaOpen ) );
HaLow = Min( Lm, Min( HaClose, HaOpen ) );
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "" + Name(), colorWhite, styleCandle | styleNoLabel );
Plot(C,"Close",colorBlue,styleThick);
_SECTION_END();
XRay,

First point
I hope you know that Heiken Ashi is not meant to compute moving average candle prices over few past days ... Code in the AFL doing that is highlighted in red. While this does not make this AFL wrong automatically, but you should be aware of the deviation being made ...

It was first thing I noticed as being off in your formula and checked up my references. You can read about Heiken Ashi here

Second Point

Close line that you had plotted in your AFL will never be above or below the Heiken Ashi's (as in never be above the Heiken's Ashi's High).

But, Heiken Ashi's Close may be below or above the actual close once in a while.... That is plotted here ...

Here is Heiken Ashi implemented as mentioned in stockcharts.com

Code:
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack),ParamColor("Titleblock",colorLightGrey ));
SetChartOptions(0,chartShowArrows|chartShowDates);
GraphXSpace=5;

HaClose = Close;
HaOpen = Open;
HaHigh = High;
HaLow  = Low;
for (i = 1; i < BarCount; i++)
{
	HaClose[i] = (Open[i]+High[i]+Low[i]+Close[i])/4;
	HaOpen[i]  = [B](HAClose[i - 1][/B] + HaOpen[i - 1]) / 2;
	HaHigh[i]  = Max(Max(HAClose[i], HaOpen[i]), High[i]);
	HaLow[i]   = Min(Min(HAClose[i], HaOpen[i]), Low[i]);
}

PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "" + Name(), colorWhite, styleCandle | styleNoLabel );
Plot(C,"Close",[B][U]IIf(HaClose >= Close, colorBlue, colorRed)[/U][/B], styleThick);
 
Last edited:

chintan786

Well-Known Member
Code:
Plot(OI, "Open_Interest", colorRed, styleThick|styleHistogram|styleOwnScale,0,4*HighestVisibleValue(OI));



:) Happy
Happy singhJi, Thanks for AFL.

Any Idea to do the same in Excel. I mean I have connected Excel sheet from NSE NOW terminal. I importing values like Time, LTP and OI. In the same cell values keep changing. I just want to plot OI graph against time.

Regards,
Chintan
 
Last edited:

mastermind007

Well-Known Member
XRAY27

Yesterday, I made a small error in the code. I've fixed it there itself. Highlighted the correction...
 

saivenkat

Well-Known Member
Re: Simple Coding Help - No Promise.b

http://www.4 s ha red.com/file/uaAaW1hw/SingleMA.html


Hi coders .. i need help.

The above link,has in it the Anant bro's single MA afl.

I want to add in it price, and volume filters in it..when doing scan and exploration process.

Buy or sell when Price > 50
volume > one lakh..

Can some one render helping hand in this connection..

Thanks and regards

Happy trading
 
Hi Happy Singh
how to combine cci and adx indicator
CCI= -199
ADX= 32
=-167

http://postimg.org/image/sx4goidjl/
thanks
Hello Muthu Brother

I don't know.

What I mean by that is, it can be done in zillions of ways, all depends on what do you want . . . :thumb:

For e.g, normally ADX is used for knowing strength of the trend, but it also had PDI & MDI to know trend direction, so one can even use those . . .

CCI is one of the oscillators, to be used as any other oscillator,
but if you google for Woodies CCI Systems or Woodies CCI Panel AFL
you will find 100s of ways CCI is used,
Woodies even recommends to use it without looking at price or volume :lol:

Further CCI has range from 300/-300, ADX will be 10-40/60 and RSI is 0 to 100

So before combining all three of them we need to normalize them,

by shifting it by -50, it is easy to convert RSI to range from -50 to +50

If at all then, ADX needs to be used as multiplying factor (trend strength), etc. . . etc . . .





Anyway, lets try and cook up some random combination of the 3 indicators you are looking for ;)

Hope it is useful to you :thumb:

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

_SECTION_BEGIN("JUGAD SYSTEM");
range = Param("Periods", 15, 1, 200, 1 );
A = ADX(range); P = PDI(range); M = MDI(range); N = 2*(P-M);
B = CCI(range); R = RSI(range); D = (N+4*(A-25)+B+2*(R-50))/3;
X = WMA(10*(RSIa(D,range)-50),range/3); 
Buy  = Cross(X,50); 
Sell = Cross(-50,X); 
PlotShapes(Buy+2*Sell,colorWhite,0,IIf(Buy,L,H),-20);
Plot((11*LowestVisibleValue(L) - HighestVisibleValue(H))/10, "", colorDefault, styleNoLine | styleNoLabel | styleNoTitle);
COL = IIf(X > 50, colorBlue,IIf(X < -50, colorRed,colorLightGrey));
Plot(X,"X-FACTOR",COL, styleOwnScale|styleThick,-150,1800);	
Plot(X,"",COL, styleOwnScale|styleHistogram|styleThick|styleNoLabel,-150,1800);
_SECTION_END();

Try it with 15/30/60 minutes charts

:) Happy
 
Last edited:

ethan hunt

Well-Known Member
Hi Happy Singh,
Kindly help me to make an AFL as per following details:
Thanks,

AFL required for following Strategy:

Trades are executed as soon as the price touches the fixed price level & not at close, open, hi, lo.

Eg:

BUY:
Price is at the moment below 5800
Price starts to move up & touches 5800
Buy as soon as price touches the fixed price level of 5800
Target exit as soon as price touches fixed price level of 5900
Stop Loss exit as soon as price touches fixed price level of 5750
Trailing stop loss exit as soon as price touches fixed price level of 5850 on it's way down


SHORT:
Price is at the moment above 5900
Price starts to fall down & touches 5900
Short as soon as price touches the fixed price level of 5900
Target exit as soon as price touches fixed price level of 5800
Stop Loss exit as soon as price touches fixed price level of 5950
Trailing stop loss exit as soon as price touches fixed price level of 5850 on it's way up


AFL requirement:
Back testing
Scanning
Plots lines of fixed price levels with labels
Flexibility to change the fixed levels from parameters options.
Flexibility to add more fixed price levels
Can be used in any time frame
Buy / Short arrows etc

Basic AFL:

_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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
PlotGrid( 5950, colorGreen );
PlotGrid( 5900, colorGreen );
PlotGrid( 5850, colorGreen );
PlotGrid( 5800, colorGreen );
PlotGrid( 5750, colorGreen );
_SECTION_END();
anyone ???
 
Hello ethan

Trading on BRNs is a good concept . . . but am sorry won't be able to code it for you, maybe someone else can help you with that.

However I have a suggestion about the concept.

As many times price will oscillate around the BRNs, as both bullish and bearish sides try to use these levels.
I suggest you can divide your trade quantity by 3 . . .

With 1/3, go for breakout over the big round number, 1/3 for close above it and 1/3 for pull back to a BRN . . .




:) Happy
 

ethan hunt

Well-Known Member
Hello ethan

Trading on BRNs is a good concept . . . but am sorry won't be able to code it for you, maybe someone else can help you with that.

However I have a suggestion about the concept.

As many times price will oscillate around the BRNs, as both bullish and bearish sides try to use these levels.
I suggest you can divide your trade quantity by 3 . . .

With 1/3, go for breakout over the big round number, 1/3 for close above it and 1/3 for pull back to a BRN . . .




:) Happy
Thanks, Happy,
It is tricky to code so that trade is executed as soon as a price is touched instead of trade execution at CLOSE, OPEN,HI,LOW ?
 

Similar threads