How to code? - page 93

 

thx but can you explain me why

BuyCondition = BuyValueCurrent1 != EMPTY_VALUE

why empty_value?

 

anyway it doesn't work and i don't understand and figure out why..

here are my variables

BuyValueCurrent = iCustom(NULL,TimeFrame,IndicatorName1,NumBars,0,1); // braintrend1 [/PHP]
BuyValueCurrent2 = iCustom(NULL,TimeFrame,IndicatorName2,NumBars,0,1); // braintrend2

and here is the statement

[PHP] BuyCondition = (BuyValueCurrent != EMPTY_VALUE && BuyValueCurrent2 != EMPTY_VALUE);

it gives totally fuzzy results even when the indicator (Braintrend2stop and BrainTrend1Stop) are SELL

 
clarc:
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:

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:

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

Your entry condition here

}

Hope that helps.

FerruFx

 
payback:
anyway it doesn't work and i don't understand and figure out why..

here are my variables

BuyValueCurrent = iCustom(NULL,TimeFrame,IndicatorName1,NumBars,0,1); // braintrend1 [/PHP]
BuyValueCurrent2 = iCustom(NULL,TimeFrame,IndicatorName2,NumBars,0,1); // braintrend2

and here is the statement

[PHP] BuyCondition = (BuyValueCurrent != EMPTY_VALUE && BuyValueCurrent2 != EMPTY_VALUE);
it gives totally fuzzy results even when the indicator (Braintrend2stop and BrainTrend1Stop) are SELL

I do not know your indic Braintrend1 and 2, I just assumed that when a buy condition is fulfilled, they draw an arrow on the chart. In MT4, the default buffer's value is a constant named "EMPTY-VALUE", so if there is no arrow the value returned by iCustom() is this constant, and if there is an arrow the returned value is the price where the arrow is put.

As I understood, you want to buy when both indics are showing an arrow, isn't that ?

 

yes is exactly what i want to do

 
payback:
yes is exactly what i want to do

So, please, check your iCustom() syntax.

 

what i have to check? maybe i miss something

double iCustom( string symbol, int timeframe, string name, ..., int mode, int shift)

well for what i suppose if there is a buy signal it is stored in buffer 0 else it is empty and buffer 1 has the sell signal

 
payback:
what i have to check? maybe i miss something
double iCustom( string symbol, int timeframe, string name, ..., int mode, int shift)
well for what i suppose if there is a buy signal it is stored in buffer 0 else it is empty and buffer 1 has the sell signal

Post your indic here, I will look.

 

ok thx!

and please explain

 
payback:
ok thx! and please explain

Open BrainTrend1Stop.mq4.

At the begining of the file you can find :

extern int NumBars=500;

extern int EnableAlerts=0;

extern int SignalID=0;[/PHP]This means that you have to fill those three parameters as arguments in the iCustom() call, like this:

BuyValueCurrent = iCustom(NULL,0,"BrainTrend1Stop",NumBars,EnableAlerts,SignalID,0,1); // braintrend1

[/PHP]About the buffer's number, you can see this:

#property indicator_color1 Magenta

#property indicator_color2 Aqua[/PHP]So the buffer 0 is Magenta and the buffer 1 is Aqua.

Thus if the Buy arrow's color is Aqua, the buffer's number is 1 and the iCustom call is:[PHP]BuyValueCurrent = iCustom(NULL,0,"BrainTrend1Stop",NumBars,EnableAlerts,SignalID,1,1); // braintrend1
A little lower you have:[PHP] SetIndexEmptyValue(1,0.0);

This means that the default empty value for the buffer 1 is set to 0.0; so when there is no arrow, the value returned by the iCustom() call will be 0.0.

So you should know the presence of the arrow checking its value against 0, like this (if the second indic follows the same behavior):[PHP]BuyCondition = (BuyValueCurrent > 0 && BuyValueCurrent2 > 0);

About the second indic, I think you should be able to do the same analyse by yourself.

Reason: