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 CaptainJack, 05-29-2026, 05:09 AM
    0 responses
    475 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 05-29-2026, 12:02 AM
    0 responses
    316 views
    0 likes
    Last Post CaptainJack  
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    253 views
    1 like
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    340 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    305 views
    0 likes
    Last Post CarlTrading  
    Working...
    X