I'm having a problem with my script sending trades to the Strategy Analyzer. Here is the code with the Strategy commands. The trades show up on the chart and I used debugPrintln to confirm trade entry and exit prices and times. (I can post all 250 lines of code but I assumed the problem was in this section.
Also, will I have any problem leaving the Statagey functions (once they are fixed) and executing broker functions in the same script?
PHP Code:
if (nLast >= nSelStop) { // this is the short trade
nBars = 1;
myEntry = nBid;
Strategy.doShort("short", Strategy.LIMIT, Strategy.THISBAR , nSize, myEntry);
myPT = (myEntry - nTGT*nTick);
mySL = (myEntry + nSTP*nTick);
DrawLn(nBars, myEntry, myPT, mySL);
vTrade = "short";
bInTrade = true;
debugPrintln(gTime()+" "+vTrade+" at "+myEntry.toFixed(2)+" PT="+myPT.toFixed(2)+" SL="+mySL.toFixed(2)+" "+sTime());
debugPrintln("short "+nSize+" is "+Strategy.isShort());
} else if (nLast <= nBuyStop) { // this is a long trade
nBars = 1;
myEntry = nAsk;
Strategy.doLong("long", Strategy.LIMIT, Strategy.THISBAR , nSize, myEntry);
myPT = (myEntry + nTGT*nTick);
mySL = (myEntry - nSTP*nTick);
DrawLn(nBars, myEntry, myPT, mySL);
vTrade = "long";
bInTrade = true;
debugPrintln(gTime()+" "+vTrade+" at "+myEntry.toFixed(2)+" PT="+myPT.toFixed(2)+" SL="+mySL.toFixed(2)+" "+sTime());
debugPrintln("long "+nSize+" is "+Strategy.isLong());
} // End test for setting entry stops
if(bInTrade == true) { // get rid of the buy/sell triggers if new trade
if (soundoff == false) Alert.playSound( "Ding.wav" );
removeShape("ss");
removeShape("bs");
removeText("s1");
removeText("b1");
}
} else if (bInTrade == true) { // we are in a trade check for PT or SL exit
DrawLn(nBars, myEntry, myPT, mySL);
if (vTrade == "short" && nLast <= myPT) {
debugPrintln("Strategy is in trade = "+Strategy.isInTrade() + " and bInTrade is "+bInTrade+" at "+sTime() );
Strategy.doCover( "Short W", Strategy.STOP, Strategy.THISBAR , nSize, nLast);
debugPrintln(gTime()+" Short Win, bars in trade="+nBars);
vWL = "W"
bInTrade = false;
}
if (vTrade == "short" && nLast >= mySL) {
debugPrintln("Strategy is in trade = "+Strategy.isInTrade() + " and bInTrade is "+bInTrade+" at "+sTime() );
Strategy.doCover( "Short L", Strategy.STOP, Strategy.THISBAR , nSize, nLast);
debugPrintln(gTime()+" Short Loss, bars in trade="+nBars);
vWL = "L"
bInTrade = false;
}
if (vTrade == "long" && nLast >= myPT) {
debugPrintln("Strategy is in trade = "+Strategy.isInTrade() + " and bInTrade is "+bInTrade+" at "+sTime() );
Strategy.doSell( "Long W", Strategy.STOP, Strategy.THISBAR , nSize, nLast);
debugPrintln(gTime()+" Long Win, bars in trade="+nBars);
vWL = "W"
bInTrade = false;
}
if (vTrade == "long" && nLast <= mySL) {
debugPrintln("Strategy is in trade = "+Strategy.isInTrade() + " and bInTrade is "+bInTrade+" at "+sTime() );
Strategy.doSell( "Long L", Strategy.STOP, Strategy.THISBAR , nSize, nLast);
debugPrintln(gTime()+" Long Loss, bars in trade="+nBars);
vWL = "L"
bInTrade = false;
}
Also, will I have any problem leaving the Statagey functions (once they are fixed) and executing broker functions in the same script?
Comment