Hi Shahariar,
For the first question, I believe it would simply be the ROC (rate of
change) function:
PriceChange = ROC(Close, iDaysToLookBack);
//you want to detect times when there is a greater than 4% loss (more
negative, so less than -4)
Sell = PriceChange < -4;
For the second question, if you want to look back more than just
yesterday, that is, compare today's Close to 2 days ago's Close, or
today's Close to 3 day ago's Close, then you can use something like my
code below. Try playing with the parameters of the Plots with the
sliders in the Parameters section when you apply it to a chart and right
click the indicator and choose Parameters. Then slide the values around.
If you set iPercentChange to 20 and DaysToLookBack to 10, this would
plot the percent change between today's close and the close 20 bar's
ago. It would also plot a signal showing when the 20 bar percent change
was more negative than the value you put into PercentChange variable.
//"i" in front of Params stands for "input"
iPercentChange = Param("PercentChange", 4, 0.1, 50, 0.1);
iDaysToLookBack = Param("DaysToLookBack", 1, 1, 200, 1);
PriceChange = ROC(Close, iDaysToLookBack);
//you want to detect times when there is a greater than 4% loss (more
negative, so less than -4)
Sell = PriceChange < -iPercentChange;
//apply to chart and have fun playing with Param sliders under
Parameters rightclick menu on indicator
Plot(PriceChange, "priceChange", colorTan, styleHistogram);
//plots Sell variable when it is true
Plot(Sell, "sell", colorRed, styleThick | styleLine | styleOwnScale);
Hope that helps.
-Paul
--- In [email protected], "shahariar4" <shahari...@...> wrote:
>
> If may pricechange cond is
>
> Pricechange=(Cg-Ref(Cg,-1))*100/Ref(Cg,-1);
>
> I want to add a sell signal when price has fallen more than 4%
>
> This can be done as
>
> Sell=!Pricechange>4;or Sell=-Pricechange>4 ( 1. which one is correct?)
>
> 2. But i want to set the sell signal as even in cumulative
pricechage;suppose in 4 cumulative days price has fallen 4% (not on a
single day) then how to code that? or keeping the number of days
open(like i can change the days number 4 or 5 or as many as i want)?
>
> Can anyone pls tell me?
>