Trend Magic Indicator MTF Required

#1
Hello Everyone,
Here is the pine script of trend magic indicator and i require a MTF version of the same.
I Would be very thankful if anyone can help me with this.
Thanks In Advance.
Regards.


//@version=2
study("Trend Magic",overlay=true)
CCI = input(20)
ATR = input(5)
Multiplier=input(1,title='ATR Multiplier')
original=input(true,title='original coloring')
thisCCI = cci(close, CCI)
lastCCI = nz(thisCCI[1])
bufferDn= high + Multiplier * sma(tr,ATR)
bufferUp= low - Multiplier * sma(tr,ATR)
if (thisCCI >= 0 and lastCCI < 0)
bufferUp := bufferDn[1]
if (thisCCI <= 0 and lastCCI > 0)
bufferDn := bufferUp[1]

if (thisCCI >= 0)
if (bufferUp < bufferUp[1])
bufferUp := bufferUp[1]
else
if (thisCCI <= 0)
if (bufferDn > bufferDn[1])
bufferDn := bufferDn[1]

x=thisCCI >= 0 ?bufferUp:thisCCI <= 0 ?bufferDn:x[1]
swap=x>x[1]?1:x<x[1]?-1:swap[1]
swap2=swap==1?lime:red
swap3=thisCCI >=0 ?lime:red
swap4=original?swap3:swap2
plot(x,color=swap4,transp=0,linewidth=3)
 
#2
/* Done by Rajandran R */

/* Author of www.marketcalls.in */



_SECTION_BEGIN("Trend Magic hourly chart");

SetBarsRequired(100000,0);

GraphXSpace = 15;

SetChartOptions(0,chartShowArrows|chartShowDates);

SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));

GfxSetBkMode(0);

GfxSetOverlayMode(1);

SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));

Plot(C,"\nPrice",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);



//SetTradeDelays(1,1,1,1);

SetPositionSize(100,spsShares);





_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));



iCCI=Param("CCI Period",50,1,100,1);
Multiplier = Param("Multiplier",2,1,10,1);


Pd=Param("ATR Periods",5,1,10,1);

price = (O+H+L)/3;

iATR = ATR(Pd);
CCIvalue = CCIa(price,iCCI);

for (i = 0; i <iCCI+1; i++) {

TrendUp = Null;

TrendDown = Null;
}

TrendUp[BarCount-1]=Null;
TrendDown[BarCount-1]=Null;

for (i = iCCI+1; i <BarCount-1; i++) {

TrendUp = Null;

TrendDown = Null;



// if (CCIvalue>=0 && CCIvalue[i-1]<0) {
// TrendUp[i-1]=TrendDown[i-1];
// }

// if (CCIvalue<=0 && CCIvalue[i-1]>0) {
// TrendDown[i-1]=TrendUp[i-1];
// }

if (CCIvalue >= 0)
{
TrendUp = (High+Low)/2 - Multiplier*iATR;
if (TrendUp < TrendUp[i- 1])
TrendUp = TrendUp[i- 1];
}
else
{
if (CCIvalue <= 0)
{
TrendDown = (High+Low)/2 + Multiplier*iATR;
if (TrendDown > TrendDown[i-1])
TrendDown = TrendDown[i-1];
}
}

} //end for loop



Plot(TrendUp,"Trend",colorGreen,stylethick);

Plot(TrendDown,"Down",colorRed,stylethick);


Buy = IsNull(TrendDown) AND !IsNull(TrendUP);
Sell = IsNull(TrendUp) AND !IsNull(TrendDown);

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


BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);


Title = EncodeColor(colorWhite)+ "Trend Magic code from www.marketcalls.in" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorYellow)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","");

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);



_SECTION_END();



_SECTION_BEGIN("Time Left");

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",50,0,1000,1);

y=Param("yposn",380,0,1000,1);



GfxSelectSolidBrush( ColorRGB( 230, 230, 230 ) );

GfxSelectPen( ColorRGB( 230, 230, 230 ), 2 );

if ( NewPeriod )

{

GfxSelectSolidBrush( colorYellow );

GfxSelectPen( colorYellow, 2 );

Say( "New period" );

}

//GfxRoundRect( x+45, y+40, x-3, y-2, 0, 0 );

//GfxSetBkMode(1);

GfxSelectFont( "Arial", 14, 700, False );

GfxSetTextColor( colorRed );

GfxTextOut( "Time Left :"+SecsToGo+"", x, y );

_SECTION_END();
 

Similar threads