I have coded the following logic for four different scenarios, yet my formula is not entering any trades. It looks fairly simple to me - am I missing something?
if (/*Long to Open Condition - Condition 1*/)) {
if (Strategy.isInTrade() == true) {
if (Strategy.isShort() == true) {
nNewTrade = 1; // Issue new Trade Trigger
nsignal = 1; // Signal 1 Opens a Long if not already in an open Long & Closes a Short if we are in a short
}
else if (Strategy.isLong() == true) {
nNewTrade = 0; // Issue NO new Trade Trigger
}
}
else if (Strategy.isInTrade() == false) {
nNewTrade = 1; // Issue new Trade Trigger
nsignal = 1; // Signal 1 Opens a Long if not already in an open Long & Closes a Sshort if we are in a short
}
}
if (/*Long to Close Condition - Condition 2*/) {
nNewTrade = 1; // Issue new Trade Trigger
nsignal = 2; // Signal 2 closes an open long and does NOT re-open another trade
}
if (/*Short to Open Condition - Condition 3*/) {
if (Strategy.isInTrade() == true) {
if (Strategy.isLong() == true) {
nNewTrade = 1; // Issue new Trade Trigger
nsignal = 3; // Signal 3 Opens a Short if not already in an open Short & Closes a Long if we are in a Long
}
else if (Strategy.isShort() == true) {
nNewTrade = 0; // Issue NO new Trade Trigger
}
}
else if (Strategy.isInTrade() == false) {
nNewTrade = 1; // Issue new Trade Trigger
nsignal = 3; // Signal 3 Opens a Short if not already in an open Short & Closes a Long if we are in a Long
}
}
if (/*Short to Close Condition - Condition 4*/) {
nNewTrade = 1; // Issue new Trade Trigger
nsignal = 4; // Signal closes an open Short and does NOT re-open another trade
}
/*----------------------------------------------------------------
// Execute Trades ONLY if nNewTrade is triggered ....
----------------------------------------------------------------- */
if (nNewTrade == 1) { //Execute New Trade
__if (Strategy.isInTrade() == true) {
if ((nsignal == 1) && (Strategy.isShort() == true)) {
Strategy.doLong("Exit Short & Rev Long", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);
}
}
if (Strategy.isInTrade() == true) {
if ((nsignal == 3) && (Strategy.isLong() == true)) {
Strategy.doShort("Exit Long & Rev Short", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);
}
}
// Closing Open Signals
if (Strategy.isInTrade() == true) {
if ((nsignal == 2) && (Strategy.isLong() == true)) {
Strategy.doSell("Exit Long & Wait", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);
}
}
if (Strategy.isInTrade() == true) {
if ((nsignal == 4) && (Strategy.isShort() == true)) {
Strategy.doCover("Cover Short & Wait", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);
}
}
if (Strategy.isInTrade() == false) {
if (nsignal == 1) {
Strategy.doLong("Go Long", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);
}
if (nsignal == 3) {
Strategy.doShort("Go Short", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);
}
} // end if IN TRADE is false
nNewTrade == 0;
} // END EXECUTE NEW TRADE
Also, in trying to debug the code, I am using
debugPrintln("This number equals: " + n);
which I believe outputs the value of n to the "debug console". Can anyone tell me where the "debug console" is ?
Many thanks.
Deax.
if (/*Long to Open Condition - Condition 1*/)) {
if (Strategy.isInTrade() == true) {
if (Strategy.isShort() == true) {
nNewTrade = 1; // Issue new Trade Trigger
nsignal = 1; // Signal 1 Opens a Long if not already in an open Long & Closes a Short if we are in a short
}
else if (Strategy.isLong() == true) {
nNewTrade = 0; // Issue NO new Trade Trigger
}
}
else if (Strategy.isInTrade() == false) {
nNewTrade = 1; // Issue new Trade Trigger
nsignal = 1; // Signal 1 Opens a Long if not already in an open Long & Closes a Sshort if we are in a short
}
}
if (/*Long to Close Condition - Condition 2*/) {
nNewTrade = 1; // Issue new Trade Trigger
nsignal = 2; // Signal 2 closes an open long and does NOT re-open another trade
}
if (/*Short to Open Condition - Condition 3*/) {
if (Strategy.isInTrade() == true) {
if (Strategy.isLong() == true) {
nNewTrade = 1; // Issue new Trade Trigger
nsignal = 3; // Signal 3 Opens a Short if not already in an open Short & Closes a Long if we are in a Long
}
else if (Strategy.isShort() == true) {
nNewTrade = 0; // Issue NO new Trade Trigger
}
}
else if (Strategy.isInTrade() == false) {
nNewTrade = 1; // Issue new Trade Trigger
nsignal = 3; // Signal 3 Opens a Short if not already in an open Short & Closes a Long if we are in a Long
}
}
if (/*Short to Close Condition - Condition 4*/) {
nNewTrade = 1; // Issue new Trade Trigger
nsignal = 4; // Signal closes an open Short and does NOT re-open another trade
}
/*----------------------------------------------------------------
// Execute Trades ONLY if nNewTrade is triggered ....
----------------------------------------------------------------- */
if (nNewTrade == 1) { //Execute New Trade
__if (Strategy.isInTrade() == true) {
if ((nsignal == 1) && (Strategy.isShort() == true)) {
Strategy.doLong("Exit Short & Rev Long", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);
}
}
if (Strategy.isInTrade() == true) {
if ((nsignal == 3) && (Strategy.isLong() == true)) {
Strategy.doShort("Exit Long & Rev Short", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);
}
}
// Closing Open Signals
if (Strategy.isInTrade() == true) {
if ((nsignal == 2) && (Strategy.isLong() == true)) {
Strategy.doSell("Exit Long & Wait", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);
}
}
if (Strategy.isInTrade() == true) {
if ((nsignal == 4) && (Strategy.isShort() == true)) {
Strategy.doCover("Cover Short & Wait", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);
}
}
if (Strategy.isInTrade() == false) {
if (nsignal == 1) {
Strategy.doLong("Go Long", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);
}
if (nsignal == 3) {
Strategy.doShort("Go Short", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);
}
} // end if IN TRADE is false
nNewTrade == 0;
} // END EXECUTE NEW TRADE
Also, in trying to debug the code, I am using
debugPrintln("This number equals: " + n);
which I believe outputs the value of n to the "debug console". Can anyone tell me where the "debug console" is ?
Many thanks.
Deax.
Comment