Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

If I only use a smaller timeframe for the sole purpose

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

    If I only use a smaller timeframe for the sole purpose

    of exiting on saturday's close, which would be a better way of writing the code?

    Code:
    [COLOR=#0000ff][COLOR=#0000ff][COLOR=#0000ff][FONT=Courier New]if[/FONT][/COLOR][/COLOR][/COLOR][FONT=Courier New][COLOR=#000000] (BarsInProgress == [/COLOR][COLOR=#800080][COLOR=#800080][COLOR=#800080]0[/COLOR][/COLOR][/COLOR][/FONT][FONT=Courier New][COLOR=#000000])[/COLOR][/FONT]
    [FONT=Courier New]{[/FONT]
    [COLOR=#0000ff][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/COLOR][FONT=Courier New] (Position.MarketPosition == MarketPosition.Flat)[/FONT]
    [FONT=Courier New]{[/FONT]
    [FONT=Courier New]DoSomething[/FONT]
    [FONT=Courier New]}[/FONT]
    [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]else[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][FONT=Courier New][COLOR=#000000] (Position.MarketPosition == MarketPosition.Long)[/COLOR][/FONT]
    [FONT=Courier New]{[/FONT]
    [/FONT][FONT=Courier New]DoSomething[/FONT]
    [FONT=Courier New]}[/FONT]
    [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]else[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][FONT=Courier New][COLOR=#000000] (Position.MarketPosition == MarketPosition.Short)[/COLOR][/FONT]
    [FONT=Courier New]{[/FONT]
    [/FONT][FONT=Courier New]DoSomething[/FONT]
    [FONT=Courier New]}[/FONT]
    }
    [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]else[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][FONT=Courier New][COLOR=#000000] (BarsInProgress == [/COLOR][/FONT][/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]1[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][FONT=Courier New][COLOR=#000000])[/COLOR][/FONT]
    [FONT=Courier New]{[/FONT]
    [/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][FONT=Courier New] (Position.MarketPosition == MarketPosition.Long)[/FONT]
    [FONT=Courier New]{[/FONT]
    [/FONT][FONT=Courier New][FONT=Courier New]}[/FONT]
    [/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][FONT=Courier New] (Position.MarketPosition == MarketPosition.Short)[/FONT]
    [FONT=Courier New]{[/FONT]
    [/FONT][FONT=Courier New][FONT=Courier New]}[/FONT]
    [FONT=Courier New]}[/FONT]
    [/FONT]
    OR

    Code:
    [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]
    [FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][FONT=Courier New][COLOR=#000000] (Position.MarketPosition == MarketPosition.Flat)[/COLOR][/FONT]
    [FONT=Courier New]{[/FONT]
    [/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][FONT=Courier New][COLOR=#000000] (BarsInProgress == [/COLOR][/FONT][/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#000000])[/COLOR][/FONT]
    [FONT=Courier New]{[/FONT]
    [FONT=Courier New]Do Something[/FONT]
    [FONT=Courier New]}[/FONT]
    [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]else[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][FONT=Courier New][COLOR=#000000] (BarsInProgress == [/COLOR][/FONT][/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]1[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][FONT=Courier New][COLOR=#000000])[/COLOR][/FONT]
    [/FONT][FONT=Courier New]{[/FONT]
    [FONT=Courier New]Do Something[/FONT]
    [FONT=Courier New]}[/FONT]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/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][COLOR=#000000](Position.MarketPosition == MarketPosition.Long)[/COLOR][/FONT]
    [FONT=Courier New]{[/FONT]
     
    if[FONT=Courier New][FONT=Courier New][COLOR=#000000] (BarsInProgress == [/COLOR][/FONT][/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#000000])[/COLOR][/FONT]
    [FONT=Courier New]{[/FONT]
    [FONT=Courier New]Do Something[/FONT]
    [FONT=Courier New]}[/FONT]
    [FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]else[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][FONT=Courier New][COLOR=#000000] (BarsInProgress == [/COLOR][/FONT][/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]1[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][FONT=Courier New][COLOR=#000000])[/COLOR][/FONT]
    [/FONT][FONT=Courier New]{[/FONT]
    [FONT=Courier New][SIZE=2][SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/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][COLOR=#000000] (Position.MarketPosition == MarketPosition.Short)[/COLOR][/SIZE][/FONT]
    [/SIZE][/FONT]{
    if[FONT=Courier New][FONT=Courier New][COLOR=#000000] (BarsInProgress == [/COLOR][/FONT][/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][COLOR=#000000])[/COLOR][/FONT]
    [FONT=Courier New]{[/FONT]
    [FONT=Courier New]Do Something[/FONT]
    [FONT=Courier New]}[/FONT]
     
    else[FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][FONT=Courier New][COLOR=#000000] (BarsInProgress == [/COLOR][/FONT][/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]1[/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New][FONT=Courier New][COLOR=#000000])[/COLOR][/FONT]
    [/FONT][FONT=Courier New]{[/FONT]
    [FONT=Courier New][SIZE=2][SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
    [/SIZE][/FONT]
    If I used the first code, are there any circumstances in which the exit on saturday is overridden?

    Regards

    Kay Wai

    #2
    Kay Wai, either way would work, but you might want to use Positions[0].MarketPosition to be sure you're checking the position of your primary series. Since you have the same instrument for both series, it probably won't be a problem, but if you decide to move to multi-instrument strategies, you must use Positions[x].MarketPosition instead of just Position.MarketPosition.
    AustinNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    579 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    334 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    554 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    551 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X