Forex
Google
New signals service!

Go Back   Forex Trading > Programming > Metatrader Programming


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack (1) Thread Tools Display Modes
  #531 (permalink)  
Old 12-07-2007, 04:58 PM
EliteJ's Avatar
Junior Member
 
Join Date: Nov 2006
Posts: 15
EliteJ is on a distinguished road
Need help with coding ease of movement indicator

I tried to code it myself but the indicator line doesn't show in the indicator window when I run it. If you go here MANUAL - TECHNICAL INDICATORS it has a definition of the indicator with the formula for calculating it.

Here's the code I have written:

//+------------------------------------------------------------------+
//| Ease of Movement.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//| Forex Trading Software: Forex Trading Platform MetaTrader 4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_minimum -50
#property indicator_maximum 50
#property indicator_buffers 1
#property indicator_color1 Yellow
//---- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
string short_name = "Ease of Movement";
IndicatorShortName(short_name);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----check for errors
if (counted_bars<0) return(-1);

//----last counted bar will be recounted
if (counted_bars>0) counted_bars--;
int k = Bars - counted_bars;
double midptT, midptY, boxR, midptM, EMV;
while (k>0)
{
midptT = (High[k] + Low[k])/2;
midptY = (High[k+1] + Low[k+1])/2;
midptM = midptT - midptY;
boxR = Volume[k]/(High[k] - Low[k]);
EMV = midptM / boxR;
ExtMapBuffer1[k] = EMV;
k--;
}

return(0);
}
//+------------------------------------------------------------------+


can anyone tell me what I'm doing wrong? I attached the indicator too if you want to try to run it for yourself.
Attached Files
File Type: mq4 Ease of Movement.mq4 (2.2 KB, 16 views)
__________________
"Duct tape is like the force: it has a dark side and a light side, and it holds the universe together."
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #532 (permalink)  
Old 12-07-2007, 05:55 PM
Beno's Avatar
Senior Member
 
Join Date: Aug 2006
Location: London
Posts: 362
Beno is on a distinguished road
Hello

I am looking for some help I have an EA that I'm using on demo and also learning to code with. I am trying to figure out how to add a comment to the system to show me which of the 4 entry criteria was used to open the position. eg if long2 was used then show long2 signal

any help would be great


cheers

Beno
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #533 (permalink)  
Old 12-07-2007, 10:39 PM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 723
wolfe is on a distinguished road
Quote:
Originally Posted by Beno View Post
Hello

I am looking for some help I have an EA that I'm using on demo and also learning to code with. I am trying to figure out how to add a comment to the system to show me which of the 4 entry criteria was used to open the position. eg if long2 was used then show long2 signal

any help would be great


cheers

Beno
After your condition is met and you use Ordersend() command, just insert a Comment(), Alert(), or Print() statement. Whichever you want to use.

Something like this:

if ( long2 == true)
{
Ordersend();
{
Print(" long2 signal taken ");
}
}


Hope that helps.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #534 (permalink)  
Old 12-08-2007, 03:30 PM
Beno's Avatar
Senior Member
 
Join Date: Aug 2006
Location: London
Posts: 362
Beno is on a distinguished road
Thanks Wolfe

I had to laugh I put in what you suggested and it worked sort of but now I only have the comment and no positions opening. any hints

bool Long = MAofRSI11>MAofRSI21 && MAofRSI12<=MAofRSI22 && VolCH>VolHL && RSIndex1<HLM && RSIndex1>HL2 && TrStop<Close[shift] && MOM>0.0 && SDLL && ma<Close[shift];

bool Short = MAofRSI11<MAofRSI21 && MAofRSI12>=MAofRSI22 && VolCH>VolHL && RSIndex1<HL1 && RSIndex1>HLM && TrStop>Close[shift] && MOM<0.0 && SDLS && ma>Close[shift];

bool Long2 = MAofRSI11>HLM && MAofRSI12<=HLM && MAofRSI21>HLM && MAofRSI22<=HLM && VolCH>VolHL && TrStop<Close[shift] && MOM>0.0 && SDLL && ma<Close[shift];

bool Short2 = MAofRSI11<HLM && MAofRSI12>=HLM && MAofRSI21<HLM && MAofRSI22>=HLM && VolCH>VolHL && TrStop>Close[shift] && MOM<0.0 && SDLS && ma>Close[shift];

bool Long3 = RSIndex1-RSIndex2>20<HL2 && TrStop<Close[shift] && MOM>0.0 && SDLL && ma<Close[shift];

bool Short3 = RSIndex2-RSIndex1>20>HL1 && TrStop>Close[shift] && MOM<0.0 && SDLS && ma>Close[shift];

bool Long4 = zscore>0.0 && ma<Close[shift];

bool Short4 = zscore<0.0 && ma>Close[shift];


buysig = Long || Long2 || Long3 || Long4;
sellsig = Short || Short2 || Short3 || Short4;



closebuy=sellsig;
closesell=buysig;

if (curprof>=AccountBalance()*ProfitExit/100.0) {
exit=true;

}
if (last>0 && (Time[0]-last)/(Period()*60)>=CancelOrderBars) {
remorder=true;
}

}

void CheckForOpen() {
int res,tr;
//---- sell conditions
co=CalculateCurrentOrders(Symbol());
if(sellsig && lastsig!=-1) {
co=CalculateCurrentOrders(Symbol());
if (co==0) {
if ( Short == true)
if ( Short2 == true)
if ( Short3 == true)

res = OpenStop(OP_SELLSTOP,LotsRisk(StopLoss), Low[shift]-OrderPipsDiff*Point, StopLoss, TakeProfit1);
Print(" Short signal taken ");
Print(" Short2 signal taken ");
Print(" Short3 signal taken ");
Print(" Short4 signal taken ");


}
lastsig=-1;
last=Time[0];
return;
}
//---- buy conditions
if(buysig && lastsig!=1) {
co=CalculateCurrentOrders(Symbol());
if (co==0) {
if ( Long == true)
if ( Long2 == true)
if ( Long3 == true)
if ( Long4 == true)
res = OpenStop(OP_BUYSTOP,LotsRisk(StopLoss), High[shift]+OrderPipsDiff*Point, StopLoss, TakeProfit1);
Print(" Long signal taken ");
Print(" Long2 signal taken ");
Print(" Long3 signal taken ");
Print(" Long4 signal taken ");

}
last=Time[0];
lastsig=1;
return;
}
}

Fixed it Thanks

Last edited by Beno; 12-08-2007 at 04:37 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #535 (permalink)  
Old 12-08-2007, 04:40 PM
Beno's Avatar
Senior Member
 
Join Date: Aug 2006
Location: London
Posts: 362
Beno is on a distinguished road
Debugging code

How and where would you use a bit of code like this. I have a Zero divide error that I can't find how the fix.

extern bool DEBUGGING = true

...

if(DEBUGGING && variableName == 0) Print("CodePoint 1 -- This variable is now ", variableName);

... more code

if(DEBUGGING && variableName == 0) Print("CodePoint 2 -- This variable is now ", variableName);

... more code

if(DEBUGGING && variableName == 0) Print("CodePoint 3 -- This variable is now ", variableName);

...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #536 (permalink)  
Old 12-09-2007, 07:21 AM
Junior Member
 
Join Date: Sep 2007
Posts: 14
deuxmille is on a distinguished road
can you help me?why there are many mistakes in the code?

this is to calculate SMMA:
for(j=0;j<Bars;j++)
{
for(i=0,sum=0;i<ma_period;i++)
{
sum=sum+Close[j+i];
// buffer[j]=(sum-sum/ma_period+Close[j+i])/ma_period;
}
buffer[j]=(sum-sum/ma_period+Close[j])/ma_period;
}




this is to calculate LWMA

for(j=0;j<Bars;j++)
{
for(i=0,sum=0,sum1=0;i<ma_period;i++)
{
sum=sum+Close[j+i];
sum1=sum1+Close[j+i]*(j+i);
// buffer[j]=sum/ma_period;
}
buffer[j]=sum1/sum;
}


and how to calculate EMA?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #537 (permalink)  
Old 12-10-2007, 02:31 AM
ajk's Avatar
ajk ajk is offline
Senior Member
 
Join Date: Dec 2005
Posts: 232
ajk is on a distinguished road
question on indicators

Hi everyone.
I am stuck on a programming issue. Does anyone know how to use 1 indicator result to change another setting? For example, if the daily stockasti was above 20, I would want a moving average of (x). I tried to get the code working below but to know avail. I don't seem to be able to get the switch or if else command to work eithor.


double fourhrUP;
double daystoch1 = iStochastic(NULL, PERIOD_D1,5, 3, 3, MODE_SMA, 0, MODE_MAIN,1);
double daystoch20 = 20;
if (daystoch1 > daystoch20) four_hrUP = 5 ;
double iMA( string symbol, int timeframe,four_hrUP, int ma_shift, int ma_method, int applied_price, int shift)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #538 (permalink)  
Old 12-10-2007, 04:18 AM
Senior Member
 
Join Date: Dec 2005
Location: In front of my trading desk
Posts: 345
Devil2000 is on a distinguished road
Quote:
Originally Posted by ajk View Post
Hi everyone.
I am stuck on a programming issue. Does anyone know how to use 1 indicator result to change another setting? For example, if the daily stockasti was above 20, I would want a moving average of (x). I tried to get the code working below but to know avail. I don't seem to be able to get the switch or if else command to work eithor.


double fourhrUP;
double daystoch1 = iStochastic(NULL, PERIOD_D1,5, 3, 3, MODE_SMA, 0, MODE_MAIN,1);
double daystoch20 = 20;
if (daystoch1 > daystoch20) four_hrUP = 5 ;
double iMA( string symbol, int timeframe,four_hrUP, int ma_shift, int ma_method, int applied_price, int shift)
Where's your MA's variable?
Maybe this could help

double ma4hr=iMA( string symbol, int timeframe,four_hrUP, int ma_shift, int ma_method, int applied_price, int shift);

if the stoch calculation is in the same loop, let say "for(int shift=limit-1; shift>=0; shift--)", the stoch code should be

double daystoch1 = iStochastic(NULL, PERIOD_D1,5, 3, 3, MODE_SMA, 0, MODE_MAIN,shift+1);

CMIIW
__________________
Need a professional MQL4 programmer? PM me

Last edited by Devil2000; 12-10-2007 at 04:25 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #539 (permalink)  
Old 12-10-2007, 09:41 AM
Junior Member
 
Join Date: Jun 2007
Posts: 3
Hisashi is on a distinguished road
Question Need EA to copy to have multiple orders with the same conditions

Hello.

I am looking for EA that copies a pending order and makes it muptiple with exactly the same conditions.
For example, let's say I have a pending order USD/JPY entry-stop sell 1 lot at 115.00, and I wanna have 5 same orders.
I do not wanna merely increase the trade size, instead of having multiple positions with the same conditions.
Is there an EA that does such a thing for me?

Also, I tried e-Trailing.mq4 but I could not place the trailing stop for multiple orders.
I need to place a trailing stop at 5 pips from the current price, for multiple open orders.
Any good EA for it?

Regards

Last edited by Hisashi; 12-10-2007 at 01:53 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #540 (permalink)  
Old 12-10-2007, 01:47 PM
Junior Member
 
Join Date: Jul 2007
Posts: 14
FXTradepro is on a distinguished road
A Little Help with an Indicator - Coder's Please Look

I am testing an MT4 Broker's Platform that uses Fractional Pips (pipettes) in it's price quotations: For Example on EURJPY they quote as 164.381 instead of 164.38 - This means that the spread has a decimal such as 4.1 pips (instead of 4).

Can anyone tell me how to MODIFY the following code so that the Spread reads properly? Right now a 4.1 pip spread would read as 41.0 in the Indicator. Any help is appreciated.

Dan

//---- spread
Spread=NormalizeDouble((Ask-Bid)/Point,1);
ObjectSetText("Spread Monitor1","Spread:", 10, "Arial", labelColor);
ObjectSetText("Spread Monitor2",DoubleToStr(Spread,1),10, "Arial", clockColor);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
candle time, CHinGsMAroonCLK, coders guru, expert advisor, forex, how to code, I_XO_A_H, mechanical trading, trading

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/metatrader-programming/554-how-code.html
Posted By For Type Date
Need an experienced programmer? - Page 2 Post #0 Refback 09-24-2008 07:24 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to code this? iscuba11 Metatrader 4 mql 4 - Development course 1 08-03-2007 05:22 PM


All times are GMT. The time now is 12:13 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.