NexusFi: Find Your Edge


Home Menu

 





Help with easy language ma indicator for tradestation


Discussion in EasyLanguage Programming

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




 
Search this Thread
  #1 (permalink)
 cjshu99 
Lake Charles, LA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: futures, options
Frequency: Daily
Posts: 7 since Jun 2022
Thanks Given: 12
Thanks Received: 1

Found this on trading view and can't get it to work in tradestation 10.

It will change the color of the moving average depending on direction - up or down.

Can anyone help?


Quoting 
//@version=4
//Color MA colors the moving average plot based on direction
//MA types are:
// 1 - simple
// 2 - exponential
// 3 - Hull
// 4 - weighted
// 5 - volume weighted

study(title = "Color MA", shorttitle="CMA", overlay = true)
length = input(9, minval=1, title="Length")
src = input(close, title="Source")
matype = input(1, minval=1, maxval=5, title="AvgType")

simplema = sma(src,length)
exponentialma = ema(src,length)
hullma = wma(2*wma(src, length/2)-wma(src, length), round(sqrt(length)))
weightedma = wma(src, length)
volweightedma = vwma(src, length)

avgval = matype==1 ? simplema : matype==2 ? exponentialma : matype==3 ? hullma : matype==4 ? weightedma : matype==5 ? volweightedma : na
Pcolor = avgval > avgval[1] ? color.green : color.red

plot(avgval,title='Color MA', color=Pcolor, linewidth=4)


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Rubios Good News Within Hours and the 30-Day Math: Why H …
Prediction Markets & Event Contracts
Al Arabiya: US-Iran Draft Deal Within Hours Contains Hor …
Prediction Markets & Event Contracts
Prediction Markets Lock Fed Pause at 99pct for April 29 …
Prediction Markets & Event Contracts
Tradeify 3.0 Overhauls Futures Prop Firm Model -- One-Ti …
Funded Trading Evaluation Firms
Iran Peace Expired NO: Ceasefire on Life Support, OPEC a …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
196 thanks
Sober Journey With S&P
27 thanks
30 Sessions
20 thanks
BERN ALGOS algo trading journal
8 thanks
Volume Indicators
8 thanks
  #2 (permalink)
 
Tripken's Avatar
 Tripken 
Knoxville, TN/USA
Legendary Market Wizard
 
Experience: Beginner
Platform: TradeStation
Broker: TradeStation
Trading: ES
Frequency: Several times daily
Duration: Minutes
Posts: 641 since Feb 2010
Thanks Given: 1,750
Thanks Received: 1,428


cjshu99 View Post
Found this on trading view and can't get it to work in tradestation.

It will change the color of the moving average depending on direction - up or down.

Can anyone help?

Here's some EL code that is similar. It changes color based on direction and calculates the angle. That can be commented out.
Perhaps you can take this and adapt your code to get it working. This one uses "Exponential" but that can be changed.

Hope it helps.
//////////////////////////////////////////////////////////
Input: Flat(LightGray), Up(Cyan), Down(Red),
Price(Close), Length(20), Displace(0);
Variables: myPlot(0), Color(green), myAngle(0);


myPlot = XAverage(Price,Length);

plot1[Displace](myPlot, "Xavg");

if C > myPlot then
SetPlotColor[1](1, Up);
if C < myPlot then
SetPlotColor[1](1, Down);
if C = myPlot then
SetPlotColor[1](1, Flat);

if C crosses above myPlot Then
Alert( " Crossing up") ;

if C crosses below myPlot Then
Alert( " crossing down ") ;


myangle = LinearRegAngle(XAverage(Price,Length), 2);


condition1 = DrawTextOnLastBar(-999999, 2, NumToStr(myangle,2) + "*", XAverage(Price,Length), white, 0);
/////////////////////////////////////////////////////////////////////////////////////////////////////


Reply With Quote
Thanked by:
  #3 (permalink)
 cjshu99 
Lake Charles, LA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: futures, options
Frequency: Daily
Posts: 7 since Jun 2022
Thanks Given: 12
Thanks Received: 1


Thanks. That looks good. Will see about making it use a sma


Started this thread Reply With Quote
  #4 (permalink)
 jwwjcw 
Washington DC
 
Experience: Intermediate
Platform: TradeStation
Trading: EC
Posts: 9 since Sep 2012
Thanks Given: 0
Thanks Received: 5

Inputs: Price(Close), matype(1), malength(9);

// Simple MA
if matype = 1 then Value1 = Average(Price, malength);

// Exponential
if matype = 2 then Value1 = XAverage(Price, malength);

// Hull
if matype = 3 then Value1 = HMA(Price, malength);

// Weighted
if matype = 4 then Value1 = WAverage(Price, malength);

// Vol Weighted - you can find this formula in the
// Mov Avg Volume-weighted indicator in Easy Language

if Value1 > Value1[1] then plot1(Value1, "MA", green)
else plot1(Value1, "MA", red);

You can use the properties tab to customize


Reply With Quote
Thanked by:




Last Updated on July 30, 2023


© 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