NexusFi: Find Your Edge


Home Menu

 





how to convert recursive variable to scalar


Discussion in ThinkOrSwim

Updated
    1. trending_up 3,606 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?
Pakistan Mediator in Tehran as Hormuz Normalization Coll …
Prediction Markets & Event Contracts
Warsh Opens Today, Hormuz June 19 -- WTI Below $80, Fran …
Prediction Markets & Event Contracts
UMA Votes Tonight: Polymarkets $80M Strategy Bitcoin Bat …
Prediction Markets & Event Contracts
Double Deadlock: Rubio Calls Hormuz Tolls "Unfeasib …
Traders Hideout
Second Night of US Strikes Crushes Iran June 15 to 3.6% …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
13 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 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