NexusFi: Find Your Edge


Home Menu

 





How to show bars ago cross for MACD


Discussion in ThinkOrSwim

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




 
Search this Thread

How to show bars ago cross for MACD

  #1 (permalink)
pollux321
atlanta
 
Posts: 3 since Jan 2015
Thanks Given: 0
Thanks Received: 0

Im trying to add a column to my watchlist that shows the bars ago crossed for the MACD. So if the MACD was bullish crossed 6 bars ago I want a green 6 and a red 6 if it was a bearish cross. That way I can sort my symbols to show symbols that have a crossed the most recent and see the ones that haven't crossed the longest. Any ideas how to do this?

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
Trade idea based off three indicators.
Traders Hideout
REcommedations for programming help
Sierra Chart
Cheap historycal L1 data for stocks
Stocks and ETFs
ZombieSqueeze
Platforms and Indicators
 
  #2 (permalink)
 growex 
Trubchevsk
 
Experience: Beginner
Platform: tos
Trading: stocks
Posts: 61 since May 2011
Thanks Given: 40
Thanks Received: 79

pollux321, paste it as custom watchlist query.
 
Code
                            
def fastLength 12;
def slowLength 26;
def MACDLength 9;
def averageType AverageType.EXPONENTIAL;
def Value MovingAverage(averageTypeclosefastLength) - MovingAverage(averageTypecloseslowLength);
def Avg MovingAverage(averageTypeValueMACDLength);
def Diff Value Avg;
def mode = if diff 0 then 1 else -1;
def bullcount = if mode == 1 then bullcount[1] + else  0;
def bearcount = if mode == -1 then bearcount[1] - else 0;
plot line = if mode == 1 then bullcount else bearcount;
line.assignValueColor(if line 0 then color.green else color.red); 

Follow me on Twitter Reply With Quote
  #3 (permalink)
pollux321
atlanta
 
Posts: 3 since Jan 2015
Thanks Given: 0
Thanks Received: 0


Ok I got that working. Is there a way I can make so the numbers sort from lowest to highest not discriminating by bull or bear but still hold colors. Like...

1 (green)
1 (red)
2 (red)
3 (green)

Reply With Quote
  #4 (permalink)
 growex 
Trubchevsk
 
Experience: Beginner
Platform: tos
Trading: stocks
Posts: 61 since May 2011
Thanks Given: 40
Thanks Received: 79


pollux321 View Post
Ok I got that working. Is there a way I can make so the numbers sort from lowest to highest not discriminating by bull or bear but still hold colors. Like...

1 (green)
1 (red)
2 (red)
3 (green)

from line 10 to end...

def bearcount = if mode == -1 then bearcount[1] + 1 else 0;
plot line = if mode == 1 then bullcount else bearcount;
line.assignValueColor(if mode == 1 then color.green else color.red);

Follow me on Twitter Reply With Quote
  #5 (permalink)
 
DougN's Avatar
 DougN 
Scottsdale, Arizona, USA and Puerto Penasco, Mx
 
Experience: Intermediate
Platform: Ninja 7, TOS
Trading: YM, ES, GC, CL
Posts: 42 since Nov 2013
Thanks Given: 35
Thanks Received: 33

Thanks for the script...very useful!
Doug

Follow me on Twitter Reply With Quote




Last Updated on July 20, 2018


© 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