NexusFi: Find Your Edge


Home Menu

 





comparing moving average and price


Discussion in ThinkOrSwim

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




 
Search this Thread
  #1 (permalink)
tlbh01
mpls mn usa
 
Posts: 1 since Sep 2020
Thanks Given: 0
Thanks Received: 0

can someone help with a script to compare two moving averages? For example, one is above the other?

movingave(5) > movingave(8)

and also check to see the price is equal to or above the moving avg?

price => movingave(5), meaning it sits on the avg or sits above it.


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Bookmap Global Plus Lifetime + Lifetime Addons For Sale
Platforms and Indicators
The June 15 Resolution Trap: Irans Agreed Text Still Pri …
Prediction Markets & Event Contracts
Czechia Live at 52.5% as England Rides 4-2 Wave to Co-Fa …
Prediction Markets & Event Contracts
Memorandum Watch: How the 60-Day MOU Framework Makes May …
Prediction Markets & Event Contracts
Saylors 41-Month HODL Breaks: Strategy Sells 32 BTC as $ …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
10 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 thanks
  #2 (permalink)
VanDriver
Jackson, MS
 
Posts: 34 since Dec 2015
Thanks Given: 1
Thanks Received: 5

Enjoy the script. It will display when two moving averages are above each other as well as when price is above the fastest moving average in the same direction (vice versa for down direction). It uses your request by default but allows users to input length and type of moving averages. It displays a color coded label in the top left corner with four results: All Up; MA UP & Neutral Price; ALL Down; and MA Down & Neutral Price.

 
Code
#VanDriver @ Futures.io on Sept 6, 2020. 
# Request: display when two moving averages are above each other as well as when price is above the fastest moving average in the same direction (vice versa for down direction). Displays four results: All Up; MA UP & Neutral Price; ALL Down; and MA Down & Neutral Price. 

# Begin script 
input price = close;
input fastLength = 5;
input FaverageType = AverageType.SIMPLE;
input slowLength = 8;
input saverageType = AverageType.SIMPLE;

plot FastMA = MovingAverage(FaverageType, price, fastLength);
fastma.setDefaultColor(color.yellow);
plot SlowMA = MovingAverage(SaverageType, price, slowLength);
slowma.setDefaultColor(color.red);

def up = fastma > slowma;
def aup = up and close > fastma;
def upn = up and close < fastma;

def dn = fastma < slowma;
def adn = dn and close < fastma;
def udn = dn and close > fastma;

AddLabel(yes, Concat(" ", (if aup then "All Up" else if upn then "MA Up, Neutral Price " else if adn then "All Down" else if udn then "MA Down, Neutral Price" else "Chop")),  if aup then Color.Green else if upn then Color.Dark_Green else if adn then Color.orange else if udn then Color.RED else Color.violet);

# end script


Attached Thumbnails
Click image for larger version

Name:	avg.png
Views:	272
Size:	35.2 KB
ID:	304761  
Reply With Quote




Last Updated on September 6, 2020


© 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