NexusFi: Find Your Edge


Home Menu

 





How do I set up a timer for when a condition is true


Discussion in TradeStation

Updated
    1. trending_up 2,349 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
Mgem
New York City
 
Posts: 15 since Apr 2021
Thanks Given: 2
Thanks Received: 0

I am trying to set up a timer for when a condition is true. For example if Condition1 = true then start timer. If timer > 30 seconds then sell next bar O. Thanks!


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Strike Pause Holds, Oil Erases Monday Spike -- May CPI W …
Traders Hideout
Election Sunday Resolves: Peru Heads to Runoff at 42pct, …
Prediction Markets & Event Contracts
CME Cuts Precious Metals Margins Up to 21% Starting Toda …
Commodities
Post-Summit Market Verdict: ES -1%, NQ -1.5%, 10-Year Yi …
Traders Hideout
Rubios Good News Within Hours and the 30-Day Math: Why H …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
205 thanks
Sober Journey With S&P
21 thanks
30 Sessions
20 thanks
Volume Indicators
8 thanks
Thanks Mike. Godspeed.
7 thanks
  #2 (permalink)
 bchip 
Torino, Italy
 
Experience: Advanced
Platform: TradeStation
Trading: ES,YM,CL,GC
Posts: 132 since Sep 2017
Thanks Given: 160
Thanks Received: 117


Mgem View Post
I am trying to set up a timer for when a condition is true. For example if Condition1 = true then start timer. If timer > 30 seconds then sell next bar O. Thanks!

Hi

You'll probably use something like

vars: ChkTime(0);

if (some cond) then ChkTime = CurrentTime + 30


if (CurrentTime > ChkTime) then Sell at next bar



CurrentTime will return a value of 101525 for 10:15:25 AM

I think the caveat here is that TS Engine might only run per bar,
not necessarily per second, so if your using a 15min timeframe it might miss the signal


Reply With Quote
Thanked by:
  #3 (permalink)
Mgem
New York City
 
Posts: 15 since Apr 2021
Thanks Given: 2
Thanks Received: 0



bchip View Post
Hi

You'll probably use something like

vars: ChkTime(0);

if (some cond) then ChkTime = CurrentTime + 30


if (CurrentTime > ChkTime) then Sell at next bar



CurrentTime will return a value of 101525 for 10:15:25 AM

I think the caveat here is that TS Engine might only run per bar,
not necessarily per second, so if your using a 15min timeframe it might miss the signal



Awesome I think this is close to what I was looking for. So then if I were to say


if (cond1 = True) then ChkTime = CurrentTime + 30


if (cond1 = False) then ChkTime = 0


Then it would pretty much restart the timer if Cond1 = False right?


Reply With Quote
  #4 (permalink)
 bchip 
Torino, Italy
 
Experience: Advanced
Platform: TradeStation
Trading: ES,YM,CL,GC
Posts: 132 since Sep 2017
Thanks Given: 160
Thanks Received: 117


Mgem View Post
Awesome I think this is close to what I was looking for. So then if I were to say


if (cond1 = True) then ChkTime = CurrentTime + 30
if (cond1 = False) then ChkTime = 0


Then it would pretty much restart the timer if Cond1 = False right?

I wouldnt make ChkTime = 0

The 2nd part of the code will then read:
if (CurrentTime > 0) then Sell at next bar

Which will be true most of the time, so you'll keep getting sell signals
if (cond1 = True) then ChkTime = CurrentTime + 30

You cant make it more than the CurrentTime either (with if False) as it continuously overwrite it.
So you should only have the red text


Reply With Quote




Last Updated on April 28, 2021


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts