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

Indicator on Some kind of Timer??

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

    Indicator on Some kind of Timer??

    I'm trying to figure Out this Time Thing and its killing me. I want to be able that when I get a Signal, the Signal Has an expiration that matches what ever time I want. So my final attempt at this was: I attempted that When Current Time Matches anything Close to the End of the Next 30 minutes, 'to do somethng.....'

    Code:
    if(BarsInProgress == 1)
    			{
    				TimeSpan expiryBars = DateTime.Now - Time[0].AddSeconds(+60);
    				
    				TimeSpan barsAgo = DateTime.Now - Time[0].AddMinutes(-30);
    				
    				TimeSpan barsFromNow = DateTime.Now - Time[0].AddMinutes(+30);
    				
    
    				
    			 DrawRectangle("myTangle",true, DateTime.Now.Subtract(barsFromNow), Lows[1][0], Time[0], Lows[1][1], Color.Blue, Color.Blue, 5);
    
    			
    //This was my Attempt at Saying that If the Current TIme is Equal to 30 Minutes from Now, '...do something'
    				if(expiryBars == barsFromNow)
    				{	
    					DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[0] + 10 * TickSize, Color.Red); 
    					
    				}
    			}

    My Attempts have NOT worked. Can anyone please show a Simple way to do this.

    1. Signal Fires Off.
    2. What ever the Time the Signal Fires, it Expires at least 30 min (or any User defined time ) after that.

    MAIN GOAL:
    The main goal is that When a Signal is Given. That I can write a Condition to check How LONG it took for that Signal to reach it's Goal.

    Second goal is to make the Signal automatically LOSE and restart once a Certain amount of Time has Elapsed.

    For Example:
    Code:
    if(High[0] == EMA(200); 
    { sellSignal = True; 
    //Now If Signal was given at 9:20am,  and it hasn't reached it's goal by 10:00am, this is a Loser.   
    
    IDEA: 
    Is there perhaps a way to make some kind of Timer that Lets say 
    1. Signal Fires off (Price touches EMA or whatever....) at 7:25am
    2. Expiration is for 8:00am
    3. Indicator Begins Counting Down so that when Time reaches 8:00am, Signal Expires.
    
    
    How would I accomplish this. I'm just throwing out some ideas. I'm really Not sure how to do Time at all. the last Post shows my attempts at this.
    I want Indicator to Have the Exact time of Signal and once Current Time (From signal) till Expiration, for it to DO something

    PLEASE HELP. I just can't get it.

    #2
    Hello ginx10k,

    Thank you for your post.

    The following code will provide the last example you used:
    Code:
    			if(High[0] == EMA(200)[0] && !sellSignal)
    			{
    				sellSignal = true;
    				sellSigTime = Time[0];
    			}
    			if(Time[0] >= sellSigTime.AddMinutes(30))
    			{
    				// sell signal end
    				sellSignal = false;
    			}
    For information on DateTime please visit the following link: http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx

    Comment


      #3
      Patrick as Always You Rock. Thank You So Much. I'll try this later and will hopefully build upon it. I appreciate it.

      Comment


        #4
        I'm STUCK

        Okay I tried my Best Patrick. Code and FUll Indicator is Attached.

        Problem is I get a Expiry Hour that makes no sense: Look at Pic http://screencast.com/t/t7R47rGb2I

        Why is the Expiry Hour Not showing the Proper Expiration that I'm looking For.

        P.S. I'm trying to get the ExpiryHour Variable so that I can make a conditional Statement like the one you showed me but I want indicator to Know exactly How Long it has Until it expires a Signal.

        PPS. Before it gets more confusing. I want you to know that I WANT The Entry Time of Signal to Be Subtracted from the End of Current Hour. and that No Matter What the Signal Expires at End of that Hour. Not Just 30 Minutes from Entry.

        The Code snippet you gave was Great. but I'm looking for Exact Expirations From Time of Entry Till End Of CURRENT HOUR.

        Thanks again

        Code:
         //STEP 1 SELL ENTRY:	If Price Touches the EMA  
        	
        			if ((!sellSignal) && High[0] == EMA(30)[0] || (CrossAbove(High, EMA(30), 1)))
        			{	
        				
        				downArrow = DrawArrowDown("My down arrow" + CurrentBar, true, 0, High[0] + 10 * TickSize, Color.Red);
        				trigBar = CurrentBar;
        				entryPrice = Close[0];
        				sellSignal = true;
        				sellSigTime = Time[0];
        				
        				barsAgo = DateTime.Now - Time[0].AddHours(1);
        				
        				endOfHour = DateTime.Now - Time[0].AddHours(1);
        			}	
        	
        			//	ExpirationTime = TimeOfSignal + (Find what Next Hour is and Subtract Remaining Time Till we get there)			;
        				//	if(Time[0] == new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 11, 0, 0))	
        					 
        						expiryTime = sellSigTime - endOfHour;
        					
        			
        			
        			//Write  Time Stamps				
        					DrawText("New Time",false, "Expiry Hour Is: " + expiryTime.ToString(), -4, Low[0] - 40 * TickSize,0, Color.Cyan, new Font("Arial", 15),StringAlignment.Center, Color.Transparent, Color.Transparent, 3);	
        					DrawText("Signal Time",false, "Signal Entry Time: " + sellSigTime.ToString(), -4, High[0] + 30 * TickSize,0, Color.Cyan, new Font("Arial", 15),StringAlignment.Center, Color.Transparent, Color.Transparent, 3);
        Attached Files
        Last edited by ginx10k; 07-31-2014, 05:01 PM.

        Comment


          #5
          Hello ginx10k,

          Thank you for your response.

          I will investigate this further and follow up with you when I have additional information.

          Comment


            #6
            Originally posted by ginx10k View Post
            Okay I tried my Best Patrick. Code and FUll Indicator is Attached.

            Problem is I get a Expiry Hour that makes no sense: Look at Pic http://screencast.com/t/t7R47rGb2I

            Why is the Expiry Hour Not showing the Proper Expiration that I'm looking For.

            P.S. I'm trying to get the ExpiryHour Variable so that I can make a conditional Statement like the one you showed me but I want indicator to Know exactly How Long it has Until it expires a Signal.

            PPS. Before it gets more confusing. I want you to know that I WANT The Entry Time of Signal to Be Subtracted from the End of Current Hour. and that No Matter What the Signal Expires at End of that Hour. Not Just 30 Minutes from Entry.

            The Code snippet you gave was Great. but I'm looking for Exact Expirations From Time of Entry Till End Of CURRENT HOUR.

            Thanks again

            Code:
             //STEP 1 SELL ENTRY:    If Price Touches the EMA  
                
                        if ((!sellSignal) && High[0] == EMA(30)[0] || (CrossAbove(High, EMA(30), 1)))
                        {    
                            
                            downArrow = DrawArrowDown("My down arrow" + CurrentBar, true, 0, High[0] + 10 * TickSize, Color.Red);
                            trigBar = CurrentBar;
                            entryPrice = Close[0];
                            sellSignal = true;
                            sellSigTime = Time[0];
                            
                            barsAgo = DateTime.Now - Time[0].AddHours(1);
                            
                            endOfHour = DateTime.Now - Time[0].AddHours(1);
                        }    
                
                        //    ExpirationTime = TimeOfSignal + (Find what Next Hour is and Subtract Remaining Time Till we get there)            ;
                            //    if(Time[0] == new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 11, 0, 0))    
                                 
                                    expiryTime = sellSigTime - endOfHour;
                                
                        
                        
                        //Write  Time Stamps                
                                DrawText("New Time",false, "Expiry Hour Is: " + expiryTime.ToString(), -4, Low[0] - 40 * TickSize,0, Color.Cyan, new Font("Arial", 15),StringAlignment.Center, Color.Transparent, Color.Transparent, 3);    
                                DrawText("Signal Time",false, "Signal Entry Time: " + sellSigTime.ToString(), -4, High[0] + 30 * TickSize,0, Color.Cyan, new Font("Arial", 15),StringAlignment.Center, Color.Transparent, Color.Transparent, 3);
            There are 60 minutes in an hour, so, is the quantity that you seek: minutes to end of hour not just:
            Code:
            expiryTime = 60 - Time[0].Minute;
            ?

            Comment


              #7
              Thx KG. but that didn't work either. Asside from the Errors I'm getting. It wouldn't do what I need regardless. Your statement is basically saying Expiry time is any 60minutes from the Time the Signal Fires.

              This is exactly what Im trying to do.

              Example 1: SELL signal Triggers at 10:17am.

              1. Indicator recognizes Current Hour is 10:00am
              2. Indicator Sets Expiry Time for 11:00am
              3. If Time becomes 11:00am = Signal Ends

              Example 2: SELL signal Triggers at 9:28am

              1. Indicator recognizes Current Hour is 9:00am
              2. Indicator Sets Expiry Time for 10:00am
              3. If Time becomes 10:00am = Signal Ends

              Example 3: SELL signal Triggers at 6:55am

              1. Indicator recognizes Current Hour is 6:00am
              2. Indicator Sets Expiry Time for 7:00am
              3. If Time becomes 7:00am = Signal Ends


              So You See it DOES NOT MATTER WHAT TIME SIGNAL TRIGGERS. I'm NOT Looking for an HOUR away from the Trigger. I'm Looking for Indicator to Know EXACT Current Hour, and that Expiration Will Always Be the beginning of New Hour. Not Just 30 minutes away or any Hour away or 60min. it has to Be Precise in knowing the CURRENT and Next hours (without me telling it every time it triggers).

              Comment


                #8
                Originally posted by ginx10k View Post
                Thx KG. but that didn't work either. Asside from the Errors I'm getting. It wouldn't do what I need regardless. Your statement is basically saying Expiry time is any 60minutes from the Time the Signal Fires.

                This is exactly what Im trying to do.

                Example 1: SELL signal Triggers at 10:17am.

                1. Indicator recognizes Current Hour is 10:00am
                2. Indicator Sets Expiry Time for 11:00am
                3. If Time becomes 11:00am = Signal Ends

                Example 2: SELL signal Triggers at 9:28am

                1. Indicator recognizes Current Hour is 9:00am
                2. Indicator Sets Expiry Time for 10:00am
                3. If Time becomes 10:00am = Signal Ends

                Example 3: SELL signal Triggers at 6:55am

                1. Indicator recognizes Current Hour is 6:00am
                2. Indicator Sets Expiry Time for 7:00am
                3. If Time becomes 7:00am = Signal Ends


                So You See it DOES NOT MATTER WHAT TIME SIGNAL TRIGGERS. I'm NOT Looking for an HOUR away from the Trigger. I'm Looking for Indicator to Know EXACT Current Hour, and that Expiration Will Always Be the beginning of New Hour. Not Just 30 minutes away or any Hour away or 60min. it has to Be Precise in knowing the CURRENT and Next hours (without me telling it every time it triggers).
                There is more than one way to code that. You did not clearly specify what your expiryTime meant, and the code that you wrote made it look it was the number of minutes to the next hour mark after your entry. What I wrote is that number. Add those minutes to the time of entry, and you will have the projected time of exit. That translates to:
                Code:
                //at entry
                entryTime = Time[0];
                exitTimeProjected = Time[0].AddMinutes(60 - Time[0].Minute);
                Sorry, you will have to translate those to your terms, as I can only think in terms of variable names that make sense to me. Both of those will have to be declared as DateTime structures.

                You can do similar to deal with the seconds component of the Time[0], if you wish. Which brings us to:
                Code:
                exitTimeProjected = Time[0].AddMinutes(60 - Time[0].Minute).AddSeconds(60 - Time[0].Second);
                An alternative is to get the exitTime by decomposing Time[0], adding 1 to the hour component and then creating a new DateTime structure from those components, using minute and second components of zero. One such translation would be:
                Code:
                exitTimeProjected = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, Time[0].Hour, 0, 0);
                exitTimeProjected = exitTimeProjected.AddHours(1);
                Another would be:
                Code:
                exitTimeProjected = Time[0].Date.AddHours(Time[0].Hour + 1);
                Last edited by koganam; 09-14-2014, 08:34 AM. Reason: Corrected grammar and spelling.

                Comment


                  #9
                  Got It.

                  Okay. Kogonam. I totally got everything to work as it should. You're a True Genius. and Thanks for taking the Time to help me.

                  Patrick, you rock as always. Much appreciated.

                  Comment


                    #10
                    Quick Question

                    Okay. just a quick question. I have the formula
                    Code:
                    Time[0].AddMinutes(60-Time[0].Minute
                    This gives me expiration time for Current Hour.

                    I used the code
                    Code:
                    if(Time[0].AddMinutes(20) <= Time[0].AddMinutes(expHourInMin-Time[0].Minute))  expiryTime = Time[0];
                    . To filter out Trades that are at least 20 Minutes till Expiration.


                    But now I would like to FIlter out Trades that are in the first 20 minutes from Expiration hour.
                    I can't get anything to work. I have tried
                    Code:
                    if(Time[0] > (expiryTime + Time[0].AddMinutes(-40)))
                    To SIMPLIFY: ALL I want is that IF Current time is Less than 40 minutes till Expiration = NO Trade. (i.e. If Time[0] < 8:21am = NO Trade)

                    Any idea how to do this?

                    Comment


                      #11
                      NeverMIND Got IT!

                      Nevermind, figured something out that worked.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by cmtjoancolmenero, Yesterday, 03:58 PM
                      10 responses
                      36 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by DayTradingDEMON, Today, 09:28 AM
                      4 responses
                      24 views
                      0 likes
                      Last Post DayTradingDEMON  
                      Started by geddyisodin, Yesterday, 05:20 AM
                      8 responses
                      51 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by George21, Today, 10:07 AM
                      1 response
                      15 views
                      0 likes
                      Last Post NinjaTrader_ChristopherJ  
                      Started by Stanfillirenfro, Today, 07:23 AM
                      9 responses
                      25 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Working...
                      X