NexusFi: Find Your Edge


Home Menu

 





how to convert recursive variable to scalar


Discussion in ThinkOrSwim

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




 
Search this Thread
  #1 (permalink)
piyushdna
Los Angeles
 
Posts: 1 since Feb 2019
Thanks Given: 1
Thanks Received: 0

how to convert recursive variable to scalar to be used in variable subscript. New to thinkscript. Please help
--------------------------------------------------------------------------
diffrence_bar_numbers should be scalar ?? in below
--------------------------------------------------------------------------
def a = HighestAll(high);
def b = LowestAll(low);
def barnumber = BarNumber();
def c = if high == a then barnumber else Double.NaN;
def d = if low == b then barnumber else Double.NaN;
rec highnumber = CompoundValue(1, if IsNaN(c) then highnumber[1] else c, c);
def highnumberall = HighestAll(highnumber);
rec lownumber = CompoundValue(1, if IsNaN(d) then lownumber[1] else d, d);
def lownumberall = LowestAll(lownumber);

def diffrence_bar_numbers = highnumberall - lownumberall;

def shift_factor = 5;
def data = high;
def data_shifted = data[-5];

# ERROR is Only constants expected here: diffrence_bar_numbers CL variable indexer of data
def data_shifted_using_bar_numbers = data[-diffrence_bar_numbers];


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trump Lands in Beijing on CPI Day: Iran Peace Expires To …
Prediction Markets & Event Contracts
Sundays Verdict: Lebanon Locked at 99.85% as Iran June 7 …
Prediction Markets & Event Contracts
Friday Update: Markets Now Pricing Fed Rate HIKES as Sta …
Traders Hideout
Thanks Mike. Godspeed.
The Elite Circle
El Clasico Draws $9.2M in Prediction Market Action -- Bi …
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)
 ocpb 
Hartford CT, USA
 
Experience: Beginner
Platform: None
Trading: ES
Posts: 126 since Jan 2015
Thanks Given: 152
Thanks Received: 126


piyushdna View Post
# ERROR is Only constants expected here: diffrence_bar_numbers CL variable indexer of data
def data_shifted_using_bar_numbers = data[-diffrence_bar_numbers];

In thinkscript, you cannot have a dynamic value as the index. As the error says, it must be a constant (integer), which may also be an input value.

Getting some ideas working in thinkscript can require some awkward brute force coding as opposed to elegance...
For instance, if you happened to know that the bar number difference was always constrained to a some useful small range(s), maybe you could use several conditional expressions to finagle the result you're after.


Reply With Quote
Thanked by:




Last Updated on March 18, 2019


© 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