Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SampleDataSeries / SampleIntrabarBacktest

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

    SampleDataSeries / SampleIntrabarBacktest

    Hello,
    I'm attaching two modified samplestrats.
    My main purpose is to understand how and with what syntax to set
    Code:
    orderBar = CurrentBar;
    lockedPlotBar = (CurrentBar-orderBar);
    statements in my code for plotting purposes - ie horiz lines, diamonds, etc. I'm using COBC=true but with a 1tick tertiary series to emulate the COBC=false. I'm trying to get the right syntax for setting the currentbar on the primary and/or secondary series and get a result for the "lockedPlotBar" per above. so far, I'm only getting zeros or huge numbers similar to CurrentBar.

    I've added some Print statements to understand what I need.
    World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.


    1) I've been using the larger timeframes for the primary. When I want a BIP for 1 tick, is it best to have it as the second or third series? I keep a secondary chart available so I can see what's happening there. But not a 1 tick...Do I need to state
    Code:
    If (FirstTickOfBar && BIP ==2) orderBar = CurrentBar;
    ? Or do I need to use BarsArray syntax?

    2) I don't understand the multiple Square and Diamond plots on the Sample DataSeries since they are COBC=true.

    3)
    Code:
    [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"primarySeries[0]:\t\t"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]+FormatPrice(primarySeries[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]));[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]Print([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"secondarySeries[0]:\t\t"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]+FormatPrice(secondarySeries[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]));[/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (BarsInProgress == [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]) Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"BIP0 primarySeries[0]:\t"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]+FormatPrice(primarySeries[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]));[/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (BarsInProgress == [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]) Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"BIP1 secondarySeries[0]:\t"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]+FormatPrice(secondarySeries[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]));[/SIZE][/FONT]
     
    [/SIZE][/FONT]
    I need to add DateTime.Now, but if I understand right, the if (BIP... ) before the Print statement allows that print to only occur once the Bar Plots per it's timeframe.
    4) How can I use BIP == 2 (for tick series) but have the "(CurrentBar-orderBar)" for the primary or secondary?
    Thanks in Advance!
    kz
    Attached Files
    Last edited by zeller4; 08-02-2010, 10:05 PM. Reason: upgraded 1 file

    #2
    Hi zeller4,

    1. To clarify, with a 1 tick chart, there's no need really for FirstTickOfBar. However if you are using something else, your implementation of FTOB and BIP looks ok.

    2. Are you referring to a specific script here?

    3. Correct on your statement about BIP, however I'm not sure what your code is doing as I can't see the logic for the custom method.

    4. You would need to place the logic under the correct BIP, as seen in this sample:
    TimNinjaTrader Customer Service

    Comment


      #3
      Thanks Tim,
      For #1, I'm expecting to see indexing count the bars back where my condition/signal first came up. So, for example if my Current Bar is 8328 and my orderBar was made current at Barnumber 8320, my index should read 8328 - 8320 = 8. I'm not getting anything like that and therefore suspect the BIP or other syntax.

      For #2, I'm referring to the attached SampleDataSeries_v01 which is printing to output as well as giving square or diamond drawobjects so I can understand the code. Just not sure why there are multiple SQ plots per bar for these: Is it because there's 2 or more BarsArray [1] bars that plot their Closes during the primary bar plot?
      Code:
       
      [SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New]DrawDiamond([/FONT][/SIZE][/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"DIA"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]+CurrentBar,[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],Closes[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]][[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]],Color.Gold);[/SIZE][/FONT]
      [SIZE=2][FONT=Courier New]DrawSquare([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"SQ"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]+CurrentBar,[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],Closes[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]][[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]],Color.Green);[/SIZE][/FONT]
       
      [/SIZE][/FONT]
      #3 was from same file to see if there differences of Print statements - you've answered it.
      #4 - okay, I've studied this link somewhat, gaining ground on it. I'm still having problem with the CurrentBar using the multiple timeframes...

      If I have a custom DataSeries (myDiamond) which is called from another indicator
      Code:
      [FONT=Courier New][SIZE=2]
      [SIZE=2][FONT=Courier New][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (BarsInProgress == [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000])[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]
      [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]{[/SIZE][/FONT]
      [/SIZE][/FONT]myDiamond10.Set(COBC_False_v05(Close,periodLR).MyDiamond[[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]);[/SIZE][/FONT][/SIZE][/FONT]
      [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]}[/SIZE][/FONT]
      [/SIZE][/FONT]
      how do I then "use" this with the correct syntax? I'm trying
      Code:
      [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]
      [SIZE=2][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/SIZE][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (BarsInProgress == [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1 && myDiamond10[0] > 0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]){ orderBar = CurrentBar;}  //...[/COLOR][/SIZE][/FONT][/SIZE][/FONT]
      [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]lockedPlotBar = (CurrentBar-orderBar);[/COLOR][/SIZE][/FONT]
      [/SIZE][/FONT]
      Or is there a way I need to use BarsArray[1] with my custom DataSeries? Or do I need to have this "lockedPlotBar" inside the BIP curly brackets?
      Thanks,
      kz

      Comment


        #4
        #1. Your print out is not assigned to a specific BIP. Therefore your use for "CurrentBar - orderBar" becomes highly BIP dependent. To ensure you are always just looking at the correct CurrentBar you can use CurrentBars[] (with an 's').

        CurrentBars[0] = CurrentBar value of primary series
        CurrentBars[1] = ' ' ' secondary series
        CurrentBars[2] = ' ' ' tertiary series

        #2. I am not sure what multiple square/diamonds you are referring to. Attached is a screenshot of what I see on my end and it is only one per time your code is evaluated to true which is accurate.

        #4. If you have a custom series that you want to call in another indicator you need to first have that series exposed. Please see the example here: http://www.ninjatrader.com/support/f...ead.php?t=4991

        Once you have exposed the series you would access it just like how you would access a plot. You would not filter it in any BIPs from the indicator doing the calling because it has no concept of what the indicator being called has in terms of BIPs. You will just get whatever return value it sees at the point of calling. Any "control" would need to be done inside the indicator logic that contains the series to begin with.

        Code:
        someIndicator().SomeCustomSeries[0];
        Attached Files
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks Josh,

          appreciate it very much.

          Once you have exposed the series you would access it just like how you would access a plot. You would not filter it in any BIPs from the indicator doing the calling because it has no concept of what the indicator being called has in terms of BIPs. You will just get whatever return value it sees at the point of calling. Any "control" would need to be done inside the indicator logic that contains the series to begin with.


          Code:
          someIndicator().SomeCustomSeries[0];
          So, if I understand "not filter it in any BIPs from the indicator doing the calling".
          My Strategy currently has
          Code:
          if (BarsInProgress == 1 && mySecondarySeries[0] > 0)
          //do something
          is not correct... you mean I don't need the BIP==1?
          Please advise.
          Kirk
          Last edited by zeller4; 08-04-2010, 12:08 PM.

          Comment


            #6
            Josh,

            I couldn't get "CurrentBars[0]" to work - I'm using 6.5...

            or where else can I read up on this before submitting my sample strat.

            thanks,
            Kirk

            Comment


              #7
              Kirk,

              Adding BarsInProgress check in the strategy does not check the BIP context of the indicator. You are filtering it for the BIP context of the strategy with such a check.

              Actually, I am not sure how you made a multi-series indicator in 6.5 as this is only available in NT7. Can you please clarify what exactly you are doing? Thank you. (Note: CurrentBars[] is only available in NT7. For 6.5 you will have to filter your code with BIP checks and just ensure you are in the correct BIP for an appropriate calculation.)
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                SampleAtmStrategy _v01

                Hello Josh,
                This is a long only strat based on the NT SampleAtmStrategy.

                I've added some cb[] code that I found and set up BIP with a bunch of Print statements to check my progress. My primary is 1 minute, secondary is 30 seconds and tertiary 10 seconds so I can see the strat operate without waiting too long for normal setups.

                It appears to be working. I think I'm getting the counting sorted out now but I still need to check if the strat is changing the entries, changing the stops/targets, or closing like I need to occur before I add the short side.

                Please let me know if you see any glaring errors.
                Thanks,
                Kirk
                ps, I noticed print statement line numbers are no longer aligned...
                Attached Files
                Last edited by zeller4; 08-04-2010, 01:45 PM.

                Comment


                  #9
                  I would not be able to comment about your line numbers as I do not know what numbers you are deciding to print in your statements. From a glance over though, the code looks fine.
                  Josh P.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  647 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  369 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  108 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  572 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  573 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X