Simple Coding Help - No Promise.

xsis

Active Member
plotting higher TF MA in lower TF

just came across a thread where some1 wntd to plot a bigger TF MA on a smaller TF! i mean 21 hourly MA on 5 min chart or any other combo on daily/weekly/monthly basis! it luks an interesting thing with loads of experimental things possible! mny tried but their codes are nt wrking out. cud any1 pls help in getting it solved as it mite help evryone here!

http://www.traderji.com/amibroker/77443-how-plot-higher-tf-ma-lower-tf-amibroker.html

cud u help in this?
 
Last edited:

pratapvb

Well-Known Member
Re: plotting higher TF MA in lower TF

just came across a thread where some1 wntd to plot a bigger TF MA on a smaller TF! i mean 21 hourly MA on 5 min chart or any other combo on daily/weekly/monthly basis! it luks an interesting thing with loads of experimental things possible! mny tried but their codes are nt wrking out. cud any1 pls help in getting it solved as it mite help evryone here!

http://www.traderji.com/amibroker/77443-how-plot-higher-tf-ma-lower-tf-amibroker.html

cud u help in this?
try this

can change TF...whether MA/EMA and whether on close/high/low etc

checkout various parameters

Code:
usetf = ParamToggle("Use TF", "No|Yes", 1) ;
// Author: Pratap Balakrishnan
// Copyright: All rights reserved. Not to be circulated or shared or posted on websites without the author's written permission.
// email id: [email protected]

alloff = ParamToggle("All off", "No|Yes", 0) ;

tf = Param("TF", 3, 1, 100000, 1);
Periods = Param("Periods", 13, 2, 1000, 1, 10 );
isema = ParamToggle("MA Type", "MA|EMA", 1) ;
MAstyle = ParamStyle("MA Style", styleThick) ;
Clrma = ParamColor( "Color Up", colorBlue);
isexpandLast = ParamToggle("Expand Mode", "First|Last", 1); 
expandmode = expandFirst ;
if (isexpandLast)
	expandmode = expandLast ;

if (NOT alloff)
{
	if (usetf)
	{
		tfs = tf *in1Minute ;
		TimeFrameSet(tfs) ;
	}
	else
		tfs = Interval() ;

Refp = ParamField("Price", 3);

	if (isema)
		MAhtf = EMA(Refp, Periods) ;
	else
		MAhtf = MA(Refp, Periods) ;

	if (usetf)
		MAhtfe = TimeFrameExpand(MAhtf, tfs, expandmode ) ;
	else
		MAhtfe = MAhtf ;

	str = NumToStr(tf, 1.0)+"Min"+"-P"+NumToStr(Periods, 1.0) ;
	Clr = Clrma ;
	if (usetf)
		Clre = TimeFrameExpand(Clr, tfs, expandmode ) ;
	else
		Clre = Clr ;

	if (usetf)
		TimeFrameRestore() ;

	RefMAhtfe = MAhtfe ;
	RefClre = Clre ;

	Plot( RefMAhtfe, str, RefClre, MAstyle|styleNoLabel|styleNoRescale); 
}
 

Raghuveer

Well-Known Member
Re: plotting higher TF MA in lower TF

Currently using this code. Can you please confirm if correct.
Code:
TimeFrameSet(in15Minute);
EMA15minute = EMA(C,20);
TimeFrameRestore();
Plot(TimeFrameExpand(EMA15minute, in15Minute, mode=expandFirst), "15minTF-20ema", ParamColor( "EMA15", colorTan), ParamStyle( "EMA15 Style", styleLine|styleDashed|styleNoRescale));

TimeFrameSet(30*in1Minute);
EMA30minute = EMA(C,20);
TimeFrameRestore();
Plot(TimeFrameExpand(EMA30minute, 30*in1Minute, mode=expandFirst), "30minTF-20ema", ParamColor( "EMA30", colorSkyblue), ParamStyle( "EMA30 Style", styleLine|styleDashed|styleNoRescale));
I am just a copy paste coder. expandFirst seems to give correct values, so used it. When would expandLast be correct?

try this

can change TF...whether MA/EMA and whether on close/high/low etc

checkout various parameters

Code:
usetf = ParamToggle("Use TF", "No|Yes", 1) ;
// Author: Pratap Balakrishnan
// Copyright: All rights reserved. Not to be circulated or shared or posted on websites without the author's written permission.
// email id: [email protected]

alloff = ParamToggle("All off", "No|Yes", 0) ;

tf = Param("TF", 3, 1, 100000, 1);
Periods = Param("Periods", 13, 2, 1000, 1, 10 );
isema = ParamToggle("MA Type", "MA|EMA", 1) ;
MAstyle = ParamStyle("MA Style", styleThick) ;
Clrma = ParamColor( "Color Up", colorBlue);
isexpandLast = ParamToggle("Expand Mode", "First|Last", 1); 
expandmode = expandFirst ;
if (isexpandLast)
	expandmode = expandLast ;

if (NOT alloff)
{
	if (usetf)
	{
		tfs = tf *in1Minute ;
		TimeFrameSet(tfs) ;
	}
	else
		tfs = Interval() ;

Refp = ParamField("Price", 3);

	if (isema)
		MAhtf = EMA(Refp, Periods) ;
	else
		MAhtf = MA(Refp, Periods) ;

	if (usetf)
		MAhtfe = TimeFrameExpand(MAhtf, tfs, expandmode ) ;
	else
		MAhtfe = MAhtf ;

	str = NumToStr(tf, 1.0)+"Min"+"-P"+NumToStr(Periods, 1.0) ;
	Clr = Clrma ;
	if (usetf)
		Clre = TimeFrameExpand(Clr, tfs, expandmode ) ;
	else
		Clre = Clr ;

	if (usetf)
		TimeFrameRestore() ;

	RefMAhtfe = MAhtfe ;
	RefClre = Clre ;

	Plot( RefMAhtfe, str, RefClre, MAstyle|styleNoLabel|styleNoRescale); 
}
 

pratapvb

Well-Known Member
Re: plotting higher TF MA in lower TF

I am just a copy paste coder. expandFirst seems to give correct values, so used it. When would expandLast be correct?
expandlast used when you want MA value to show only when bar is completed
 

Cubt

Algo Trader
Happy,

It would be great if you could make the following changes in the code.

Its a ORB intraday trading system.

1. After breakout of 5 Mins bar, the position needs to be exited once the Target of 10 points is reached.

2. Stop loss is when 5 mins bar closes above/below the opening range. (i.e. above/below 1st 5 mins bar)

3. If neither Target or Stop Loss is hit, the position should be exited @ 03:20 PM @ market price.

4. When backtesting, it should be considered as Intraday trade. i.e no positions should be carried over.


I guess the 3rd point will not happen as the target is very less, either the target or stop loss will be triggered before 3:20PM. If you feel the same, you can skip this part in the code.

I tried making the changes in the code, but its not showing the correct results. I think am writing a wrong code in the

stop loss part. Pls help. Thanks.

ORBHSL = ORBH;
ORBLSL = ORBL;
ORBHTarget = ORBH + 10;
ORBLTarget = ORBL - 10;


actual AFL
Code:
function ParamOptimize( pname, defaultval, minv, maxv, step )
{
return Optimize( pname,
Param( pname, defaultval, minv, maxv, step ),
minv, maxv, step );
}




_SECTION_BEGIN("Augubhai's ORB System v1.1"); 

//--Intraday time frame 
TimeFrameSet(in5Minute); //If reseting, check formula for TimeFrameInMinutes 
TimeFrameInMinutes = 5;

//--Define all params 
EntryBufferPct = ParamOptimize("Entry Buffer %", 0, 0, 2, 0.1);
SLPct = ParamOptimize("SL %", 1.4, 0.1, 10, 0.1);
TargetPct = ParamOptimize("Target %", 0, 0, 20, 0.5);
MaxTarget = 100;
TargetPct = IIf(TargetPct == 0, MaxTarget, TargetPct); 
EntryTimeStart = ParamOptimize("Entry Time Start (Minutes)", 5, 5, 120, 5);
EntryBarStart = floor(EntryTimeStart/TimeFrameInMinutes) - 1;
EntryTimeEnd = ParamOptimize("Entry Time End (Minutes)", 25, 10, 180, 5);
EntryBarEnd = floor(EntryTimeEnd/TimeFrameInMinutes) - 1;
EntryBarEnd = IIf(EntryBarEnd < EntryBarStart, EntryBarStart, EntryBarEnd);  

//--Plot Price Candle Chart
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", colorBlack, styleNoTitle | GetPriceStyle() ); 

//--New Day & Time. End Day & Time . End Day & Time is null till end of day 1  
NewDay = (Day()!= Ref(Day(), -1)) OR BarIndex() == 0; 
printf("\n NewDay  : " + NewDay ); 
EndDay = (Day()!= Ref(Day(), 1)); 
printf("\n EndDay  : " + EndDay );
FirstBarTime = ValueWhen(NewDay,TimeNum(),1); 
EndTime = ValueWhen(EndDay,TimeNum(),1);
SquareOffTime = EndTime;

//--Calculate ORB, and SL
HighestOfDay = HighestSince(NewDay,H,1); 
LowestOfDay = LowestSince(NewDay,L,1); 
BarsSinceNewDay = BarsSince(NewDay);
ORBH = ValueWhen(BarsSinceNewDay<=EntryBarStart,HighestOfDay ,1) * (1 + (EntryBufferPct/100)); 
ORBL = ValueWhen(BarsSinceNewDay<=EntryBarStart,LowestOfDay ,1) * (1 - (EntryBufferPct/100)); 
ORBHSL = ORBH * (1-(SLPct/100)); 
//ORBHSL = ORBL; 
ORBLSL = ORBL * (1+(SLPct/100));
//ORBLSL = ORBH; 
ORBHTarget = ORBH * (1+(TargetPct/100));
ORBLTarget = ORBL * (1-(TargetPct/100));

//--Find Buy, Sell, Short & Cover Signals
BuySignal = (H >= ORBH) AND (BarsSinceNewDay  > EntryBarStart); 
printf("\nBuySignal : " + BuySignal ); 
ShortSignal = (L <= ORBL) AND (BarsSinceNewDay  > EntryBarStart) ; 
printf("\nShortSignal  : " + ShortSignal ); 
BarsSinceLastBuySignal = (BarsSince(Ref(BuySignal,-1)) + 1);
BarsSinceLastShortSignal = (BarsSince(Ref(ShortSignal,-1)) + 1);
BarsSinceLastEntrySignal = Min(BarsSinceLastBuySignal, BarsSinceLastShortSignal);
BothEntrySignalsNull = IsNull(BarsSinceLastBuySignal) AND IsNull(BarsSinceLastShortSignal); //true for start of Day 1
printf("\n\nBarsSinceNewDay : " + BarsSinceNewDay ); 
printf("\n BarsSinceLastEntrySignal : " + BarsSinceLastEntrySignal); 
Buy = (H >= ORBH) AND (BarsSinceNewDay  > EntryBarStart) AND (BarsSinceNewDay <= EntryBarEnd) AND ((BarsSinceNewDay < BarsSinceLastEntrySignal) OR BothEntrySignalsNull ); 
Sell = (L <= ORBHSL) OR (H >= ORBHTarget) OR (TimeNum() > SquareOffTime-1) AND (BarsSinceNewDay > BarsSinceLastBuySignal); 
Short = (L <= ORBL) AND (BarsSinceNewDay  > EntryBarStart) AND (BarsSinceNewDay <= EntryBarEnd) AND ((BarsSinceNewDay < BarsSinceLastEntrySignal) OR BothEntrySignalsNull ); 
Cover = (H >= ORBLSL) OR (L <= ORBLTarget) OR (TimeNum() > SquareOffTime-1) AND (BarsSinceNewDay > BarsSinceLastShortSignal); 
printf("\nBuy : " + Buy ); 
printf("\nSell : " + Sell ); 
printf("\nShort : " + Short ); 
printf("\nCover : " + Cover ); 

//--Handle if ORB broken both sides on same bar
//--And remove duplicate Sell & Cover signals, since ExRem did not work as needed when Buy & Sell on same bar
orbBothSides = IIf(Buy AND Short, 1, 0); 
Buy = IIf(orbBothSides AND C <= O, 0, Buy); 
Short = IIf(orbBothSides AND C > O, 0, Short); 
Sell = IIf(orbBothSides AND C > O AND (L <= ORBHSL), 1, Sell); 
Sell = IIf((BarsSince(Buy) < (BarsSince(Ref(Sell,-1))+1)) OR (BarsSince(Buy) AND IsNull(BarsSince(Ref(Sell,-1)))),Sell,0);
Cover = IIf(orbBothSides AND C <= O AND (H >= ORBLSL), 1, Cover); 
Cover = IIf((BarsSince(Short) < (BarsSince(Ref(Cover,-1))+1)) OR (BarsSince(Short) AND IsNull(BarsSince(Ref(Cover,-1)))),Cover,0);
printf("\n\norbBothSides : " + orbBothSides); 
printf("\nBuy : " + Buy ); 
printf("\nSell : " + Sell ); 
printf("\nShort : " + Short ); 
printf("\nCover : " + Cover ); 

//--Special Condition for 18 & 19 May 2009 for the Indian Market
Buy =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Buy );
Sell =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Sell );
Short =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Short );
Cover =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Cover );

//--Set prices
BuyPrice = IIf(Buy, ORBH, Null); 
SellPrice = IIf(Sell, IIf(H >= ORBHTarget, ORBHTarget, Max(ORBHSL, L)), Null); 
ShortPrice = IIf(Short, ORBL, Null); 
CoverPrice = IIf(Cover, IIf(L <= ORBLTarget, ORBLTarget, Min(ORBLSL, H)), Null); 

//--Plot ORB, and SL 
Plot(ORBHSL,"",colorRed,styleDashed); 
Plot(ORBLSL,"",colorRed,styleDashed); 
Plot(IIf(TargetPct == MaxTarget, Null, ORBHTarget),"",colorGreen,styleDashed);
Plot(IIf(TargetPct == MaxTarget, Null, ORBLTarget),"",colorGreen,styleDashed);
PlotOHLC( ORBL, ORBH, ORBL, ORBH, "", colorYellow, styleCloud); 
 
//--Plot Signals
shape1 = Buy * shapeUpArrow + Sell * shapeDownArrow; 
PlotShapes( shape1, IIf( Buy, colorGreen, colorGreen), 0, IIf( Buy, Low, High ) ); 
shape2 = Cover * shapeUpArrow + Short * shapeDownArrow; 
PlotShapes( shape2, IIf( Cover, colorRed, colorRed), 0, IIf( Cover, Low, High ) ); 
GraphXSpace = 5; 

//--Restore time frame 
TimeFrameRestore(); 
_SECTION_END();
 
Happy,

It would be great if you could make the following changes in the code.

Its a ORB intraday trading system.

1. After breakout of 5 Mins bar, the position needs to be exited once the Target of 10 points is reached.

2. Stop loss is when 5 mins bar closes above/below the opening range. (i.e. above/below 1st 5 mins bar)

3. If neither Target or Stop Loss is hit, the position should be exited @ 03:20 PM @ market price.

4. When backtesting, it should be considered as Intraday trade. i.e no positions should be carried over.


I guess the 3rd point will not happen as the target is very less, either the target or stop loss will be triggered before 3:20PM. If you feel the same, you can skip this part in the code.

I tried making the changes in the code, but its not showing the correct results. I think am writing a wrong code in the

stop loss part. Pls help. Thanks.

ORBHSL = ORBH;
ORBLSL = ORBL;
ORBHTarget = ORBH + 10;
ORBLTarget = ORBL - 10;


actual AFL
Code:
function ParamOptimize( pname, defaultval, minv, maxv, step )
{
return Optimize( pname,
Param( pname, defaultval, minv, maxv, step ),
minv, maxv, step );
}




_SECTION_BEGIN("Augubhai's ORB System v1.1"); 

//--Intraday time frame 
TimeFrameSet(in5Minute); //If reseting, check formula for TimeFrameInMinutes 
TimeFrameInMinutes = 5;

//--Define all params 
EntryBufferPct = ParamOptimize("Entry Buffer %", 0, 0, 2, 0.1);
SLPct = ParamOptimize("SL %", 1.4, 0.1, 10, 0.1);
TargetPct = ParamOptimize("Target %", 0, 0, 20, 0.5);
MaxTarget = 100;
TargetPct = IIf(TargetPct == 0, MaxTarget, TargetPct); 
EntryTimeStart = ParamOptimize("Entry Time Start (Minutes)", 5, 5, 120, 5);
EntryBarStart = floor(EntryTimeStart/TimeFrameInMinutes) - 1;
EntryTimeEnd = ParamOptimize("Entry Time End (Minutes)", 25, 10, 180, 5);
EntryBarEnd = floor(EntryTimeEnd/TimeFrameInMinutes) - 1;
EntryBarEnd = IIf(EntryBarEnd < EntryBarStart, EntryBarStart, EntryBarEnd);  

//--Plot Price Candle Chart
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", colorBlack, styleNoTitle | GetPriceStyle() ); 

//--New Day & Time. End Day & Time . End Day & Time is null till end of day 1  
NewDay = (Day()!= Ref(Day(), -1)) OR BarIndex() == 0; 
printf("\n NewDay  : " + NewDay ); 
EndDay = (Day()!= Ref(Day(), 1)); 
printf("\n EndDay  : " + EndDay );
FirstBarTime = ValueWhen(NewDay,TimeNum(),1); 
EndTime = ValueWhen(EndDay,TimeNum(),1);
SquareOffTime = EndTime;

//--Calculate ORB, and SL
HighestOfDay = HighestSince(NewDay,H,1); 
LowestOfDay = LowestSince(NewDay,L,1); 
BarsSinceNewDay = BarsSince(NewDay);
ORBH = ValueWhen(BarsSinceNewDay<=EntryBarStart,HighestOfDay ,1) * (1 + (EntryBufferPct/100)); 
ORBL = ValueWhen(BarsSinceNewDay<=EntryBarStart,LowestOfDay ,1) * (1 - (EntryBufferPct/100)); 
ORBHSL = ORBH * (1-(SLPct/100)); 
//ORBHSL = ORBL; 
ORBLSL = ORBL * (1+(SLPct/100));
//ORBLSL = ORBH; 
ORBHTarget = ORBH * (1+(TargetPct/100));
ORBLTarget = ORBL * (1-(TargetPct/100));

//--Find Buy, Sell, Short & Cover Signals
BuySignal = (H >= ORBH) AND (BarsSinceNewDay  > EntryBarStart); 
printf("\nBuySignal : " + BuySignal ); 
ShortSignal = (L <= ORBL) AND (BarsSinceNewDay  > EntryBarStart) ; 
printf("\nShortSignal  : " + ShortSignal ); 
BarsSinceLastBuySignal = (BarsSince(Ref(BuySignal,-1)) + 1);
BarsSinceLastShortSignal = (BarsSince(Ref(ShortSignal,-1)) + 1);
BarsSinceLastEntrySignal = Min(BarsSinceLastBuySignal, BarsSinceLastShortSignal);
BothEntrySignalsNull = IsNull(BarsSinceLastBuySignal) AND IsNull(BarsSinceLastShortSignal); //true for start of Day 1
printf("\n\nBarsSinceNewDay : " + BarsSinceNewDay ); 
printf("\n BarsSinceLastEntrySignal : " + BarsSinceLastEntrySignal); 
Buy = (H >= ORBH) AND (BarsSinceNewDay  > EntryBarStart) AND (BarsSinceNewDay <= EntryBarEnd) AND ((BarsSinceNewDay < BarsSinceLastEntrySignal) OR BothEntrySignalsNull ); 
Sell = (L <= ORBHSL) OR (H >= ORBHTarget) OR (TimeNum() > SquareOffTime-1) AND (BarsSinceNewDay > BarsSinceLastBuySignal); 
Short = (L <= ORBL) AND (BarsSinceNewDay  > EntryBarStart) AND (BarsSinceNewDay <= EntryBarEnd) AND ((BarsSinceNewDay < BarsSinceLastEntrySignal) OR BothEntrySignalsNull ); 
Cover = (H >= ORBLSL) OR (L <= ORBLTarget) OR (TimeNum() > SquareOffTime-1) AND (BarsSinceNewDay > BarsSinceLastShortSignal); 
printf("\nBuy : " + Buy ); 
printf("\nSell : " + Sell ); 
printf("\nShort : " + Short ); 
printf("\nCover : " + Cover ); 

//--Handle if ORB broken both sides on same bar
//--And remove duplicate Sell & Cover signals, since ExRem did not work as needed when Buy & Sell on same bar
orbBothSides = IIf(Buy AND Short, 1, 0); 
Buy = IIf(orbBothSides AND C <= O, 0, Buy); 
Short = IIf(orbBothSides AND C > O, 0, Short); 
Sell = IIf(orbBothSides AND C > O AND (L <= ORBHSL), 1, Sell); 
Sell = IIf((BarsSince(Buy) < (BarsSince(Ref(Sell,-1))+1)) OR (BarsSince(Buy) AND IsNull(BarsSince(Ref(Sell,-1)))),Sell,0);
Cover = IIf(orbBothSides AND C <= O AND (H >= ORBLSL), 1, Cover); 
Cover = IIf((BarsSince(Short) < (BarsSince(Ref(Cover,-1))+1)) OR (BarsSince(Short) AND IsNull(BarsSince(Ref(Cover,-1)))),Cover,0);
printf("\n\norbBothSides : " + orbBothSides); 
printf("\nBuy : " + Buy ); 
printf("\nSell : " + Sell ); 
printf("\nShort : " + Short ); 
printf("\nCover : " + Cover ); 

//--Special Condition for 18 & 19 May 2009 for the Indian Market
Buy =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Buy );
Sell =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Sell );
Short =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Short );
Cover =IIf(DateNum()==1090518 OR (DateNum()==1090519 AND NewDay),0,Cover );

//--Set prices
BuyPrice = IIf(Buy, ORBH, Null); 
SellPrice = IIf(Sell, IIf(H >= ORBHTarget, ORBHTarget, Max(ORBHSL, L)), Null); 
ShortPrice = IIf(Short, ORBL, Null); 
CoverPrice = IIf(Cover, IIf(L <= ORBLTarget, ORBLTarget, Min(ORBLSL, H)), Null); 

//--Plot ORB, and SL 
Plot(ORBHSL,"",colorRed,styleDashed); 
Plot(ORBLSL,"",colorRed,styleDashed); 
Plot(IIf(TargetPct == MaxTarget, Null, ORBHTarget),"",colorGreen,styleDashed);
Plot(IIf(TargetPct == MaxTarget, Null, ORBLTarget),"",colorGreen,styleDashed);
PlotOHLC( ORBL, ORBH, ORBL, ORBH, "", colorYellow, styleCloud); 
 
//--Plot Signals
shape1 = Buy * shapeUpArrow + Sell * shapeDownArrow; 
PlotShapes( shape1, IIf( Buy, colorGreen, colorGreen), 0, IIf( Buy, Low, High ) ); 
shape2 = Cover * shapeUpArrow + Short * shapeDownArrow; 
PlotShapes( shape2, IIf( Cover, colorRed, colorRed), 0, IIf( Cover, Low, High ) ); 
GraphXSpace = 5; 

//--Restore time frame 
TimeFrameRestore(); 
_SECTION_END();
seems you posted this twice. Anyway same suggestion . . .

Hi

Before we change any code try setting a profit stop of 10 points . . .
can set it in Backtest Settings >> Stops >> Profit > Points > 10 > exit intraday at stop

Without the SL if you are getting enough number of winners then only one should try introducing a SL.

:) Happy


try testing if you like it we can code for exit on low if first bar


Code:
SetPositionSize(1,4);
ApplyStop(0,2,10);  //Ajust points for Stop Loss (3rd parameter)
ApplyStop(1,2,10); //Ajust points for Profit Stop (3rd parameter)
 

xsis

Active Member
Re: plotting higher TF MA in lower TF

dear pratap

thks for the code! but the values are still nt matching! i have attached the screenshot using ur code and original MA code!

also, if i want to use 10 period MA of Daily TF on 15min intra chart, what should i enter in the TF 1440 or 375 (6hrs & 15 min session for our mkt unlike the global mkts where daily=1440mins)




try this

can change TF...whether MA/EMA and whether on close/high/low etc

checkout various parameters

Code:
usetf = ParamToggle("Use TF", "No|Yes", 1) ;
// Author: Pratap Balakrishnan
// Copyright: All rights reserved. Not to be circulated or shared or posted on websites without the author's written permission.
// email id: [email protected]

alloff = ParamToggle("All off", "No|Yes", 0) ;

tf = Param("TF", 3, 1, 100000, 1);
Periods = Param("Periods", 13, 2, 1000, 1, 10 );
isema = ParamToggle("MA Type", "MA|EMA", 1) ;
MAstyle = ParamStyle("MA Style", styleThick) ;
Clrma = ParamColor( "Color Up", colorBlue);
isexpandLast = ParamToggle("Expand Mode", "First|Last", 1); 
expandmode = expandFirst ;
if (isexpandLast)
	expandmode = expandLast ;

if (NOT alloff)
{
	if (usetf)
	{
		tfs = tf *in1Minute ;
		TimeFrameSet(tfs) ;
	}
	else
		tfs = Interval() ;

Refp = ParamField("Price", 3);

	if (isema)
		MAhtf = EMA(Refp, Periods) ;
	else
		MAhtf = MA(Refp, Periods) ;

	if (usetf)
		MAhtfe = TimeFrameExpand(MAhtf, tfs, expandmode ) ;
	else
		MAhtfe = MAhtf ;

	str = NumToStr(tf, 1.0)+"Min"+"-P"+NumToStr(Periods, 1.0) ;
	Clr = Clrma ;
	if (usetf)
		Clre = TimeFrameExpand(Clr, tfs, expandmode ) ;
	else
		Clre = Clr ;

	if (usetf)
		TimeFrameRestore() ;

	RefMAhtfe = MAhtfe ;
	RefClre = Clre ;

	Plot( RefMAhtfe, str, RefClre, MAstyle|styleNoLabel|styleNoRescale); 
}
 
xsis put the cursor on the previous bars and check . . .


also


change this parameter "Expand Mode" and see if it matches
 

Similar threads