Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Performance on back-test is hindered from specific logic within my code.

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

    Performance on back-test is hindered from specific logic within my code.

    Hello,

    I have two separate Strategies that are made to work together. Because they are separate I have learned that I cannot test them in the strategy optimizer together, therefore I am testing them in the playback connection feed.

    I have both strategies calculate OnEachTick. One Strategy (strat name = LS) places a long order 4 ticks above the open of bar[0] and the other (strat name = SS) places it 4 ticks below the open. Sometimes, either strategy may be in a position when a new bar appears. To prevent one strategy from placing new orders while the other strategy is till in a position, I inserted a CancelOrder logic. Below are some snippets of my codes.

    Strategy : LS (Calculate = Calculate.OnEachTick)
    {
    public static bool IsLong;
    private static Order LongOrder;
    Benchmark = Open[0]

    OnBarUpdate()
    {
    if GetCurrentBid||Ask == Benchmark
    EnterLongStopMarket(...."LSEntry")

    if (Position.MarketPosition == MarketPosition.Long)
    IsLong = true

    if (SS.IsShort == true)
    CancelOrder(LongOrder)

    }
    }

    protected override void OnOrderUpdate ()
    {
    if (order.Name == "LSEntry")

    LongOrder = order;
    }

    Strategy : SS (Calculate = Calculate.OnEachTick)
    {
    public static bool IsShort;
    private static Order ShortOrder;
    Benchmark = Open[0]

    if GetCurrentBid||Ask == Benchmark
    EnterLongStopMarket(...."SSEntry")

    if (Position.MarketPosition == MarketPosition.Short)
    IsShort = true

    if (LS.IsLong == true)
    CancelOrder(ShortOrder)


    }

    protected override void OnOrderUpdate ()
    {
    if (order.Name == "SSEntry")

    ShortOrder = order;
    }


    After inserting the CancelOrder Logic and I run the strategy on any day in the playback connection, the playback will tend to glitch and stall, sometimes staying frozen in time from anywhere between a few seconds to just crashing my PC at times when the strategy cancels orders upon the open of a new bar, making backtesting quite unbearable. This also happens when the market reaches a stoploss. I assume that because of Calculate OnEachTick, there is so much data coming in that will hinder the performance of my computer. Is is possible to have the CancelOrder method calculate on something else so that the backtesting process may be smoother?

    Last edited by Don22Trader1; 12-17-2021, 11:49 AM.

    #2
    Hello Don22Trader1,

    Thank you for your post.

    We would suggest if the strategies are intended to run on same account/instrument, why not bake them both into one strategy? That would allow optimizing and would not be as messy with inter-strategy communication.

    If it's calculating On Each Tick it may be sending multiple cancellation requests before the orders are cancelled.

    I'd like to take a look at your log and trace files to see what is actually occurring, however, I'd like you to send those in directly from the platform as they may contain personally identifiable information.

    You can do this by going to the Control Center-> Help-> Email Support

    Ensuring 'Log and Trace Files' is checked will include these files. This is checked by default.

    Please reference the following ticket number in the body of the email: 3403387 ATTN Kate W. and please include a link to this forum thread in the body of the email.

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Ninjatrader_Kate

      The reason for using two separate strategies is because my whole trading approach is primarily placing a long stop and a short stop order simultaneously while still keeping the orders 'managed' in my custom code. It works similar to the "straddle" strategy used in options trading; however, I am not holding two positions at the same time. I just place the orders simultaneously and when I take a position, say the market hits my long stop entry order first, the short stop entry order is cancelled. I have tried combining the strategies together but when I do, the strategy will only place one entry order. To work around this, I separated it into two where one bot is responsible for the long side orders and the other for the short side. This has allowed me to place opposing orders simultaneously in the same market. If there is a way to achieve this within one strategy, I have not figured it out since I am still new to trading with algorithms.

      Comment


        #4
        Hello Don22Trader1,

        Thank you for your reply.

        We would suggest using the unmanaged approach if you're looking to place an OCO order for your entries, which would allow you to combine the two strategies.

        Please see the example strategy on this forum post:



        Also, please see this section of our help guide on using the Unmanaged approach:



        You'll need to use the unmanaged order methods to submit orders and also do your own handling for rejections, however, this would allow the behavior you're looking for from a single strategy.

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by RookieTrader, Today, 09:37 AM
        0 responses
        1 view
        0 likes
        Last Post RookieTrader  
        Started by KennyK, 05-29-2017, 02:02 AM
        3 responses
        1,282 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by AttiM, 02-14-2024, 05:20 PM
        11 responses
        184 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by fernandobr, Today, 09:11 AM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by timmbbo, Today, 08:59 AM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X