Multiple Time frame EMA crossover

extremist

Well-Known Member
#2


the code will run somewhat like this.
i'm not yet completely finished with it.
as i do.
i will post it here for all.

thank u for ur interest.

CODE :

SetChartOptions(0,chartShowArrows|chartShowDates);
bc=ParamColor("Bacground Color",colorGrey40 );
SetChartBkColor( bc);
DayH = TimeFrameGetPrice("H", inDaily, 0);
DayL = TimeFrameGetPrice("L", inDaily, 0);
DayC = TimeFrameGetPrice("C", inDaily, 0);
DayO = TimeFrameGetPrice("O", inDaily, 0);
pDayC = TimeFrameGetPrice("C", inDaily, -1);


pi= (DayH + DayL +DayC+DayO)/4;
if( ParamToggle("Plot current day Pivot", "No|Yes", 0))
Plot( pi," \nPiv : ", ParamColor( "Color", colorBlack ), ParamStyle("Style") );

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} \n Op=> %g, \n Hi=> %g, \n Lo=> %g, \n Cl=> %g, \n "+ EncodeColor(colorBlue)+"Pi=> %g
{{VALUES}}", O, H, L, C, pi ));
function GetSecondNum()
{
Time = Now( 4 );
Seconds = int( Time % 100 );
Minutes = int( Time / 100 % 100 );
Hours = int( Time / 10000 % 100 );
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
return SecondNum;
}
RequestTimedRefresh( 1 );
TimeFrame = Interval();
SecNumber = GetSecondNum();
Newperiod = SecNumber % TimeFrame == 0;
SecsLeft = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;
SecsToGo = TimeFrame - SecsLeft;

x=Param("xposn",300,0,1000,1);
y=Param("yposn",50,0,1000,1);

GfxSelectSolidBrush( ColorRGB( 230, 230, 230 ) );
GfxSelectPen( ColorRGB( 230, 230, 230 ), 2 );
if ( NewPeriod )
{
GfxSelectSolidBrush( colorYellow );
GfxSelectPen( colorYellow, 2 );
}
GfxRoundRect( x+75, y+17, x-3, y-2, 0, 0 );
GfxSetBkMode(1);
GfxSelectFont( "Arial", 12, 700, False );
GfxSetTextColor( colorBlack );
GfxTextOut( ""+SecsToGo+" / "+NumToStr( TimeFrame, 1.0 ), x, y );


FS=Param("Font Size",15,11,100,1);
GfxSelectFont("Callibri", FS , 700, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( colorBlack );
Hor1=Param("Horizontal Position1",820,1,1200,1);
Ver1=Param("Vertical Position1",1,1,830,1);
GfxTextOut(""+C, Hor1, Ver1);
GfxSetTextColor( colorGrey50 );
GfxTextOut("PC:"+pDayC,700, Ver1);
GfxSetTextColor( colorBlue );
GfxTextOut("C:"+DayC, 600, Ver1);
GfxSetTextColor(colorRed );
GfxTextOut("L:"+DayL,500, Ver1);
GfxSetTextColor(colorBrightGreen );
GfxTextOut("H:"+DayH,400, Ver1);
GfxSetTextColor( colorLightBlue );
GfxTextOut("O:"+DayO,300, Ver1);

DD=Prec(C-pDayC ,2);
xx=Prec((DD/pDayC )*100,2);
GfxSelectFont("Times New Roman", 11, 700, True );
GfxSetBkMode( colorBlack );
GfxSetTextColor(colorBlack );
GfxTextOut(""+DD+" ("+xx+"%)", Hor1, Ver1+ 45 );


//1m
ec=WriteIf(EMA(C,5)>EMA(C,13) OR EMA(C,5)<EMA(C,13),"One","x");
ec2=WriteIf(EMA(C,5)>EMA(C,13) AND EMA(C,5)>EMA(C,20),"On","x");
ec3=WriteIf(EMA(C,5)<EMA(C,13) AND EMA(C,5)<EMA(C,20),"Oe","x");
//5m
TimeFrameSet(in5Minute);
e5=EMA(C,5);
e13=EMA(C,13);
e20=EMA(C,20);
TimeFrameRestore();

e5x5=TimeFrameExpand( e5, in5Minute,expandLast );
e5x13=TimeFrameExpand( e13, in5Minute,expandLast );
e5x20=TimeFrameExpand( e20, in5Minute,expandLast );


e5c=WriteIf(e5x5>e5x13 OR e5x5<e5x13,"One","x");
e5c2=WriteIf(e5x5>e5x13 AND e5x5>e5x20,"On","x");
e5c3=WriteIf(e5x5<e5x13 AND e5x5<e5x20,"Oe","x");

//15m
TimeFrameSet(in15Minute);
e15=EMA(C,5);
e113=EMA(C,13);
e120=EMA(C,20);
TimeFrameRestore();

e15x5=TimeFrameExpand( e15, in15Minute,expandLast );
e15x13=TimeFrameExpand( e113, in15Minute,expandLast );
e15x20=TimeFrameExpand( e120, in15Minute,expandLast );

e15c=WriteIf(e15x5>e15x13 OR e15x5<e15x13,"One","x");
e15c2=WriteIf(e15x5>e15x13 AND e15x5>e15x20,"On","x");
e15c3=WriteIf(e15x5<e15x13 AND e15x5<e15x20,"Oe","x");
//1h
TimeFrameSet(inHourly);
e51=EMA(C,5);
e131=EMA(C,13);
e201=EMA(C,20);
TimeFrameRestore();

ehx5=TimeFrameExpand( e51, inHourly,expandLast );
ehx13=TimeFrameExpand( e131, inHourly,expandLast );
ehx20=TimeFrameExpand( e201, inHourly,expandLast );

ehc=WriteIf(ehx5>ehx13 OR ehx5<ehx13,"One","x");
ehc2=WriteIf(ehx5>ehx13 AND ehx5>ehx20,"On","x");
ehc3=WriteIf(ehx5<ehx13 AND ehx5<ehx20,"Oe","x");
//4h
TimeFrameSet(inHourly*4);
eh51=EMA(C,5);
eh131=EMA(C,13);
eh201=EMA(C,20);
TimeFrameRestore();

eh4x5=TimeFrameExpand( eh51, inHourly*4,expandLast );
eh4x13=TimeFrameExpand( eh131, inHourly*4,expandLast );
eh4x20=TimeFrameExpand( eh201, inHourly*4,expandLast );

e4hc=WriteIf(eh4x5>eh4x13 OR eh4x5<eh4x13,"One","x");
e4hc2=WriteIf(eh4x5>eh4x13 AND eh4x5>eh4x20,"On","x");
e4hc3=WriteIf(eh4x5<eh4x13 AND eh4x5<eh4x20,"Oe","x");
//d
TimeFrameSet(inDaily);
ed5=EMA(C,5);
ed13=EMA(C,13);
ed20=EMA(C,20);
TimeFrameRestore();

edx5=TimeFrameExpand( ed5, inDaily,expandLast );
edx13=TimeFrameExpand( ed13, inDaily,expandLast );
edx20=TimeFrameExpand( ed20, inDaily,expandLast );

edc=WriteIf(edx5>edx13 OR edx5<edx13,"One","x");
edc2=WriteIf(edx5>edx13 AND edx5>edx20,"On","x");
edc3=WriteIf(edx5<edx13 AND edx5<edx20,"Oe","x");



Hor=Param("Horizontal Position",600,1,1200,1);
Ver=Param("Vertical Position",35,30,1000,1);
///1
GfxSelectFont("Callibri", 10 , 700, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( colorBlack );
GfxTextOut("EMA Sig ",Hor, Ver);
GfxSetTextColor( colorBlack );
GfxTextOut("1 M ",Hor+72, Ver-15);

if(ec=="One")
GfxSelectSolidBrush(colorGold);
if(ec2=="On")
GfxSelectSolidBrush(colorBrightGreen);
if(ec3=="Oe")
GfxSelectSolidBrush(colorRed);
GfxSelectPen( colorBlack, 1 ); // broader color
GfxRectangle( Hor+70,Ver+5,Hor+100,Ver+15 );
///2
GfxSetTextColor( colorBlack );
GfxTextOut("5 M ",Hor+112, Ver-15);


if(e5c=="One")
GfxSelectSolidBrush(colorGold);
if(e5c2=="On")
GfxSelectSolidBrush(colorBrightGreen);
if(e5c3=="Oe")
GfxSelectSolidBrush(colorRed);
GfxRectangle( Hor+110,Ver+5,Hor+140,Ver+15 );
///3
GfxSetTextColor( colorBlack );
GfxTextOut("15 M ",Hor+150, Ver-15);


if(e15c=="One")
GfxSelectSolidBrush(colorGold);
if(e15c2=="On")
GfxSelectSolidBrush(colorBrightGreen);
if(e15c3=="Oe")
GfxSelectSolidBrush(colorRed);
GfxRectangle( Hor+150,Ver+5,Hor+180,Ver+15 );
///4
GfxSetTextColor( colorBlack );
GfxTextOut("1 H ",Hor+193, Ver-15);


if(ehc=="One")
GfxSelectSolidBrush(colorGold);
if(ehc2=="On")
GfxSelectSolidBrush(colorBrightGreen);
if(ehc3=="Oe")
GfxSelectSolidBrush(colorRed);
GfxRectangle( Hor+190,Ver+5,Hor+220,Ver+15 );
//5
GfxSetTextColor( colorBlack );
GfxTextOut("4 H ",Hor+233, Ver-15);


if(e4hc=="One")
GfxSelectSolidBrush(colorGold);
if(e4hc2=="On")
GfxSelectSolidBrush(colorBrightGreen);
if(e4hc3=="Oe")
GfxSelectSolidBrush(colorRed);
GfxRectangle( Hor+230,Ver+5,Hor+260,Ver+15 );
//6
GfxSetTextColor( colorBlack );
GfxTextOut("D ",Hor+280, Ver-15);


if(edc=="One")
GfxSelectSolidBrush(colorGold);
if(edc2=="On")
GfxSelectSolidBrush(colorBrightGreen);
if(edc3=="Oe")
GfxSelectSolidBrush(colorRed);
GfxRectangle( Hor+270,Ver+5,Hor+300,Ver+15 );
 
Last edited:

extremist

Well-Known Member
#4
Code:
SetChartOptions(0,chartShowArrows|chartShowDates);
bc=ParamColor("Bacground Color",colorGrey40 );
SetChartBkColor( bc); 
DayH = TimeFrameGetPrice("H", inDaily, 0);	
DayL = TimeFrameGetPrice("L", inDaily, 0);	
DayC = TimeFrameGetPrice("C", inDaily, 0);	
DayO = TimeFrameGetPrice("O", inDaily, 0);	
pDayC = TimeFrameGetPrice("C", inDaily, -1);	


pi=	(DayH + DayL +DayC+DayO)/4;
if( ParamToggle("Plot current day Pivot", "No|Yes", 0))	
Plot( pi," \nPiv : ", ParamColor( "Color", colorBlack ), ParamStyle("Style") ); 

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} \n Op=> %g, \n Hi=> %g, \n Lo=> %g, \n Cl=> %g, \n "+ EncodeColor(colorBlue)+"Pi=> %g 
{{VALUES}}", O, H, L, C, pi ));
function GetSecondNum()
{
Time = Now( 4 );
Seconds = int( Time % 100 );
Minutes = int( Time / 100 % 100 );
Hours = int( Time / 10000 % 100 );
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
return SecondNum;
}
RequestTimedRefresh( 1 );
TimeFrame = Interval();
SecNumber = GetSecondNum();
Newperiod = SecNumber % TimeFrame == 0;
SecsLeft = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;
SecsToGo = TimeFrame - SecsLeft;

x=Param("xposn",300,0,1000,1);
y=Param("yposn",50,0,1000,1);

GfxSelectSolidBrush( ColorRGB( 230, 230, 230 ) );
GfxSelectPen( ColorRGB( 230, 230, 230 ), 2 );
if ( NewPeriod )
{
GfxSelectSolidBrush( colorYellow );
GfxSelectPen( colorYellow, 2 );
}
GfxRoundRect( x+75, y+17, x-3, y-2, 0, 0 );
GfxSetBkMode(1);
GfxSelectFont( "Arial", 12, 700, False );
GfxSetTextColor( colorBlack );
GfxTextOut( ""+SecsToGo+" / "+NumToStr( TimeFrame, 1.0 ), x, y );


FS=Param("Font Size",15,11,100,1);
GfxSelectFont("Callibri", FS , 700, True ); 
GfxSetBkMode( colorWhite ); 
GfxSetTextColor( colorBlack ); 
Hor1=Param("Horizontal Position1",820,1,1200,1);
Ver1=Param("Vertical Position1",1,1,830,1); 
GfxTextOut(""+C, Hor1, Ver1);
GfxSetTextColor( colorGrey50 ); 
GfxTextOut("PC:"+pDayC,700, Ver1);
GfxSetTextColor( colorBlue ); 
GfxTextOut("C:"+DayC, 600, Ver1);
GfxSetTextColor(colorRed ); 
GfxTextOut("L:"+DayL,500, Ver1);
GfxSetTextColor(colorBrightGreen ); 
GfxTextOut("H:"+DayH,400, Ver1);
GfxSetTextColor( colorLightBlue ); 
GfxTextOut("O:"+DayO,300, Ver1);

DD=Prec(C-pDayC ,2);
xx=Prec((DD/pDayC )*100,2);
GfxSelectFont("Times New Roman", 11, 700, True ); 
GfxSetBkMode( colorBlack ); 
GfxSetTextColor(colorBlack ); 
GfxTextOut(""+DD+" ("+xx+"%)", Hor1, Ver1+ 45 );


//1m
ec=WriteIf(EMA(C,5)>EMA(C,13) OR EMA(C,5)<EMA(C,13),"One","x");
ec2=WriteIf(EMA(C,5)>EMA(C,13) AND EMA(C,5)>EMA(C,20),"On","x");
ec3=WriteIf(EMA(C,5)<EMA(C,13) AND EMA(C,5)<EMA(C,20),"Oe","x");
//5m
TimeFrameSet(in5Minute);
e5=EMA(C,5);
e13=EMA(C,13);
e20=EMA(C,20);
TimeFrameRestore(); 

e5x5=TimeFrameExpand( e5, in5Minute,expandLast );
e5x13=TimeFrameExpand( e13, in5Minute,expandLast );
e5x20=TimeFrameExpand( e20, in5Minute,expandLast );


e5c=WriteIf(e5x5>e5x13 OR e5x5<e5x13,"One","x");
e5c2=WriteIf(e5x5>e5x13 AND e5x5>e5x20,"On","x");
e5c3=WriteIf(e5x5<e5x13 AND e5x5<e5x20,"Oe","x");

//15m
TimeFrameSet(in15Minute);
e15=EMA(C,5);
e113=EMA(C,13);
e120=EMA(C,20);
TimeFrameRestore(); 

e15x5=TimeFrameExpand( e15, in15Minute,expandLast );
e15x13=TimeFrameExpand( e113, in15Minute,expandLast );
e15x20=TimeFrameExpand( e120, in15Minute,expandLast );

e15c=WriteIf(e15x5>e15x13 OR e15x5<e15x13,"One","x");
e15c2=WriteIf(e15x5>e15x13 AND e15x5>e15x20,"On","x");
e15c3=WriteIf(e15x5<e15x13 AND e15x5<e15x20,"Oe","x");
//1h
TimeFrameSet(inHourly);
e51=EMA(C,5);
e131=EMA(C,13);
e201=EMA(C,20);
TimeFrameRestore(); 

ehx5=TimeFrameExpand( e51, inHourly,expandLast );
ehx13=TimeFrameExpand( e131, inHourly,expandLast );
ehx20=TimeFrameExpand( e201, inHourly,expandLast );

ehc=WriteIf(ehx5>ehx13 OR ehx5<ehx13,"One","x");
ehc2=WriteIf(ehx5>ehx13 AND ehx5>ehx20,"On","x");
ehc3=WriteIf(ehx5<ehx13 AND ehx5<ehx20,"Oe","x");
//4h
TimeFrameSet(inHourly*4);
eh51=EMA(C,5);
eh131=EMA(C,13);
eh201=EMA(C,20);
TimeFrameRestore(); 

eh4x5=TimeFrameExpand( eh51, inHourly*4,expandLast );
eh4x13=TimeFrameExpand( eh131, inHourly*4,expandLast );
eh4x20=TimeFrameExpand( eh201, inHourly*4,expandLast );

e4hc=WriteIf(eh4x5>eh4x13 OR eh4x5<eh4x13,"One","x");
e4hc2=WriteIf(eh4x5>eh4x13 AND eh4x5>eh4x20,"On","x");
e4hc3=WriteIf(eh4x5<eh4x13 AND eh4x5<eh4x20,"Oe","x");
//d
TimeFrameSet(inDaily);
ed5=EMA(C,5);
ed13=EMA(C,13);
ed20=EMA(C,20);
TimeFrameRestore(); 

edx5=TimeFrameExpand( ed5, inDaily,expandLast );
edx13=TimeFrameExpand( ed13, inDaily,expandLast );
edx20=TimeFrameExpand( ed20, inDaily,expandLast );

edc=WriteIf(edx5>edx13 OR edx5<edx13,"One","x");
edc2=WriteIf(edx5>edx13 AND edx5>edx20,"On","x");
edc3=WriteIf(edx5<edx13 AND edx5<edx20,"Oe","x");



Hor=Param("Horizontal Position",600,1,1200,1);
Ver=Param("Vertical Position",35,30,1000,1); 
///1
GfxSelectFont("Callibri", 10 , 700, True ); 
GfxSetBkMode( colorWhite ); 
GfxSetTextColor( colorBlack );
GfxTextOut("EMA Sig ",Hor, Ver);
GfxSetTextColor( colorBlack );
GfxTextOut("1 M ",Hor+72, Ver-15);

if(ec=="One") 
GfxSelectSolidBrush(colorGold);
if(ec2=="On") 
GfxSelectSolidBrush(colorBrightGreen);
if(ec3=="Oe") 
GfxSelectSolidBrush(colorRed);
GfxSelectPen( colorBlack, 1 ); // broader color 
GfxRectangle( Hor+70,Ver+5,Hor+100,Ver+15 );
///2
GfxSetTextColor( colorBlack );
GfxTextOut("5 M ",Hor+112, Ver-15);


if(e5c=="One") 
GfxSelectSolidBrush(colorGold);
if(e5c2=="On") 
GfxSelectSolidBrush(colorBrightGreen);
if(e5c3=="Oe") 
GfxSelectSolidBrush(colorRed);
GfxRectangle( Hor+110,Ver+5,Hor+140,Ver+15 );
///3
GfxSetTextColor( colorBlack );
GfxTextOut("15 M ",Hor+150, Ver-15);


if(e15c=="One") 
GfxSelectSolidBrush(colorGold);
if(e15c2=="On") 
GfxSelectSolidBrush(colorBrightGreen);
if(e15c3=="Oe") 
GfxSelectSolidBrush(colorRed);
GfxRectangle( Hor+150,Ver+5,Hor+180,Ver+15 );
///4
GfxSetTextColor( colorBlack );
GfxTextOut("1 H ",Hor+193, Ver-15);


if(ehc=="One") 
GfxSelectSolidBrush(colorGold);
if(ehc2=="On") 
GfxSelectSolidBrush(colorBrightGreen);
if(ehc3=="Oe") 
GfxSelectSolidBrush(colorRed);
GfxRectangle( Hor+190,Ver+5,Hor+220,Ver+15 );
//5
GfxSetTextColor( colorBlack );
GfxTextOut("4 H ",Hor+233, Ver-15);


if(e4hc=="One") 
GfxSelectSolidBrush(colorGold);
if(e4hc2=="On") 
GfxSelectSolidBrush(colorBrightGreen);
if(e4hc3=="Oe") 
GfxSelectSolidBrush(colorRed);
GfxRectangle( Hor+230,Ver+5,Hor+260,Ver+15 );
//6
GfxSetTextColor( colorBlack );
GfxTextOut("D ",Hor+280, Ver-15);


if(edc=="One") 
GfxSelectSolidBrush(colorGold);
if(edc2=="On") 
GfxSelectSolidBrush(colorBrightGreen);
if(edc3=="Oe") 
GfxSelectSolidBrush(colorRed);
GfxRectangle( Hor+270,Ver+5,Hor+300,Ver+15 );
Just to remind fellow trader tht this code exists here since long.
I don't remember but seen somebody requesting for such code.

Hope he may find this helpfull
 

Similar threads