Trading with OBV - for Beginners only !!

raju.vzm

Well-Known Member
#72
One more beginner question, is this OBV method only suitable for 1 min charts? Or else can we use it for other timelines,i.e 1 day charts to identify long term / uptrend movement?

Sent from my MI 3W using Tapatalk
 
#73
One more beginner question, is this OBV method only suitable for 1 min charts? Or else can we use it for other timelines,i.e 1 day charts to identify long term / uptrend movement?

Sent from my MI 3W using Tapatalk
Use it on 1day timeframe charts and see for yourself...if you do the backtest then share the results here....

Smart_trade
 

vijkris

Learner and Follower
#74
One more beginner question, is this OBV method only suitable for 1 min charts? Or else can we use it for other timelines,i.e 1 day charts to identify long term / uptrend movement?

Sent from my MI 3W using Tapatalk
It is suitable for all timeframes.. 5min tf can be used for swing trades as well..
1 day tf obv can be used to identify long term movement.

Yes, as St sir said, pls share ur findings, specially u r an investor.
thanks
 

vijkris

Learner and Follower
#75
@ vivek bhai, 7th post of this thread contains the afl u need to backtest.

anyway reposting it now along with modification to include 5 period obv.

@xray bhai, i cant dig up in varun ji's thread, but in afl we have to change 15 to 5 for daily period.

Here in this afl, added param function, slide the "obv hi lo periods" from 15 to 5 for backtesting daily tf.

@ vivek bhai. Don't drag this but take a new sheet and use "insert chart".
The support/res lines drawn by default is based on obv ribbon change. Myself didn find it useful, but u can change it to price based sup/res, which is equivalent to visual pivots.
In Parameters locate "Pvt type":"obv" .. change obv to price.


Code:
SetChartBkGradientFill( ParamColor("Inner panel upper",colorDarkGrey),ParamColor("Inner panel lower",colorGrey40 ));
SetChartBkColor(colorBlack);

_SECTION_BEGIN("Price");
SetChartOptions( 2,chartShowArrows+ chartShowDates |   chartWrapTitle );

_N(Title = StrFormat("OBV 2nd Method : {{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() ); 
Layer = Param("Layer", 0, -5, 5, 1) ;
//Plot( C, "Close",  colorTeal, styleNoTitle |styleCandle,0,0,0 ); 
HiVolume = IIf(V > (2 * MA(V,10)), True, False); 
PlotShapes(shapeSmallCircle * HiVolume, IIf(C > O, colorRed, colorWhite), 0, (O+C)/2, 0);
ToolTip = "Open = " + O + "\nHigh = " + H + "\nLow = " + L + "\nClose = " + C ;

_SECTION_BEGIN("Price Hi Lo"); 
y = Param("Ribbon price location",15,0,500,5);

HiP= HHV(H,15);        LoP= LLV(L,15); 

B2 = Cross(C,Ref(HiP,-1));    S2 = Cross(Ref(LoP,-1),C); 

B2 = ExRem(B2,S2);        S2 = ExRem(S2,B2); 

UP2 = Flip(B2,S2);        DN2 = Flip(S2,B2); 

//Plot(12,"p",IIf(UP2,colorGreen,colorOrange),styleOwnScale|styleNoLabel|styleThick,0,200,0,-5,8); 
PlotOHLC(y,Y+10,y,y,"",IIf(UP2,colorGreen,colorOrange),styleOwnScale|styleNoLabel|styleCloud,0,500);
//Plot(IIf(b2,1,0),"",colorBlue,styleOwnScale|styleNoLabel|styleHistogram|styleDashed,0,1);
//Plot(IIf(s2,1,0),"",colorRed, styleOwnScale|styleNoLabel|styleHistogram|styleDashed,0,1);

_SECTION_END();
_SECTION_BEGIN("OBV Hi Lo"); 
y = Param("Ribbon obv location",5,0,500,5);
periods = Param("OBV hiLo periods",15,0,100);

Ob = OBV();    Hi = HHV(Ob,periods);    Lo = LLV(Ob,periods); 

B1 = Cross(Ob,Ref(Hi,-1));    S1 = Cross(Ref(Lo,-1),Ob); 

B1 = ExRem(B1,S1);        S1 = ExRem(S1,B1); 

UP1 = Flip(B1,S1);        DN1 = Flip(S1,B1); 

//Plot(10,"",IIf(UP1,colorBlue,colorRed),styleOwnScale|styleNoLabel|styleThick,0,500,0,-5,8); 
PlotOHLC(y,Y+10,y,y,"",IIf(UP1,colorBlue,colorRed),styleOwnScale|styleNoLabel|styleCloud,0,500);
showVerticalObvlines15 = ParamToggle("Show vertical line for 15 ribbon change", "No|Yes", 0) ;
if (showVerticalObvlines15)
{
Plot(IIf(B1,1,0),"",colorBlue,styleOwnScale|styleNoLabel|styleHistogram|styleDashed,0,1);
Plot(IIf(S1,1,0),"",colorRed, styleOwnScale|styleNoLabel|styleHistogram|styleDashed,0,1); //vertical lines
}
_SECTION_BEGIN("Alerts");
bluetored = s1;
redtoblue = b1;

RequestTimedRefresh(20);
AlertIf(redtoblue,"SOUND C:\\Windows\\Media\\Ding.wav", "buy"+Name(),1,1+2+4); 
AlertIf(bluetored,"SOUND C:\\Windows\\Media\\Ding.wav", "Sell"+Name(),2,1+2+4);
_SECTION_END();

_SECTION_BEGIN("OBV hi/lo and Supp/Res");


ro = ParamField("Open", 0) ;
rh = ParamField("High", 1) ;
rl = ParamField("Low", 2) ;
rc = ParamField("Close", 3) ;


P = (rH+rL+rC)/3 ;
// = Param("Fast", 1, 1, 100, 1) ;
// = Param("Slow", 3, 1, 100, 1) ;

isemapvts = ParamToggle("Want Pivots ", "No|Yes", 1) ;
pvttype = ParamToggle("Pvt type", "Price|Obv",1);
periodtype = ParamToggle("15 period or 60 period lines?","60 period|15 period",1);


ismph = H-H ;
ismpl = L-L ;


if (isemapvts)
{

 if(pvttype)
{
 if(periodtype)
{
upcross = b1 ; // 15 obv
downcross = s1 ;
}
else
{
upcross = b60; //60obv
downcross = s60;
}
}

else
{
upcross = b2; // price
downcross = s2;
}
bi = BarIndex() ;

mphbar = HighestSinceBars(upcross, rH) ;
mplbar = LowestSinceBars(downcross, rL) ;

mphbi = ValueWhen(downcross, bi, 0) - ValueWhen(downcross, mphbar, 0) ;
ismph = mphbi == bi ;

mplbi = ValueWhen(upCross, bi, 0) - ValueWhen(upCross, mplbar, 0) ;
ismpl = mplbi == bi ;

ismph = IIf(downCross AND mphbar == 0, True, ismph) ;
ismpl = IIf(upcross AND mplbar == 0, True, ismpl) ;

}

_SECTION_BEGIN("OBV Sup/res lines Plot");
showobvSupResline = ParamToggle("Show Obv Sup/Res line", "No|Yes", 1) ;
if (showobvSupResline)
{
//Ch = Param("ch", 5,1,15,1);
bi = Cum(1)-1;
cbar = Param("cbar",2,2,50,1);



P1 = ismph;//GetTop(Ch);
V1 = ismpl;//GetValley(Ch);
P1 = IIf(P1,IIf(ValueWhen(P1,bi,2) < ValueWhen(V1,bi),P1,IIf(ValueWhen(P1,H,2) > H,False,P1)),P1);
P1 = IIf(P1 AND ValueWhen(P1,bi,0) > bi,IIf(ValueWhen(P1,bi,0) < ValueWhen(V1,bi,0),IIf(ValueWhen(P1,H,0) >= H,False,P1),P1),P1);
V1 = IIf(V1,IIf(ValueWhen(V1,bi,2) < ValueWhen(P1,bi),V1,IIf(ValueWhen(V1,L,2)<L,False, V1)),V1);
V1 = IIf(V1 AND ValueWhen(V1,bi,0) > bi ,IIf(ValueWhen(V1,bi,0) < ValueWhen(P1,bi,0),IIf(ValueWhen(V1,L,0) <= L, False,V1),V1),V1); 
RF=ValueWhen(P1,H);
SF=ValueWhen(V1,L);
RF1 = IIf(RF AND BarsSince(P1) <=cbar,RF,Null);
SF1 = IIf(SF AND BarsSince(V1) <=cbar,SF,Null);
Plot(RF1,"",colorBlue,styleDots | styleNoLine|styleNoRescale);
Plot(SF1,"",colorBlue,styleDots | styleNoLine|styleNoRescale); 
Plot(RF,"",ParamColor("Resistance",colorRed),40+16+2048);//2048 is stylenorescale
Plot(SF,"",ParamColor("Support",colorGreen),40+16+2048);
PlotShapes(IIf(P1, shapeSmallSquare,shapeNone),colorGreen,0,H,10);
PlotShapes(shapeSmallCircle*P1,colorBlack,0,H,10);
PlotShapes(IIf(V1, shapeSmallSquare,shapeNone),colorGreen,0,L,-10);
PlotShapes(shapeSmallCircle*V1,colorCustom12,0,L,-10);
}
_SECTION_END();  

_SECTION_BEGIN("EMA1");
P = C;
Periods = Param("Periods", 200, 2, 300, 1, 0 );
EMA1 = EMA(P,Periods);
Plot( eMA1, _DEFAULT_NAME(), ParamColor( "Color", colorPink ), ParamStyle("Style",styleDashed|styleNoRescale) );

After putting the above afl ur sheet should look like this:


Now Vjay bhai had asked to change color of obv based on above 200 ema or below ema. I liked the chart as it is more clean.
If u still want to display ema, remove "//" in the corresponding lines.

Now in the same sheet double click / insert chart. automatically 2nd pane will be taken.
No drag drop pls...

Code:
//I want OBV line(white) as green when its above 200 ema 
//AND Red when its below 200 EMA .
SetChartOptions( 2,chartShowArrows+ chartShowDates |   chartWrapTitle );

GraphXSpace=10;
_SECTION_BEGIN("On Balance Volume");
Ob = OBV();	e36 = EMA(Ob,36);	e200 = EMA(Ob,200);
Color = IIf(ob>e200,colorGreen,colorRed); 
Plot(Ob,"ob",color,styleThick);
Plot(0,"",colorWhite,styleNoLabel|styleNoRescale|styleDashed,0,0,5,-5);
//Plot(e200,"",colorBrightGreen,styleNoLabel|styleNoRescale);
//Plot(e36, "",colorGold,styleNoLabel|styleNoRescale|styleDashed);
_SECTION_END();
ND = Day()!=Ref(Day(),-1);	
LB = Day()!=Ref(Day(),1);
Ob = OBV();	
Zero = ValueWhen(LB,Ob);
Plot(Zero,"",colorWhite,styleNoLabel|styleNoRescale|styleStaircase|styleDashed);



@ ST sir, My ribbon method afl backtest for 1tf was not showing good results. did backtest for 1yr data. 36% winners, net loss.
Most probably some more filters have to be included.. thats why did not put up the results.

(My pm box is full, now going out, will make space later.)
 

VJAY

Well-Known Member
#76
@ vivek bhai, 7th post of this thread contains the afl u need to backtest.

anyway reposting it now along with modification to include 5 period obv.

@xray bhai, i cant dig up in varun ji's thread, but in afl we have to change 15 to 5 for daily period.

Here in this afl, added param function, slide the "obv hi lo periods" from 15 to 5 for backtesting daily tf.

@ vivek bhai. Don't drag this but take a new sheet and use "insert chart".
The support/res lines drawn by default is based on obv ribbon change. Myself didn find it useful, but u can change it to price based sup/res, which is equivalent to visual pivots.
In Parameters locate "Pvt type":"obv" .. change obv to price.


Code:
SetChartBkGradientFill( ParamColor("Inner panel upper",colorDarkGrey),ParamColor("Inner panel lower",colorGrey40 ));
SetChartBkColor(colorBlack);

_SECTION_BEGIN("Price");
SetChartOptions( 2,chartShowArrows+ chartShowDates |   chartWrapTitle );

_N(Title = StrFormat("OBV 2nd Method : {{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() ); 
Layer = Param("Layer", 0, -5, 5, 1) ;
//Plot( C, "Close",  colorTeal, styleNoTitle |styleCandle,0,0,0 ); 
HiVolume = IIf(V > (2 * MA(V,10)), True, False); 
PlotShapes(shapeSmallCircle * HiVolume, IIf(C > O, colorRed, colorWhite), 0, (O+C)/2, 0);
ToolTip = "Open = " + O + "\nHigh = " + H + "\nLow = " + L + "\nClose = " + C ;

_SECTION_BEGIN("Price Hi Lo"); 
y = Param("Ribbon price location",15,0,500,5);

HiP= HHV(H,15);        LoP= LLV(L,15); 

B2 = Cross(C,Ref(HiP,-1));    S2 = Cross(Ref(LoP,-1),C); 

B2 = ExRem(B2,S2);        S2 = ExRem(S2,B2); 

UP2 = Flip(B2,S2);        DN2 = Flip(S2,B2); 

//Plot(12,"p",IIf(UP2,colorGreen,colorOrange),styleOwnScale|styleNoLabel|styleThick,0,200,0,-5,8); 
PlotOHLC(y,Y+10,y,y,"",IIf(UP2,colorGreen,colorOrange),styleOwnScale|styleNoLabel|styleCloud,0,500);
//Plot(IIf(b2,1,0),"",colorBlue,styleOwnScale|styleNoLabel|styleHistogram|styleDashed,0,1);
//Plot(IIf(s2,1,0),"",colorRed, styleOwnScale|styleNoLabel|styleHistogram|styleDashed,0,1);

_SECTION_END();
_SECTION_BEGIN("OBV Hi Lo"); 
y = Param("Ribbon obv location",5,0,500,5);
periods = Param("OBV hiLo periods",15,0,100);

Ob = OBV();    Hi = HHV(Ob,periods);    Lo = LLV(Ob,periods); 

B1 = Cross(Ob,Ref(Hi,-1));    S1 = Cross(Ref(Lo,-1),Ob); 

B1 = ExRem(B1,S1);        S1 = ExRem(S1,B1); 

UP1 = Flip(B1,S1);        DN1 = Flip(S1,B1); 

//Plot(10,"",IIf(UP1,colorBlue,colorRed),styleOwnScale|styleNoLabel|styleThick,0,500,0,-5,8); 
PlotOHLC(y,Y+10,y,y,"",IIf(UP1,colorBlue,colorRed),styleOwnScale|styleNoLabel|styleCloud,0,500);
showVerticalObvlines15 = ParamToggle("Show vertical line for 15 ribbon change", "No|Yes", 0) ;
if (showVerticalObvlines15)
{
Plot(IIf(B1,1,0),"",colorBlue,styleOwnScale|styleNoLabel|styleHistogram|styleDashed,0,1);
Plot(IIf(S1,1,0),"",colorRed, styleOwnScale|styleNoLabel|styleHistogram|styleDashed,0,1); //vertical lines
}
_SECTION_BEGIN("Alerts");
bluetored = s1;
redtoblue = b1;

RequestTimedRefresh(20);
AlertIf(redtoblue,"SOUND C:\\Windows\\Media\\Ding.wav", "buy"+Name(),1,1+2+4); 
AlertIf(bluetored,"SOUND C:\\Windows\\Media\\Ding.wav", "Sell"+Name(),2,1+2+4);
_SECTION_END();

_SECTION_BEGIN("OBV hi/lo and Supp/Res");


ro = ParamField("Open", 0) ;
rh = ParamField("High", 1) ;
rl = ParamField("Low", 2) ;
rc = ParamField("Close", 3) ;


P = (rH+rL+rC)/3 ;
// = Param("Fast", 1, 1, 100, 1) ;
// = Param("Slow", 3, 1, 100, 1) ;

isemapvts = ParamToggle("Want Pivots ", "No|Yes", 1) ;
pvttype = ParamToggle("Pvt type", "Price|Obv",1);
periodtype = ParamToggle("15 period or 60 period lines?","60 period|15 period",1);


ismph = H-H ;
ismpl = L-L ;


if (isemapvts)
{

 if(pvttype)
{
 if(periodtype)
{
upcross = b1 ; // 15 obv
downcross = s1 ;
}
else
{
upcross = b60; //60obv
downcross = s60;
}
}

else
{
upcross = b2; // price
downcross = s2;
}
bi = BarIndex() ;

mphbar = HighestSinceBars(upcross, rH) ;
mplbar = LowestSinceBars(downcross, rL) ;

mphbi = ValueWhen(downcross, bi, 0) - ValueWhen(downcross, mphbar, 0) ;
ismph = mphbi == bi ;

mplbi = ValueWhen(upCross, bi, 0) - ValueWhen(upCross, mplbar, 0) ;
ismpl = mplbi == bi ;

ismph = IIf(downCross AND mphbar == 0, True, ismph) ;
ismpl = IIf(upcross AND mplbar == 0, True, ismpl) ;

}

_SECTION_BEGIN("OBV Sup/res lines Plot");
showobvSupResline = ParamToggle("Show Obv Sup/Res line", "No|Yes", 1) ;
if (showobvSupResline)
{
//Ch = Param("ch", 5,1,15,1);
bi = Cum(1)-1;
cbar = Param("cbar",2,2,50,1);



P1 = ismph;//GetTop(Ch);
V1 = ismpl;//GetValley(Ch);
P1 = IIf(P1,IIf(ValueWhen(P1,bi,2) < ValueWhen(V1,bi),P1,IIf(ValueWhen(P1,H,2) > H,False,P1)),P1);
P1 = IIf(P1 AND ValueWhen(P1,bi,0) > bi,IIf(ValueWhen(P1,bi,0) < ValueWhen(V1,bi,0),IIf(ValueWhen(P1,H,0) >= H,False,P1),P1),P1);
V1 = IIf(V1,IIf(ValueWhen(V1,bi,2) < ValueWhen(P1,bi),V1,IIf(ValueWhen(V1,L,2)<L,False, V1)),V1);
V1 = IIf(V1 AND ValueWhen(V1,bi,0) > bi ,IIf(ValueWhen(V1,bi,0) < ValueWhen(P1,bi,0),IIf(ValueWhen(V1,L,0) <= L, False,V1),V1),V1); 
RF=ValueWhen(P1,H);
SF=ValueWhen(V1,L);
RF1 = IIf(RF AND BarsSince(P1) <=cbar,RF,Null);
SF1 = IIf(SF AND BarsSince(V1) <=cbar,SF,Null);
Plot(RF1,"",colorBlue,styleDots | styleNoLine|styleNoRescale);
Plot(SF1,"",colorBlue,styleDots | styleNoLine|styleNoRescale); 
Plot(RF,"",ParamColor("Resistance",colorRed),40+16+2048);//2048 is stylenorescale
Plot(SF,"",ParamColor("Support",colorGreen),40+16+2048);
PlotShapes(IIf(P1, shapeSmallSquare,shapeNone),colorGreen,0,H,10);
PlotShapes(shapeSmallCircle*P1,colorBlack,0,H,10);
PlotShapes(IIf(V1, shapeSmallSquare,shapeNone),colorGreen,0,L,-10);
PlotShapes(shapeSmallCircle*V1,colorCustom12,0,L,-10);
}
_SECTION_END();  

_SECTION_BEGIN("EMA1");
P = C;
Periods = Param("Periods", 200, 2, 300, 1, 0 );
EMA1 = EMA(P,Periods);
Plot( eMA1, _DEFAULT_NAME(), ParamColor( "Color", colorPink ), ParamStyle("Style",styleDashed|styleNoRescale) );

After putting the above afl ur sheet should look like this:


Now Vjay bhai had asked to change color of obv based on above 200 ema or below ema. I liked the chart as it is more clean.
If u still want to display ema, remove "//" in the corresponding lines.

Now in the same sheet double click / insert chart. automatically 2nd pane will be taken.
No drag drop pls...

Code:
//I want OBV line(white) as green when its above 200 ema 
//AND Red when its below 200 EMA .
SetChartOptions( 2,chartShowArrows+ chartShowDates |   chartWrapTitle );

GraphXSpace=10;
_SECTION_BEGIN("On Balance Volume");
Ob = OBV();	e36 = EMA(Ob,36);	e200 = EMA(Ob,200);
Color = IIf(ob>e200,colorGreen,colorRed); 
Plot(Ob,"ob",color,styleThick);
Plot(0,"",colorWhite,styleNoLabel|styleNoRescale|styleDashed,0,0,5,-5);
//Plot(e200,"",colorBrightGreen,styleNoLabel|styleNoRescale);
//Plot(e36, "",colorGold,styleNoLabel|styleNoRescale|styleDashed);
_SECTION_END();
ND = Day()!=Ref(Day(),-1);	
LB = Day()!=Ref(Day(),1);
Ob = OBV();	
Zero = ValueWhen(LB,Ob);
Plot(Zero,"",colorWhite,styleNoLabel|styleNoRescale|styleStaircase|styleDashed);



@ ST sir, My ribbon method afl backtest for 1tf was not showing good results. did backtest for 1yr data. 36% winners, net loss.
Most probably some more filters have to be included.. thats why did not put up the results.

(My pm box is full, now going out, will make space later.)
Dear Vijay bro,
Please post your reults with 3 and 5 tf .... we always expressed our concern about 1tf trading earlier about mechanical go this method...varunjis experience with this method giving him perfect results ...but for new ones its looks great in hindsight but in reality its disaster ...these are my personal views nothing with others views ...
 

aja

Well-Known Member
#77
Now Vjay bhai had asked to change color of obv based on above 200 ema or below ema. I liked the chart as it is more clean.
If u still want to display ema, remove "//" in the corresponding lines.
I liked this code very much :clap:

Thanks for coding and sharing it.
 

vijkris

Learner and Follower
#78
Dear Vijay bro,
Please post your reults with 3 and 5 tf .... we always expressed our concern about 1tf trading earlier about mechanical go this method...varunjis experience with this method giving him perfect results ...but for new ones its looks great in hindsight but in reality its disaster ...these are my personal views nothing with others views ...
I realise that I suck at afl backtesting. :(

Anyway here is the 3 min tf report. its swing..
buy when both ema and price above 200 ema, vice versa for sell and reverse short..



For 5 tf
 

vijkris

Learner and Follower
#80
:) Seems non performing..
My coding skills are bad bhai..
Just plain vanilla rules rules is not sufficient.. Some of the 4 huge losses are event days, which in common sense can be avoided..
Like that there are a few more..

Its better to forward test in realtime for atleast 90 trades to come to a conclusion. :thumb:
 

Similar threads