♥ 0 |
Hi Pete, Please help setting up scan for Buy and Sell with following conditions: Scan for Buy: KPeriod and DPeriod must both be below “20” (over_sold) and cross over. Scan for Sell: KPeriod and DPeriod must both be above “80” (over_bought) and cross over. Here’s the StochasticFast: # declare lower; input over_bought = 80; plot FastK = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 1, averageType).FullK; def upK = FastK crosses above OverSold; plot UpSignal;
Marked as spam
|
Private answer
This is a very common request and a search of our Q&A forum should turn up numerous examples you can use. https://www.hahn-tech.com/ans/stochastic-1-and-4-hour-scan/ https://www.hahn-tech.com/ans/macd-stochastics-scan/ https://www.hahn-tech.com/thinkorswim-custom-scan-stochastic-macd/ Marked as spam
|
|||
Private answer
In response to Kim’s reply on August 18th, here is the solution I would use. I examined Kim’s code and found it jumps through a lot of hoops that I find unnecessary. If you check if FullD of the previous bar is above overbought or below oversold, you already know that FullK is also in that condition, because it is on the other side of FullD before the cross. So just create the statements that define the crosses and then check for when a cross has occurred. The final condition is to check if FullD was in correct relation to overbought/oversold on the bar immediately prior to the cross. I am sure this has already been demonstrated on the site. Everyone seems to find a use for this sort of thing. So I suppose adding one more solution on this topic will make it that much easier for folks to find.
Marked as spam
|
Please log in to post questions.
Pete, please check the code below to see if my logic correct. Thank you!
————-
declare lower;
input over_bought = 80;
input over_sold = 20;
input KPeriod = 14;
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input averageType = AverageType.SIMPLE;
def FastK = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 1, averageType).FullK;
def FastD = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 1, averageType).FullD;
def OverBought = over_bought;
def OverSold = over_sold;
def pivotLowFastK = FastK[2] > FastK[1] and FastK[1] < FastK and FastK < OverSold; def pivotLowFastD = FastD[2] > FastD[1] and FastD[1] < FastD and FastD < OverSold; def pivotHighFastK = FastK[2] < FastK[1] and FastK[1] > FastK and FastK > OverBought;
def pivotHighFastD = FastD[2] < FastD[1] and FastD[1] > FastD and FastD > OverBought;
def lastPivotLowPriceFastK = if pivotLowFastK then FastK[1] else if FastK < OverSold then lastPivotLowPriceFastK[1] else FastK; def lastPivotLowPriceFastD = if pivotLowFastD then FastD[1] else if FastD < OverSold then lastPivotLowPriceFastD[1] else FastD; def lastPivotHighPriceFastK = if pivotHighFastK then FastK[1] else if FastK > OverBought then lastPivotHighPriceFastK[1] else FastK;
def lastPivotHighPriceFastD = if pivotHighFastD then FastD[1] else if FastD > OverBought then lastPivotHighPriceFastD[1] else FastD;
# use this to scan for FastK & FastD pivot low cross but still below OverSold
plot scan = lastPivotLowPriceFastK crosses above lastPivotLowPriceFastD and FastK < OverSold and FastD < OverSold; # use this to scan for FastK & FastD pivot high cross but still above OverBought #plot scan = lastPivotHighPriceFastK crosses below lastPivotHighPriceFastD and FastK > OverBought and FastD > OverBought;