The following code results in getting in and out of a position on the same day when long, but not getting out until one or more days after entry when short, although the actions look "symmetrical" to me.
In other words, why doesn't a short position exit on the same day as entry?
The entire program is displayed below, after the following snippets of code displayed here to help explain the problem.
if (
close(-1) - open(-1) >= 0
) onAction1()
else if (
close(-1) - open(-1) < 0
) onAction2();
function onAction1() {
Strategy.doLong("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);
Strategy.doSell("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
vLastAlert = 1;
}
function onAction2() {
Strategy.doShort("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);
Strategy.doSell("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
vLastAlert = 2;
}
//****************ENTIRE PROGRAM******************
//{{EFSWizard_Description
//
// This formula was generated by the Alert Wizard
//
//}}EFSWizard_Description
//{{EFSWizard_Declarations
var vLastAlert = -1;
//}}EFSWizard_Declarations
function preMain() {
/**
* This function is called only once, before any of the bars are loaded.
* Place any study or EFS configuration commands here.
*/
//{{EFSWizard_PreMain
setPriceStudy(false);
setStudyTitle("joe junk test1 DEC4 ");
//}}EFSWizard_PreMain
}
function main() {
/**
* The main() function is called once per bar on all previous bars, once per
* each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
* in your preMain(), it is also called on every tick.
*/
//{{EFSWizard_Expressions
//{{EFSWizard_Expression_1
if (
close(-1) - open(-1) >= 0
) onAction1()
//}}EFSWizard_Expression_1
//{{EFSWizard_Expression_2
else if (
close(-1) - open(-1) < 0
) onAction2();
//}}EFSWizard_Expression_2
//}}EFSWizard_Expressions
//{{EFSWizard_Return
return null;
//}}EFSWizard_Return
}
function postMain() {
/**
* The postMain() function is called only once, when the EFS is no longer used for
* the current symbol (ie, symbol change, chart closing, or application shutdown).
*/
}
//{{EFSWizard_Actions
//{{EFSWizard_Action_1
function onAction1() {
Strategy.doLong("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);
Strategy.doSell("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
vLastAlert = 1;
}
//}}EFSWizard_Action_1
//{{EFSWizard_Action_2
function onAction2() {
Strategy.doShort("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);
Strategy.doSell("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
vLastAlert = 2;
}
//}}EFSWizard_Action_2
//}}EFSWizard_Actions
In other words, why doesn't a short position exit on the same day as entry?
The entire program is displayed below, after the following snippets of code displayed here to help explain the problem.
if (
close(-1) - open(-1) >= 0
) onAction1()
else if (
close(-1) - open(-1) < 0
) onAction2();
function onAction1() {
Strategy.doLong("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);
Strategy.doSell("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
vLastAlert = 1;
}
function onAction2() {
Strategy.doShort("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);
Strategy.doSell("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
vLastAlert = 2;
}
//****************ENTIRE PROGRAM******************
//{{EFSWizard_Description
//
// This formula was generated by the Alert Wizard
//
//}}EFSWizard_Description
//{{EFSWizard_Declarations
var vLastAlert = -1;
//}}EFSWizard_Declarations
function preMain() {
/**
* This function is called only once, before any of the bars are loaded.
* Place any study or EFS configuration commands here.
*/
//{{EFSWizard_PreMain
setPriceStudy(false);
setStudyTitle("joe junk test1 DEC4 ");
//}}EFSWizard_PreMain
}
function main() {
/**
* The main() function is called once per bar on all previous bars, once per
* each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
* in your preMain(), it is also called on every tick.
*/
//{{EFSWizard_Expressions
//{{EFSWizard_Expression_1
if (
close(-1) - open(-1) >= 0
) onAction1()
//}}EFSWizard_Expression_1
//{{EFSWizard_Expression_2
else if (
close(-1) - open(-1) < 0
) onAction2();
//}}EFSWizard_Expression_2
//}}EFSWizard_Expressions
//{{EFSWizard_Return
return null;
//}}EFSWizard_Return
}
function postMain() {
/**
* The postMain() function is called only once, when the EFS is no longer used for
* the current symbol (ie, symbol change, chart closing, or application shutdown).
*/
}
//{{EFSWizard_Actions
//{{EFSWizard_Action_1
function onAction1() {
Strategy.doLong("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);
Strategy.doSell("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
vLastAlert = 1;
}
//}}EFSWizard_Action_1
//{{EFSWizard_Action_2
function onAction2() {
Strategy.doShort("", Strategy.MARKET, Strategy.THISBAR, Strategy.DEFAULT, 0);
Strategy.doSell("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
vLastAlert = 2;
}
//}}EFSWizard_Action_2
//}}EFSWizard_Actions
Comment