Forex
Google

Go Back   Forex Trading > Programming > Metatrader Programming
Forex Forum Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


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 Thread Tools Display Modes
  #911 (permalink)  
Old 05-13-2008, 06:07 AM
birami birami is offline
Member
 
Join Date: Nov 2006
Posts: 31
birami is on a distinguished road
hello
on this expert I'd like modify all sl to last orders sl same as tp but I couldn't
please help me
Attached Files
File Type: mq4 javadea.mq4 (8.4 KB, 2 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #912 (permalink)  
Old 05-13-2008, 10:30 AM
benitohau benitohau is offline
Junior Member
 
Join Date: Jan 2006
Posts: 10
benitohau is on a distinguished road
What have I done?

I need help coding in MT4

I have some code below:
StopLoss=EMAtrend-iClose(NULL,0,1);
TakeProfit=StopLoss

If(EMAshort>EMAlong && EMAshort_prev<EMAlong_prev)
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Ask+StopLoss* Point,Bid+TakeProfit*Point,"Buy at close price",10000,0,Green);
}

If(EMAshort<EMAlong && EMAshort_prev>EMAlong_prev)
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,0,StopLoss,Bid +TakeProfit*Point,"Sell at close price",11000,0,Red);
}


The idea were:
1. Open order at close price when criteria met;
2. I want to make the EMAtrend to be the stoploss level;
3. The distance between EMAtrend to Close price bar will be the distance for takeprofit from opened price

I try the code above but nothing happen and there is an error 130.

Please help me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #913 (permalink)  
Old 05-13-2008, 11:36 AM
basza basza is offline
Member
 
Join Date: Dec 2005
Posts: 95
basza is on a distinguished road
Need help with code

Hi all

I am trying to get an ea to compile, but it comes up with the following error:

Code:
'TradeSymbol' - expression on global scope not allowed	I:\Program Files\MetaTrader - Alpari\experts\TTL.mq4 (65, 34)
Now the part of the ea causing this is right at the start of the code :

Code:
string         TradeSymbol;      TradeSymbol=Symbol();
If I block this out it comes up with errors for the following bit of code :

Code:
 if(TotalTradesThisSymbol(TradeSymbol)==0) {  int BS=0,SS=0,BL=0,SL=0;   }
   if(TotalTradesThisSymbol(TradeSymbol)>0)  {
      for(cnt=0;cnt<total;cnt++) {
         OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
         if(OrderSymbol()== Symbol) {
            if(OrderMagicNumber()==11) { BS=OrderTicket(); }
            if(OrderMagicNumber()==22) { SS=OrderTicket(); }
            if(OrderMagicNumber()==33) { BL=OrderTicket(); }
            if(OrderMagicNumber()==44) { SL=OrderTicket(); }
            }//end if(OrderSymbol
         }//end for
  }//end if   */
What I am wanting to know is if there is an easy way to fix this.
I'm no good at coding , only copying and pasteing.

Thanks in advance
Basza
__________________
This is what might be needed to help fund your Forex Habit. Profitmatic
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #914 (permalink)  
Old 05-13-2008, 02:56 PM
Michel Michel is offline
Senior Member
 
Join Date: Feb 2006
Posts: 502
Michel is on a distinguished road
Quote:
Originally Posted by basza View Post
Hi all

I am trying to get an ea to compile, but it comes up with the following error:

Code:
'TradeSymbol' - expression on global scope not allowed	I:\Program Files\MetaTrader - Alpari\experts\TTL.mq4 (65, 34)
Now the part of the ea causing this is right at the start of the code :

Code:
string         TradeSymbol;      TradeSymbol=Symbol();
If I block this out it comes up with errors for the following bit of code :

Code:
 if(TotalTradesThisSymbol(TradeSymbol)==0) {  int BS=0,SS=0,BL=0,SL=0;   }
   if(TotalTradesThisSymbol(TradeSymbol)>0)  {
      for(cnt=0;cnt<total;cnt++) {
         OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
         if(OrderSymbol()== Symbol) {
            if(OrderMagicNumber()==11) { BS=OrderTicket(); }
            if(OrderMagicNumber()==22) { SS=OrderTicket(); }
            if(OrderMagicNumber()==33) { BL=OrderTicket(); }
            if(OrderMagicNumber()==44) { SL=OrderTicket(); }
            }//end if(OrderSymbol
         }//end for
  }//end if   */
What I am wanting to know is if there is an easy way to fix this.
I'm no good at coding , only copying and pasteing.

Thanks in advance
Basza
You can define TradeSymbol as string on global scoop, but there you cannot evaluate the function Symbol(). So replace all "TradeSymbol" by "Symbol()", or assign the value in the init() or start() function like this:
PHP Code:
void Init(){TradeSymbol=Symbol();} 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #915 (permalink)  
Old 05-14-2008, 12:11 PM
payback payback is offline
Junior Member
 
Join Date: May 2008
Posts: 17
payback is on a distinguished road
help in programming

Hi i was trying to program an ea, and i followed your course (very intresting!)
I know quite well how to program in java and some c++

I was trying to program an ea with brain trend indicators the idea behind is
when brainTrend2stop and braintrend1stop DOTs are present buy (and viceversa)

but if i call the icustom function like this

BuyValueCurrent = iCustom(NULL,TimeFrame,IndicatorName1,NumBars,0,1) ;

i get only the value of the indicator in the present bar
is there a way to make it boolean? i'd like to write a function like

buy=true

BuyCondition = (IndicatorName1=true && IndicatorName2=true);

can someone help please please please???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #916 (permalink)  
Old 05-14-2008, 03:31 PM
clarc's Avatar
clarc clarc is offline
Junior Member
 
Join Date: May 2006
Posts: 17
clarc is on a distinguished road
Control if an Entry Order is Executed...

i have an EA wich open and mange the position, but sometimes give the indikator the same signal multiple and the EA open everytime this signal comes out an new position - but i dont want a second or third and so on and on position, i will only the first one - is it possible that the EA checks the open position by the basis of the magic number and pair to avoid such multiple entrys ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #917 (permalink)  
Old 05-14-2008, 08:38 PM
Michel Michel is offline
Senior Member
 
Join Date: Feb 2006
Posts: 502
Michel is on a distinguished road
Quote:
Originally Posted by payback View Post
Hi i was trying to program an ea, and i followed your course (very intresting!)
I know quite well how to program in java and some c++

I was trying to program an ea with brain trend indicators the idea behind is
when brainTrend2stop and braintrend1stop DOTs are present buy (and viceversa)

but if i call the icustom function like this

BuyValueCurrent = iCustom(NULL,TimeFrame,IndicatorName1,NumBars,0,1) ;

i get only the value of the indicator in the present bar
is there a way to make it boolean? i'd like to write a function like

buy=true

BuyCondition = (IndicatorName1=true && IndicatorName2=true);

can someone help please please please???
PHP Code:
BuyCondition BuyValueCurrent1 != EMPTY_VALUE && BuyValueCurrent2 != EMPTY_VALUE
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #918 (permalink)  
Old 05-15-2008, 12:43 AM
payback payback is offline
Junior Member
 
Join Date: May 2008
Posts: 17
payback is on a distinguished road
thx but can you explain me why
BuyCondition = BuyValueCurrent1 != EMPTY_VALUE
why empty_value?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #919 (permalink)  
Old 05-15-2008, 12:56 AM
payback payback is offline
Junior Member
 
Join Date: May 2008
Posts: 17
payback is on a distinguished road
anyway it doesn't work and i don't understand and figure out why..

here are my variables
PHP Code:
 BuyValueCurrent   iCustom(NULL,TimeFrame,IndicatorName1,NumBars,0,1);  // braintrend1 
PHP Code:
 BuyValueCurrent2   iCustom(NULL,TimeFrame,IndicatorName2,NumBars,0,1);  // braintrend2 
and here is the statement

PHP Code:
 BuyCondition  = (BuyValueCurrent != EMPTY_VALUE && BuyValueCurrent2 != EMPTY_VALUE); 
it gives totally fuzzy results even when the indicator (Braintrend2stop and BrainTrend1Stop) are SELL
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #920 (permalink)  
Old 05-15-2008, 01:23 AM
FerruFx FerruFx is offline
Senior Member
 
Join Date: Feb 2007
Posts: 526
FerruFx is on a distinguished road
Quote:
Originally Posted by clarc View Post
i have an EA wich open and mange the position, but sometimes give the indikator the same signal multiple and the EA open everytime this signal comes out an new position - but i dont want a second or third and so on and on position, i will only the first one - is it possible that the EA checks the open position by the basis of the magic number and pair to avoid such multiple entrys ?
Here's the idea:

Quote:
int CountLongs()
{
int count=0;
int trade;
int trades=OrdersTotal();
for(trade=0;trade<trades;trade++) {
OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber() != MagicNumber) continue;
if(OrderType()==OP_BUY) count++;
} //---- for
return(count);
}

int CountShorts()
{
int count=0;
int trade;
int trades=OrdersTotal();
for(trade=0;trade<trades;trade++) {
OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber() != MagicNumber) continue;
if(OrderType()==OP_SELL) count++;
} //---- for
return(count);
}
And in the start() function:

Quote:
if(CountLongs() == 0 && CountShorts() == 0) {

Your entry condition here
}
Hope that helps.

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
Reply


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
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 04:22 PM


All times are GMT. The time now is 10:49 PM.