# How to apply the code in monthly time frame chart?

Dear Experts,

Have a look at the below code were the conditions are as follows:-

1. Buy Condition = Beta > 1.1 and Stochk > StochD
2. Stop Loss = Buy Condition price - (ATR * 2)
3 First Target Price = Buy Condition price + (ATR * 3)
4 Second Target Price = Buy Condition price + (ATR * 6)
``````//This exploration is made to scan stocks were the Beta > 1.1 and Stochastic Crossover

inDaily

ticker = ParamStr("Ticker","nsenifty");
P = Foreign(ticker,"C",1);
Periods = Param("period",7,1,50,1);
AT = ATR(7);

// Calculation of Beta
Beta = ((Periods * Sum(ROC(C,1) * ROC(P,1),Periods)) - (Sum(ROC(C,1),Periods) * Sum(ROC(P,1),Periods))) /
((Periods * Sum((ROC(P,1)^2),Periods)) - (Sum(ROC(P,1),Periods)^2));

BC = Beta > 1.1 AND StochK(8,3) > StochD(8,3,3)

//Stop Loss
SL = BC - (AT * 2);

//Target Price
FTP = BC + (AT * 3);
STP = BC + (AT * 6);

Filter = BC;

``````

There are lots of errors in the code...please kindly help to solve them.

Regards,

Sonjoe

``````//This exploration is made to scan stocks were the Beta > 1.1 and Stochastic Crossover

inDaily

ticker = ParamStr("Ticker","nsenifty");
P = Foreign(ticker,"C",1);
Periods = Param("period",7,1,50,1);
AT = ATR(7);

// Calculation of Beta
Beta = ((Periods * Sum(ROC(C,1) * ROC(P,1),Periods)) - (Sum(ROC(C,1),Periods) * Sum(ROC(P,1),Periods))) /
((Periods * Sum((ROC(P,1)^2),Periods)) - (Sum(ROC(P,1),Periods)^2));

BC = Beta > 1.1 AND StochK(8,3) > StochD(8,3,3);

//Stop Loss
SL = BC - (AT * 2);

//Target Price
FTP = BC + (AT * 3);
STP = BC + (AT * 6);

Filter = BC;

``````

This is the code sorry for the first one pasted wrong

This code i want to apply in a monthly chart ..

Made the following changes in the code but still the buy price is coming as all 1 and stochastic crossover are not coming right. Please help me to correct the code below

``````//This exploration is made to scan stocks were the Beta > 1.1 and Stochastic Crossover

TimeFrameSet( inMonthly ); // switch to Monthly time frame

ticker = ParamStr("Ticker","nsenifty");
P = Foreign(ticker,"C",1);
Periods = Param("period",7,1,50,1);
AT = ATR(7);

// Calculation of Beta
Beta = ((Periods * Sum(ROC(C,1) * ROC(P,1),Periods)) - (Sum(ROC(C,1),Periods) * Sum(ROC(P,1),Periods))) /
((Periods * Sum((ROC(P,1)^2),Periods)) - (Sum(ROC(P,1),Periods)^2));

BC = Beta > 1.1 AND StochK(8,3) > StochD(8,3,3);

//Stop Loss
SL = BC - (AT * 2);

//Target Price
FTP = BC + (AT * 3);
STP = BC + (AT * 6);

Filter = BC;

``````

You need to set the time frame before defining your variables, restore it after defining them then expand them to the default time frame before applying a filter.

``````TimeFrameSet( inMonthly );

TimeFrameRestore();

BC = TimeFrameExpand( BC, inMonthly ) ;

Filter = BC;

``````
``````//This exploration is made to scan stocks were the Beta > 1.1 and Stochastic Crossover

TimeFrameSet( inMonthly ); // switch to Monthly time frame

ticker = ParamStr("Ticker","nsenifty");
P = Foreign(ticker,"C",1);
Periods = Param("period",7,1,50,1);
AT = ATR(7);

// Calculation of Beta
Beta = ((Periods * Sum(ROC(C,1) * ROC(P,1),Periods)) - (Sum(ROC(C,1),Periods) * Sum(ROC(P,1),Periods))) /
((Periods * Sum((ROC(P,1)^2),Periods)) - (Sum(ROC(P,1),Periods)^2));

BC = Beta > 1.1 AND StochK(8,3) > StochD(8,3,3);

//Stop Loss
SL = BC - (AT * 2);

//Target Price
FTP = BC + (AT * 3);
STP = BC + (AT * 6);

TimeFrameRestore();
BC = TimeFrameExpand(BC,inMonthly);

Filter = BC;

``````

I have made the following changes in the code but still when i run the exploration its showing BC as 1 and even when i check the charts its showing the sell stochastic crossovers. How to correct this ya ..help me out.

Hello Experts waiting for the necessary corrections.

I don't understand it yet.

Look at variable BC, its first defined here `BC = Beta > 1.1 AND ...`
This makes it of Type Boolean, that is 0 or 1

Now what are you trying to do here, as you are using BC arithmatically

``````SL = BC - (AT * 2);

//Target Price
FTP = BC + (AT * 3);
``````

What do you expect it to be? bcos it'll be 0 or 1, that is True or False and that's what you have applied the Filter to.
Filter variable filters only those results that are True or 1.