The script works however in real time without SetComputeonClose() there is a minor problem.
There is a condition that states;
if (close() > Previous Donchian Channel UPPER){
then do the following.... see code.
If however the market moves one tick above the Previous Donchian Channel UPPER and then turns and moves down and the close of the candle is not higher then Previous Donchian Channel UPPER the computation should not be done.
Is there any other way to do what I want without using SetComputeonClose().
I use the script on a four hour chart.
I would like it to update in real time but properly.
Thank you for any help
Here is the code:
var StopA;
var vstart = "true";
function preMain() {
setStudyTitle("SATR Range Stop");
setDefaultBarFgColor(Color.red, 0);
setCursorLabelName("SP AVG", 0);
setPriceStudy(true);
var fp1 = new FunctionParameter("DCHLength1", FunctionParameter.NUMBER);
fp1.setName("DCH SATR Length"); //6 on a four hour gives a 24hr True Range
fp1.setLowerLimit(1);
fp1.setDefault(6);
var fp2 = new FunctionParameter("Spread", FunctionParameter.NUMBER);
fp2.setName("Spread");
fp2.setLowerLimit(.0001);
fp2.setDefault(.0004);
var fp3 = new FunctionParameter("DCHLength", FunctionParameter.NUMBER);
fp3.setName("DCH Length"); //1 week channel on 4 hour chart
fp3.setLowerLimit(1);
fp3.setDefault(30);
var fp4 = new FunctionParameter("vATR_Start", FunctionParameter.NUMBER);
fp4.setName("SATR Start");
fp4.setLowerLimit(2);
fp4.setDefault(2);
var fp5 = new FunctionParameter("vATR_Finish", FunctionParameter.NUMBER);
fp5.setName("SATR Finish");
fp5.setLowerLimit(2);
fp5.setDefault(20); // 80 Hours on 4 hour chart - 120 Hours equls 1 week
}
function main(vATR_Start, vATR_Finish, DCHLength, DCHLength1, Spread) {
var vValue1, vValue2, vValue3, vValue4, avg;
if (getBarState() == BARSTATE_ALLBARS) {
myDCHstudy1 = new DonchianStudy(DCHLength1, 0);
myDCHstudy2 = new DonchianStudy(DCHLength, 0);
}
vValue1 = myDCHstudy1.getValue(DonchianStudy.UPPER, 0, -vATR_Finish);
vValue2 = myDCHstudy1.getValue(DonchianStudy.LOWER, 0, -vATR_Finish);
vValue3 = myDCHstudy2.getValue(DonchianStudy.UPPER, 0, -2);
vValue4 = myDCHstudy2.getValue(DonchianStudy.LOWER, 0, -2);
if (vValue1 == null || vValue2 == null || vValue3 == null || vValue4 == null) return;
var Len1 = vATR_Finish - vATR_Start+1
var Len2 = vATR_Start;
var Len3 = 8
if (vstart == "true"){
SATR = new Array(Len1);
Sum = new Array(Len1);
Stop = new Array(Len3);
for(i = 0; i < Len1; i++)
SATR[i] = 0;
for(i = 0; i < Len3; i++)
Stop[i] = 0;
vstart ="false";
}
if (close() > vValue3[1]){
var avgSum = 0;
for(i = 0; i < Len1; i++)
Sum[i] = 0;
for(j = 0; j < Len1; j++){
for(i = 0; i < Len2; i++){
Sum[j] += (vValue1[i] + Spread - vValue2[i]);
}
SATR[j] = Sum[j] / (Len2);
Len2 = Len2 + 1;
}
for(k = 0; k < Len1; k++)
avgSum += SATR[k];
avg = avgSum/(Len1);
StopA = vValue3[0] - avg
}
if (close() < vValue4[1]){
var avgSum = 0;
for(i = 0; i < Len1; i++)
Sum[i] = 0;
for(j = 0; j < Len1; j++){
for(i = 0; i < Len2; i++){
Sum[j] += (vValue1[i] + Spread - vValue2[i]);
}
SATR[j] = Sum[j] / (Len2);
Len2 = Len2 + 1;
}
for(k = 0; k < Len1; k++)
avgSum += SATR[k];
avg = avgSum/(Len1);
StopA = vValue4[0] + avg;
}
return (StopA);
}
There is a condition that states;
if (close() > Previous Donchian Channel UPPER){
then do the following.... see code.
If however the market moves one tick above the Previous Donchian Channel UPPER and then turns and moves down and the close of the candle is not higher then Previous Donchian Channel UPPER the computation should not be done.
Is there any other way to do what I want without using SetComputeonClose().
I use the script on a four hour chart.
I would like it to update in real time but properly.
Thank you for any help
Here is the code:
var StopA;
var vstart = "true";
function preMain() {
setStudyTitle("SATR Range Stop");
setDefaultBarFgColor(Color.red, 0);
setCursorLabelName("SP AVG", 0);
setPriceStudy(true);
var fp1 = new FunctionParameter("DCHLength1", FunctionParameter.NUMBER);
fp1.setName("DCH SATR Length"); //6 on a four hour gives a 24hr True Range
fp1.setLowerLimit(1);
fp1.setDefault(6);
var fp2 = new FunctionParameter("Spread", FunctionParameter.NUMBER);
fp2.setName("Spread");
fp2.setLowerLimit(.0001);
fp2.setDefault(.0004);
var fp3 = new FunctionParameter("DCHLength", FunctionParameter.NUMBER);
fp3.setName("DCH Length"); //1 week channel on 4 hour chart
fp3.setLowerLimit(1);
fp3.setDefault(30);
var fp4 = new FunctionParameter("vATR_Start", FunctionParameter.NUMBER);
fp4.setName("SATR Start");
fp4.setLowerLimit(2);
fp4.setDefault(2);
var fp5 = new FunctionParameter("vATR_Finish", FunctionParameter.NUMBER);
fp5.setName("SATR Finish");
fp5.setLowerLimit(2);
fp5.setDefault(20); // 80 Hours on 4 hour chart - 120 Hours equls 1 week
}
function main(vATR_Start, vATR_Finish, DCHLength, DCHLength1, Spread) {
var vValue1, vValue2, vValue3, vValue4, avg;
if (getBarState() == BARSTATE_ALLBARS) {
myDCHstudy1 = new DonchianStudy(DCHLength1, 0);
myDCHstudy2 = new DonchianStudy(DCHLength, 0);
}
vValue1 = myDCHstudy1.getValue(DonchianStudy.UPPER, 0, -vATR_Finish);
vValue2 = myDCHstudy1.getValue(DonchianStudy.LOWER, 0, -vATR_Finish);
vValue3 = myDCHstudy2.getValue(DonchianStudy.UPPER, 0, -2);
vValue4 = myDCHstudy2.getValue(DonchianStudy.LOWER, 0, -2);
if (vValue1 == null || vValue2 == null || vValue3 == null || vValue4 == null) return;
var Len1 = vATR_Finish - vATR_Start+1
var Len2 = vATR_Start;
var Len3 = 8
if (vstart == "true"){
SATR = new Array(Len1);
Sum = new Array(Len1);
Stop = new Array(Len3);
for(i = 0; i < Len1; i++)
SATR[i] = 0;
for(i = 0; i < Len3; i++)
Stop[i] = 0;
vstart ="false";
}
if (close() > vValue3[1]){
var avgSum = 0;
for(i = 0; i < Len1; i++)
Sum[i] = 0;
for(j = 0; j < Len1; j++){
for(i = 0; i < Len2; i++){
Sum[j] += (vValue1[i] + Spread - vValue2[i]);
}
SATR[j] = Sum[j] / (Len2);
Len2 = Len2 + 1;
}
for(k = 0; k < Len1; k++)
avgSum += SATR[k];
avg = avgSum/(Len1);
StopA = vValue3[0] - avg
}
if (close() < vValue4[1]){
var avgSum = 0;
for(i = 0; i < Len1; i++)
Sum[i] = 0;
for(j = 0; j < Len1; j++){
for(i = 0; i < Len2; i++){
Sum[j] += (vValue1[i] + Spread - vValue2[i]);
}
SATR[j] = Sum[j] / (Len2);
Len2 = Len2 + 1;
}
for(k = 0; k < Len1; k++)
avgSum += SATR[k];
avg = avgSum/(Len1);
StopA = vValue4[0] + avg;
}
return (StopA);
}
Comment