Basic questions ... - page 2

 

I'll try to explain myself :

Suppose I have 3 different systems:

system 1 works best on EUR/USD 1M chart.

system 2 works best on EUR/USD 5M chart.

system 3 works best on EUR/USD 1H chart.

Now I want my expert advisor to open 1 position per chart and no more. In other words, I want to open 1 position only for system 1, 1 position for system 2, and 1 to system 3.

The previous solution you wrote limit 1 position per symbol, and now I want to limit 1 position per chart type...

 

. In other words, I want to open 1 position only for system 1, 1 position for system 2, and 1 to system 3.

OK

then you work with MAGIC Number per system

#property copyright "system 1"

#property link ""

#define MAGIC 01901

.

.

.

if ( ExistPosition() == False) {

OrderSend(Symbol(),op,Lots,pp,SLIPPAGE,ldStop,ldTake,lsComm,MAGIC,0,clOpen); // MAGIC = system 1

}

// if open 1 position only for system 1 MAGIC ?

bool ExistPosition() {

bool Exist=False;

for (int i=0; i<OrdersTotal(); i++) {

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {

if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) Exist=True;

}

}

return(Exist);

}

can you posting you systems ?

 

10x!

I don't have specific system. It was only an example.

I'm new to metaTrader and that was some basic question I had ...

As soon as I'll write something good' I'll upload it here for comments...

 

How to make ea trade once per candle?

I was wondering if there is a piece of code that I can add to an EA so that it only trades once per candle.

Thanks in advance

 
basza:
I was wondering if there is a piece of code that I can add to an EA so that it only trades once per candle. Thanks in advance

static datetime timeprev;

if(timeprev==Time[0]) {

return(0); //only execute on new bar

} else if (timeprev==0) {

timeprev=Time[0]; // do nothing if freshly added to chart

return(0);

} else {

timeprev=Time[0];

// bar processing here

}

 
ra300z:
static datetime timeprev;

if(timeprev==Time[0]) {

return(0); //only execute on new bar

} else if (timeprev==0) {

timeprev=Time[0]; // do nothing if freshly added to chart

return(0);

} else {

timeprev=Time[0];

// bar processing here

}

Thank you ra300z

 

Display percentage target ?

Hello

I am trying to display a percentage target in the form of a comment within a ea.

I have this bit of code which displays the current balance as a comment:

"Percentage Target : " + AccountBalance()"\n"

At the start of the ea I have the following:

extern int ProfitPercentage=25;

Now what I want to do is : AccountBalance * ProfitPercentage and display the results. eg. $5675.69 * 25% = $1418.92 and display only $1418.69.

Thanks in advance

 

hi guyss....

1:how to make the EA to trade only one time persignal..( what i mean is the code)

for example ma cross EA... when the ma cross up and with target 20 pip it will closed but when the trend is continue it will try to open another trade since the fast ma still above slow ma.it only have to open another trade when the ma cross down.

fast ma > slow ma = need only one trade persignal

fast ma < slow ma = also need only one trade persignal

2:is there anyway to put time delay on the crossing? I only know pip seperation (whatever they call it) mean it will wait maybe 10-15 pip after the crossing the only open a trade.

just a newbie trying to learn mq4 language:)

 

one way would be to make the EA look at historical MA readings rather than the current ones. In principle it'd be:

// Recognise past crossing (up or down)

if ( fast( past+1 ) slow( past ) )

then cmd = OP_BUY;

else if ( fast( past+1 ) >= slow( past+1 ) && fast( past ) < slow( past ) )

then cmd = OP_SELL;

else return;

// If processing reaches this point, then a trade decision of either OP_BUY

// or OP_SELL has been made, due to recognising a supporting MA crossing

// at "past" number of bars in history.

// Limit to only one trade in a direction

static int last_trade = -1;

if ( last_trade == cmd ) return;

last_trade = cmd;

// If processing reaches this point, then this processing is the first time

// that the supporting MA crossing is recognised.

That would make a decision at the "past" number of bars following the bar where the crossing occurs, and only allow a trade the first time the crossing is detected.

 

thank bro for the code...

Reason: