Newbie scripter needs help scripting MT4 LWMA indicator - MetaTrader | futures io social day trading
futures io futures trading


Newbie scripter needs help scripting MT4 LWMA indicator
Updated: Views / Replies:1,640 / 1
Created: by kashix Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Newbie scripter needs help scripting MT4 LWMA indicator

  #1 (permalink)
Elite Member
Los Angeles California/USA
 
Futures Experience: Beginner
Platform: NinjaTrader
Favorite Futures: Currency Futures
 
Posts: 3 since Nov 2011
Thanks: 0 given, 0 received

Newbie scripter needs help scripting MT4 LWMA indicator

I'm using a strategy that uses the 2 period LWMA to get into trades as price will oscillate around this band. I want to make an indicator that plots the 4 hour LWMA on the 15 minute chart. There are 16 15 minute candles in 1 4 hour candle, therefore, 2 periods would make it 32 candles. Because it's LWMA (Linear Weighted), I can't just change the period to 32 as it will look different.


LMWA Calculation from investopedia

"For example, in a 15-day linearly-weighted moving average, today's closing price is multiplied by 15, yesterday's by 14, and so on until day 1 in the period's range is reached. These results are then added together and divided by the sum of the multipliers (15 + 14 + 13 + ... + 3 + 2 + 1 = 120)."


So a 2-four hour linearly-weighted moving average would be:
([close the 32nd candle] * 2) + ([close of the 16th candle] * 1) / (2+1))

EDIT: I want to use the LOW and HIGH instead of the close. So it would be the low of every block of X candles.


I would need a command that returns the low or high of every block of X candles.
I would also need a way to plot the return value on the chart.

Below is the moving average coding for LWMA. I figure I could take the plotting part from that as it would be easiest. And then make changes for the high and lows of every block of x candles. Any assistance would be appreciated as I have no MT4 coding experience. I'll work on breaking down the code for now. Hopefully someone can lend me a hand.


Last edited by kashix; April 27th, 2012 at 04:57 PM.
Reply With Quote
 
  #2 (permalink)
Elite Member
Los Angeles California/USA
 
Futures Experience: Beginner
Platform: NinjaTrader
Favorite Futures: Currency Futures
 
Posts: 3 since Nov 2011
Thanks: 0 given, 0 received

(Metaquotes MA Indicator)

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- indicator parameters
extern int MA_Period=13;
extern int MA_Shift=0;
extern int MA_Method=0;
//---- indicator buffers
double ExtMapBuffer[];
//----
int ExtCountedBars=0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
int draw_begin;
string short_name;
//---- drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexShift(0,MA_Shift);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
if(MA_Period<2) MA_Period=13;
draw_begin=MA_Period-1;
//---- indicator short name
switch(MA_Method)
{
case 1 : short_name="EMA("; draw_begin=0; break;
case 2 : short_name="SMMA("; break;
case 3 : short_name="LWMA("; break;
default :
MA_Method=0;
short_name="SMA(";
}
IndicatorShortName(short_name+MA_Period+")");
SetIndexDrawBegin(0,draw_begin);
//---- indicator buffers mapping
SetIndexBuffer(0,ExtMapBuffer);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
if(Bars<=MA_Period) return(0);
ExtCountedBars=IndicatorCounted();
//---- check for possible errors
if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
if (ExtCountedBars>0) ExtCountedBars--;
//----
switch(MA_Method)
{
case 0 : sma(); break;
case 1 : ema(); break;
case 2 : smma(); break;
case 3 : lwma();
}
//---- done
return(0);
}

//-- cases 0-2 truncated from code

//+------------------------------------------------------------------+
//| Linear Weighted Moving Average |
//+------------------------------------------------------------------+
void lwma()
{
double sum=0.0,lsum=0.0;
double price;
int i,weight=0,pos=Bars-ExtCountedBars-1;
//---- initial accumulation
if(pos<MA_Period) pos=MA_Period;
for(i=1;i<=MA_Period;i++,pos--)
{
price=Close[pos];
sum+=price*i;
lsum+=price;
weight+=i;
}
//---- main calculation loop
pos++;
i=pos+MA_Period;
while(pos>=0)
{
ExtMapBuffer[pos]=sum/weight;
if(pos==0) break;
pos--;
i--;
price=Close[pos];
sum=sum-lsum+price*MA_Period;
lsum-=Close[i];
lsum+=price;
}
//---- zero initial bars
if(ExtCountedBars<1)
for(i=1;i<MA_Period;i++) ExtMapBuffer[Bars-i]=0;
}
//+------------------------------------------------------------------+


Last edited by kashix; April 27th, 2012 at 04:58 PM.
Reply With Quote

Reply



futures io > > > > Newbie scripter needs help scripting MT4 LWMA indicator

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
VSA indicator for MT4 sam1197 MetaTrader 12 December 21st, 2015 08:15 PM
Converting mt4 indicator ? tradingstarpro MetaQuotes MetaTrader MQL Programming 8 May 26th, 2015 02:14 PM
Method of scripting to project price series IN FRONT of current bar? forrestang NinjaTrader Programming 4 May 2nd, 2012 12:01 PM
Needs help with an MT4 trend indicator...TMA raindrop NinjaTrader Programming 5 April 26th, 2011 12:05 AM
Converting Indicator From Mt4 to Ninja tradingstarpro NinjaTrader Programming 4 May 3rd, 2010 01:25 AM


All times are GMT -4. The time now is 07:09 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-11 in 0.07 seconds with 19 queries on phoenix via your IP 54.92.194.75