I wan to see the same price zone

Hello,

I have two time frames, 4h and 1h. I want to compare the price and indicators at the same price but in different time frames. The problem is that if I go to a price in 4h, then I have to go to 1h and look for that to see where it is exactly. The second problem is that when I draw something in 4h I cannot find it in 1h. Could you please help me in this regard?
image
Best regards,

go to your Study properties, and select Default layer for it

image

I tried it but It doesn't work

You could use staticvars.
In one chart you can write:

_SECTION_BEGIN("Set Pricelevel");
LevelF1=Study("F1",GetChartID());
SVLevelF1=Staticvarset("SVLevelF1",LevelF1);
_SECTION_END();

In the second:
_SECTION_BEGIN("Read Pricelevel"); LevelF1=Staticvarget("SVLevelF1"); Plot(LevelF1,"LevelF1",colorRed,styleThick); _SECTION_END();

Are those levels done through AFL or drawing tools?

If you take that 4 hour chart and change it to 1 hour do you see the levels?

I’ve always had the same charts used with 3 time frames windowed up. I’ve created them via “ default chart”. Their synced together. My lines from my weekly chart show on my daily chart.

If you have them as two different charts and not the same template you’d have to draw on both.

1 Like

I am sorry, I tried it but It doesn't work

Thanks for your reply, it works if I don't have any afl code on the default chart. Do you know how can I recover the initial "default chart"?

I could recover my default chart. Now, I have all the charts, but the problem is that when I apply a MA on a daily it appears on the 4h and 1h and I don't want it. What can I do?
image

@simon, one way to do it is using the Interval() function in your formula to conditionally wrap some sections of your code to show (or not) the desired indicators.

if (Interval() == inDaily) {
    // Your code to PLOT the indicators
    // Calculating them for other purposes may still be required outside of the conditionals
}	
1 Like

Thank you very much. It was exactly something that I was looking for. :+1:

Dear @beppe, I did what you said and I got what I was looking for but today I understood that when I change the parameter of the indicators for example in interval 1 hour, it doesn't change. Why is that? thanks in advance for your help

@simon, I'm sorry, but I do not understand your issue. Please, elaborate on your request and, if possible, post your modified code so we can better figure out your intentions.

Dear @beppe,

This is my code for three timeframes, daily, 4 hourly, and hourly.

_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() ); //main price
_SECTION_END();

if (Interval() == inDaily)
{
Periods_d = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( C, Periods_d ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );

b0 = Cross(C, MA( C, Periods_d ));
Buy = b0;

s0 = Cross(MA( C, Periods_d ),C);
Sell = s0;

short = sell;
cover = buy;

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

cover = ExRem (cover, short);
short = ExRem (short, cover);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0, L, Offset = -10);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0, L, Offset = -20);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0, L, Offset = -15);

PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset = 10);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset = 20);                      
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0, H, Offset = -15);

}

if (Interval() == 4*inHourly)
{
Periods_4h = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( C, Periods_4h ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );

b0 = Cross(C, MA( C, Periods_4h ));
Buy = b0;

s0 = Cross(MA( C, Periods_4h ),C);
Sell = s0;

short = sell;
cover = buy;

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

cover = ExRem (cover, short);
short = ExRem (short, cover);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0, L, Offset = -10);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0, L, Offset = -20);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0, L, Offset = -15);

PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset = 10);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset = 20);                      
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0, H, Offset = -15);

}

if (Interval() == inHourly)
{
Periods_h = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( C, Periods_h ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );

b0 = Cross(C, MA( C, Periods_h ));
Buy = b0;

s0 = Cross(MA( C, Periods_h ),C);
Sell = s0;

short = sell;
cover = buy;

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

cover = ExRem (cover, short);
short = ExRem (short, cover);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0, L, Offset = -10);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0, L, Offset = -20);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0, L, Offset = -15);

PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset = 10);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset = 20);                      
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0, H, Offset = -15);

}

Now, suppose I am in an hourly timeframe and then, right-click and go to the parameter and try to change the MA parameter. There is no difference between MA(15) and MA(50), please take a look at the following pics:
image

image

Thanks in advance for your help.

Param* are cached. You should not put them inside if statement.
Also do give distinct period for each interval you have to give different Param name for each interval.

So overall rather do like this:

_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() ); //main price
_SECTION_END();

Periods_d = Param("Periods Daily", 15, 2, 300, 1, 10 );
Periods_4h = Param("Periods 4h", 15, 2, 300, 1, 10 );
Periods_h = Param("Periods Hourly", 15, 2, 300, 1, 10 );

Periods = 1e9;

if ( Interval() == inDaily )
{
    Periods = Periods_d;
}

if ( Interval() == 4 * inHourly )
{
    Periods = Periods_4h;
}

if ( Interval() == inHourly )
{
    Periods = Periods_h;
}

printf( "Periods: %g", Periods);
_TRACEF( "Periods:%g", Periods);

myMA = MA( C, Periods );

Plot( myMA, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );

b0 = Cross(C, myMA);
Buy = b0;
s0 = Cross(myMA,C);
Sell = s0;

short = sell;
cover = buy;

Buy = ExRem (Buy, Sell);
Sell = ExRem (Sell, Buy);
cover = ExRem (cover, short);
short = ExRem (short, cover);

PlotShapes(Buy*shapeSquare,colorLime, 0, L, Offset = -10);
PlotShapes(Buy*shapeSquare,colorLime, 0, L, Offset = -20);  
PlotShapes(Buy*shapeUpArrow,colorWhite, 0, L, Offset = -15);
PlotShapes(Sell*shapeSquare,colorRed, 0, H, Offset = 10);
PlotShapes(Sell*shapeSquare,colorRed, 0, H, Offset = 20);  
PlotShapes(Sell*shapeDownArrow,colorWhite, 0, H, Offset = -15);
1 Like

Here is a better version to disable plot in other intervals other than defined ones:

_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() ); //main price
_SECTION_END();

Periods_h = Param("Periods Hourly", 15, 2, 300, 1, 10 );
Periods_4h = Param("Periods 4H", 15, 2, 300, 1, 10 );
Periods_d = Param("Periods Daily", 15, 2, 300, 1, 10 );

switch (Interval()) {
	case inHourly:		Periods = Periods_h; break;
	case 4 * inHourly:	Periods = Periods_4h; break;
	case inDaily: 		Periods = Periods_d; break;
	// by default very small number between 0 and 1
	default:			Periods = 1e-9; break; 
}

printf( "Periods: %g", Periods);
_TRACEF( "Periods:%g", Periods);

color = ParamColor( "Color", colorCycle );
style = ParamStyle("Style");

if ( Periods >= 1 ) {
	myMA = MA(C, Periods);

	Plot( myMA, _DEFAULT_NAME(), color, style );

	b0 = Cross(C, myMA);
	Buy = b0;
	s0 = Cross(myMA,C);
	Sell = s0;

	Short = Sell;
	Cover = Buy;

	Buy = ExRem (Buy, Sell);
	Sell = ExRem (Sell, Buy);
	cover = ExRem (cover, short);
	short = ExRem (short, cover);

	PlotShapes(Buy*shapeSquare,colorLime, 0, L, Offset = -10);
	PlotShapes(Buy*shapeSquare,colorLime, 0, L, Offset = -20);  
	PlotShapes(Buy*shapeUpArrow,colorWhite, 0, L, Offset = -15);
	PlotShapes(Sell*shapeSquare,colorRed, 0, H, Offset = 10);
	PlotShapes(Sell*shapeSquare,colorRed, 0, H, Offset = 20);  
	PlotShapes(Sell*shapeDownArrow,colorWhite, 0, H, Offset = -15);
}

Thanks for your reply but unfortunately it doesn't work. If you apply that code and then go to your chart and try to change the parameters for daily, 4 hourly, and hourly, the MA doesn't change. Take a look at the following pics:
this is daily and 15 period
image

This one is daily and 50 period but the charts are the same
image

Wrong!
I do not post code that does not work.

The code works fine!

Make sure the code is applied as one and only one. Re-copy and save a separate AFL and apply on chart. Click reset all in parameter window.

It makes zero sense not working. If it would not work then it would not draw anything because of default 1e-9 for periods. So it makes zero sense. You seem to have some mixed code there.

Here is proof of it working for all time frames involved.

1-Hour
8

4-hour
7

Daily
6

Do you think I am wasting time here posting code not working???


DO DEBUG.
I have put in there Printf and TRACE.
What are the outputs via either one?

I swear that I didn't mean something bad. I am sorry for misunderstanding but I tried one more time but the MA doesn't change for me :frowning:
I copy and paste the same code, and a new afl but it doesn't work (for me). Could you please help me in this regard?