MQL4 Learning - page 12

 

Need coding to close out positions created by EA on Friday just before close of week!

1) Can anyone help to provide the ea coding to close out all positions just before the market closes on Friday.

2) Also, coding needed to put each ea to sleep at the same time on Friday PM (So it does not open up any new positions) until Sunday PM when it will allow the ea to trade again.

My time zone is GMT -6.

Many thanks to your generosity in advance!

Dave

<<<
 

Error 65 & 128 explanation

Hi, I was hoping someone could help me and explain a couple of errors I received while testing an EA I am writing.

I ran the EA through the night to see if it was working properly and when I woke there were a couple of errors that I can't find an explanation for.

Error(65) : Invalid Account

Error(128) : Trade Timeout

Error(129) : Invalid Price

I've never run into these errors before. Does this mean that I was trading on OFF market hours?

Please help, thanks

Sean

EDIT:

Never Mind. Didn't realize that the demo account was for only 30days, and just so happens last night was the 30 day mark.

my bad

 

Opend Order - Splitting

Hallo,

gives a way or code for closing smaller Lots - from opend position?

example: open 1 - close 0.5 ... or close 0.3 - from this position?

Thanks

diskus

 

MQL4 Learning

subtracting the counted_bars from the total count of the bars on chart.

Thanks.

 

Does anybody know what this means? I need help with it.:)

 
MQL4:
subtracting the counted_bars from the total count of the bars on chart. Thanks.

Take a look to the mql4 help file:

int IndicatorCounted( )

The function returns the amount of bars not changed after the indicator had been launched last. The most calculated bars do not need any recalculation. In most cases, same count of index values do not need for recalculation. The function is used to optimize calculating.

Note: The latest bar is not considered to be calculated and, in the most cases, it is necessary to recalculate only this bar. However, there occur some boundary cases where custom indicator is called from the expert at the first tick of the new bar. It is possible that the last tick of the previous bar had not been processed (because the last-but-one tick was being processed when this last tick came), the custom indicator was not called and it was not calculated because of this. To avoid indicator calculation errors in such situations, the IndicatorCounted() function returns the count of bars minus one.
 

I think it is the number of the bars which was not changed after the last indicator's call.

For example we had 300 bars. Then EA may call indicator for the signal or to open the order. For example: H1 timeframe. So we still have 300 unchanged bars. Because 301th bar is open bar and this bar will not be counted.

Because many indicators and EAs are calculated using i bars so using this function we may be sure that this i number of bars was unchanged and indicator will not re-paint and everything will be on close bar.

It is example in help file:

int start()

{

int limit;

int counted_bars=IndicatorCounted();

//----

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

//----

for(int i=0; i<limit; i++)

{

//----

ExtBlueBuffer=iMA(NULL,0,JawsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);

ExtRedBuffer=iMA(NULL,0,TeethPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);

ExtLimeBuffer=iMA(NULL,0,LipsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);

}

//----

return(0);

}

But, sorry, I am not a coder so may be wrong.

 

Thank You guys, I have one more question please:

I spent many hours, and I cannot solve the problem to this code:

if (MODE_ASK==121.10)

{

ticket=OrderSend(Symbol()..............

I want the USD\JPY to trigger a buy at this point. What's wrong with this code?

Can somebody tell me a code syntax that will trigger a buy at a certain time?

Thank You. God bless You.

 

MQL4 Learning

I spent many hours, and I cannot solve the problem to this code:

if (MODE_ASK==121.10)

{

ticket=OrderSend(Symbol()..............

I want the USD\JPY to trigger a buy at this point. What's wrong with this code?

Also, can someone tell me a code syntax that will trigger a buy at a certain time?

Thank You. God bless You.

 

MODE_ASK?? who told you that the constant MODE_ASK means more than the number 10.

Well, MODE_ASK is used with the function MarketInfo to get the ask price of a currency not the one hosting the EA.

double ask =MarketInfo("EURUSD",MODE_ASK);

so, your code should be:

double ask =MarketInfo("EURUSD",MODE_ASK);

if(ask == 121.10)

{

//do whatever you want.

}[/php]

And about setting time to buy you can use:

[PHP]if (TimeHour(TimeCurrent()) == 12 && TimeMinute(TimeCurrent()) >= 30)

{

//place a buy order

}

The code above place an order at 12:30 PM

MQL4:
I spent many hours, and I cannot solve the problem to this code:

if (MODE_ASK==121.10)

{

ticket=OrderSend(Symbol()..............

I want the USD\JPY to trigger a buy at this point. What's wrong with this code?

Also, can someone tell me a code syntax that will trigger a buy at a certain time?

Thank You. God bless You.
Reason: