NexusFi: Find Your Edge


Home Menu

 





Calculate Indicator on Bar Close


Discussion in ThinkOrSwim

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




 
Search this Thread

Calculate Indicator on Bar Close

  #1 (permalink)
 
InsideTheMarket's Avatar
 InsideTheMarket 
Orlando, Florida/USA
 
Experience: Master
Platform: ThinkorSwim, NinjaTrader
Trading: ES, NQ, YM, ZB, ZN, GC, SI, HG, CL, NG, ZS, ZC, ZW, 6E, 6B, 6A, 6J
Posts: 7 since Jul 2017
Thanks Given: 0
Thanks Received: 1

I have an ThinkScript (ThinkOrSwim Platform) indicator that I created… how do I make it so it only calculates this indicator that I made on bar close and NOT every tick. It is a 1min chart. Thanks.

Update: I found this command: declare once_per_bar; but, it doesn't seem to consistently process the code in the indicator at the end of each bar... perhaps because I'm using 1m bars.

Any tips or guidance is appreciated.

Follow me on Twitter Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Cheap historycal L1 data for stocks
Stocks and ETFs
About a successful futures trader who didnt know anythin …
Psychology and Money Management
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
  #2 (permalink)
 
Skidboot's Avatar
 Skidboot 
Houston, TX
 
Posts: 202 since Dec 2010
Thanks Given: 203
Thanks Received: 299


InsideTheMarket View Post
I have an ThinkScript (ThinkOrSwim Platform) indicator that I created… how do I make it so it only calculates this indicator that I made on bar close and NOT every tick. It is a 1min chart. Thanks.

Can you not try your calc for previous bar (ex. MACD()."Value"[1] crosses above 0) and not for the current bar?

Reply With Quote
  #3 (permalink)
 
InsideTheMarket's Avatar
 InsideTheMarket 
Orlando, Florida/USA
 
Experience: Master
Platform: ThinkorSwim, NinjaTrader
Trading: ES, NQ, YM, ZB, ZN, GC, SI, HG, CL, NG, ZS, ZC, ZW, 6E, 6B, 6A, 6J
Posts: 7 since Jul 2017
Thanks Given: 0
Thanks Received: 1



Skidboot View Post
Can you not try your calc for previous bar (ex. MACD()."Value"[1] crosses above 0) and not for the current bar?

If I understand you right....I tried that but then it makes it one bar late...

The way I have it now for example:
def main = close("/ES");
def bullsigna1 = main > main[1];

Now if I use this at the top of the code: declare once_per_bar;
it does seem to test the indicator once per bar but not consistently at the same time... ie. at the close of the current bar.
And if I don't use that declaration... it tests the indicator each tick.

Now... if I use this code:
def bullsigna1 = main[1] > main[2];
Then obviously, the indicator is now lagging inherently by 1 bar...

Question is [0] the same as the current bar or is [0] referencing the last "closed" bar?
ie. is def bullsigna1 = main[0] > main[1]; what you're talking about?

Follow me on Twitter Started this thread Reply With Quote
  #4 (permalink)
sunnydaze
Manhattan NY/USA
 
Posts: 4 since May 2020
Thanks Given: 2
Thanks Received: 0

Def CURRENT= isnan(close[-1]) and !isnan(close);


I believe that’s what you need?
Makes the indicator only on current candle


Sent using the NexusFi mobile app

Reply With Quote
  #5 (permalink)
 
InsideTheMarket's Avatar
 InsideTheMarket 
Orlando, Florida/USA
 
Experience: Master
Platform: ThinkorSwim, NinjaTrader
Trading: ES, NQ, YM, ZB, ZN, GC, SI, HG, CL, NG, ZS, ZC, ZW, 6E, 6B, 6A, 6J
Posts: 7 since Jul 2017
Thanks Given: 0
Thanks Received: 1


sunnydaze View Post
Def CURRENT= isnan(close[-1]) and !isnan(close);


I believe that’s what you need?
Makes the indicator only on current candle


Sent using the NexusFi mobile app



But that doesn't prevent it from updating on every tick?

Follow me on Twitter Started this thread Reply With Quote
  #6 (permalink)
sunnydaze
Manhattan NY/USA
 
Posts: 4 since May 2020
Thanks Given: 2
Thanks Received: 0

Try this:
When the candle closes, you can use “plot signal = INDICATOR and !INDICATOR[-1]; ”

So it will only show when the candle closes and new candle opens (so will be a candle behind)


Sent using the NexusFi mobile app

Reply With Quote
  #7 (permalink)
 
InsideTheMarket's Avatar
 InsideTheMarket 
Orlando, Florida/USA
 
Experience: Master
Platform: ThinkorSwim, NinjaTrader
Trading: ES, NQ, YM, ZB, ZN, GC, SI, HG, CL, NG, ZS, ZC, ZW, 6E, 6B, 6A, 6J
Posts: 7 since Jul 2017
Thanks Given: 0
Thanks Received: 1


sunnydaze View Post
Try this:
When the candle closes, you can use “plot signal = INDICATOR and !INDICATOR[-1]; ”

So it will only show when the candle closes and new candle opens (so will be a candle behind)


Sent using the NexusFi mobile app


This looks promising... of course the market is closed now and I gotta wait until Sunday Night / Monday morning to test - lol.

When you say be a candle behind... you mean behind only the CURRENT bar - right? ie. say it's a 2min chart... it will be as current as the last closed bar... but not really "behind" in the context of what I'm trying to accomplish?

and in your example: plot signal = INDICATOR and !INDICATOR[-1];
isn't INDICATOR the current bar?
And !INDICATOR[-1] is the future bar?
So, how would that accomplish what I'm trying to make happen... with the indicator not getting processed until the end of the current bar? The future bar isn't even and shouldn't be... considered anyways... and using INDICATOR... would still have the indicator updating each tick, which is what I don't want? Not trying to be a jerk... just asking.


And how is the set of code you just gave... different than the other one: Def CURRENT= isnan(close[-1]) and !isnan(close);

Follow me on Twitter Started this thread Reply With Quote
  #8 (permalink)
 
InsideTheMarket's Avatar
 InsideTheMarket 
Orlando, Florida/USA
 
Experience: Master
Platform: ThinkorSwim, NinjaTrader
Trading: ES, NQ, YM, ZB, ZN, GC, SI, HG, CL, NG, ZS, ZC, ZW, 6E, 6B, 6A, 6J
Posts: 7 since Jul 2017
Thanks Given: 0
Thanks Received: 1


sunnydaze View Post
Def CURRENT= isnan(close[-1]) and !isnan(close);


I believe that’s what you need?
Makes the indicator only on current candle


Sent using the NexusFi mobile app

I'm trying to just have the indicator process or be ran at the very end of the current candle... ie. not tick for tick throughout that candle's timeframe.
It could also process the indicator at the very beginning of the new candle for the previous candle... but needs to happen immediately on the new candle.

Follow me on Twitter Started this thread Reply With Quote
  #9 (permalink)
sunnydaze
Manhattan NY/USA
 
Posts: 4 since May 2020
Thanks Given: 2
Thanks Received: 0

Yea correct, this will only show on the previous bar that just closed, so only 1 bar behind.
The !indicator[-1] IS for the future bar, however the “!” In front of it means, “not true” for the next bar.

As far as the Isnan code, that you would use if you wanted your signal to appear on the CURRENT bar, not the PREVIOUS (which is the code i just provided). Hope that makes sense...im still new in coding but had the same issue and these codes worked for me



Sent using the NexusFi mobile app

Reply With Quote
  #10 (permalink)
sunnydaze
Manhattan NY/USA
 
Posts: 4 since May 2020
Thanks Given: 2
Thanks Received: 0



InsideTheMarket View Post
I'm trying to just have the indicator process or be ran at the very end of the current candle... ie. not tick for tick throughout that candle's timeframe.

It could also process the indicator at the very beginning of the new candle for the previous candle... but needs to happen immediately on the new candle.



Yes, i believe the code i included will work, it will only show at the end of the candle/start of a new one


Sent using the NexusFi mobile app

Reply With Quote




Last Updated on July 4, 2020


© 2024 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 - Privacy Policy - Downloads - Top
no new posts