• 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

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)[0]-Close[0])
        From,

        Code:
        (MAX(High,BarCountOverbought)[CurrentBar-RetestBar]-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:
            https://www.youtube.com/watch?v=K8v_...tu.be&t=48m45s

            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 Da vinci, Today, 04:19 PM
            0 responses
            8 views
            0 likes
            Last Post Da vinci  
            Started by brunoviveiros, Today, 09:36 AM
            1 response
            20 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by GARZONJ, Today, 11:22 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by KonalGondal, Today, 10:18 AM
            1 response
            19 views
            0 likes
            Last Post NinjaTrader_Kate  
            Started by Jorge.andres.o, Today, 09:24 AM
            4 responses
            24 views
            0 likes
            Last Post NinjaTrader_PaulH  
            Working...
            X