Urgent !!!

 

how do i get an ea to alert the current ask price everytime it changes.

suggest routine

 
junglelion:
how do i get an ea to alert the current ask price everytime it changes. suggest routine

if (OldPrice != Ask)

Alert("Yoohoo - Change in Ask Price...");

OldPrice = Ask;

.... but why would you want to - the ask price changes very often which means you would get an alert every few seconds (at least...)

 

I was supposed to write the EA in start() not init() hence i was having trouble.

I wanted the price to update each time it changed, getting alert was not on the criteria.

Okay that done, my next problem is :

Getting the day high and day low price difference.

tropen = MarketInfo(Symbol(), MODE_OPEN);

trclose = MarketInfo(Symbol(), MODE_CLOSE);

tr = (trclose - tropen);

//Alert(trc);

This returns 0 each time. My objective is to let the EA work only when the market has moved less than 50 pips in any direction and not to bother if the move is more.

This is to filter out longer trades from shorter trades.

Sorry I am new to EA programming, I hope you understand.

 

Junglelion,

I have a feeling that you decared the tropenand trclose as int type.

You have to declare them as double type:

double tropen, trclose ;

 
junglelion:
I was supposed to write the EA in start() not init() hence i was having trouble.

I wanted the price to update each time it changed, getting alert was not on the criteria.

Okay that done, my next problem is :

Getting the day high and day low price difference.

tropen = MarketInfo(Symbol(), MODE_OPEN);

trclose = MarketInfo(Symbol(), MODE_CLOSE);

tr = (trclose - tropen);

//Alert(trc);

This returns 0 each time. My objective is to let the EA work only when the market has moved less than 50 pips in any direction and not to bother if the move is more.

This is to filter out longer trades from shorter trades.

Sorry I am new to EA programming, I hope you understand.

No problem. The easiest way is just :-

iATR(NULL,PERIOD_D1,1,0);

If you want to complicate things, you could use :-

iHigh(NULL,PERIOD_D1,0) - iLow(NULL,PERIOD_D1,0);

 

I took the longest method

tropen = MarketInfo(Symbol(), MODE_HIGH);

trclose = MarketInfo(Symbol(), MODE_LOW);

int digit = MarketInfo(Symbol(), MODE_DIGITS);

double tr = MathAbs(trclose - tropen);

if (digit == 2) tr = tr * 100;

if (digit == 4) tr = tr * 10000;

int tr2 = MathFloor(tr);

Alert(Symbol() + " " + tr2);

I will check the ATR method, looks reasonably small

Got it working with this now

if (OrdersTotal() == 0 && tr2 < 50)

So this filters out trades after the market has moved, so I do not get caught in reversals.

 

How do we increase the size of the comments

Or can we put them as BIG labels ?

 
junglelion:
I took the longest method

tropen = MarketInfo(Symbol(), MODE_HIGH);

trclose = MarketInfo(Symbol(), MODE_LOW);

int digit = MarketInfo(Symbol(), MODE_DIGITS);

double tr = MathAbs(trclose - tropen);

if (digit == 2) tr = tr * 100;

if (digit == 4) tr = tr * 10000;

int tr2 = MathFloor(tr);

Alert(Symbol() + " " + tr2);

I will check the ATR method, looks reasonably small

Got it working with this now

if (OrdersTotal() == 0 && tr2 < 50)

So this filters out trades after the market has moved, so I do not get caught in reversals.

Hmm...

I think the ATR is the fastest one (method from few posts bellow) but if you want to use your code you could write it like that too :

tropen = iHigh(Symbol(),PERIOD_D1,0);

trclose = iLow(Symbol(),PERIOD_D1,0);

int tr2 = (trclose - tropen)/Point;

But the fastest way is to use iATR function.

 
junglelion:
How do we increase the size of the comments Or can we put them as BIG labels ?

Yes, this is a good way

 

How do I get the OrderSelect() function to work?

OrderSelect(1, SELECT_BY_TICKET , MODE_TRADES);

Alert(Symbol() + " " + OrderProfit());

This gives 0 each time.

---------

Got it to work with

int nCnt;

for(nCnt = 0; nCnt < OrdersTotal(); nCnt++)

{

OrderSelect(nCnt, SELECT_BY_POS, MODE_TRADES);

}

 

Implementing trailing stop loss

Do we implement trailing stop loss in this manner??

if (OrderType() == OP_SELL && OrderProfit() > 20)

{

if(TrailingStop > 0)

{

if(ask > (OrderOpenPrice() + (Point * TrailingStop)))

{

if(OrderStopLoss() < ask + (Point *TrailingStop))

{

OrderModify(OrderTicket(),OrderOpenPrice(),ask - Point*TrailingStop,OrderTakeProfit(),0,Blue);

return(0);

}

}

}

OrderClose(ticket, lot_size, ask, 0, Green);

}

Reason: