Forex



Go Back   Forex Trading > Programming > MetaTrader
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1571 (permalink)  
Old 02-09-2009, 09:18 PM
MrM MrM is offline
Member
 
Join Date: Jul 2007
Posts: 81
MrM is on a distinguished road
adding stdev bands

Hi, sorry for the stupid question, but pls help me out here:

If you have any indicator that consists of 1 line in the chart window, and you want to add standard deviation bands to that line, like Bollinger bands. How do you do this:
let's say your buffer that plots your original indicator is named abc
so first you declare these:
extern int BandsPeriod=20;
extern int BandsShift=0;
extern double BandsDeviations=2.0;
1) you change
#property indicator_buffers 1 (1 becomes 3)
2)
SetIndexBuffer(0,abc);
SetIndexStyle(0,DRAW_LINE);
and add
SetIndexBuffer(1,UpperBuffer);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(2,LowerBuffer);
SetIndexStyle(2,DRAW_LINE);
SetIndexDrawBegin(0,BandsPeriod+BandsShift);
SetIndexDrawBegin(1,BandsPeriod+BandsShift);
3) you add the rest of the bollinger bands code into the initialization loop
int start()
{
int i,k,counted_bars=IndicatorCounted();
double deviation,sum,oldval,newres;

//----
if(Bars<=BandsPeriod) return(0);
//---- initial zero
if(counted_bars<1)
and so on....
4) but how the heck do you replace the buffer called MovingBuffer in the original bands.mq4 code by your new buffer from your indicator, called "abc"?

What's the best way to go about this?
Should I try to get my indicator code into the bands.mq4 code or the other way around?

I attached a well-known piece of code called bands.mq4 so you can see what I'm working with.

again, sorry for my coding-ignorance

Maybe someone knows of a 'adding stdev bands tutorial' ? That would be what I need right now. Thx
Attached Files
File Type: mq4 Bands.mq4 (2.8 KB, 11 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1572 (permalink)  
Old 02-10-2009, 12:43 PM
Junior Member
 
Join Date: Jan 2009
Posts: 18
PEDCORD is on a distinguished road
AFStar indicator

Hi,

who can help me put sound in AFStar Indicator wen the arrows apears, I have very good results in time frame 15 and 30. For me this indicator is very, very good.

Thanks

//+------------------------------------------------------------------+
//| AFStar.mq4 |
//| Copyright © 2005, Forex-Experts |
//| Forex-Experts For Metatrader - Home |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Forex-Experts"
#property link "http://www.forex-experts.com"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Green
//---- input parameters
extern double StartFast=3;
extern double EndFast=3.5;
extern double StartSlow=8;
extern double EndSlow=9;
extern double StepPeriod=0.2;
extern double StartRisk=1;
extern double EndRisk=2.8;
extern double StepRisk=0.5;
extern int AllBars=500;
//----
int shift=0,RiskCnt=0, EndScan1=0, EndScan2=0;
double iMaSlowPrevious=0, iMaSlowCurrent=0, iMaFastPrevious=0, iMaFastCurrent=0;
double FastCnt=0, SlowCnt=0;
double Buy1[1000], Sell1[1000];
double Buy2[1000], Sell2[1000];
double Buy=0, Sell=0;
//---- buffers
double val1[];
double val2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator line
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,226);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,225);
SetIndexBuffer(0,val1);
SetIndexBuffer(1,val2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
if (AllBars>=1000) AllBars=1000;
//----
SetIndexDrawBegin(0,Bars-AllBars+11+1);
SetIndexDrawBegin(1,Bars-AllBars+11+1);
int i,shift,counted_bars=IndicatorCounted();
int Counter,i1,value10,value11;
double value1,x1,x2;
double value2,value3;
double TrueCount,Range,AvgRange,MRO1,MRO2;
double Table_value2[1000];
//----
if(Bars<=11+1) return(0);
//---- initial zero
if(counted_bars<11+1)
{
for(i=1;i<=0;i++) val1[AllBars-i]=0.0;
for(i=1;i<=0;i++) val2[AllBars-i]=0.0;
}
//---- TODO: add your code here
//for (shift=(AllBars-11-1); shift<=0; shift--)
//{
shift=AllBars-11-1;
while(shift>=0)
{
Sell1[shift]=0;
Buy1[shift]=0;
EndScan1=0;
SlowCnt=StartSlow;
while(SlowCnt<=EndSlow)
{
if (EndScan1==1) break;
FastCnt=StartFast;
while(FastCnt<=EndFast)
{
if (EndScan1==1) break;
//Scan Parameters
iMaSlowPrevious=iMA(NULL,0,SlowCnt,0,MODE_EMA, PRICE_CLOSE, shift-1);
iMaSlowCurrent=iMA(NULL,0,SlowCnt,0,MODE_EMA, PRICE_CLOSE, shift);
iMaFastPrevious=iMA(NULL,0,FastCnt,0, MODE_EMA, PRICE_CLOSE, shift-1);
iMaFastCurrent=iMA(NULL,0,FastCnt,0, MODE_EMA, PRICE_CLOSE, shift);
if (iMaFastPrevious<iMaSlowPrevious && iMaFastCurrent>iMaSlowCurrent) { EndScan1=1; Sell1[shift]=1;}
if (iMaFastPrevious>iMaSlowPrevious && iMaFastCurrent<iMaSlowCurrent) { EndScan1=1; Buy1[shift]=1;}
FastCnt=FastCnt+StepPeriod;
}
SlowCnt=SlowCnt+StepPeriod;
}
EndScan2=0;
Sell2[shift]=0;
Buy2[shift]=0;
RiskCnt=StartRisk;
// while (RiskCnt<=EndRisk)
if (RiskCnt<=EndRisk)
{
if (EndScan2!=1)
{
value10=3+RiskCnt*2;
x1=67+RiskCnt;
x2=33-RiskCnt;
value11=value10;
//----
// shift=AllBars-11-1;
// while(shift>=0)
// {
Counter=shift;
Range=0.0;
AvgRange=0.0;
for(Counter=shift; Counter<=shift+9; Counter++) AvgRange=AvgRange+MathAbs(High[Counter]-Low[Counter]);
//----
Range=AvgRange/10;
Counter=shift;
TrueCount=0;
while(Counter<shift+9 && TrueCount<1)
{
if (MathAbs(Open[Counter]-Close[Counter+1])>=Range*2.0) TrueCount=TrueCount+1;
Counter=Counter+1;
}
if (TrueCount>=1) {MRO1=Counter;} else {MRO1=-1;}
Counter=shift;
TrueCount=0;
while(Counter<shift+6 && TrueCount<1)
{if (MathAbs(Close[Counter+3]-Close[Counter])>=Range*4.6) TrueCount=TrueCount+1;
Counter=Counter+1;
}
if (TrueCount>=1) {MRO2=Counter;} else {MRO2=-1;}
if (MRO1>-1) {value11=3;} else {value11=value10;}
if (MRO2>-1) {value11=4;} else {value11=value10;}
value2=100-MathAbs(iWPR(NULL,0,value11,shift)); // PercentR(value11=9)
Table_value2[shift]=value2;
val1[shift]=0;
val2[shift]=0;
value3=0;
if (value2<x2)
{
i1=1;
while(Table_value2[shift+i1]>=x2 && Table_value2[shift+i1]<=x1){i1++;}
if (Table_value2[shift+i1]>x1)
{
value3=High[shift]+Range*0.5;
Sell2[shift]=value3;
// val1[shift]=value3;
}
}
if (value2>x1)
{i1=1;
while(Table_value2[shift+i1]>=x2 && Table_value2[shift+i1]<=x1){i1++;}
if (Table_value2[shift+i1]<x2)
{
value3=Low[shift]-Range*0.5;
Buy2[shift]=value3;
// val2[shift]=value3;
}
}
}
if (Buy2[shift]>0 || Sell2[shift]>0) {EndScan2=1;}
//----
RiskCnt=RiskCnt+StepRisk;
}
//Main decision module
Buy=0; Sell=0;
//----
if ((Buy1[shift]>0 && Buy2[shift]>0) || (Buy1[shift]>0 && Buy2[shift+1]>0) || (Buy1[shift+1]>0 && Buy2[shift]>0)) Buy=Low[shift]-1*Point;
if ((Sell1[shift]>0 && Sell2[shift]>0) || (Sell1[shift]>0 && Sell2[shift+1]>0) || (Sell1[shift+1]>0 && Sell2[shift]>0)) Sell=High[shift]+1*Point;
//Ignore if we have two signals
if (Buy!=0 && Sell!=0)
{
Buy=0; Sell=0;
}
val1[shift]=Sell;
val2[shift]=Buy;
shift--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1573 (permalink)  
Old 02-10-2009, 01:42 PM
Junior Member
 
Join Date: Dec 2008
Posts: 12
rwb181 is on a distinguished road
Coding for an EA

Hello all,
I would like to create some coding that will keep an EA from trading if it has already had a profitable trade for the current trading session.

I have a number of EA's that I built that allow me to choose the opening time and closing time for trading each day. The EA also only does anything on the opening of each new bar. So, if I have a trade going and it is closed because it either hit my stop loss or my take profit, the EA will wait until the opening of the next bar before opening a new trade.

For example, I have the EA set to trade between 6:00 AM and 2:00 PM on a one hour chart. At 6:00 AM a trade is opened. At 9:23, my take profit is hit and the trade is closed. At 10:00 AM a new trade will be opened and will remain open until either the new stop loss or take profit is hit, or the time reaches 2:00 PM, at which time the trade is closed and trading is done for the rest of the day.

What I would like the EA to do is not only recognize the time of day but also recognize whether I have already had a winning trade during the trading session. So, in the example above, even though it is still during the trading time period for the day, the EA would not open a new trade at 10:00 AM because a profit has already been made. On the other hand, if it was my stop loss that was hit in the above example, the EA would open a new trade at 10:00 AM because no profit was made yet.

I'm thinking that I would need to use the "OrderSelect" function along with the "Mode_History" parameter to look at previously closed trades and then compare the opening price to the closing price for the order to determine whether a profit or loss was realized. Does that sound about right? Being a novice at programming, I am not sure if that is the best way to approach the problem and if it is, it will take me a long, long time to get it in the correct format to work properly.

If anyone could help me out or at the least, just give me some insights or ideas on how to tackle this problem, I would be grateful. If my example doesn't make any sense, let me know and I will try to explain it better.

Thanks in advance for any help that is offered.

Ron
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1574 (permalink)  
Old 02-10-2009, 04:12 PM
Member
 
Join Date: Sep 2008
Posts: 93
Wiley is on a distinguished road
Checking for order losses...

On this site, at this link http://www.forex-tsd.com/87589-post372.html is a copy of the DIN_Kukus_EA_V2.6. If you view the EA's contents, you will find a function that checks for order losses in your order history, just as you have discribed doing for yourself. You can use this working example of how to extract the number of successful trades from your order history. You can modify it to extract history for a particular period of time as well, but I hope this will help you see how to accomplish what you propose to do for yourself...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1575 (permalink)  
Old 02-11-2009, 06:21 AM
Junior Member
 
Join Date: Aug 2008
Location: Sacramento
Posts: 10
kevin07 is on a distinguished road
Question wanting to use indicator results in EA

Hello All,
The Gliding_Channels indicator puts current channel data in comment area of the Data Window. It tells the vertical depth of channel on the current bar, the angle of the channel (both positive and negative), the high limit and the low limit. I want to see that data, however it conflicts with the data my EA shows in the comment area causing my comments to flicker.
I tried to add a SetIndexBuffer for each of the four datum in the indicator so I could reference them in my EA using iCustom. I was only able to bring one of the four values into my EA comments that way. (I also continued to have the flickering problem).
Would anybody please show me the correct way to access those four indicator results in my EA?
In my EA, I will be calling these four values "depth, angle, limitHI, and limitLO."
Attached Files
File Type: mq4 Gliding_Channels_[CF]_v2.mq4 (11.7 KB, 24 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1576 (permalink)  
Old 02-11-2009, 01:37 PM
increase's Avatar
Senior Member
 
Join Date: May 2006
Posts: 844
increase is on a distinguished road
Quote:
Originally Posted by PEDCORD View Post
Hi,

who can help me put sound in AFStar Indicator wen the arrows apears, I have very good results in time frame 15 and 30. For me this indicator is very, very good.
Here is an MTF version I did for you with alert
Attached Files
File Type: mq4 #MTF_AFStar.mq4 (4.0 KB, 80 views)
__________________
New to Forex? Get all you need for Free at my site Click Here
You can also get my Hot Forex System (scroll to the bottom of the page): Click Here
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1577 (permalink)  
Old 02-12-2009, 12:17 AM
Junior Member
 
Join Date: Nov 2005
Posts: 4
CajunFX is on a distinguished road
Post Programing Help?

Hi All,

Been ages since I have been on the board or done any trading but am currently working on a new EA and need some help.

Right now I am setting the LotsValue in the EA as follows:
extern double LotsValue = 1;
and the order is sent as follows:
int Ticket = OrderSend(Symbol(), Type, LotsValue, Price, Spread, 0, 0, Currency, Magic, 0, ArrowColor);

What I would like to do is set the number of lots based on a percentage of equity ~vs~ balance as the EA trades multiple pairs simultaneously.

Any help or suggestions would be greatly appreciated.

Also, if anyone can recommend a professional programer (MQL4) please let me know as I have lost contact with the one I was working with in China (I am in the USA).

Regards to all,

CajunFX
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1578 (permalink)  
Old 02-12-2009, 12:30 AM
Member
 
Join Date: Jan 2006
Posts: 59
hiachiever is on a distinguished road
CajunFx,

Here's a simple Lot Size calculator from one of my EA's.

double GetLotSize()
{
double LotSize = ManualLots;

double MaxLots = MarketInfo( Symbol(), MODE_MAXLOT );
double MinLots = MarketInfo( Symbol(), MODE_MINLOT );
double LotStep = MarketInfo( Symbol(), MODE_LOTSTEP );
int LotDigits = 1;
if (LotStep == 0.01) LotDigits = 2;

bool MicroLotsAllowed = False;
bool MicroLotStepsAllowed = False;

if( MinLots == 0.01 ) MicroLotsAllowed = true;
if( LotStep == 0.01 ) MicroLotStepsAllowed = true;

if( UseMoneyManagement )
LotSize = MMPercent * AccountBalance() / ( MarketInfo( Symbol(), MODE_TICKVALUE ) / Point * PipPoint ) / 10000;


if( MicroLotsAllowed )
LotSize = NormalizeDouble( LotSize, 2 );
else if( MicroLotStepsAllowed && LotSize > 0.1 )
LotSize = NormalizeDouble( LotSize, 2 );
else if( MinLots < 0.5 )
LotSize = NormalizeDouble( LotSize, 1 );
else
LotSize = NormalizeDouble( LotSize, 0 );

LotSize = MathMin(LotSize,MaxLots);
LotSize = MathMax(LotSize,MinLots);

return( LotSize );
}

Note:
UseMoneyManagement is an setting built into the options section of the EA.
I generally set these three options to work in conjuction with the LotSizing Function.

extern string MM = "===== MONEY MANAGEMENT =====";
extern double ManualLots = 0.1;
extern bool UseMoneyManagement = False;
extern double MMPercent = 3;

If you want to use Equity instead of balance, then simply change the reference in the code from AccountBalance() to AccountEquity().

Hope this helps.

Cheers,
Hiachiever
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1579 (permalink)  
Old 02-12-2009, 12:59 AM
Senior Member
 
Join Date: Nov 2006
Posts: 308
luxinterior is on a distinguished road
Here's a simple way to do it...

Code:
   // money management
   if(LOTS == 0)LOTS = (AccountFreeMargin()*RISK/100.0)/STOPLOSS;
Hope that helps.

Lux
__________________
Build An Expert Advisor. FREE E-course As Seen On TV
ForexArea.com
Users of Gap Trader from 'Forex-Assistant' MUST Read This

Last edited by luxinterior; 02-12-2009 at 06:18 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1580 (permalink)  
Old 02-12-2009, 03:48 AM
Junior Member
 
Join Date: Nov 2005
Posts: 4
CajunFX is on a distinguished road
Gents,

Thanks for the help. Not being a programmer I am lost on the first code snipet (sorry hiachiever, no offense).

I tried the second snipet and it worked after I removed the /STOPLOSS (EA uses a dynamic SL) and added a few more zeros but now getting an OrderSend error 4051 invalid lots amount. Believe this is because previously I was using a whole value for LotsValue and now it is wanting to send fractional LotsValue... eg; 1 ~vs 1.3.

Looks like I am on the right track though so will keep plugging away at it.

BTW... signed up for the Build An Expert Advisor course... maybe this will help me to get a handle on things.

Thanks,

CajunFX
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
#include, candle time, CHinGsMAroonCLK, code, coders guru, conditionally, dll, eli hayun, Eur_harvester.ex4, expert adviser, expert advisor, forex, higher high, how to code, indicator, I_XO_A_H, kehedge, mechanical trading, metatrader command line, mt4, MT4-LevelStop-Reverse, OrderReliable.mqh, programming, rectangle tool, trading, volty channel stop


Currently Active Users Viewing This Thread: 2 (0 members and 2 guests)
 
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

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 08:47 AM.



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