Simple Coding Help - No Promise.

Help needed to plot 200EMA of different time frames (hourly , 4hourly and daily) in 1 hourly chart.
The strategy is
1)Buy when prices bounce back from 200 EMA (Hourly) , provided
price close > Hourly 200EMA > 4 Hourly 200EMA > Daily 200EMA
i.e. trend is same (buy) in all these time frames .
2)The vice-versa ia valid for sell.
Well tested strategy , but the problem is to switch over to different timeframes for each script to check 200EMA for each time frame.

Help needed from the expert.

:clap: :clap: :clap: :clap: :clap:
 

amitrandive

Well-Known Member
Help needed to plot 200EMA of different time frames (hourly , 4hourly and daily) in 1 hourly chart.
The strategy is
1)Buy when prices bounce back from 200 EMA (Hourly) , provided
price close > Hourly 200EMA > 4 Hourly 200EMA > Daily 200EMA
i.e. trend is same (buy) in all these time frames .
2)The vice-versa ia valid for sell.
Well tested strategy , but the problem is to switch over to different timeframes for each script to check 200EMA for each time frame.

Help needed from the expert.

:clap: :clap: :clap: :clap: :clap:
Plotting should work by using this code

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();

TimeFrameSet( inHourly*4 ); // switch now to hourly
P0 = Param("4 Hr P", 21, 3, 250,1);
mah_4Hr = MA( C, P0); //  moving average from hourly data
Plot( TimeFrameExpand( mah_4Hr, inHourly*4), " EMA 4Hrly",ParamColor( "4Hr EMA", colorCycle ), ParamStyle("4Hr style",styleLine | styleThick| styleNoRescale));
TimeFrameRestore(); // restore time frame to original
 
TimeFrameSet( inHourly ); // switch now to hourly
P1 = Param("Hr P", 21, 3, 250,1);
mah_Hr = MA( C, P1 ); //  moving average from hourly data
Plot( TimeFrameExpand( mah_Hr, inHourly), " EMA Hrly",ParamColor( "Hr EMA", colorCycle ), ParamStyle("Hr style",styleLine | styleThick| styleNoRescale));
TimeFrameRestore(); // restore time frame to original

TimeFrameSet( inDaily ); // switch now to hourly
P2 = Param("Daily P", 21, 3, 250,1);
mah_13D = MA( C, p2 ); // moving average from daily data
Plot( TimeFrameExpand( mah_13D, inDaily), " EMA Daily",ParamColor( "Daily EMA", colorCycle ), ParamStyle("Daily style",styleLine | styleThick| styleNoRescale));
TimeFrameRestore(); // restore time frame to original
 

Snake.Head

Well-Known Member
EMA of close 20 on 15min and 60 min
Drag and drop in chart
If you want change ema then edit EMA(Close,20)
Time then edit TimeFrameSet for eg 30min it should be "in30Minute"
you can add ParamColor if you color ema

Code:
TimeFrameSet(in15Minute);
m15= EMA(Close,20) ;
Plot(TimeFrameExpand(m15, in15Minute), "EMA 15", colorBlack,styleLine|styleDashed); 
TimeFrameRestore();

TimeFrameSet(60*in1Minute);
m60= EMA(Close,20) ;
Plot(TimeFrameExpand(m60, 60*in1Minute), "EMA 60", colorBlack,styleLine|styleDashed); 
TimeFrameRestore();
 
sir,can you code for getting value of day before yesterday's poc from market profile afl given below...I tried but able to get only yesterday's POC value from variable pocn.

--------------------------------------------------------------------------------------------
_SECTION_BEGIN("Market Profile");

Plot( C, "Close", BarColor, styleNoTitle | ParamStyle("Style") |GetPriceStyle() );
//PlotOHLC(O,H,L,C,"Price",IIf(C>O,colorGreen,colorRed),styleCandle);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g,Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

function Lastthursday()
{
Daysinmonth=IIf(Month()==1 OR Month()==3 OR Month()==5 OR Month()==7 OR Month()==8 OR Month()==10 OR Month()==12,31,30);
Daysinmonthfeb=IIf(Year()%4 == 0 AND Year()%100!=0,29,28);
Daysinmonthfinal=IIf(Month()==2,Daysinmonthfeb,Daysinmonth);
returnvalue=IIf(Daysinmonthfinal-Day()<7 AND DayOfWeek()==4,1,IIf(Daysinmonthfinal-Day()<8 AND DayOfWeek()==3 AND Ref(DayOfWeek(),1)!=4,1,0));
return returnvalue;
}

FirstVisibleBar = Status( "FirstVisibleBar" );
Lastvisiblebar = Status( "LastVisibleBar" );

totalVisible=Lastvisiblebar-FirstVisibleBar;
//if(totalVisible<1500){

//Den = Param("Density", 1, 0.1, 10, 0.1);
percent=Param("Value Area", 70, 1, 100, 1);
Type=ParamList("Type","Price Profile|Volume Profile");
Period= ParamList("Base","Hourly|Daily|Weekly|Monthly|Last thursday|Yearly",1);
x_scale=Param("Horizontal_scale", 2, 0, 10, 0.1);
EnMP2= ParamStyle("Style",styleLine|styleNoLabel,maskAll) ;
styleLines=styleDots;
EnIB = ParamToggle("Show Initial Balance", "No|Yes",0);
IBBars = Param("Initial Balance Bars", 2, 1, 10, 1);
ViewYvalues= ParamToggle("Show Yesterdays Values", "No|Yes",1);
ViewVlines= ParamToggle("Show Vertical Base Lines", "No|Yes",1);
Viewvalues= ParamToggle("Show Values", "No|Yes",0);
ViewVpoc= ParamToggle("Show Virgin POC", "No|Yes",1);
ViewTPO=ParamToggle("Show TPO Count", "No|Yes",0);

if(Period=="Hourly"){
BarsInDay = BarsSince(Hour() != Ref(Hour(), -1));Bot = TimeFrameGetPrice("L", inHourly, 0);Top = TimeFrameGetPrice("H", inHourly, 0);Vol = TimeFrameGetPrice("V", inHourly, 0);
}
if(Period=="Daily" ){//OR Interval()==3600
BarsInDay = BarsSince(Day() != Ref(Day(), -1) ) ;Bot = TimeFrameGetPrice("L", inDaily, 0);Top = TimeFrameGetPrice("H", inDaily, 0);Vol = TimeFrameGetPrice("V", inDaily, 0);
}
if(Period=="Weekly" OR Interval()==24 * 3600 ){
BarsInDay = BarsSince(DayOfWeek() < Ref( DayOfWeek(), -1 ));Bot = ValueWhen(Ref(BarsInDay,1)==1 OR BarIndex()>BarCount-2 ,LLV(L,BarsInDay),0);Top =ValueWhen(Ref(BarsInDay,1)==1 OR BarIndex()>BarCount-2,HHV(H,BarsInDay),0);Vol = TimeFrameGetPrice("V", inWeekly, 0);
}
if(Period=="Monthly" ){
BarsInDay = BarsSince(Month() != Ref(Month(), -1));Bot = TimeFrameGetPrice("L", inMonthly, 0);Top = TimeFrameGetPrice("H", inMonthly, 0);Vol = TimeFrameGetPrice("V", inMonthly, 0);
}
if(Period=="Lastthursday" ){
BarsInDay = BarsSince(Lastthursday()==1 AND Ref(Lastthursday(), -1)==0);Bot = ValueWhen(Ref(BarsInDay,1)==1 OR BarIndex()>BarCount-2 ,LLV(L,BarsInDay),0);Top =ValueWhen(Ref(BarsInDay,1)==1 OR BarIndex()>BarCount-2,HHV(H,BarsInDay),0);Vol = ValueWhen(Ref(BarsInDay,1)==1 OR BarIndex()>BarCount-2 ,Sum(V,BarsInDay),0);

}
if(Period=="Yearly" ){
BarsInDay = BarsSince(Year() != Ref(Year(), -1));Bot = TimeFrameGetPrice("L", inYearly, 0);Top = TimeFrameGetPrice("H", inYearly, 0);Vol = TimeFrameGetPrice("V", inYearly, 0);
}



CurTop = HHV(H,BarsInDay+1);
Curbot = LLV(L,BarsInDay+1);

Range = Top-Bot;
coverage=LastValue(Ref(ATR(10),-1));

den=(coverage/10);

//den=1;

//multiplier=IIf(round(totalVisible<500,1,IIf(round( totalVisible)<1000,2));


multiplier=IIf(round(totalVisible)/300<1,1,round(totalVisible)/300);


if(ViewVlines==1)
{
Plot(BarsInDay==0, "", ParamColor("Base Line Color",colorDarkGrey), styleHistogram | styleOwnScale | styleLine | styleNoLabel);
}


relTodayRange = 0;
x=0;
basey=0;
basex=0;
newday=0;
total=0;
shiftup=0;
shiftdn=0;
Line=Null;
Voloumeunit=0;


for ( i = IIf(FirstVisibleBar-100>1,FirstVisibleBar-100,FirstVisibleBar); i <Lastvisiblebar AND i<BarCount-1 ; i++ )
{
if(BarsInDay==0)
{t=BarsInDay[i-1];




Col=ParamColor("IB Color",colorWhite);
IBstyle=ParamStyle("IB style",styleLine,maskAll);
if(EnIB==1)
{
IBH=HHV(H,IBBars);
IBL=LLV(L,IBBars);
Line1 = LineArray(basex, IBH[basex+IBBars-1],i, IBH[basex+IBBars-1]);
Plot(Line1,"",Col,IBstyle);
Line2 = LineArray(basex, IBL[basex+IBBars-1],i, IBL[basex+IBBars-1]);
Plot(Line2,"",Col,IBstyle);
}
//////////////////////////////////
poc=0;pocj=0;
midrange = int(relTodayRange/2)+1;


for (j=1; j<= relTodayRange+1 ; j++)
{
if(poc < x[j])
{
poc=x[j]; pocj=j;}
else if(poc == x[j])
{
if (abs(midrange-j)< abs(midrange-pocj)){
poc = x[j]; pocj = j;
}
}

}

for ( n = 1; n <= relTodayRange; n++ )
{
total[n]=x[n]+total[n-1];
}

Value_area=(total[relTodayRange]*percent)/100;


for ( a = 1; a <= relTodayRange; a++ )
{
if(pocj-a>0 AND pocj+a<relTodayRange)
{
if(poc+total[pocj+a]-total[pocj]+(total[pocj]-poc)-total[pocj-(a+1)]>=Value_area) {shiftup=a; shiftdn=a; break;}
}
else if(pocj-a<1 )
{
if(poc+total[pocj+a]-total[pocj]+(total[pocj]-poc)>=Value_area){shiftup=a; shiftdn=pocj; break;}
}
else if(pocj+a>relTodayRange )
{
if(poc+total[relTodayRange]-total[pocj]+(total[pocj]-poc)-total[pocj-(a+1)] >=Value_area){shiftup=floor(relTodayRange)-pocj; shiftdn=a+1; break;}
}
}


if(ViewVpoc==1)
{
Virginpoc=basey+pocj*den;
newi=0;
for( j = i+1; j <= (BarCount - 1) ; j++ )
if( L[j] < Virginpoc AND H[j]>Virginpoc )
{newi=j;break;}
else{newi=BarCount;}
//Plot(LineArray(basex,basey+pocj*den,newi,basey+pocj*den),"",ParamColor ("Virgin Poc Color",colorBlue),styleLine|styleNoRescale);
}

Vah = LineArray(baseX, baseY+(pocj+shiftup)*den, i, baseY+(pocj+shiftup)*den);
Val = LineArray(baseX, baseY+(pocj-shiftdn)*den, i, baseY+(pocj-shiftdn)*den);
pocline=LineArray(basex,basey+pocj*den,basex+poc,basey+pocj*den);


Vahn = LineArray(i, baseY+(pocj+shiftup)*den, i+t, baseY+(pocj+shiftup)*den);
pocn = LineArray(i, baseY+(pocj)*den, i+t, baseY+(pocj)*den); //pocn contains yesterday's poc value
Valn = LineArray(i, baseY+(pocj-shiftdn)*den, i+t, baseY+(pocj-shiftdn)*den);


Plot(pocline,"",ParamColor("Color_POC_Line",colorYellow),styleLine|styleNoRescale|styleNoLabel);

if(ViewYvalues==1)
{
Plot(Vahn,"",ParamColor("YVAH",colorWhite),styleDashed|styleNoRescale);
Plot(Valn,"",ParamColor("YVAL",colorWhite),styleDashed|styleNoRescale);
Plot(pocn,"",ParamColor("YPOC",colorYellow),styleDashed|styleNoRescale);

}
//PlotOHLC(Vahn,Vahn,Valn,Valn,"",colorPink,styleClo ud|styleOwnScale);


if(ViewTPO==1)
{
nnn=HHV(H,BarsInDay);
PlotText(""+(total[relTodayRange]-total[pocj]),basex,nnn,colorDarkRed);
PlotText(""+(total[pocj-1]),basex,basey-den,colorDarkRed);

}

if(Viewvalues==1)
{
PlotText(""+((basey+pocj*den)),baseX,basey+pocj*den,colorWhite,colorDarkGrey);
PlotText(""+((baseY+(pocj+shiftup)*den)),baseX,baseY+(pocj+shiftup)*den,colorWhite,colorDarkGrey );
PlotText(""+((baseY+(pocj-shiftdn)*den)),baseX,baseY+(pocj-shiftdn)*den,colorWhite,colorDarkGrey);
}


for (p = 0; p <= relTodayRange+1; p=p+multiplier)
{
if(P>0){
line = LineArray(baseX, baseY+(p)*Den, baseX+x[p], baseY+(p)*Den);
}
//Plot(line,"",IIf(p>(pocj+shiftup),ParamColor("Colo r_Above_VA", colorGrey40),IIf(p<=(pocj+shiftup)AND p>=(pocj-shiftdn),ParamColor("Color_VA", colorBlueGrey),ParamColor("Color_Below_VA", colorGrey40))) , EnMP2);
}




///////////////////

basex=0;
x=0;
Basex=i;
baseY=Bot;
relTodayRange=Range/Den;
Voloumeunit=Vol/LastValue(BarsInDay);

}

for (j=0; j<= relTodayRange ; j++)
{
if (L <= Bot+j*Den AND H >= Bot+j*Den )
{

if(Type=="Price Profile"){x[j]=(x[j])+x_scale;}
else if(Type=="Volume Profile"){x[j]=x[j]+round(V/Voloumeunit)+1;}

}
}
}

Col=ParamColor("IB Color",colorWhite);
IBstyle=ParamStyle("IB style",styleLine,maskAll);
if(EnIB==1)
{
IBH=HHV(H,IBBars);
IBL=LLV(L,IBBars);
Line1 = LineArray(basex, IBH[basex+IBBars-1],i, IBH[basex+IBBars-1]);
Plot(Line1,"",Col,IBstyle);
Line2 = LineArray(basex, IBL[basex+IBBars-1],i, IBL[basex+IBBars-1]);
Plot(Line2,"",Col,IBstyle);
}

//////////////////////////////////
poc=0;pocj=0;
midrange = int(relTodayRange/2)+1;

for (j=1; j<= relTodayRange+1 ; j++)
{
if(poc < x[j])
{
poc=x[j]; pocj=j;}
else if(poc == x[j])
{
if (abs(midrange-j)< abs(midrange-pocj)){
poc = x[j]; pocj = j;
}
}

}

for ( n = 1; n <= relTodayRange; n++ )
{
total[n]=x[n]+total[n-1];
}

Value_area=(total[relTodayRange]*percent)/100;


for ( a = 1; a <= relTodayRange; a++ )
{
if(pocj-a>0 AND pocj+a<relTodayRange)
{
if(poc+total[pocj+a]-total[pocj]+(total[pocj]-poc)-total[pocj-(a+1)]>=Value_area) {shiftup=a; shiftdn=a; break;}
}
else if(pocj-a<1 )
{
if(poc+total[pocj+a]-total[pocj]+(total[pocj]-poc)>=Value_area){shiftup=a; shiftdn=pocj; break;}
}
else if(pocj+a>relTodayRange )
{
if(poc+total[relTodayRange]-total[pocj]+(total[pocj]-poc)-total[pocj-(a+1)] >=Value_area){shiftup=floor(relTodayRange)-pocj; shiftdn=a+1; break;}
}
}

Vah = LineArray(baseX, baseY+(pocj+shiftup)*den, i, baseY+(pocj+shiftup)*den);
Val = LineArray(baseX, baseY+(pocj-shiftdn)*den, i, baseY+(pocj-shiftdn)*den);
pocline=LineArray(basex,basey+pocj*den,basex+poc,basey+pocj*den);






if(ViewTPO==1)
{
PlotText(""+(total[relTodayRange]-total[pocj]),basex,top,colorDarkRed);
PlotText(""+(total[pocj-1]+x_scale),basex,basey-den,colorDarkRed);
}

if(Viewvalues==1)
{
PlotText(""+((basey+pocj*den)),baseX,basey+pocj*den,colorWhite,colorDarkGrey);
PlotText(""+((baseY+(pocj+shiftup)*den)),baseX,baseY+(pocj+shiftup)*den,colorWhite,colorDarkGrey );
PlotText(""+((baseY+(pocj-shiftdn)*den)),baseX,baseY+(pocj-shiftdn)*den,colorWhite,colorDarkGrey);
}


for (p = 0; p <= relTodayRange+1; p=p+multiplier)
{
line = LineArray(baseX, baseY+p*Den, baseX+x[p], baseY+p*Den);

Plot(line,"",IIf(p>(pocj+shiftup),ParamColor("Colo r_Above_VA", colorGrey40),IIf(p<=(pocj+shiftup)AND p>=(pocj-shiftdn),ParamColor("Color_VA", colorBlueGrey),ParamColor("Color_Below_VA",colorGrey40))),EnMP2);
Plot(pocline,"",ParamColor("Color_POC_Line",colorYellow),styleLine|styleNoRescale|styleNoLabel);

}

_SECTION_END();
 
Last edited:

extremist

Well-Known Member
Dear seniors

please correct below code buy sell arrow not showing also if exploration add its better for me.

Abhishek


_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();

TimeFrameSet(inHourly);
hA=MACD();
hB=Signal();


Hbuy= Cross((ha AND hb),0) ;
Hsell= Cross(0,(ha AND hb));

TimeFrameRestore();

tf=Param("MACD Time Frame (min)",60,1,100000,1);
tfrm=in1Minute*tf;
haBuy=TimeFrameExpand(hBuy,TFRM,expandFirst);
haSell = TimeFrameExpand(hSell,Tfrm,expandFirst);

A=MACD();
B=Signal();

Buy = IIf(Habuy,Cross(a,b),0);
Sell = IIf(Hasell,Cross(b,a),0);

Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
Short=Sell;
Cover=Buy;
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorBrightGreen, 0,L, Offset=-10);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-10);
I hope this will fulfill ur need

Code:
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() ); 
TimeFrameSet(inHourly);
mhh=MACD(12,26);
shh=Signal(12,26,9);
TimeFrameRestore();

mh=TimeFrameExpand( mhh, inHourly,expandFirst );
sh=TimeFrameExpand( shh, inHourly,expandFirst );

m=MACD(12,26);
s=Signal(12,26,9);

Buy=sh>0 AND s>0;
Sell=sh<0 AND s<0;
if( ParamToggle("Plot Arrows", "No|Yes", 0))	
{
PlotShapes(Buy*shapeUpArrow, colorGreen, 0, Low, -28);
PlotShapes(Sell*shapeDownArrow, colorRed, 0, High, -28);
}

col=IIf(Buy,colorBrightGreen,IIf(Sell,colorRed,colorLightGrey));
if( ParamToggle("Plot DT Ribbon", "No|Yes", 1))	
Plot( 2,"",col,styleOwnScale|styleArea|styleNoLabel, 1, 100,0,-1);
 

amitrandive

Well-Known Member
I hope this will fulfill ur need

Code:
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() ); 
TimeFrameSet(inHourly);
mhh=MACD(12,26);
shh=Signal(12,26,9);
TimeFrameRestore();

mh=TimeFrameExpand( mhh, inHourly,expandFirst );
sh=TimeFrameExpand( shh, inHourly,expandFirst );

m=MACD(12,26);
s=Signal(12,26,9);

Buy=sh>0 AND s>0;
Sell=sh<0 AND s<0;
if( ParamToggle("Plot Arrows", "No|Yes", 0))	
{
PlotShapes(Buy*shapeUpArrow, colorGreen, 0, Low, -28);
PlotShapes(Sell*shapeDownArrow, colorRed, 0, High, -28);
}

col=IIf(Buy,colorBrightGreen,IIf(Sell,colorRed,colorLightGrey));
if( ParamToggle("Plot DT Ribbon", "No|Yes", 1))	
Plot( 2,"",col,styleOwnScale|styleArea|styleNoLabel, 1, 100,0,-1);
Extremist
Thanks for the code.
Just 2 points
1)We need to add Exrem to Buy and sell to remove excessive signals.
2)If I understand correctly, Abhi wants to have Multi Time Frame crossover of MACD.Specifically Hourly and Minute Time frame for the crossover which can be changed from the parameters.
 
Extremist
Thanks for the code.
Just 2 points
1)We need to add Exrem to Buy and sell to remove excessive signals.
2)If I understand correctly, Abhi wants to have Multi Time Frame crossover of MACD.Specifically Hourly and Minute Time frame for the crossover which can be changed from the parameters.
Dear amit,

u can use above afl with ur cover & sell condition instead of exrem function it will be more suitable.



Buy=sh>0 AND s>0;
Short=sh<0 AND s<0;
sell= ................
cover=.................

Also thanks to extremist to solved my problem always he did my request many many thanks to u sir. u r really big diamond of tj forum


Abhishek
 

Similar threads