NexusFi: Find Your Edge


Home Menu

 





SMA down X% in X bars and price X% below SMA


Discussion in ThinkOrSwim

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




 
Search this Thread
  #1 (permalink)
Brandonoh777
Indianapolis
 
Posts: 4 since Oct 2019
Thanks Given: 0
Thanks Received: 0

I am fairly good at backwards engineering code to do what i want with custom TOS scans but this one kinda has me stumped.... I want to look for ex. 21 period SMA 20% or more lower then 21 period SMA form 20 bars ago and.... price (low) is 10% or more below the current bar 21 period SMA

i would like to figure out the code for each condition individually then i can just add them both into my scann


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Second Night of US Strikes Crushes Iran June 15 to 3.6% …
Prediction Markets & Event Contracts
April 2026 Jobs Report: +115k vs +65k Expected
Traders Hideout
Saylors 41-Month HODL Breaks: Strategy Sells 32 BTC as $ …
Prediction Markets & Event Contracts
Kalshi Sets $4.13B All-Time Weekly Record as Polymarket …
Prediction Markets & Event Contracts
CME Launches Bitcoin Volatility Futures June 1 -- First …
Cryptocurrency
 
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)
Nube
Minneapolis Minnesota
 
Posts: 24 since Jul 2019
Thanks Given: 0
Thanks Received: 13


Brandonoh777 View Post
I am fairly good at backwards engineering code to do what i want with custom TOS scans but this one kinda has me stumped.... I want to look for ex. 21 period SMA 20% or more lower then 21 period SMA form 20 bars ago and.... price (low) is 10% or more below the current bar 21 period SMA

i would like to figure out the code for each condition individually then i can just add them both into my scann


 
Code
declare lower;

input length = 21;
input price = close;
input averageType = averageType.SIMPLE;
input compareToBarsAgo = 20;

def ma = MovingAverage(averageType, price, length);

plot MA_Condition = ma < ma[compareToBarsAgo] * .8; 
plot Price_Condition = low < ma * .9;


Reply With Quote
  #3 (permalink)
Brandonoh777
Indianapolis
 
Posts: 4 since Oct 2019
Thanks Given: 0
Thanks Received: 0



Nube View Post
 
Code
declare lower;

input length = 21;
input price = close;
input averageType = averageType.SIMPLE;
input compareToBarsAgo = 20;

def ma = MovingAverage(averageType, price, length);

plot MA_Condition = ma < ma[compareToBarsAgo] * .8; 
plot Price_Condition = low < ma * .9;

ok thanks ill try that!!! if its in a scan do i need the plot scan statement?


Reply With Quote
  #4 (permalink)
Brandonoh777
Indianapolis
 
Posts: 4 since Oct 2019
Thanks Given: 0
Thanks Received: 0


Nube View Post
 
Code
declare lower;

input length = 21;
input price = close;
input averageType = averageType.SIMPLE;
input compareToBarsAgo = 20;

def ma = MovingAverage(averageType, price, length);

plot MA_Condition = ma < ma[compareToBarsAgo] * .8; 
plot Price_Condition = low < ma * .9;

and in the future if i wanted to look at the flip side 21 period sma X % higher then 21 period sma form x bars ago i would change it to declare higher?


Reply With Quote
  #5 (permalink)
Brandonoh777
Indianapolis
 
Posts: 4 since Oct 2019
Thanks Given: 0
Thanks Received: 0


Nube View Post
 
Code
declare lower;

input length = 21;
input price = close;
input averageType = averageType.SIMPLE;
input compareToBarsAgo = 20;

def ma = MovingAverage(averageType, price, length);

plot MA_Condition = ma < ma[compareToBarsAgo] * .8; 
plot Price_Condition = low < ma * .9;

the OK button is grayed out


Attached Thumbnails
Click image for larger version

Name:	disk 6 error.jpg
Views:	284
Size:	72.6 KB
ID:	277904  
Reply With Quote




Last Updated on October 20, 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