Announcement

Collapse
No announcement yet.

Trades not executing

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trades not executing

    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.

    PHP Code:
            if (nLast >= nSelStop) {                // this is the short trade  
                
    nBars 1
                
    myEntry nBid;
                
    Strategy.doShort("short"Strategy.LIMITStrategy.THISBAR nSizemyEntry);
                
    myPT = (myEntry nTGT*nTick);
                
    mySL = (myEntry nSTP*nTick);
                
    DrawLn(nBarsmyEntrymyPTmySL);
                
    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.LIMITStrategy.THISBAR nSizemyEntry);
                
    myPT = (myEntry nTGT*nTick);
                
    mySL = (myEntry nSTP*nTick);
                
    DrawLn(nBarsmyEntrymyPTmySL);            
                
    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 == falseAlert.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(nBarsmyEntrymyPTmySL);

            if (
    vTrade == "short" && nLast <= myPT) {
            
    debugPrintln("Strategy is in trade = "+Strategy.isInTrade() + " and bInTrade is "+bInTrade+" at "+sTime() );
                
    Strategy.doCover"Short W"Strategy.STOPStrategy.THISBAR nSizenLast);
                
    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.STOPStrategy.THISBAR nSizenLast);
                
    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.STOPStrategy.THISBAR nSizenLast);
                
    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.STOPStrategy.THISBAR nSizenLast);
                
    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?

  • #2
    The first thing I would suggest is you check the HIGH and LOW of the bars you are trying to execute on to determine if the price you want to execute AT is available. The esignal backtester will not execute the trade if the price is not available on the bar.

    The way I handle it is as follows :

    PHP Code:

    var myEntryPrice 25.00;

    if ((
    high() >= myEntryPrice) && (low() <= myEntryPrice)) {
      
    //price bar spans the price I'm trying to enter at
       
    Strategy.doShort("short"Strategy.LIMITStrategy.THISBAR 10myEntryPrice);


    } else {
      
    //price bar does not span my price, enter at open
       
    Strategy.doShort("short"Strategy.LIMITStrategy.THISBAR 10open());



    Hope this helps??
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Brad, thanks for the input.

      I thought I had that covered. Elsewhere I'm Getting Last and MostRecent Bid and Ask. My triggers are based on last trade. So if Last is > my sell stop, I will sell at the Most Recent Bid.

      For longs if Last < buy stop then buy the Ask.

      I didn't think of the Analyzer not having bid/ask data, any suggestion for a workaround? I want to preserve that part of the logic for testing with the broker functions.

      Comment

      Working...
      X