Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Backtest a Reversal System

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

    Backtest a Reversal System

    I have been a TradeStation Programmer for over 20 years but I am new to NT. I have a couple of basic questions. I've gone through several posts in the forum regarding reversing a position, but it seems that they all relate to real time trading, not backtesting. At this point I am only interested in backtesting and I am using the Managed Approach.

    1) I assume that the Unmanaged Approach can only be used for real time, is this correct?

    2) I am trying to backtest a strategy that enters on a stop and always has a stop and limit associated with the entry. I would like to be able to reverse the position if, in a trade that has not been taken out by a stop or limit. I can't get the strategy to reverse. Below is a condensed version of the entry/exit code. Is there anyway to allow reversals under these conditions in the Managed Approach. can I use the unmanaged approach for backtesting?

    NOTE- The undefined variables below are defind in the actual code. I used "....." as place holders

    protected override void OnBarUpdate()
    {
    .
    .
    .

    // Long Entry
    Condition1 = ......;

    if(Condition1 && Position.MarketPosition != MarketPosition.Long )
    {
    EnterLongStop(ContractsToTrade,FactorBuyPrice,"Fac torBuy");

    Factor_LongStopPrice = .....;
    Factor_ShortStopPrice = ......;
    }

    // Short Entry
    Condition2 = ........

    if(Condition2 && Position.MarketPosition != MarketPosition.Short )
    {
    EnterShortStop(ContractsToTrade,FactorSellPrice,"F actorSell");

    Factor_ShortStopPrice = .......;
    Factor_ShortLimitPrice = .......;

    }

    // Exits
    ExitLongStop(ContractsToTrade,Factor_LongStopPrice ,"FactorL_Stop","FactorBuy");
    ExitLongLimit(ContractsToTrade,Factor_LongLimitPri ce,"FactorL_Limit","FactorBuy");

    ExitShortStop(ContractsToTrade,Factor_ShortStopPri ce,"FactorS_Stop","FactorSell");
    ExitShortLimit(ContractsToTrade,Factor_ShortLimitP rice,"FactorS_Limit","FactorSell");
    }

    #2
    Hello,

    Thanks for your post and welcome to the forums!

    Yes, you can use Unmanaged or managed approach for backtesting or live testing

    Yes the managed approach would prevent what you are trying to do. Here are the Internal Order Handling Rules that Reduce Unwanted Positions (for entries)

    Methods that generate orders to enter a position will be ignored if:
    • A position is open and an order submitted by an exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction
    • A position is open and an order submitted by a set method (SetStopLoss() for example) is active and the order is used to open a position in the opposite direction
    • The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
    • The entry signal name is not unique

    Reference: http://ninjatrader.com/support/helpG...d_approach.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you. It wasn't clear in the documenttion that I could use the Unmanaged approach in backtesting. It may be there and I may have missed it. This will sove my problem.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by timmbbo, Today, 08:59 AM
      1 response
      2 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by KennyK, 05-29-2017, 02:02 AM
      2 responses
      1,279 views
      0 likes
      Last Post marcus2300  
      Started by fernandobr, Today, 09:11 AM
      0 responses
      2 views
      0 likes
      Last Post fernandobr  
      Started by itrader46, Today, 09:04 AM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by bmartz, 03-12-2024, 06:12 AM
      5 responses
      33 views
      0 likes
      Last Post NinjaTrader_Zachary  
      Working...
      X