hello !
i´m playing a little bit with strategycoding.
i got something together, but i have a problem to code
that if the signalbar was valid, the system should wait until we got a price that was 2 points higher then the high of the signalbar (for longtrades) or 2 point lower then the low (for shorttrades).
i´m not sure, on what place i have to insert this coding.
i tryed to change the tradeentryprice-rule and as a aditional rule for the valid signal.
the best would be, if i could make a variable, that i get as soon i had a valid signalbar. then i could use the variable for the second requirement.
it would be great if you could help me.
thank you
************************************************** **
var nNewTrade;
var nsignal;
var nTradeEntryPrice;
var ProfitTarget1 = 20.0;
function premain() {
setPriceStudy(true);
setStudyTitle("Sample Profit Code");
setCursorLabelName("PT CODE");
}
function main() {
if ((Strategy.isInTrade() == true) && (nNewTrade == 1)) {
nTradeEntryPrice = open();
nNewTrade = 0;
}
if ((Strategy.isInTrade() == true) && (Strategy.isShort() == true)) {
if (low() <= (nTradeEntryPrice - ProfitTarget1)) {
Strategy.doCover("Short PT1 Exit", Strategy.STOP, Strategy.THISBAR, Strategy.getDefaultLotSize(), (nTradeEntryPrice - ProfitTarget1));
}
}
if ((Strategy.isInTrade() == true) && (Strategy.isLong() == true)) {
if (high() >= (nTradeEntryPrice + ProfitTarget1)) {
Strategy.doSell("Long PT1 Exit", Strategy.STOP, Strategy.THISBAR, Strategy.getDefaultLotSize(), (nTradeEntryPrice + ProfitTarget1));
}
}
if (Strategy.isInTrade() == false) {
if ((high()-low()) > 12.5 && close() >= open() && open()-low() > high()-close() && open()-low() >= close()-open() && close() > ((high()+low())/2) && low() < low(-1)) {
nNewTrade = 1;
nsignal = 1;
}
if ((high()-low()) > 12.5 && close() >= open() && high()-close() > open()-low() && high()-close() >= close()-open() && open() < ((high()+low())/2) && high() > high(-1)) {
nNewTrade = 1;
nsignal = -1;
}
}
if (nNewTrade == 1) {
if (Strategy.isInTrade() == true) {
if ((nsignal > 0) && (Strategy.isShort() == true)) {
Strategy.doCover("Exit Short", Strategy.MARKET, Strategy.NEXTBAR);
Strategy.doLong("Rev Long", Strategy.MARKET, Strategy.NEXTBAR);
}
if ((nsignal < 0) && (Strategy.isLong() == true)) {
Strategy.doSell("Exit Long", Strategy.MARKET, Strategy.NEXTBAR);
Strategy.doShort("Rev Short", Strategy.MARKET, Strategy.NEXTBAR);
}
} else {
if ((nsignal > 0)) {
Strategy.doLong("Go Long", Strategy.MARKET, Strategy.NEXTBAR);
}
if ((nsignal < 0)) {
Strategy.doShort("Go Short", Strategy.MARKET, Strategy.NEXTBAR);
}
}
}
}
i´m playing a little bit with strategycoding.
i got something together, but i have a problem to code
that if the signalbar was valid, the system should wait until we got a price that was 2 points higher then the high of the signalbar (for longtrades) or 2 point lower then the low (for shorttrades).
i´m not sure, on what place i have to insert this coding.
i tryed to change the tradeentryprice-rule and as a aditional rule for the valid signal.
the best would be, if i could make a variable, that i get as soon i had a valid signalbar. then i could use the variable for the second requirement.
it would be great if you could help me.
thank you
************************************************** **
var nNewTrade;
var nsignal;
var nTradeEntryPrice;
var ProfitTarget1 = 20.0;
function premain() {
setPriceStudy(true);
setStudyTitle("Sample Profit Code");
setCursorLabelName("PT CODE");
}
function main() {
if ((Strategy.isInTrade() == true) && (nNewTrade == 1)) {
nTradeEntryPrice = open();
nNewTrade = 0;
}
if ((Strategy.isInTrade() == true) && (Strategy.isShort() == true)) {
if (low() <= (nTradeEntryPrice - ProfitTarget1)) {
Strategy.doCover("Short PT1 Exit", Strategy.STOP, Strategy.THISBAR, Strategy.getDefaultLotSize(), (nTradeEntryPrice - ProfitTarget1));
}
}
if ((Strategy.isInTrade() == true) && (Strategy.isLong() == true)) {
if (high() >= (nTradeEntryPrice + ProfitTarget1)) {
Strategy.doSell("Long PT1 Exit", Strategy.STOP, Strategy.THISBAR, Strategy.getDefaultLotSize(), (nTradeEntryPrice + ProfitTarget1));
}
}
if (Strategy.isInTrade() == false) {
if ((high()-low()) > 12.5 && close() >= open() && open()-low() > high()-close() && open()-low() >= close()-open() && close() > ((high()+low())/2) && low() < low(-1)) {
nNewTrade = 1;
nsignal = 1;
}
if ((high()-low()) > 12.5 && close() >= open() && high()-close() > open()-low() && high()-close() >= close()-open() && open() < ((high()+low())/2) && high() > high(-1)) {
nNewTrade = 1;
nsignal = -1;
}
}
if (nNewTrade == 1) {
if (Strategy.isInTrade() == true) {
if ((nsignal > 0) && (Strategy.isShort() == true)) {
Strategy.doCover("Exit Short", Strategy.MARKET, Strategy.NEXTBAR);
Strategy.doLong("Rev Long", Strategy.MARKET, Strategy.NEXTBAR);
}
if ((nsignal < 0) && (Strategy.isLong() == true)) {
Strategy.doSell("Exit Long", Strategy.MARKET, Strategy.NEXTBAR);
Strategy.doShort("Rev Short", Strategy.MARKET, Strategy.NEXTBAR);
}
} else {
if ((nsignal > 0)) {
Strategy.doLong("Go Long", Strategy.MARKET, Strategy.NEXTBAR);
}
if ((nsignal < 0)) {
Strategy.doShort("Go Short", Strategy.MARKET, Strategy.NEXTBAR);
}
}
}
}
Comment