Announcement

Collapse
No announcement yet.

Buying and selling in a backtest?

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

  • Buying and selling in a backtest?

    I'm not sure what i'm doing wrong here I've tried everything, in this code if i have going long and short it looks ok but if i just want to have it short and covering but not going long it doesn't recognize going short, could anybody tell me what i'm doing wrong?
    Attached Files

  • #2
    I believe you have to use Strategy.doCover or Strategy.doSell which will close your position.

    Comment


    • #3
      yeah i was about to post that i figured it out...thanks though

      Comment


      • #4
        actually does something look wrong with this code ?

        if (Strategy.isInTrade() == true && (Strategy.isShort() == true)) {
        hi = high();
        if ((hi - nTradeEntryPrice) > .005){
        nStopLevel = hi;
        Strategy.doCover("Loss stop out", Strategy.STOP, Strategy.THISBAR, nStopLevel);
        }
        }

        Comment


        • #5
          You will probably figure this out ... the only thing that I see that you could add is a Strategy.ALL flag. Otherwise, all looks well... your command structure is similar to working code I have.

          One other implementation of the strategy that I use is Strategy.doCover(sAction,Strategy.CLOSE, Strategy.THISBAR,Strategy.ALL) where sAction is my text message. I use this to exit at the end of trading hours.

          btw, unusual avatar

          Comment


          • #6
            That Avatar is just what I needed to break the ice this morning.
            LOL

            To funny
            Excellent book on JavaScript for beginners

            Comment


            • #7
              thanks for the compliments on the avatar, it was either that one or the fat kid going crazy...anyways i thought it looked good too but if i comment out that stop the code works fine, but if i leave it in the indicator doesn't show up...any ideas?
              Attached Files

              Comment

              Working...
              X