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
  #1271 (permalink)  
Old 09-10-2008, 04:54 AM
Senior Member
 
Join Date: Oct 2007
Posts: 224
Dave137 is on a distinguished road
Question

Quote:
Originally Posted by luxinterior View Post
instead of having startcolor as a string have it as a color

Lux
Lux, It would work this way if I had only one indicator color to change (example from red to green), but I have two indicator colors to change dependent on condition change: Condition 1 to Condition 2 of Indicator:

Bool Condition 1 = True: Indicator A color = Yellow //UP Direction - Buffer 2
Bool Condition 1 = True: Indicator B color = Clr_NONE - Buffer 3

Bool Condition 2 = False: Indicator A color = Clr_NONE - Buffer 2
Bool Condition 2 = False: Indicator B color= Magenta //Down Direction - Buffer 3

Lux, How do I resolve this then??


Anxiously awaiting your reply! And Thanks for responding

Dave

Last edited by Dave137; 09-10-2008 at 04:57 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1272 (permalink)  
Old 09-11-2008, 12:15 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
matrixebiz is on a distinguished road
Could someone please tell me the code I need to make the EA open trades quicker. For some reason my EA may open a trade 1 minute or two later. Just wondering what code to add to have the EA check trade conditions more often. I have EachTick = True but that is at the very beginning of the EA. Should that be changed?

How do I add more loop subroutines?
Thanks

Last edited by matrixebiz; 09-11-2008 at 01:00 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1273 (permalink)  
Old 09-11-2008, 02:08 PM
Senior Member
 
Join Date: Feb 2007
Posts: 947
FerruFx is on a distinguished road
Quote:
Originally Posted by matrixebiz View Post
Could someone please tell me the code I need to make the EA open trades quicker. For some reason my EA may open a trade 1 minute or two later. Just wondering what code to add to have the EA check trade conditions more often. I have EachTick = True but that is at the very beginning of the EA. Should that be changed?

How do I add more loop subroutines?
Thanks
If the EA check already each tick, your issue may be that some pairs are very quiet and have ticks spaced by minutes sometimes.

FerruFx
__________________
THE HEART of FOREX & THE PROBABILITY METER - Trade with 100% confidence and ... Stress Less!!!
Coding services: Experts Advisors, indicators, alerts, etc ... more info by PM
NEW: video presentation of the Probability Meter ... 24hrs action on the website
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1274 (permalink)  
Old 09-11-2008, 03:06 PM
Junior Member
 
Join Date: Sep 2008
Posts: 1
hamabdul11 is on a distinguished road
Need Help for this Expert Advisor "FirefilyEA

Please can someone assist me review this EA i just design but still having error and takes too long to start like 5 miniutes please i need your help if you can edit you can send the code to me e-mail: hamabdul11@yahoo.com thanks

code:

//+------------------------------------------------------------------+
//| FireFly EA.mq4 |
//| Copyright © 2008, SuperHamza |
//| hamabdul11@yahoo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, SuperHamza"
#property link "hamabdul11@yahoo.com"

extern int
MagicNumber = 12345,
Slippage = 2,
TakeProfit = 40,
StopLoss = 20,
TrailingStop = 20,
TSMinProfit = 0;
extern double
Lots = 0.1;
extern bool
WaitForBarClose = true,
OneEntryPerBar = true;

datetime entrytime;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

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

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int ticket = 0;
int shift = 0;
if(WaitForBarClose)
{
shift = 1;
}

double Stoch = iStochastic(Symbol(),0,3,1,1,MODE_SMA,1,MODE_MAIN, shift);
double Envy = StochEnvyVal(shift);
double StochLast = iStochastic(Symbol(),0,3,1,1,MODE_SMA,1,MODE_MAIN, shift+1);
double EnvyLast = StochEnvyVal(shift+1);

double RSI = iRSI(Symbol(),0,3,PRICE_CLOSE, shift);
Comment("Stoch: "+Stoch+" |RSI: "+RSI+" |Envy: "+Envy);

//----------------------- TRAILING STOP
if(TrailingStop>0 && subTotalTrade()>0)
{
int total = OrdersTotal();
for(int cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL &&
OrderSymbol()==Symbol() &&
OrderMagicNumber()==MagicNumber)
{
subTrailingStop(OrderType());
}
}
}
if(!OneEntryPerBar)
{
entrytime = 0;
}
if(subTotalTrade()<1)
{
//OP_BUY
if((Stoch>Envy&&StochLast<EnvyLast&&RSI>50)&&entry time!=iTime(Symbol(),0,0))
{
ticket = subOpenOrder(OP_BUY, Lots, StopLoss, TakeProfit,MagicNumber);
if(ticket>0)entrytime=iTime(Symbol(),0,0);
}
//OP_SELL
if((Stoch<Envy&&StochLast>EnvyLast&&RSI<50)&&entry time!=iTime(Symbol(),0,0))
{
ticket = subOpenOrder(OP_SELL, Lots, StopLoss, TakeProfit,MagicNumber);
if(ticket>0)entrytime=iTime(Symbol(),0,0);
}
}

if((subTotalTrade()>0)&&entrytime!=iTime(Symbol(), 0,0))
{
//CLOSE_SELL
if(Stoch>Envy)
{
subCloseOrder(OP_SELL);
}
//CLOSE_BUY
if(Stoch<Envy)
{
subCloseOrder(OP_BUY);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
double StochEnvyVal(int shift)
{
double stoch[];
ArrayResize(stoch, Bars);
ArraySetAsSeries(stoch,true);
for(int i=Bars; i>=0; i--)
{
stoch[i]=iStochastic(Symbol(),0,3,1,1,MODE_SMA,1,MODE_MAIN ,i+shift);
}
double envy = iEnvelopesOnArray(stoch, 0, 41, MODE_LWMA, 0, 70, MODE_LOWER, 0) ;
return(envy);
}

int subOpenOrder(int type, double Lotz, int stoploss, int takeprofit,int MagicNumber)
{
int NumberOfTries = 15;
string TicketComment = "FireFly EA";
int
ticket = 0,
err = 0,
c = 0;

double
aStopLoss = 0,
aTakeProfit = 0,
bStopLoss = 0,
bTakeProfit = 0;

if(stoploss!=0)
{
aStopLoss = NormalizeDouble(Ask-stoploss*Point,4);
bStopLoss = NormalizeDouble(Bid+stoploss*Point,4);
}

if(takeprofit!=0)
{
aTakeProfit = NormalizeDouble(Ask+takeprofit*Point,4);
bTakeProfit = NormalizeDouble(Bid-takeprofit*Point,4);
}

if(type==OP_BUY)
{
for(c=0;c<NumberOfTries;c++)
{
ticket=OrderSend(Symbol(),OP_BUY,Lotz,Ask,Slippage ,aStopLoss,aTakeProfit,TicketComment,MagicNumber,0 ,Green);
err=GetLastError();
if(err==0)
{
if(ticket>0) break;
}
else
{
if(err==0 || err==4 || err==136 || err==137 || err==138 || err==146) //Busy errors
{
Sleep(5000);
continue;
}
else //normal error
{
if(ticket>0) break;
}
}
}
}
if(type==OP_SELL)
{
for(c=0;c<NumberOfTries;c++)
{
ticket=OrderSend(Symbol(),OP_SELL,Lotz,Bid,Slippag e,bStopLoss,bTakeProfit,TicketComment,MagicNumber, 0,Red);
err=GetLastError();
if(err==0)
{
if(ticket>0) break;
}
else
{
if(err==0 || err==4 || err==136 || err==137 || err==138 || err==146) //Busy errors
{
Sleep(5000);
continue;
}
else //normal error
{
if(ticket>0) break;
}
}
}
}
return(ticket);
}
//----------------------- CLOSE ORDER FUNCTION
void subCloseOrder(int TYPE)
{
int
NumberOfTries=10,
cnt,
total = 0,
ticket = 0,
err = 0,
c = 0;

total = OrdersTotal();
for(cnt=total-1;cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()==TYPE&&OrderSymbol() == Symbol() &&
OrderMagicNumber()==MagicNumber)
{
switch(OrderType())
{
case OP_BUY :
for(c=0;c<NumberOfTries;c++)
{
ticket=OrderClose(OrderTicket(),OrderLots(),Bid,Sl ippage,Violet);
err=GetLastError();
if(err==0)
{
if(ticket>0) break;
}
else
{
if(err==0 || err==4 || err==136 || err==137 || err==138 || err==146) //Busy errors
{
Sleep(5000);
continue;
}
else //normal error
{
if(ticket>0) break;
}
}
}
break;

case OP_SELL :
for(c=0;c<NumberOfTries;c++)
{
ticket=OrderClose(OrderTicket(),OrderLots(),Ask,Sl ippage,Violet);
err=GetLastError();
if(err==0)
{
if(ticket>0) break;
}
else
{
if(err==0 || err==4 || err==136 || err==137 || err==138 || err==146) //Busy errors
{
Sleep(5000);
continue;
}
else //normal error
{
if(ticket>0) break;
}
}
}
break;

case OP_BUYLIMIT :
case OP_BUYSTOP :
case OP_SELLLIMIT:
case OP_SELLSTOP :
OrderDelete(OrderTicket());
}
}
}
}
int subTotalTrade()
{
int
cnt,
total = 0;

for(cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() &&
OrderMagicNumber()==MagicNumber) total++;
}
return(total);
}
void subTrailingStop(int Type)
{
if(Type==OP_BUY) // buy position is opened
{
//----------------------- AFTER PROFIT TRAILING STOP

if(Bid-OrderOpenPrice()>Point*TSMinProfit &&
OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}

}
if(Type==OP_SELL) // sell position is opened
{
//----------------------- TRAILING STOP AFTER PROFIT

if(OrderOpenPrice()-Ask>Point*TSMinProfit)
{
if(OrderStopLoss()>Ask+Point*TrailingStop || OrderStopLoss()==0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Poi nt*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}



}
}

//+------------------------------------------------------------------+
//End End End End End End End End End End End End|
//+------------------------------------------------------------------+
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1275 (permalink)  
Old 09-12-2008, 04:07 PM
Member
 
Join Date: Dec 2006
Posts: 87
dwmcqueen is on a distinguished road
Looping without Freezing MetaTrader

I have an EA (or perhaps it should be a script) that needs to continously loop and monitor current orders. What is the best method to do this such that it won't lock up MetaTrader?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1276 (permalink)  
Old 09-13-2008, 02:14 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 723
wolfe is on a distinguished road
Quote:
Originally Posted by dwmcqueen View Post
I have an EA (or perhaps it should be a script) that needs to continously loop and monitor current orders. What is the best method to do this such that it won't lock up MetaTrader?
Use a sleep function at the end of your loop.

Example:

PHP Code:
while (OrderProfit() < 999999)
 {
    
Code you want to loop here;
    
Sleep(1000);
 } 
Sleep(1000) will give you about a 1 second delay. I have had success with this in experts. It DOES NOT work in indicators, I'm not sure why.

Hope this helps.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1277 (permalink)  
Old 09-13-2008, 02:19 AM
nondisclosure007's Avatar
Senior Member
 
Join Date: Apr 2007
Posts: 100
nondisclosure007 is on a distinguished road
Why can't I pull the values from an indicator

I'm attaching a blank EA that will put the values, or so I thought, of the indicator in a comment section.

The indicator in question is TrendStrength_v2.mq4. I can't post it because it belongs to Igorad and I don't have his permission. But, in the secure forum where he posted it ( I don't remember where ) is the source code.

Igorad, if you need it, let me know. I can get it to you.

I'm trying to pull values but All I get are the same values over and over again. put the EA in a backtest just to grab values and you'll see what I mean.

If anyone has this indicator, are you getting the same problems?

Any help would be great!

THANKS IN ADVANCE!
Attached Files
File Type: mq4 Blank EA.mq4 (2.9 KB, 14 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1278 (permalink)  
Old 09-16-2008, 06:01 PM
Junior Member
 
Join Date: Aug 2007
Posts: 6
Orest is on a distinguished road
Retracement: piece of code needed

Hi All,
I wonder if somebody has a piece of mql coding (or help me to make it ) for retracement implementation.

Here is what I need exactly (for BUY).
Let's have 15 min chart, shouldn't matter actually and a High for period from T1 to T2. Now, my current price is equal to that High, but I don't want to enter that breakout because I'm smart and want to wait for price's retracement (pullback). Then the future price makes a new High I'll wait for next candle to open and then that new candle makes another new High only then I enter.

What worries me in coding is obviouosely I want everything to be happened withing several candles. If price goes all a way down (opposite direction) and then back up I don't want that breakout triggered at all.

I probably want too much.

Thanks,
Orest
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1279 (permalink)  
Old 09-16-2008, 10:09 PM
nondisclosure007's Avatar
Senior Member
 
Join Date: Apr 2007
Posts: 100
nondisclosure007 is on a distinguished road
TrendStrength availbility

Is this version (or any newer ones) available in the Elite section? Or the public section?

Quote:
Originally Posted by Flytox View Post
It's TrendStrength v2.2
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1280 (permalink)  
Old 09-19-2008, 04:48 PM
Junior Member
 
Join Date: May 2008
Posts: 5
i2trader is on a distinguished road
How does one add the LSMA to EA'S

I am new to this code writing stuff. But the EMA Cross.mq4. only use the EMA as is its trend. How can I add or change the trend to the LSMA? This trend indicator seems to be more reliable than the EMA or the others that are offer in the MQ4 language. Where does one find the code for this LSMA and where do you place it in the code. I would like to add the LSMA to this EA also. The 100 pips. Any ideas? Here is some of the code for the 100 pips. I beleive that this is where the EA find the trend.


if(timeframe==0) {timeframe=Period();}
double diClose0=iClose(Symbol(),timeframe,0);
double diMA1=iMA(Symbol(),timeframe,7,0,MODE_SMA,PRICE_OP EN,0);
double diClose2=iClose(Symbol(),timeframe,0);
double diMA3=iMA(Symbol(),timeframe,6,0,MODE_SMA,PRICE_OP EN,0);



As you can see the 100 pips uses the SMA. How do we change that to the LSMA the language does not support that indicator or does it? Iam lost.


Moving Average calculation method used with iAlligator(), iEnvelopes(), iEnvelopesOnArray, iForce(), iGator(), iMA(), iMAOnArray(), iStdDev(), iStdDevOnArray(), iStochastic() indicators.
It can be any of the following values:

Constant Value Description
MODE_SMA 0 Simple moving average,
MODE_EMA 1 Exponential moving average,
MODE_SMMA 2 Smoothed moving average,
MODE_LWMA 3 Linear weighted moving average.

Last edited by i2trader; 09-19-2008 at 04:53 PM. Reason: want to attach files
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:08 PM.



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