Login Page - Create Account

Support Board


Date/Time: Sun, 24 Nov 2024 00:30:41 +0000



[User Discussion] - Who can code this Indi for Sierras ?

View Count: 9934

[2013-06-12 10:11:15]
Michael Weder - Posts: 1
Hello,
I found an indicator at ff in this thread (link below) and my question is, if
somebody here is able to code it for Sierra ?

It`s called TMA, but has nothing or nearly nothing to do with the Triangular moving average we have in the sierra indicator list.
It`s a channel with upper, middle and lower band.
The post in the link below shows screenshots how it looks and how it`s coded for metatrader4

http://www.forexfactory.com/showthread.php?p=6609629#post6609629

At the end of the post it`s the TMA.mq4 I`m interested in.

BTW. Im not interested in this trading system, just in this TMA-Channel.

Thanks
Mike

[2015-02-05 09:26:36]
User89195 - Posts: 5
Supports the request!
[2015-02-05 15:38:33]
ehlaban - Posts: 50
Is there any more explanation or source code available from other programs?
[2015-02-06 09:44:34]
User89195 - Posts: 5
There is an indicator MT4. Thanks!

//+------------------------------------------------------------------+
//| TriangularMA centered bands.mq4 |
//| mladen |
//| forex-tsd elite section only |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link "mladenfx@gmail.com"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 LimeGreen
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_style2 STYLE_DOT
#property indicator_style3 STYLE_DOT

//
//
//
//
//

extern string TimeFrame = "current time frame";
extern int HalfLength = 20;
extern int Price = PRICE_CLOSE;
extern double ATRMultiplier = 2.0;
extern int ATRPeriod = 100;
extern bool Interpolate = true;

extern bool alertsOn = false;
extern bool alertsOnCurrent = false;
extern bool alertsOnHighLow = false;
extern bool alertsMessage = false;
extern bool alertsSound = false;
extern bool alertsEmail = false;

//
//
//
//
//

double buffer1[];
double buffer2[];
double buffer3[];
double trend[];

//
//
//
//
//

string indicatorFileName;
bool calculateValue;
bool returnBars;
int timeFrame;

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//

int init()
{
IndicatorBuffers(4);
HalfLength=MathMax(HalfLength,1);
SetIndexBuffer(0,buffer1); SetIndexDrawBegin(0,HalfLength);
SetIndexBuffer(1,buffer2); SetIndexDrawBegin(1,HalfLength);
SetIndexBuffer(2,buffer3); SetIndexDrawBegin(2,HalfLength);
SetIndexBuffer(3,trend);

//
//
//
//
//

indicatorFileName = WindowExpertName();
returnBars = TimeFrame=="returnBars"; if (returnBars) return(0);
calculateValue = TimeFrame=="calculateValue"; if (calculateValue) return(0);
timeFrame = stringToTimeFrame(TimeFrame);

//
//
//
//
//

IndicatorShortName(timeFrameToString(timeFrame)+" TMA bands )"+HalfLength+")");
return(0);
}
int deinit() { return(0); }




//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//

int start()
{
int counted_bars=IndicatorCounted();
int i,j,k,limit;

if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=MathMin(Bars-1,Bars-counted_bars+HalfLength);
if (returnBars) { buffer1[0] = limit+1; return(0); }

//
//
//
//
//

if (calculateValue || timeFrame==Period())
{
for (i=limit; i>=0; i--)
{
double sum = (HalfLength+1)*iMA(NULL,0,1,0,MODE_SMA,Price,i);
double sumw = (HalfLength+1);

for(j=1, k=HalfLength; j<=HalfLength; j++, k--)
{
sum += k*iMA(NULL,0,1,0,MODE_SMA,Price,i+j);
sumw += k;

if (j<=i)
{
sum += k*iMA(NULL,0,1,0,MODE_SMA,Price,i-j);
sumw += k;
}
}

//
//
//
//
//

double range = iATR(NULL,0,ATRPeriod,i+10)*ATRMultiplier;
buffer1[i] = sum/sumw;
buffer2[i] = buffer1[i]+range;
buffer3[i] = buffer1[i]-range;

//
//
//
//
//

trend[i] = 0;
if (alertsOnHighLow)
{
if (High[i] > buffer2[i]) trend[i] = 1;
if (Low[i] < buffer3[i]) trend[i] = -1;
}
else
{
if (Close[i] > buffer2[i]) trend[i] = 1;
if (Close[i] < buffer3[i]) trend[i] = -1;
}
}
if (!calculateValue) manageAlerts();
return(0);
}

//
//
//
//
//

limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,indicatorFileName,"returnBars",0,0)*timeFrame/Period()));
for(i=limit; i>=0; i--)
{
int y = iBarShift(NULL,timeFrame,Time[i]);
buffer1[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateTma",HalfLength,Price,ATRMultiplier,ATRPeriod,0,y);
buffer2[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateTma",HalfLength,Price,ATRMultiplier,ATRPeriod,1,y);
buffer3[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateTma",HalfLength,Price,ATRMultiplier,ATRPeriod,2,y);
trend[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateTma",HalfLength,Price,ATRMultiplier,ATRPeriod,3,y);

//
//
//
//
//

if (timeFrame <= Period() || y==iBarShift(NULL,timeFrame,Time[i-1])) continue;
if (!Interpolate) continue;

//
//
//
//
//

datetime time = iTime(NULL,timeFrame,y);
for(int n = 1; i+n < Bars && Time[i+n] >= time; n++) continue;  
for(k = 1; k < n; k++)
{
buffer1[i+k] = buffer1[i] +(buffer1[i+n]-buffer1[i])*k/n;
buffer2[i+k] = buffer2[i] +(buffer2[i+n]-buffer2[i])*k/n;
buffer3[i+k] = buffer3[i] +(buffer3[i+n]-buffer3[i])*k/n;
}
}

//
//
//
//
//

manageAlerts();
return(0);
}

//+-------------------------------------------------------------------
//|
//+-------------------------------------------------------------------
//
//
//
//
//

void manageAlerts()
{
if (alertsOn)
{
if (alertsOnCurrent)
int whichBar = 0;
else whichBar = 1; whichBar = iBarShift(NULL,0,iTime(NULL,timeFrame,whichBar));
if (trend[whichBar] != trend[whichBar+1])
{
if (trend[whichBar] == 1) doAlert(whichBar,"up");
if (trend[whichBar] ==-1) doAlert(whichBar,"down");
}
}
}

//
//
//
//
//

void doAlert(int forBar, string doWhat)
{
static string previousAlert="nothing";
static datetime previousTime;
string message;

if (previousAlert != doWhat || previousTime != Time[forBar]) {
previousAlert = doWhat;
previousTime = Time[forBar];

//
//
//
//
//

message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," "+timeFrameToString(timeFrame)+" TMA bands price penetrated ",doWhat," band");
if (alertsMessage) Alert(message);
if (alertsEmail) SendMail(StringConcatenate(Symbol(),"TMA bands "),message);
if (alertsSound) PlaySound("alert2.wav");
}
}

//+-------------------------------------------------------------------
//|
//+-------------------------------------------------------------------
//
//
//
//
//

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

//
//
//
//
//

int stringToTimeFrame(string tfs)
{
tfs = StringUpperCase(tfs);
for (int i=ArraySize(iTfTable)-1; i>=0; i--)
if (tfs==sTfTable[i] || tfs==""+iTfTable[i]) return(MathMax(iTfTable[i],Period()));
return(Period());
}
string timeFrameToString(int tf)
{
for (int i=ArraySize(iTfTable)-1; i>=0; i--)
if (tf==iTfTable[i]) return(sTfTable[i]);
return("");
}

//
//
//
//
//

string StringUpperCase(string str)
{
string s = str;

for (int length=StringLen(str)-1; length>=0; length--)
{
int chars = StringGetChar(s, length);
if((chars > 96 && chars < 123) || (chars > 223 && chars < 256))
s = StringSetChar(s, length, chars - 32);
else if(chars > -33 && chars < 0)
s = StringSetChar(s, length, chars + 224);
}
return(s);
}

attachmentTMA.mq4 - Attached On 2015-02-06 09:40:18 UTC - Size: 8.43 KB - 772 views
Attachment Deleted.
[2015-02-08 12:28:22]
ehlaban - Posts: 50
Can somebody post an example of this indicator on a daily chart of the S&P 500 Index and/or the daily EUR/USD.
Please include the settings e.g. length and/or halflength used.

I need this to compare it with what i'm coding
Date Time Of Last Edit: 2015-02-08 15:15:13
[2015-02-08 16:18:01]
User89195 - Posts: 5
Please take a look, alerts are not important.. Thank U!
Date Time Of Last Edit: 2015-02-08 16:19:51
image2015-02-08_16-09-10.jpg / V - Attached On 2015-02-08 16:15:08 UTC - Size: 259.97 KB - 1231 views
image2015-02-08_16-12-49.jpg / V - Attached On 2015-02-08 16:15:25 UTC - Size: 239.42 KB - 974 views
[2015-02-08 16:47:40]
ehlaban - Posts: 50
Thanks this is what i needed.

Can you also tell what the settings are in both pictures like halflength and ATR and ATR multiplier.
This is crucial for me to replicate the indicator!
[2015-02-08 17:47:58]
ehlaban - Posts: 50
This is what i got so far, quite identical. Try to end it in a few days.
imageTMA bands.PNG / V - Attached On 2015-02-08 17:46:04 UTC - Size: 313.62 KB - 1216 views
[2015-02-09 08:00:40]
User89195 - Posts: 5
Please see. In more detail, I do not know.
image2015-02-09_7-55-34.jpg / V - Attached On 2015-02-09 08:00:25 UTC - Size: 56.7 KB - 920 views
[2015-02-09 08:11:29]
User89195 - Posts: 5
Please see drawn. Thanks!
image11.PNG / V - Attached On 2015-02-09 08:11:17 UTC - Size: 307.64 KB - 853 views
[2015-02-12 18:55:47]
ehlaban - Posts: 50
As I don't know Metatrader i looked at http://www.traderji.com/amibroker/74960-triangular-moving-average-tma-bands.html for a reference.
But i'm afraid i can't get it correctly coded. The last part is always wrong.

Perhaps somebody else can figure it out.


// The top of every source code file must include this line
#include <math.h>
#include "sierrachart.h"

// This line is required. Change the text within the quote
// marks to what you want to name your group of custom studies.
SCDLLName("ehlTMABands")

SCSFExport scsf_ehlTMABands(SCStudyInterfaceRef sc)
{
  // Reference the Plots and the inputs
  SCSubgraphRef   midBand  = sc.Subgraph[0];
  SCSubgraphRef   topBand = sc.Subgraph[1];
  SCSubgraphRef   lowBand = sc.Subgraph[2];

  SCFloatArrayRef sma = midBand.Arrays[0];
  SCFloatArrayRef iatr = midBand.Arrays[1];

  SCInputRef     HalfLength    = sc.Input[0];
  SCInputRef     ATRPeriod    = sc.Input[1];
  
  if (sc.SetDefaults)
  {
  // Section 1 - Set the configuration variables and defaults
    sc.GraphName       = "ehlTMAbands"; // Name in study overview
    sc.StudyDescription   = "TMA Bands Indicator";    
        
    sc.GraphRegion       = 0;  // Set the Chart Region to draw the graph in. Region 0 is the main price graph
    sc.FreeDLL         = 1;  // During dev set this flag to 1, so DLL can be rebuilt without restarting Sierra
    sc.AutoLoop       = 0;  //Auto looping is enabled.
    
  // Reference the Plots and the inputs and define them
    midBand.Name = "midBand";
    midBand.DrawStyle = DRAWSTYLE_LINE;      // Look in scconstants.h for other draw styles
    midBand.PrimaryColor = RGB(0, 128, 0);    // Red  
    midBand.LineWidth = 2;

    topBand.Name = "topBand";
    topBand.DrawStyle = DRAWSTYLE_POINT;    // Look in scconstants.h for other draw styles
    topBand.PrimaryColor = RGB(255, 0, 0);    // Light Green  
    topBand.LineWidth = 1;

    lowBand.Name = "lowBand";
    lowBand.DrawStyle = DRAWSTYLE_POINT;    // Look in scconstants.h for other draw styles
    lowBand.PrimaryColor = RGB(0, 128, 0);    // Green  
    lowBand.LineWidth = 1;
    
    HalfLength.Name = "Length";
    HalfLength.SetInt(20);
    HalfLength.SetIntLimits(1, 300);

    ATRPeriod.Name = "Forecast";
    ATRPeriod.SetInt(100);
    ATRPeriod.SetIntLimits(1, INT_MAX);
    return;
  }
  // Section 2 - Do data processing here
  float dSum, sumw;
  int j = 1, k, limit;
  int intHalfLength = HalfLength.GetInt();
  int intATRPeriod = ATRPeriod.GetInt();
  limit = sc.ArraySize - 1;
    
  for (int i = 0; i < sc.ArraySize; i++)
  //for (int i = sc.UpdateStartIndex; i < sc.ArraySize; i++)
  {
    dSum = (intHalfLength + 1) * sc.BaseDataIn[SC_LAST][i];
    sumw = (intHalfLength + 1);

    for (j = 1, k = intHalfLength; j <= intHalfLength; j++, k--)
    {
      if (i + j >= sc.ArraySize) break;
      
      dSum += k * sc.BaseDataIn[SC_LAST][i + j];
      sumw += k;

      if (j <= i)
      {
        dSum += k * sc.BaseDataIn[SC_LAST][i - j];
        sumw += k;
      }
    }
    midBand[i] = (dSum / sumw) ;

    float ATR = sc.Subgraph[4][i];
    topBand[i] = midBand[i] + (2 * ATR);
    lowBand[i] = midBand[i] - (2 * ATR); // ATR;
  }    
    return;
      
}



[2015-02-15 10:52:52]
ehlaban - Posts: 50
I finally created something that actually can be very useful. I hope.

In the coming week(s) i will do some posts in a separate thread to show
how it works.
imageTMA-bands.PNG / V - Attached On 2015-02-15 10:51:49 UTC - Size: 93.41 KB - 1506 views
[2015-09-03 14:10:51]
buylosellhi - Posts: 60
Hi Ehlaban,

Did you post any indicators that draw the TMA bands ?

thanks much !
[2015-09-03 15:28:24]
buylosellhi - Posts: 60
also, is this a repainting study ?
[2015-09-04 17:54:43]
buylosellhi - Posts: 60
hi ehleban, any feedback on this ? thx
[2016-02-11 11:33:27]
aaronmc - Posts: 1
ehlaban have you got a copy of this indi I have been looking for tma bands for ages.

cheers
[2016-10-05 18:46:11]
User964132 - Posts: 93
Hi I really like that TMA indicator too, and use it to find the extremes on a 4hr chart, I think it repaints but on higher time frames this is not noticeable.
Would love to have this coded!
Keep smiling, Cheers
imageDAILY AND 4HR TMA lines.png / V - Attached On 2016-10-05 18:44:28 UTC - Size: 62.77 KB - 971 views
Private File
[2016-10-06 17:27:01]
mkata - Posts: 103
I'm willing to give this a shot if someone can post a current M5 chart of Crude or ES to compare it to. Please include parameter settings also.
[2016-10-06 19:27:56]
User964132 - Posts: 93
Hi, here are a 5min Oil & S&P chart from today. Thanks for taking this up!!! Keep smiling, Nicolaas
Date Time Of Last Edit: 2016-10-06 19:28:35
imageCL Chart 5min.png / V - Attached On 2016-10-06 19:27:18 UTC - Size: 83.38 KB - 827 views
imageS&P 5min chart.png / V - Attached On 2016-10-06 19:27:29 UTC - Size: 68.36 KB - 670 views
[2016-10-06 20:34:16]
User488039 - Posts: 114
This indicator seems a lot like Keltner Channels.
[2016-10-06 23:11:22]
mkata - Posts: 103
Ok, I think I've got it as close as I can. This things repaints like crazy on lower timeframe so I added in a smoothing length to lessen the effect (if so desired).
attachmentTMA_Bands.dll - Attached On 2016-10-06 23:10:28 UTC - Size: 22 KB - 584 views
[2016-10-07 08:57:22]
User964132 - Posts: 93
Hi MKata! Thanks for coding this! And so fast! THANKS!.
I attached a daily CL chart from MT4 and Sierra, unfortunately there are quite some big differences the closer you come to the current price, I tried all the different moving averages (the Linear Regression MA, does not give any output)but can't get anywhere close to the TMA lines from the MT4 original indicator :-( It doesn't need to be exact, since I am looking for the area's, it gives a nice head's up (IF you combine a weekly, daily and 4Hr TMA) Could you take one more look at this? You help is Highly appreciated!! Keep smiling, Nicolaas
imageoil daily CL.png / V - Attached On 2016-10-07 08:51:50 UTC - Size: 55.6 KB - 941 views
imageOil daily on Sierra charts.png / V - Attached On 2016-10-07 08:52:26 UTC - Size: 102.9 KB - 1176 views
[2016-10-08 19:09:25]
mkata - Posts: 103
I've been reading about this indicator (see post #1) and have discovered it is nothing more than a displaced triangular moving average with the last one-half input length extrapolated in some manner to attempt to fill in the "missing" data. Because of this it will always be repainting and extrapolation methods can vary. With that said, I tried to get it ballpark close. Personally I would never use this indicator myself since I think it's useless, but to each his own.
attachmentTMA_Bands.dll - Attached On 2016-10-08 19:03:58 UTC - Size: 19.5 KB - 575 views
[2018-05-03 13:46:01]
User964132 - Posts: 93
Dear Mkata,

I am using your TMA indy a lot, and although it repaints, it is very useful to point out a possible area of overboard-oversold.
Is it possible to update the indicator with a second ATR multiplier, in the same indicator? So you have two top-band lines, two bottom-band lines and one middle band line.(see attachment)
Again, THANKS A LOT!
Nicolaas
imageOil TMA bands.PNG / V - Attached On 2018-05-03 13:44:25 UTC - Size: 197.2 KB - 1010 views

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account