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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    157 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    91 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    143 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    131 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    107 views
    0 likes
    Last Post CarlTrading  
    Working...
    X