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.



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



    Let me know if any questions.

    -Brett

    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);



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

        Then use this sample to use SMA.



        -Brett

        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

            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

                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 junkone, Today, 11:37 AM
                    2 responses
                    15 views
                    0 likes
                    Last Post junkone
                    by junkone
                     
                    Started by frankthearm, Yesterday, 09:08 AM
                    12 responses
                    44 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by quantismo, 04-17-2024, 05:13 PM
                    5 responses
                    35 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by proptrade13, Today, 11:06 AM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by love2code2trade, 04-17-2024, 01:45 PM
                    4 responses
                    36 views
                    0 likes
                    Last Post love2code2trade  
                    Working...
                    X