Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do I reset a variable at the start of each session?

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

    How do I reset a variable at the start of each session?

    I want to run a strategy only once per session. I know I can use flags (variables) to limit # of runs but I want to reset variable at start of every session. How? Thanks for your help.

    #2
    You can work with with bools for this task and reset them on session break to allow triggering again, here's a pseudo code snippet you can change to fit your needs - this would for example to allow one trade to be done per day / session.

    Code:
     
    // in your code variables section
    private bool canTrade = true;
     
    OnBarUpdate()
    {
    if (SessionBreak)
    canTrade = true;
    if (long trade conditions are met)
    {
    canTrade = false;
    EnterLong(...);
    }
    if (short conditions are met)
    {
    canTrade = false;
    EnterShort(...);
    }
    BertrandNinjaTrader Customer Service

    Comment


      #3
      You can also use this :

      Code:
      if(Time[0].Day != Time[1].Day) 
      {
             //Reset var
      }
      But SessionBreak is maybe more appropriate

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Haiasi, 04-25-2024, 06:53 PM
      2 responses
      17 views
      0 likes
      Last Post Massinisa  
      Started by Creamers, Today, 05:32 AM
      0 responses
      5 views
      0 likes
      Last Post Creamers  
      Started by Segwin, 05-07-2018, 02:15 PM
      12 responses
      1,786 views
      0 likes
      Last Post Leafcutter  
      Started by poplagelu, Today, 05:00 AM
      0 responses
      3 views
      0 likes
      Last Post poplagelu  
      Started by fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,407 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Working...
      X