Simple Coding Help - No Promise.

Sir... Does it show the HA Price or real price sir....
Add following line in code somewhere after Ha is computed to get the title

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} O %g, H %g, L %g, C %g (%.1f%%) H.O %g, H.H %g, H.L %g, H.C %g {{VALUES}}"
, Open, High, Low, Close, SelectedValue(ROC(Close, 1)), HaOpen, HaHigh, HaLow, HaClose ));
 

Nehal_s143

Well-Known Member
H Nehal, Thank you for being kind enough to help others with coding.
I was wondering if you or others could put together a code for the requirements I mentioned in my post #2822.

Thanks
only seniors can help for this kind of coding, I know only abc of about afl
 
Last edited:
Yes, you can do that ...

Code:
_SECTION_BEGIN("HA Looping ( no AMA() )");
///////////////////////////////////////////////////////////
// Heikin Ashi - Calculated Properly without using AMA
// JF Derzi, December 2012

HaClose[0] = (Open[0]+High[0]+Low[0]+Close[0]) / 4;
HaOpen[0]  = (HaClose[0] + Open[0]) / 2;
HaHigh[0]  = Max( High[0], Max( HaClose[0], HaOpen[0] ) );
HaLow[0]   = Min( Low[0], Min( HaClose[0], HaOpen[0] ) );

for (i = 1; i < BarCount; i++)
{
HaClose[i] = (Open[i]+High[i]+Low[i]+Close[i]) / 4;
Haopen[i]  = (HaClose[i-1] + HaOpen[i-1]) / 2;
// Here is the problem when using Arrays: Haopen always uses its own previous value
HaHigh[i]  = Max( High[i], Max( HaClose[i], HaOpen[i] ) );
Halow[i]   = Min( Low[i], Min( HaClose[i], HaOpen[i] ) );
}

PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", colorBlack, styleCandle);
Title = Name()+" "+Date()+" Heikin Ashi -- HaOpen:"+NumToStr(HaOpen,1.2,True)+" / HaHigh:"+NumToStr(HaHigh,1.2,True)+" / HaLow:"+NumToStr(Halow,1.2,True)+" HaClose:"+NumToStr(Haclose,1.2, True);
_SECTION_END();

_SECTION_BEGIN("MA");
Periods = Param("Periods", 15, 2, 300, 1, 10 );
simpleMA = MA( HaClose, Periods ); 
Plot( simpleMA, "MA2", ParamColor( "Color", colorCycle ), ParamStyle("Style") ); _SECTION_END();
_SECTION_END();

_SECTION_BEGIN("OSMA");
// osma implementation for Amibroker
// version 0.2 (c) 28th April 2011, [email protected] 

FastEma=Param("Fast EMA", 12, 1 , 25, 1);
SlowEma=Param("Slow EMA", 26, 1 , 50, 1);
SignalEma=Param("Signal EMA", 9, 1 , 25, 1);
// signals 
OsMA=MACD( FastEma, SlowEma )-Signal( FastEma, SlowEma, SignalEma );
// Plot removed
_SECTION_END();

_SECTION_BEGIN("Momentum");
momentum = HaClose * 100 / Ref(HaClose, -Param("Period", 10, 1, 100 ) );
// Plot removed
_SECTION_END();

_SECTION_BEGIN("RSIa");
periods = Param("Periods", 15, 1, 200, 1 );
rxRsi =  RSIa( HaClose, periods);
_SECTION_END();

longCond1 = Cross(HaClose, simpleMA);
longCond2 = OsMA > 0;
longCond3 = momentum > 100;
longCond4 = rxRsi > 50;
PlotShapes(longCond1 * shapeDigit1, colorBlue, 0, HaLow - 5);
PlotShapes(longCond2 * shapeDigit2, colorBlue, 0, HaLow - 10);
PlotShapes(longCond3 * shapeDigit3, colorBlue, 0, HaLow - 15);
PlotShapes(longCond4 * shapeDigit4, colorBlue, 0, HaLow - 20);

Buy = ((HaOpen < HaClose) AND Cross(HaClose, simpleMA) AND (OsMA > 0) AND (momentum > 100) AND (rxRsi > 50));
Short = ((HaOpen > HaClose) AND Cross(HaClose, simpleMA) AND (OsMA < 0) AND (momentum < 100) AND (rxRsi < 50));
....

Itz showing only buy signals in Scan Option...
 

Nehal_s143

Well-Known Member
Itz showing only buy signals in Scan Option...
try this

Code:
_SECTION_BEGIN("HA Looping ( no AMA() )");
///////////////////////////////////////////////////////////
// Heikin Ashi - Calculated Properly without using AMA
// JF Derzi, December 2012

HaClose[0] = (Open[0]+High[0]+Low[0]+Close[0]) / 4;
HaOpen[0]  = (HaClose[0] + Open[0]) / 2;
HaHigh[0]  = Max( High[0], Max( HaClose[0], HaOpen[0] ) );
HaLow[0]   = Min( Low[0], Min( HaClose[0], HaOpen[0] ) );

for (i = 1; i < BarCount; i++)
{
HaClose[i] = (Open[i]+High[i]+Low[i]+Close[i]) / 4;
Haopen[i]  = (HaClose[i-1] + HaOpen[i-1]) / 2;
// Here is the problem when using Arrays: Haopen always uses its own previous value
HaHigh[i]  = Max( High[i], Max( HaClose[i], HaOpen[i] ) );
Halow[i]   = Min( Low[i], Min( HaClose[i], HaOpen[i] ) );
}

PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", colorBlack, styleCandle);
Title = Name()+" "+Date()+" Heikin Ashi -- HaOpen:"+NumToStr(HaOpen,1.2,True)+" / HaHigh:"+NumToStr(HaHigh,1.2,True)+" / HaLow:"+NumToStr(Halow,1.2,True)+" HaClose:"+NumToStr(Haclose,1.2, True);
_SECTION_END();

_SECTION_BEGIN("MA");
Periods = Param("Periods", 15, 2, 300, 1, 10 );
simpleMA = MA( HaClose, Periods ); 
Plot( simpleMA, "MA2", ParamColor( "Color", colorCycle ), ParamStyle("Style") ); _SECTION_END();
_SECTION_END();

_SECTION_BEGIN("OSMA");
// osma implementation for Amibroker
// version 0.2 (c) 28th April 2011, [email protected] 

FastEma=Param("Fast EMA", 12, 1 , 25, 1);
SlowEma=Param("Slow EMA", 26, 1 , 50, 1);
SignalEma=Param("Signal EMA", 9, 1 , 25, 1);
// signals 
OsMA=MACD( FastEma, SlowEma )-Signal( FastEma, SlowEma, SignalEma );
// Plot removed
_SECTION_END();

_SECTION_BEGIN("Momentum");
momentum = HaClose * 100 / Ref(HaClose, -Param("Period", 10, 1, 100 ) );
// Plot removed
_SECTION_END();

_SECTION_BEGIN("RSIa");
periods = Param("Periods", 15, 1, 200, 1 );
rxRsi =  RSIa( HaClose, periods);
_SECTION_END();

longCond1 = Cross(HaClose, simpleMA);
longCond2 = OsMA > 0;
longCond3 = momentum > 100;
longCond4 = rxRsi > 50;
//PlotShapes(longCond1 * shapeDigit1, colorBlue, 0, HaLow - 5);
//PlotShapes(longCond2 * shapeDigit2, colorBlue, 0, HaLow - 10);
//PlotShapes(longCond3 * shapeDigit3, colorBlue, 0, HaLow - 15);
//PlotShapes(longCond4 * shapeDigit4, colorBlue, 0, HaLow - 20);

Buy = ((HaOpen < HaClose) AND (HaClose>simpleMA) AND (OsMA > 0) AND (momentum > 100) AND (rxRsi > 50));
Sell = ((HaOpen > HaClose) AND (HaClose<simpleMA) AND (OsMA < 0) AND (momentum < 100) AND (rxRsi < 50));
Short = ((HaOpen > HaClose) AND (HaClose<simpleMA) AND (OsMA < 0) AND (momentum < 100) AND (rxRsi < 50));
Cover = ((HaOpen < HaClose) AND (HaClose>simpleMA) AND (OsMA > 0) AND (momentum > 100) AND (rxRsi > 50));


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

PlotShapes(Buy*shapeUpArrow,colorBlue,0,L,-21);
//PlotShapes(Sell*shapeHollowSmallDownTriangle,colorPink,0,L,-51);
PlotShapes(Short*shapeDownArrow,colorRed,0,H,-21);
//PlotShapes(Cover*shapeHollowSmallUpTriangle,colorSkyblue,0,H,-51);


Filter = Buy OR Sell OR Short OR Cover;
AddColumn(IIf(Buy, BuyPrice, 0),  "Buy", 6.2);
AddColumn(IIf(Sell, SellPrice, 0),  "Sell", 6.2);
AddColumn(IIf(Short, ShortPrice, 0),  "Short", 6.2);
AddColumn(IIf(Cover, CoverPrice, 0),  "Cover", 6.2);
AddColumn(Close,"Close",1.2);
 
try this

Code:
_SECTION_BEGIN("HA Looping ( no AMA() )");
///////////////////////////////////////////////////////////
// Heikin Ashi - Calculated Properly without using AMA
// JF Derzi, December 2012

HaClose[0] = (Open[0]+High[0]+Low[0]+Close[0]) / 4;
HaOpen[0]  = (HaClose[0] + Open[0]) / 2;
HaHigh[0]  = Max( High[0], Max( HaClose[0], HaOpen[0] ) );
HaLow[0]   = Min( Low[0], Min( HaClose[0], HaOpen[0] ) );

for (i = 1; i < BarCount; i++)
{
HaClose[i] = (Open[i]+High[i]+Low[i]+Close[i]) / 4;
Haopen[i]  = (HaClose[i-1] + HaOpen[i-1]) / 2;
// Here is the problem when using Arrays: Haopen always uses its own previous value
HaHigh[i]  = Max( High[i], Max( HaClose[i], HaOpen[i] ) );
Halow[i]   = Min( Low[i], Min( HaClose[i], HaOpen[i] ) );
}

PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", colorBlack, styleCandle);
Title = Name()+" "+Date()+" Heikin Ashi -- HaOpen:"+NumToStr(HaOpen,1.2,True)+" / HaHigh:"+NumToStr(HaHigh,1.2,True)+" / HaLow:"+NumToStr(Halow,1.2,True)+" HaClose:"+NumToStr(Haclose,1.2, True);
_SECTION_END();

_SECTION_BEGIN("MA");
Periods = Param("Periods", 15, 2, 300, 1, 10 );
simpleMA = MA( HaClose, Periods ); 
Plot( simpleMA, "MA2", ParamColor( "Color", colorCycle ), ParamStyle("Style") ); _SECTION_END();
_SECTION_END();

_SECTION_BEGIN("OSMA");
// osma implementation for Amibroker
// version 0.2 (c) 28th April 2011, [email protected] 

FastEma=Param("Fast EMA", 12, 1 , 25, 1);
SlowEma=Param("Slow EMA", 26, 1 , 50, 1);
SignalEma=Param("Signal EMA", 9, 1 , 25, 1);
// signals 
OsMA=MACD( FastEma, SlowEma )-Signal( FastEma, SlowEma, SignalEma );
// Plot removed
_SECTION_END();

_SECTION_BEGIN("Momentum");
momentum = HaClose * 100 / Ref(HaClose, -Param("Period", 10, 1, 100 ) );
// Plot removed
_SECTION_END();

_SECTION_BEGIN("RSIa");
periods = Param("Periods", 15, 1, 200, 1 );
rxRsi =  RSIa( HaClose, periods);
_SECTION_END();

longCond1 = Cross(HaClose, simpleMA);
longCond2 = OsMA > 0;
longCond3 = momentum > 100;
longCond4 = rxRsi > 50;
//PlotShapes(longCond1 * shapeDigit1, colorBlue, 0, HaLow - 5);
//PlotShapes(longCond2 * shapeDigit2, colorBlue, 0, HaLow - 10);
//PlotShapes(longCond3 * shapeDigit3, colorBlue, 0, HaLow - 15);
//PlotShapes(longCond4 * shapeDigit4, colorBlue, 0, HaLow - 20);

Buy = ((HaOpen < HaClose) AND (HaClose>simpleMA) AND (OsMA > 0) AND (momentum > 100) AND (rxRsi > 50));
Sell = ((HaOpen > HaClose) AND (HaClose<simpleMA) AND (OsMA < 0) AND (momentum < 100) AND (rxRsi < 50));
Short = ((HaOpen > HaClose) AND (HaClose<simpleMA) AND (OsMA < 0) AND (momentum < 100) AND (rxRsi < 50));
Cover = ((HaOpen < HaClose) AND (HaClose>simpleMA) AND (OsMA > 0) AND (momentum > 100) AND (rxRsi > 50));


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

PlotShapes(Buy*shapeUpArrow,colorBlue,0,L,-21);
//PlotShapes(Sell*shapeHollowSmallDownTriangle,colorPink,0,L,-51);
PlotShapes(Short*shapeDownArrow,colorRed,0,H,-21);
//PlotShapes(Cover*shapeHollowSmallUpTriangle,colorSkyblue,0,H,-51);


Filter = Buy OR Sell OR Short OR Cover;
AddColumn(IIf(Buy, BuyPrice, 0),  "Buy", 6.2);
AddColumn(IIf(Sell, SellPrice, 0),  "Sell", 6.2);
AddColumn(IIf(Short, ShortPrice, 0),  "Short", 6.2);
AddColumn(IIf(Cover, CoverPrice, 0),  "Cover", 6.2);
AddColumn(Close,"Close",1.2);

Thanks @Nehal_s143... It seems to be working now.... It does not plot the other indicators and uses it to scan...right???

Cover signal comes when OsMA turns red right???
 

sr114

Well-Known Member
afl - all vakueas of rsi, osma ams momentum is on haclose

_SECTION_BEGIN("Background_Setting");
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),
ParamColor("BgBottom", colorDarkGrey),ParamColor("TitleBack",colorGrey40));
SetChartBkColor(ParamColor("Outer Panel",colorBlack));
SetChartOptions(0,chartShowArrows|chartShowDates);
_SECTION_END();

_SECTION_BEGIN("HA ");
Haclose=Hahigh=Halow=Haopen=0;

for (i=1; i<BarCount; i++)
{
HaClose = (Open+High+Low+Close) / 4;
Haopen = (HaClose[i-1] + HaOpen[i-1]) / 2; // Here is the problem when using Arrays: Haopen always uses its previous value
HaHigh = Max( High, Max( HaClose, HaOpen ) );
Halow = Min( Low, Min( HaClose, HaOpen ) );
}

Col_dig=IIf(Haclose>MA(Haclose,14),colorBrightGreen,colorRed);
PlotOHLC(Haopen,Hahigh,Halow,Haclose,"\nHA_Close",Col_dig,64);
_SECTION_END();

_SECTION_BEGIN("RSI");
AdjFactor = Param( "AdjFactor", 5, 0, 10, 0.25 );
R = RSIa(haclose,14);
PH = 20; // Height of RSI in percent pane height
RSIHeight = 100 / PH * 100;
GraphXSpace = AdjFactor * PH;
Plot( R, "\nRSI frm Haclose", colorBlue, 1 | styleThick|styleOwnScale, 0, RSIHeight );
//Plot( 100, "", colorDarkGrey, styleArea | styleOwnScale | styleNoLabel, 0, RSIHeight );
Plot( 50, "", colorBlack, styleOwnScale | styleLine, 0, RSIHeight );
_SECTION_END();

_SECTION_BEGIN("OSMA");
//Haclose=0;

for (i=1; i<BarCount; i++)
{
HaClose = (Open+High+Low+Close) / 4;
}

procedure SaveRestorePrices( DoSave )
{
global SaveC;

if( DoSave )
{
HaClose[0] = (Open[0]+High[0]+Low[0]+Close[0]) / 4;

}
else
{

Close = HaClose;
}
}

SaveRestorePrices( True );

customArray = ( Haclose );
Close = customArray;
SaveRestorePrices( False );

OsMA=MACD( 12, 26 )-Signal( 12, 26, 9 );

function Momentum( array, period )
{
return (array /Ref( array, -period ))*100;
}
m1=Momentum( Haclose, 14 );

_SECTION_END();

_SECTION_BEGIN("BS");
b1 = HaClose > MA(Haclose,14) AND r > 50 AND osma>0 AND m1>100;
s1 = HaClose < MA(Haclose,14) AND r < 50 AND osma<0 AND m1<100;

Buy=Ref(b1,-1);
Sell=Ref(s1,-1);

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

b1=ExRem(b1,s1);
s1=ExRem(s1,b1);

PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBrightGreen,0,halow,-20);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,Hahigh,-20);

PlotShapes(IIf(B1,shapeSmallCircle,shapeNone),colorSeaGreen,0,halow,-20);
PlotShapes(IIf(S1,shapeSmallCircle,shapeNone),colorLightOrange,0,Hahigh,20);
_SECTION_END();

Title = "";
_SECTION_BEGIN("Exploration");
Filter=1;// Buy OR Sell;
AddColumn( C ,"CMP", 1.2, colorBlue,colorWhite);
AddColumn( MA(Haclose,14) ,"SMA 14", 1.2, colorBlue,colorWhite);
AddColumn(r ,"RSI 14", 1.2, colorBlue,colorWhite);
AddColumn( Osma,"OSMA", 1.2, colorBlue,colorWhite);
AddColumn( m1 ,"MOM 14", 1.2, colorBlue,colorWhite);
AddColumn(IIf(Buy, 66, 83), "TRIG", formatChar, colorBlack, IIf(Buy, colorBrightGreen, colorOrange));
//AddColumn(IIf(B1, 66, 83), "actl TRIG", formatChar, colorBlack, IIf(B1, colorBrightGreen, colorOrange));

SetSortColumns( 8,1,2 );
_SECTION_END();
//by Vidyasagar, [email protected]//
FS=Param("Font Size",11,8,100,1);
GfxSelectFont("Verdana", FS, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorAqua) );
Hor=Param("Horizontal Position",350,1,1200,1);
Ver=Param("Vertical Position",1,1,1,1);
GfxTextOut("Close LTP : "+ NumToStr(C,1.2) ,Hor , Ver );
GfxTextOut("RSI : "+ NumToStr(r,1.2) ,Hor , Ver+15 );
//GfxTextOut(symbol1+" "+NumToStr(idx1c ,1.2) ,Hor , Ver+45 );
//GfxTextOut(symbol2 +" "+NumToStr(idx2c ,1.2) ,Hor , Ver+60 );
_SECTION_END();
 

Similar threads