Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Just 1 order per day?

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

    Just 1 order per day?

    Hey there,

    So i programmed a strategy that opens a order every Wednesday.
    I also added a stoploss to it.


    Code:
    if (Time[0].DayOfWeek == DayOfWeek.Wednesday)
    
    
    {
    				EnterLong(Convert.ToInt32(DefaultQuantity), "");
    			
    			
    		}


    The only problem I have is that im getting more then 1 order per day because the old order got stopped.

    So if a order gets in and this order gets stopped, a second order gets in.


    Is there a way to limit this?

    I only want 1 order per day.

    #2
    Originally posted by SpaceGrey View Post
    Hey there,

    So i programmed a strategy that opens a order every Wednesday.
    I also added a stoploss to it.


    Code:
    if (Time[0].DayOfWeek == DayOfWeek.Wednesday)
    
    
    {
                    EnterLong(Convert.ToInt32(DefaultQuantity), "");
                
                
            }
    The only problem I have is that im getting more then 1 order per day because the old order got stopped.

    So if a order gets in and this order gets stopped, a second order gets in.


    Is there a way to limit this?

    I only want 1 order per day.
    Use a boolean flag.
    Code:
    //In Variables section
    private bool TradingEnabled = false;
    
    //In OBU
    if (Time[0].DayOfWeek == DayOfWeek.Tuesday)
    {
                    TradingEnabled = true;
    } 
           
    if (Time[0].DayOfWeek == DayOfWeek.Wednesday && TradingEnabled)
    {
                    EnterLong(Convert.ToInt32(DefaultQuantity), "");
                    TradingEnabled = false;
    }

    Comment


      #3
      Hm that doesnt seem to work:

      This is how I did it:


      Code:
        
      
      // my variable section
      	private bool TradingEnabled = false;
      
      
      
      
      
      // my onBarUpdate() section
      
       // set 1
      			if (Time[0].DayOfWeek == DayOfWeek.Wednesday)
      			{
      				EnterLong(Convert.ToInt32(DefaultQuantity), "");
      			TradingEnabled = true;
      				
      			
      		}		
      
      
      
      I still have more then one order every wednesday

      Comment


        #4
        Hello SpaceGrey,

        I have attached a sample which will make only 1 trade per day.

        To do this I reset the bool in the if statement,
        Code:
        if (Bars.IsFirstBarOfSession == true)
        Please see attached and let us know if you need further assistance.
        Attached Files
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_AlanP View Post
          Hello SpaceGrey,

          I have attached a sample which will make only 1 trade per day.

          To do this I reset the bool in the if statement,
          Code:
          if (Bars.IsFirstBarOfSession == true)
          Please see attached and let us know if you need further assistance.
          Hey thank you very much Alan - I converted it into NinjaTrader 7 and now it works perfect
          Last edited by SpaceGrey; 09-05-2017, 03:10 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Tim-c, Today, 03:54 AM
          0 responses
          3 views
          0 likes
          Last Post Tim-c
          by Tim-c
           
          Started by FrancisMorro, Today, 03:24 AM
          0 responses
          3 views
          0 likes
          Last Post FrancisMorro  
          Started by Segwin, 05-07-2018, 02:15 PM
          10 responses
          1,772 views
          0 likes
          Last Post Leafcutter  
          Started by Rapine Heihei, 04-23-2024, 07:51 PM
          2 responses
          31 views
          0 likes
          Last Post Max238
          by Max238
           
          Started by Shansen, 08-30-2019, 10:18 PM
          24 responses
          945 views
          0 likes
          Last Post spwizard  
          Working...
          X