• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Equity curve SMA

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

    Equity curve SMA

    Hi,

    I would like to add simple moving average (SMA) to my equity curve in a backtest.
    I would like to disable opening new positions when my equity curve is below equity SMA and enable opening new positions when equity curve is above equity SMA.

    As you could note strategy shall simulate every position in order to build equity curve but include in backtest results only these trades which meet "above equity SMA" requirement.

    #2
    Hello,

    Thanks for the note.

    You would need to do this using this to access to Performance staticstiv information. Run this through an SMA and then use a condition on your entries to trade or not to trade if above or below the SMA value.

    http://www.ninjatrader.com/support/h...collection.htm

    Please see this sample as well which will get you started.

    http://www.ninjatrader.com/support/f...ead.php?t=4084

    Let me know if any questions.

    -Brett
    BrettNinjaTrader Product Management

    Comment


      #3
      Thanks for quick reply.

      What you mean by "Run this through an SMA"? Please clarify in details.

      Comment


        #4
        Hello,

        You can turn the PnL into a DataSeries and run it throught the SMA indicator to output a value that would be your SMA price.

        SMA( YourTradePerformanceThisBar, 14);

        http://www.ninjatrader.com/support/f...ead.php?t=7299

        Use this sample for starting the performance data into a DataSeries Object.

        Then use this sample to use SMA.

        http://www.ninjatrader.com/support/h...simple_sma.htm

        -Brett
        BrettNinjaTrader Product Management

        Comment


          #5
          Hi,

          If I understand right this will help me to stop opening new positions when my equity curve drops below equity SMA.
          In that case how it will be possible to resume opening new positions?

          Comment


            #6
            Hello,

            You would need to write code to basically decide when you want to reset these conditions to allow trading again.

            if (I want to start trading again)
            {

            Reset PnL counts to allow trading again

            }

            -Brett
            BrettNinjaTrader Product Management

            Comment


              #7
              Hi Brett,

              I am not sure if we understand each other.

              Please find below an example (SMA period = 5):

              1. trade -> 200 USD profit / equity = 200 USD
              2. trade -> 100 USD profit / equity = 300 USD
              3. trade -> -100 USD loss / equity = 200 USD
              4. trade -> -100 USD loss / equity = 100 USD
              5. trade -> 200 USD profit / equity = 300 USD / equity SMA (5) = 220 USD

              Equity is above equity SMA so I can trade:
              6. trade -> 100 USD profit / equity = 400 USD / equity SMA (5) = 260 USD

              My equity is above equity SMA so I can trade:
              7. trade -> -200 USD loss / equity = 200 USD / equity SMA (5) = 240 USD

              Equity is below equity SMA so I stop trading, but I have to simulate trades in order to build equity curve.

              8. trade (simulated only, "paper" trade) -> 100 USD profit / equity = 300 USD / equity SMA (5) = 260 USD

              Equity curve is above equity SMA again so I can trade again:
              9. trade -> 100 USD profit / equity = 400 USD / equity SMA (5) = 320 USD

              ...

              Please note that I build equity and equity SMA with every trade but my real equity is 300 USD.

              I trade every trade above except 8. one so my backtest result shall be 300 USD cum. profit.

              My concern is how to simulate every trade but do not include all of them in backtest results.

              Looking forward to hearing from you.

              Comment


                #8
                Hello,

                You would essentially need to do all tracking yourself in the strategy.

                Not actually place the trades but use coding to mark the entry price, then mark the exit price. Take the gain/loss and multiple that by the QTY you are using to get the number of ticks you made then multiple this times the point value of the instrument to get the PnL. Then add this PnL to your equity curve at the end of the trade.

                Since you are not actually taking a trade and you cannot change the account you trade too you must simulate the trade inside the strategy and not actually use any NinjaScript commands to execute a trade.

                -Brett
                BrettNinjaTrader Product Management

                Comment


                  #9
                  You rock . Thanks for your great support.
                  Last edited by kucharek; 04-20-2012, 05:29 AM.

                  Comment


                    #10
                    Hi, Has anyone written a code example using a simple long entry strategy to show this code working. It seems a bit complex and I would like to see a example for guidance.

                    Thanks Frank

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by ralett, Today, 06:20 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post ralett
                    by ralett
                     
                    Started by grizzlytrader, Today, 06:24 AM
                    1 response
                    18 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by andrewtrades, Today, 01:43 PM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by FuturesRon, Today, 03:09 AM
                    1 response
                    18 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by Ivantr, Today, 05:24 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post Ivantr
                    by Ivantr
                     
                    Working...
                    X