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
  #1161 (permalink)  
Old 08-16-2008, 01:11 PM
Member
 
Join Date: Aug 2008
Posts: 32
fercan is on a distinguished road
i have created a really simple EA. and a system which i use in atleast 3 Timeframe..May problem it doesn't stop opening and i don't want to have 3 EA and 3 chart for one pair.

i need a code that would only do one order for buy and for sell per bar per TF and still open if it is on a different bar. i can have buy and sell and the same bar.

Sometimes i have 3 signal in 3 different TF. i want to take all order but i want only one order per TF and i can still take another order in another TF if it is still open but in a different bar.

example:
1 signal in 4h
1 signal in 1h but it falls in bar for 4h
1 signal in 30 min but only one bar for 1h and 4h.
3 signal will be open.

i am ok with using magic number as means of filter.

can someone help me? thank you very much.

so far this is what i thought:
for 30 mins
if (magicnumber == 123)
{
if (iTime(OrderOpenTime()) != iTime(Symbol(),PERIOD_M30,0))
{//my order code}

}

i don't have MT4 but i know somethings is not right in the logic or code. So guys please help me.

also i think we have similar problem with matrixebiz
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1162 (permalink)  
Old 08-17-2008, 05:24 PM
mystified's Avatar
Senior Member
 
Join Date: Jun 2006
Posts: 145
mystified is on a distinguished road
I have added levels to HMA:

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Black
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_level1 80
#property indicator_level2 60
#property indicator_level3 40
#property indicator_level4 20
#property indicator_levelcolor DarkSlateGray


But the indicator doesnt appear on a seperate window properly.Any help much appreciated.
Attached Files
File Type: mq4 HMA_v2[1].mq4 (5.9 KB, 12 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1163 (permalink)  
Old 08-18-2008, 01:39 AM
Linuxser's Avatar
Moderator
 
Join Date: May 2006
Location: Helliconia (Spring)
Posts: 3,322
Blog Entries: 46
Linuxser has disabled reputation
Quote:
Originally Posted by mystified View Post
I have added levels to HMA:

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Black
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_level1 80
#property indicator_level2 60
#property indicator_level3 40
#property indicator_level4 20
#property indicator_levelcolor DarkSlateGray


But the indicator doesnt appear on a seperate window properly.Any help much appreciated.
Because the indicator is forced bounded:

Remove this two lines:
#property indicator_minimum 0
#property indicator_maximum 100

Levels only works fine on bounded indicators but to do a bounded indicator the calculation must include the limits.

Example: RSI = 100-(100/(1+U/D))

We know by that formula that the indicator will move between 0-100 and because that we could include 70-30 levels without fear to they would disappear.

Another example is MACD = EMA(CLOSE, 12)-EMA(CLOSE, 26)).
We set a level on M5 and when we move to H1 most probable is the level has gone.

So, we take the same formula and we make some changes MACD = (EMA(CLOSE, 12)-EMA(CLOSE, 26))/EMA(CLOSE, 26). And now we have a percent indicator. Is not bounded but we have less probabilities to lost our levels.
__________________
Elite Manual Trading | Portfolio | Calendar | Suggestions to improve the forum | My Blog

Remember: Signatures must have three lines as maximum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1164 (permalink)  
Old 08-18-2008, 08:15 AM
mystified's Avatar
Senior Member
 
Join Date: Jun 2006
Posts: 145
mystified is on a distinguished road
Thanks Linuxer.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1165 (permalink)  
Old 08-18-2008, 12:53 PM
Member
 
Join Date: Aug 2008
Posts: 32
fercan is on a distinguished road
Quote:
i have created a really simple EA. and a system which i use in atleast 3 Timeframe..May problem it doesn't stop opening and i don't want to have 3 EA and 3 chart for one pair.

i need a code that would only do one order for buy and for sell per bar per TF and still open if it is on a different bar. i can have buy and sell and the same bar.

Sometimes i have 3 signal in 3 different TF. i want to take all order but i want only one order per TF and i can still take another order in another TF if it is still open but in a different bar.

example:
1 signal in 4h
1 signal in 1h but it falls in bar for 4h
1 signal in 30 min but only one bar for 1h and 4h.
3 signal will be open.

i am ok with using magic number as means of filter.

can someone help me? thank you very much.

so far this is what i thought:
for 30 mins
if (magicnumber == 123)
{
if (iTime(OrderOpenTime()) != iTime(Symbol(),PERIOD_M30,0))
{//my order code}

}

i don't have MT4 but i know somethings is not right in the logic or code. So guys please help me.

also i think we have similar problem with matrixebiz
Can anyone help me please?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1166 (permalink)  
Old 08-18-2008, 04:05 PM
Linuxser's Avatar
Moderator
 
Join Date: May 2006
Location: Helliconia (Spring)
Posts: 3,322
Blog Entries: 46
Linuxser has disabled reputation
Quote:
Originally Posted by mystified View Post
Thanks Linuxer.
This is just the example (because now you have the Oscillator HMA ) from previous post, still it's MACD but calculated on a different way.
Attached Images
File Type: gif projection5.gif (19.2 KB, 103 views)
__________________
Elite Manual Trading | Portfolio | Calendar | Suggestions to improve the forum | My Blog

Remember: Signatures must have three lines as maximum

Last edited by Linuxser; 08-18-2008 at 04:09 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1167 (permalink)  
Old 08-18-2008, 08:06 PM
Junior Member
 
Join Date: Nov 2007
Posts: 8
CEHansen is on a distinguished road
Whatīs wrong with this indicator?

Hereīs one that is probably very simple to figure out but Iīm relatively new to this and have no clue how to solve the problem.

This indicator compiles without problems but thereīs nothing showing up on the charts. Iīm sure some of you more experienced programmers might see quickly where I made a mistake. Any help is greatly appreciated.

The indicator should draw an arrow on the charts when certain criteria are met... I wrote the explanations into the code, that makes it easier to follow...


I attached the mq4 file... i have not been able to insert the code into this box without making it look really messy .....


Iīd be thrilled if anyone can help me with it... THANKS GUYS!


CEH

P.S. perhaps you can figure out how to insert the code into the message box and then comment on it, that way more people can learn from it...
Attached Files
File Type: mq4 George.mq4 (4.7 KB, 8 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1168 (permalink)  
Old 08-19-2008, 03:18 AM
tcl's Avatar
tcl tcl is offline
Member
 
Join Date: Apr 2008
Posts: 83
tcl is on a distinguished road
Question How to start trading on the opening candle in D1 ??

is there anyone know the code to ask the EA start open trade when the new bar start in D1 time frame ??

here is the logic:
in D1 TF, when the new candle (it's mean a new day) is start then EA will open 2 position, BUY and SELL with TP=10 pips for each position.
When the candle closed then EA close all position and start opening position again for the new candle.

very simple rule, but still I cann't find the code for this simple rule....

I'm realy new in MQL4 coding and already search and read many source and forum to learn more about MQL4 coding, but cann't find what I'm need.

Thanks before...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1169 (permalink)  
Old 08-19-2008, 06:10 AM
tcl's Avatar
tcl tcl is offline
Member
 
Join Date: Apr 2008
Posts: 83
tcl is on a distinguished road
here is my code.... please help me to fix it

I tried to code what I have ask before, here is the sample EA code:

Quote:
int start()
{

LastPrice=0;
LastProfit=0;
LastTicket=0;
LastLots=Lots;
Profit=0;
ProfitPip=0;
PairOrder=0;
OrdersOpened = 0;

PreviousOrders = OrdersOpened;

double Spread = MarketInfo(Symbol(),MODE_SPREAD);
PipValue=MarketInfo(Symbol(),MODE_TICKVALUE);
ArrayCopyRates(rates, Symbol(), PERIOD_D1);

if(DayOfWeek()==0 || DayOfWeek()==6)
{
//no trade on holiday;
return(0);
}
else
{
if (newbar()==Period())
{
for (int cnt = OrdersTotal() - 1; cnt >= 0; cnt --)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, Color1);
}
}

OpenBuy();
OpenSell();
}
}


}

int newbar()
{
double g;
int m,s,k;
m=Time[0]+Period()*60-TimeCurrent();
g=m/60.0;
s=m%60;
m=(m-m%60)/60;
return(m);
}

void OpenBuy()
{
double ldLot, ldStop, ldTake;
string lsComm;

ldLot = GetSizeLot();
ldStop = Ask-Point*StopLoss;
ldTake = NormalizeDouble(GetTakeProfitBuy(),Digits);
OrderSend(Symbol(),OP_BUY,ldLot,NormalizeDouble(As k,Digits),Slippage,ldStop,ldTake,"BUY",Magic,0,Col or1);
}

void OpenSell()
{
double ldLot, ldStop, ldTake;
string lsComm;

ldLot = GetSizeLot();
ldStop = Bid+Point*StopLoss;
ldTake = NormalizeDouble(GetTakeProfitSell(),Digits);
OrderSend(Symbol(),OP_SELL,ldLot,NormalizeDouble(B id,Digits),Slippage,ldStop,ldTake,"SELL",Magic,0,C olor1);
}

double GetSizeLot()
{
return(Lots);
}

double GetTakeProfitBuy()
{
return(Ask+TakeProfit*Point);
}

double GetTakeProfitSell()
{
return(Bid-TakeProfit*Point);
}
Last night I uploaded to my vps, but this morning I check it up but my sample EA doesn't open any trade, can someone here help me to fix my sample EA here ??

btw, I attached it here too
Attached Files
File Type: mq4 HeMart_Modiv2.mq4 (2.9 KB, 4 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1170 (permalink)  
Old 08-19-2008, 11:05 AM
Junior Member
 
Join Date: Nov 2007
Posts: 8
CEHansen is on a distinguished road
code...

hereīs the code, thought it wouldnīt fit in here but when I pressed "preview post" it all looked neat.....
I canīt figure out why there arenīt any arrows showing up on the chart... probably just a simple mistake...


#
//+------------------------------------------------------------------+
//| George.mq4 |
//| Copyright Đ 2008, CEH |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright Đ 2008, CEH"
#property link ""

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Green

extern int Trend_Period = 100; //period of overall trend indicator
extern int Trend_Mode = 1; //0=sma, 1=ema, 2=smma, 3=lwma, 4=lsma
extern int Trend_Shift = 0; //shift of overall trend indicator
extern int Sto_Lookback = 3; //lookback period for stochastic indicator

double buyit[];
int Current = 0;
bool triggup, trendup, stochup, sloppystochup;


//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW, EMPTY, 3);
SetIndexArrow(0, 233);
SetIndexBuffer(0, buyit);


//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{

int Current = 0;
int i = 0;

//this is intended to create a lookback period where the program finds out if
//there was a certain condition within "i" bars...
for (i = 1; i <= Sto_Lookback; i++)
{

//overall trend indicator... now and previous to calculate direction itīs going
double trend_ma_now = iMA(NULL, 0, Trend_Period, Trend_Shift, Trend_Mode, PRICE_CLOSE, Current + 1);
double trend_ma_pre = iMA(NULL, 0, Trend_Period, Trend_Shift, Trend_Mode, PRICE_CLOSE, Current + 2);

//triggerline... now and previous to calculate if it was crossed
double trigg_ma_now = iMA(NULL, 0, 5, 1, MODE_EMA, PRICE_CLOSE, Current + 1);
double trigg_ma_pre = iMA(NULL, 0, 5, 1, MODE_EMA, PRICE_CLOSE, Current + 2);

//short stochastics... now and previous to calculate which direction it is moving
double sto_short_now = iStochastic(NULL, 0, 8, 3, 3, MODE_SMA, 0, MODE_MAIN, Current + 1);
double sto_short_pre = iStochastic(NULL, 0, 8, 3, 3, MODE_SMA, 0, MODE_MAIN, Current + 2);

//long stochastics
double sto_long_now = iStochastic(NULL, 0, 36, 3, 3, MODE_SMA, 0, MODE_MAIN, Current +1);

//short stochastics value at "i"
double sto_short = iStochastic(NULL, 0, 8, 3, 3, MODE_SMA, 0, MODE_MAIN, i);

//long stochastics value at "i"
double sto_long = iStochastic(NULL, 0, 36, 3, 3, MODE_SMA, 0, MODE_MAIN, i);

//if last bar closed above overall trend and trendline moves up then trendup is true
if (Close[Current + 1] > trend_ma_now && trend_ma_now > trend_ma_pre)
{trendup = true;}

//if last bar closed above triggerline while closing below/at it the bar before (a cross up) then triggup is true
if (Close[Current +1] > trigg_ma_now && Close[Current +2] <= trigg_ma_pre)
{triggup = true;}

//if short stochastics move up... and both short and long stochastics
//have both been below 25 anywhere within the last "i" bars then stochup is true
if (sto_short_now > sto_short_pre && sto_short <= 25 && sto_long <= 25)
{stochup = true;}

//if short stochastics move up... and anywhere within "i" bars short stochastics have been
//at least 10 points lower than long stochastics... and long stochastics are still above 35..
//then sloppystochup is true
if (sto_short_now > sto_short_pre && sto_short + 10 <= sto_long && sto_long_now > 35)
{sloppystochup = true;}


//if triggup, trendup and stochup are all true.. OR... triggup, trendup and sloppystochup are all true...
if (triggup == true && trendup == true && stochup == true || triggup == true && trendup == true && sloppystochup == true)

//then draw an arrow below the low of the last closed candle...
{buyit[Current + 1] = Low[Current + 1];}




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

Last edited by CEHansen; 08-20-2008 at 11:55 AM.
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 09:12 AM.



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