NexusFi: Find Your Edge


Home Menu

 





ana SuperTrend.......


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one Fat Tails with 12 posts (11 thanks)
    2. looks_two cbritton with 9 posts (13 thanks)
    3. looks_3 Serger with 5 posts (0 thanks)
    4. looks_4 tst1 with 5 posts (0 thanks)
      Best Posters
    1. looks_one cbritton with 1.4 thanks per post
    2. looks_two sptrader with 1 thanks per post
    3. looks_3 Fat Tails with 0.9 thanks per post
    4. looks_4 ABCTG with 0.8 thanks per post
    1. trending_up 33,248 views
    2. thumb_up 32 thanks given
    3. group 17 followers
    1. forum 48 posts
    2. attach_file 14 attachments




 
Search this Thread

ana SuperTrend.......

  #1 (permalink)
 
Serger's Avatar
 Serger 
Quebec
 
Experience: Intermediate
Platform: Multicharts 64 +VolProfile
Broker: Interactive Brokers
Trading: Ym, Es
Posts: 74 since Oct 2010
Thanks Given: 64
Thanks Received: 25

are what anyone would be able to turn this fantastic
anaSuperTrend vertion in MC??
it is absolutely genial this indicator ....
thank you for your help in advance!

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
Better Renko Gaps
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
MC PL editor upgrade
MultiCharts
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Diary of a simple price action trader
26 thanks
Just another trading journal: PA, Wyckoff & Trends
24 thanks
Tao te Trade: way of the WLD
21 thanks
My NQ Trading Journal
16 thanks
HumbleTraders next chapter
9 thanks
  #2 (permalink)
 
cbritton's Avatar
 cbritton 
Atlanta, Georgia
 
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256

I looked at the NT code for this and started to port the MovingMedian indicator to easy language first since anaSuperTrend depends on that. Can someone post a screenshot of the NT version on some daily chart so I can compare it?

Here's the function for moving median:

 
Code
inputs:
    Price(NumericSeries),
    length(NumericSimple);

variables: 
    int period(0),
    int idx(0),
    int meanIdx(0),
    int priorIdx(0),
    float MA(0.0);
    
Array: float mArray[](0);
    
if period < 1 then period = 1 else period = length; //throw some exception

Array_SetMaxIndex(mArray, period);

if currentbar < period then begin
    value1 = currentbar + 1;
    for idx = 0 to value1 - 1 begin  // inclusive?
        mArray[idx] = price[idx];
    end;
    value2 = SortArray(mArray,period,1);  //ascending?? should not matter since we're getting the median
    
    if mod(period, 2) = 0 then MA = 0.5 * (mArray[value1/2] + mArray[value1/2-1])
    else MA = mArray[(value1-1)/2];

end else begin

    for idx = 0 to period - 1 begin
        mArray[idx] = price[idx];
    end;
    value2 = SortArray(mArray,period,1);
    if mod(period, 2) = 0 then 
        MA = 0.5 * (mArray[period/2] + mArray[period/2-1])
    else
        MA = mArray[(period-1)/2];

end;

_MovingMedian = MA;
and the indicator. Nothing fancy like rising/falling colors.

 
Code
input: price(close),
        period(17);

Plot1(_MovingMedian(price, period), "MovMed");
This works in TradeStation.

I will try to make sense of the anaSuperTrend indicator next.

Regards,
-C

“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
Reply With Quote
Thanked by:
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102



cbritton View Post
I looked at the NT code for this and started to port the MovingMedian indicator to easy language first since anaSuperTrend depends on that. Can someone post a screenshot of the NT version on some daily chart so I can compare it?

Here is a daily chart of the S&P 500 index with the anaSuperTrend applied. Let me know, if you need any help in understanding the code.

Attached Thumbnails
Click image for larger version

Name:	^SP500 (Daily)  11_11_2010 - 25_05_2011.jpg
Views:	1310
Size:	75.0 KB
ID:	39386  
Reply With Quote
Thanked by:
  #4 (permalink)
 
cbritton's Avatar
 cbritton 
Atlanta, Georgia
 
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256


Fat Tails View Post
Here is a daily chart of the S&P 500 index with the anaSuperTrend applied. Let me know, if you need any help in understanding the code.

Thanks! I'll try to have something to post later today or tomorrow.

-C

“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
Reply With Quote
Thanked by:
  #5 (permalink)
 
cbritton's Avatar
 cbritton 
Atlanta, Georgia
 
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256

Here's my first stab at it. I'm sure there are some things I did not do right, so pick it apart and make it better!

I coded this as a show me in TradeStation instead of an indicator. No real reason for that. I included the commentary block if you feel like you need to debug it for whatever reason. Just set debug to true (the default). The NT code logic did not translate well to EL, so I did some minor tweaking to make this work.

Attached is a screen shot of the show me applied to the daily SPY. The yellow "+" indicates the up/down arrows on the NT version.

 
Code
inputs:
    price(close),
    medianPeriod(5),
    atrPeriod(21),
    atrMultiplier(3),
    showStopLine(true),
    showArrows(true);

vars: 
      stopLine(0),
      upTrend(true), 
      currentUpTrend(true),
      color(0),
      newstop(0),
      priorStop(0), 
      priorcolor(0),
      MM(0),
      MAE(0),
      debug(true);

MM = _MovingMedian(price, medianPeriod);
MAE = _AvgTrueRange(atrPeriod);

// Define the rising/falling colors
if 1 = 0 then begin
    Plot1(close, "rising");
    Plot2(close, "falling");
end;

if CurrentBar = 0 then begin
    stopLine = close;
    upTrend = true;
end;

if close > stopLine[1] then begin
    upTrend = true;
    newStop = MM - atrMultiplier * MAE;
    currentUpTrend = true;

    if upTrend[1] = false then stopline = newStop
    else stopline = maxlist(newStop, stopline[1]);
    
end else if close < stopLine[1] then begin

    upTrend = false;
    newStop = MM + atrmultiplier * MAE;
    currentUpTrend = false;
    
    if UpTrend[1] = true then stopLine = newStop 
    else stopLine = minlist(newStop, StopLine[1]); 

end else begin

    upTrend = upTrend[1];
    currentUpTrend = upTrend;
    stopline = stopline[1];

end;


if debug = true then begin
    #beginCmtry
        CommentaryCL("*************************************************");
        CommentaryCL("MM: ", MM);
        CommentaryCL("MAE: ", MAE);
        CommentaryCL("close: " ,c);
        CommentaryCL("upTrend: ", upTrend);
        CommentaryCL("upTrend[1]: ", upTrend[1]);
        CommentaryCL("currentUpTrend: ", currentUpTrend);
        CommentaryCL("stopLine: ", stopLine);
        CommentaryCL("priorStop: ", priorStop);
        CommentaryCL("*************************************************");
    #End;
end;

if showArrows then begin
    value3 = MinMove/PriceScale;
    if currentUpTrend = true and upTrend[1]<> true then begin
    
        value2 = newStop - 2 * value3;
        Plot3(newStop - 2* value3, "Arrow down");
        
    end else if currentUpTrend <> true and upTrend[1]=true  then begin

        value2 = newStop + 2 * value3;
        Plot4(newStop + 2* value3, "Arrow up");
    end;

end;


if showStopLine then begin

    if UpTrend = true and upTrend[1] <> true then begin
        color = GetPlotColor(1); // up color
    end else if UpTrend = true then begin
        color = GetPlotcolor(1); // up Color
    end else if UpTrend <> true and upTrend[1]=true then begin
        color = GetPlotColor(2); // down color
    end else begin
        color = GetPlotColor(2); // down color
    end;
    
    Plot5(stopLine, "Stop Line", color);

end;
Regards,
-C

“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
Attached Thumbnails
Click image for larger version

Name:	2011-05-27_13-27-31.png
Views:	706
Size:	49.0 KB
ID:	39434   Click image for larger version

Name:	2011-05-27_13-27-58.png
Views:	427
Size:	35.7 KB
ID:	39435  
Reply With Quote
Thanked by:
  #6 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102

The result looks near correct. The Easy Language version seems to track price closer than the origianl version. However, when I checked the code, it looks correct. The only difference I found:

The anaSuperTrend uses the statistical Median of the Median[0], the latter being (High[0]+Low[0])/2. This means that the median is not calculated from the closes. I am not sure about the Easy Language version.

With the same parameters that you used, the NinjaTrader chart looks like this:

Attached Thumbnails
Click image for larger version

Name:	^SP500 (Daily)  18_10_2010 - 26_05_2011.jpg
Views:	625
Size:	83.6 KB
ID:	39447  
Reply With Quote
  #7 (permalink)
 
cbritton's Avatar
 cbritton 
Atlanta, Georgia
 
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256

There's nothing interesting about ATR, so it's probably a difference in how the moving median is computed as far as these differences are concerned. Here's a screenshot of the indicator I posted earlier with a 10 period moving median on the daily close of SPY. Seems anyone can just pick a decent moving average indicator to base the ATR off of. A "pick your own" type of indicator like what we have around this site would allow people to adjust the super trend to their style.

Just my 0.02
-C

“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
Attached Thumbnails
Click image for larger version

Name:	2011-05-27_16-55-08.png
Views:	410
Size:	40.7 KB
ID:	39458  
Reply With Quote
Thanked by:
  #8 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


cbritton View Post
There's nothing interesting about ATR, so it's probably a difference in how the moving median is computed as far as these differences are concerned. Here's a screenshot of the indicator I posted earlier with a 10 period moving median on the daily close of SPY. Seems anyone can just pick a decent moving average indicator to base the ATR off of. A "pick your own" type of indicator like what we have around this site would allow people to adjust the super trend to their style.

Just my 0.02
-C

But did you see that my indicator does not use Median(Close,n) but Median((High+Low)/2,n) ?

Reply With Quote
Thanked by:
  #9 (permalink)
 
cbritton's Avatar
 cbritton 
Atlanta, Georgia
 
Experience: Intermediate
Platform: NT
Broker: DDT
Trading: ZN, ZB
Posts: 230 since Mar 2010
Thanks Given: 152
Thanks Received: 256


Fat Tails View Post
But did you see that my indicator does not use Median(Close,n) but Median((High+Low)/2,n) ?

Well I feel stupid now.

Here's my updated chart.

“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
Attached Thumbnails
Click image for larger version

Name:	2011-05-27_17-44-38.png
Views:	636
Size:	44.0 KB
ID:	39462  
Reply With Quote
Thanked by:
  #10 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102



cbritton View Post
Well I feel stupid now.

Here's my updated chart.

Looks good now. If it is not identical, it comes very close at least. I think you made it.

Reply With Quote
Thanked by:




Last Updated on April 10, 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