NexusFi: Find Your Edge


Home Menu

 





how to convert recursive variable to scalar


Discussion in ThinkOrSwim

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




 
Search this Thread

how to convert recursive variable to scalar

  #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?
Exit Strategy
NinjaTrader
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
MC PL editor upgrade
MultiCharts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Spoo-nalysis ES e-mini futures S&P 500
28 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
20 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #2 (permalink)
 ocpb 
Hartford CT, USA
 
Experience: Beginner
Platform: None
Trading: ES
Posts: 126 since Jan 2015
Thanks Given: 152
Thanks Received: 125


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


© 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