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

Time to run Walk fwd optimization

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

    Time to run Walk fwd optimization

    Hi

    I have the below section in my trading strategy. If I swap out the orange highlighted part, for the part below, the time taken to run a walk fwd opt (without changing the Max/Mins or the increments on each variable), over doubles in time; it goes from running it in 2.5 hours, to taking 6 hours.

    Any idea why this is?

    MAX(High, CurrentBar-OverboughtBar)[0]-Close[0]

    As you can see from the below, the above MAX(High.....) is used to define the stopshort and also to move the stop in the ROLL STOP @ A section below, so it would be more consistent to use it.

    I just can't understand why the walk forward opt takes so much longer.


    else if(Breaklow
    && Close[0]>=Open[0]
    // 61.8% Fib is based on the highest high of the double top, not the entire range (inconsistent to the stop and roll positions)
    && (Close[0]-MIN(Low,CurrentBar-RetestBar)[0])/(MAX(High,BarCountOverbought)[CurrentBar-RetestBar]-Close[0])>1.55
    && MAX(High,CurrentBar-OverboughtBar)[0]-Close[0]>0.001
    && ToTime(Time[0])>70000 && ToTime(Time[0])<170000
    && Close[0]-MIN(Low,CurrentBar-RetestBar)[0]>0.001
    )

    {

    int AvTR=(s1*(Convert.ToInt32(Math.Round((ATR(14)[0]/TickSize)))));
    // Stop position and roll positions based on the highest high of the entire range, not just the double top. Change this, need to change the rolls as well
    int stopShort=Convert.ToInt32((MAX(High, CurrentBar-OverboughtBar)[0]-Close[0])/TickSize)+AvTR;
    int profitShort=Convert.ToInt32((Close[0]-MIN(Low,CurrentBar-RetestBar)[0])/TickSize);
    double capitalToRisk=100;
    double TickValue=Instrument.MasterInstrument.PointValue*I nstrument.MasterInstrument.TickSize;
    int GBPperpoint = (int)Instrument.MasterInstrument.RoundDownToTickSi ze((capitalToRisk/TickValue));
    int xUnits =(int)(GBPperpoint/(stopShort));
    SetStopLoss("GoShort", CalculationMode.Ticks,stopShort, false);
    SetProfitTarget("GoShort", CalculationMode.Ticks,profitShort);
    EnterShort(xUnits,"GoShort");
    EntryBar=CurrentBar;
    Breaklow=false;
    Notrade=true;
    rolA=true;
    Oversold=false;

    }



    //////////////////////////////////////////////////////////////////////////////////////

    // ROLL STOP @ A: roll the stop to protect the position
    if (Position.MarketPosition == MarketPosition.Short
    && rolA
    && Close[0]<Position.AveragePrice-((x1*1*TickSize*(Convert.ToInt32((MAX(High, EntryBar-OverboughtBar)[BarsSinceEntryExecution("GoShort")+1]-Close[BarsSinceEntryExecution("GoShort")+1])/TickSize))+(s1*(Convert.ToInt32(Math.Round((ATR(14 )[BarsSinceEntryExecution("GoShort")+1]/TickSize))))))
    )
    )
    {
    rolA=false;
    int stopShort=Convert.ToInt32((MAX(High, EntryBar-OverboughtBar)[BarsSinceEntryExecution("GoShort")+1]-Close[BarsSinceEntryExecution("GoShort")+1])/TickSize)+(s1*(Convert.ToInt32(Math.Round((ATR(14)[BarsSinceEntryExecution("GoShort")+1]/TickSize)))));
    SetStopLoss("GoShort", CalculationMode.Price,Close[0]+(stopShort)*TickSize, false);
    rolB=true;


    }

    #2
    Hello lancasterstephen,

    Thank you for your note.

    When you are running an optimization, what is the range you are testing for your OverboughtBar parameter? For example, between 1 -10?

    How far back from the current bar would you like the high bar? The current bar on the last bar of a data series (most current) could be a very large number, for example 2000.

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hi Alan

      OverboughtBar is defined as equal to CurrentBar earlier in the strategy; it's not a parameter I vary in the optimization.

      There is another part of my strategy which then resets everything back to the start if CurrentBar-OverboughtBar>20

      This is just so the difference between the two bars does not get to a crazy number.

      There is then another part of my strategy which then resets everything back to the start if CurrentBar-RetestBar>15

      In effect therefore the max number of bars can be 35, otherwise it resets everything back to 0 and starts to look for step 1 in the strategy again.

      Thanks
      STeve

      Comment


        #4
        Hello lancasterstephen,

        If you hardcode the barsAgo value of your MAX method, for example,
        Code:
        (MAX(High,BarCountOverbought)[B][0][/B]-Close[0])
        From,

        Code:
        (MAX(High,BarCountOverbought)[B][CurrentBar-RetestBar][/B]-Close[0])
        Does that improve optimization times?

        I look forward to your reply.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Hi Alan

          It's the version without the barsAgo being hardcoded which is actually performing to c.2.5 hours.

          The version which is taking over 6 is with barsAgo being hardcoded. i.e. MAX(High, CurrentBar-OverboughtBar)[0]-Close[0]

          Would this make sense to you; That having the intperiod not hardcoded takes so much longer? As above, this is also used throughout the remainder of the strategy to roll stops.


          I'm only talking about swapping out the part in orange for the part above which drives such a large increase in time taken to run the optimization.

          Cheers
          Steve

          Comment


            #6
            Hello lancasterstephen,

            Without the full code I would be unable to test however I could imagine passing the following to the period for which the high value is looped for would increase times. CurrentBar-OverboughtBar.

            I would suggest adding prints to the script to test.

            For example you could do,

            int periodforMax = CurrentBar-OverboughtBar;
            Print("periodforMax "+periodforMax.ToString());
            MAX(High, periodforMax)[0]-Close[0]

            Then run the script in the optimizer with the output window open. Is the value for periodMax very large?

            I’ve provided a link to a youtube video which covers an example of using prints to understand behavior:
            Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...


            I’ve provided a link covering debugging which you may find helpful.
            Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

            I look forward to your reply.
            Alan P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CortexZenUSA, Today, 12:53 AM
            0 responses
            1 view
            0 likes
            Last Post CortexZenUSA  
            Started by CortexZenUSA, Today, 12:46 AM
            0 responses
            1 view
            0 likes
            Last Post CortexZenUSA  
            Started by usazencortex, Today, 12:43 AM
            0 responses
            5 views
            0 likes
            Last Post usazencortex  
            Started by sidlercom80, 10-28-2023, 08:49 AM
            168 responses
            2,265 views
            0 likes
            Last Post sidlercom80  
            Started by Barry Milan, Yesterday, 10:35 PM
            3 responses
            12 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Working...
            X