NexusFi: Find Your Edge


Home Menu

 





Help with moving average code


Discussion in ThinkOrSwim

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




 
Search this Thread

Help with moving average code

  #1 (permalink)
guspenskiy13
Boston, MA USA
 
Posts: 2 since May 2014
Thanks Given: 0
Thanks Received: 0

Hey everybody, I have a little problem with my thinkorswim script.

I tweaked the Symbol Relation study from TOS and added a simple moving average to it.

However, SMA is not displayed right after the open - and the higher is the length of SMA - the longer it takes to appear on the chart.

I would really appreciate, if someone could help me with this and fix it....

Thanks..
_________

script:

declare lower;
input price = FundamentalType.CLOSE;
input relationWithSecurity = "VXX";
input length = 9;
input displace = 0;
def price1 = fundamental(price);
def price2 = fundamental(price, relationWithSecurity);
plot Relation = if price2 == 0 then Double.NaN else price2 / price1;
Relation.SetDefaultColor(GetColor(1));
plot SMA = Average(Relation[-displace], length);
SMA.SetDefaultColor(GetColor(5));

screenshot (can't post links - remove the spaces...)

ht t p : // tinypic. com /r / migl94 /8

On the left side I have SPY chart with SMA(60); on the right SMA(9)

I want SMA to be displayed right off the open - for some reason it does not appear.

Thanks.

P.S.

Each +1 in length of SMA shortens it. I wonder what's the reason for that.

For some reason 5-minute chart gets the longest MA...

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Strategy stop orders partially filled
EasyLanguage Programming
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
What broker to use for trading palladium futures
Commodities
REcommedations for programming help
Sierra Chart
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
24 thanks
What is Markets Chat (markets.chat) real-time trading ro …
19 thanks
ApexTraderFunding.com experience and review
17 thanks
GFIs1 1 DAX trade per day journal
13 thanks
EG Indicators
11 thanks
  #2 (permalink)
 
rmejia's Avatar
 rmejia 
Puerto Rico
 
Experience: Intermediate
Platform: thinkorswim
Broker: TD Ameritrade
Trading: Options
Posts: 379 since Oct 2010
Thanks Given: 3,614
Thanks Received: 441

There are some gaps in the candles of the premarket VXX "relation" line; each blank space it is restarting the MA length count. The Moving Average is an average of the defined length. If using a length of 9, after the first gap count 9 candles and then the MA starts. With 60, it needs a length of 60 candles to average before the MA line plot starts.

Reply With Quote
  #3 (permalink)
guspenskiy13
Boston, MA USA
 
Posts: 2 since May 2014
Thanks Given: 0
Thanks Received: 0


I see.

But then, I get (VXX)/(SPY) in Prophet with any average and it seems to be... fine...?

and why 5 minute chart gets better results than 1 minute?

Reply With Quote




Last Updated on May 14, 2014


© 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