Basic questions ... - page 9

 
Zen_Leow:
matrixebiz, have you considered the possibility of a trade opening and closing in the same candle before the candle has closed? you should probably check the history list as well.

I've always port this little function I wrote to all my EAs, perhaps you may find it useful too.

bool DecideToOpenTrade()

{

int total = OrdersTotal();

if (total > 0)

{

for(int cnt=0;cnt<total;cnt++)

{

if(OrderSelect(cnt,SELECT_BY_POS))

{

if(OrderSymbol()==Symbol() && OrderMagicNumber() == EA_MAGIC_NUM)

{

return (false);

}

}

}

}

// in case trades has already opened and closed within the candle

int histotal = OrdersHistoryTotal();

if (histotal > 0)

{

for(cnt=0;cnt<histotal;cnt++)

{

if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY))

{

if(OrderSymbol()==Symbol() && OrderMagicNumber() == EA_MAGIC_NUM)

{

if (Time[0] <= OrderOpenTime()) // don't open a new position if we're still on the same candle

{

return (false);

}

}

}

}

}

return (true);

}

int start()

{

// some time check codes first.. blah blah

// ...

// ...

// ...

// check signals

if (Should_Buy())

{

if (DecideToOpenTrade())

{

//... trade opening codes here

}

}

if (Should_Sell())

{

if (DecideToOpenTrade())

{

//... trade opening codes here

}

}

}

note: this function assumes you've set a unique value to EA_MAGIC_NUM. That way the check won't look at trades opened by other EAs.

Should_Buy() and Should_Sell() are functions I create in all my EAs to determine if a buy or sell signal has occurred.

hope this helps. PM me if you need further clarifications.

regards,

Zen

Thank you Zen I think this will do me fine just probably need to make a few changes because my EA is a multi currency trading EA so that is why I wasn't able to check for a specific currency not knowing which currency pair the EA had traded with, hence the reason why the code I have to change to look for a specific OrderComment() instead of what you have OrderSymbol(). I was using this code below to check if trades already existed currently but was having trouble with checking if trades were already closed on the the same bar.

for(int i=totalorders-1;i>=0;i--)

{

OrderSelect(i, SELECT_BY_POS);

if (OrderComment() == EA_Name + MagicNumber) GoOrders = false; }

if (GoOrders){orders();}

 

1 trade per signal

Hello anybody who can help

i am very new to codeing and am having a probelm with an ea i am working on i would like very much for this ea to place a trade and then wait for another signal before it enters another trade

right now it places a trade and as soon as that trade closes it reenters another trade without waiting for the next signal now i would like to know if anybody knows the code that i use to wait for next signal before entering again

thanks for any help in advance

 

Please help me clear this error

Im working on this expert recently.but still cannot clear this error so I really hope anyone in here can help me to make this expert close an order when the condition is in opposite direction.Please...

below are the error;

2009.01.07 08:46:58 2008.05.28 04:20 USDJPY,H1: unknown ticket 197 for OrderClose function

2009.01.07 08:46:58 2008.05.28 04:20 USDJPY,H1: OrderClose error 4108

thanks in advance.

int start()

{

if( iMA(NULL,0,5, 0,MODE_EMA, PRICE_CLOSE, 0) <iMA(NULL,0,30, 0,MODE_EMA, PRICE_CLOSE, 0)

)

{

OrderSend(Symbol( ),OP_SELL, Lots,Bid, 0,Bid+StopLoss* Point,Bid- TakeProfit* Point,"", SystemMagicNumbe r,0,Red);

return(0);

}

if( iMA(NULL,0,5, 0,MODE_EMA, PRICE_CLOSE, 0)>iMA(NULL,0,30, 0,MODE_EMA, PRICE_CLOSE, 0)

)

{

OrderSend(Symbol( ),OP_BUY, Lots,Ask, 0,Ask-StopLoss* Point,Ask+ TakeProfit* Point,"", SystemMagicNumbe r,0,Blue) ;

return(0);

}

if (OrderType() ==OP_SELL)

{

if (iMA(NULL,0, 5,0,MODE_ EMA, PRICE_CLOSE, 0)>iMA(NULL,0,30, 0,MODE_EMA, PRICE_CLOSE, 0))

{

OrderClose(SystemMa gicNumber, Lots,OrderCloseP rice(),0) ;

return(0);

}

}

if (OrderType() ==OP_BUY)

{

if (iMA(NULL,0, 5,0,MODE_ EMA, PRICE_CLOSE, 0)<iMA(NULL,0,30, 0,MODE_EMA, PRICE_CLOSE, 0))

{

OrderClose(SystemMa gicNumber, Lots,OrderCloseP rice(),0) ;

return(0);

}

}

 

How to create finite line object

It is possible to create trendline_object which is infinite. But how can I draw finite line from one point to another? Thank you for any reply.

 
MetaMaster:
It is possible to create trendline_object which is infinite. But how can I draw finite line from one point to another? Thank you for any reply.

set OBJPROP_RAY to false

 

The EA send order every tick after signal. HELP.

right now i'm studying to make EA.

how to make EA understand, that i want just send one order at every single signal appear.

the logic is

before it give signal, it remain calm,

immediately after signal appear, it send order, once.

and wait for another signal.

the problem is

this Ea should be able to send order no matter previous order was liquiditated or not.

so, i can't coding it to send order only after previous order closed.

Thank you.

 

help for ea base on indicator

--------------------------------------------------------------------------------

dear all

i have indicator(3ma cross with signal)i need to change it to ea , can i copy ind init() to expert init() and ind start() to expert start() and then put sell and buy function when the arrow give me signal??

i do it but it dosent work

 

help with coding issue

Hi

I'm trying to write a very simple EA which opens a number of pending orders at fixed intervals. In use it opens the orders but then keeps on opening them endlessly. How can I code it so that the orders only open once, and also if an order becomes live and hits TP or SL, then it is replaced with a new pending order from the original list?

Many thanks for any help offered,

Dan

 

One trade per magic number?

I am scripting an EA that will auto open a trade based on manual trading decisions. For example, I will look at the chart and determine what price I want the order to be opened at, what the stop and take is, etc... I'll then set the EA and when the price is reached it will open the trade.

I need to make it so the EA will only open one trade per magic number. I will manual set the magic number and each number will be unique. This way, if the trade is opened and then stopped out the EA will not try to open another trade if the trade price is reached again.

Any thoughts on the best what to achieve this? Some code examples would be helpful too

 

...

jerzzhere:
I am scripting an EA that will auto open a trade based on manual trading decisions. For example, I will look at the chart and determine what price I want the order to be opened at, what the stop and take is, etc... I'll then set the EA and when the price is reached it will open the trade.

I need to make it so the EA will only open one trade per magic number. I will manual set the magic number and each number will be unique. This way, if the trade is opened and then stopped out the EA will not try to open another trade if the trade price is reached again.

Any thoughts on the best what to achieve this? Some code examples would be helpful too

I had a tread on this forum that had a magik number solution...unfortunately davidke & walander hated my innovative ideas & raised stink all over the board...consequently my tread was deleted...