MQL4 Learning - page 116

 

Why does this not work????

All I want is for sell = 1 when the slow stochastic k line is larger than 80, but every time I use it in tester it never works.

This is what I have currently

if (iStochastic(NULL,0,15,6,0,MODE_SMA,0,MODE_MAIN,0) >= 80){

sell = 1;}

Many thanks,

Sapere

 
Change it to this :
if (iStochastic(NULL,0,15,6,1,MODE_SMA,0,MODE_MAIN,0) >= 80){

sell = 1;}

If you use 0 for slowing parameter in a call to iStochastic() it will always return 0 as a result
Sapere:
All I want is for sell = 1 when the slow stochastic k line is larger than 80, but every time I use it in tester it never works.

This is what I have currently

if (iStochastic(NULL,0,15,6,0,MODE_SMA,0,MODE_MAIN,0) >= 80){

sell = 1;}

Many thanks,

Sapere
 
mladen:
Change it to this :
if (iStochastic(NULL,0,15,6,1,MODE_SMA,0,MODE_MAIN,0) >= 80){

sell = 1;}

If you use 0 for slowing parameter in a call to iStochastic() it will always return 0 as a result

A million thanks kind sir that was driving me up the wall

 

OrderCloseBy

Hello,

I'm new to coding and to this forum, but I see a lot of help around here.

Been studying MQL lately, and try to code my own ideas into EA's or indicators, or even scripts.

Now I was looking at the function OrderCloseBy.

Suppose I have 10 trades running, both long and short.

I have some pendingorders waiting to be executed.

Suppose I want to close a running trade and want to close a running trade with a pending order to reverse that particular trade.

So use OrderCloseby to close the buy trade, with a pending shortorder ?

 

How can I fetch the color of a spefic indicator buffer?

Hello, I want to draw some objects that colors are same as indicator lines.

For example, the indicator plot MA on chart and draw a descriptive text label that is same color as the MA line.

This can be solved partially by setting color through external variables, but if I change it in color tab, the indicator has no way to know the color of MA line.

Is there any way to know what the color is ?

 
void:
Hello, I want to draw some objects that colors are same as indicator lines.

For example, the indicator plot MA on chart and draw a descriptive text label that is same color as the MA line.

This can be solved partially by setting color through external variables, but if I change it in color tab, the indicator has no way to know the color of MA line.

Is there any way to know what the color is ?

Unfortunately there is no way to do that. Run-time values of drawing buffer colors are inaccessible

 
rbowles:
I have been working on an EA the last few days and with the help of this forum I have made some progress. I want to know how I would print an arrow or sometime of graphic that indicates where It is getting in a trade and where it is getting out. I no how to do it for an indicator but not for an EA.

Thanks in advance

Randy

In MT4, if EA enter or exit trader, then there will be automatically generate some arrows. I am not sure if you can control arrow and other symbols in EA. I guess you can't handle them.

 

OrderSend not executed

hi, I am new in MT4 programming and I have written a simple program which sends an order using OrderSend as follows.

OrderSend("EURUSD",OP_SELL, lot, MarketInfo("GBPJPY",MODE_BID), 7, NULL, NULL, NULL, magic, 0, CLR_NONE);

It works well until I decided to test my error handling routine. I changed "EURUSD" to "EURUSS" which is not a valid symbol. The MT4 did return an error to my routine, but from there on, all my subsequent OrderSend commands are not working at all. I tried to restart the MT4, but the result is still the same.

I am not sure if my test routine has resulted in some internal MT4 jam. Anyone has similar experience on this, or if anyone knows why such incidence occurred ? Please advise. Thanks.

Alternatively, can anyone advise how to test if OrderSend is executed properly, and if not, how to find out the reason or error message? Please advise. Thanks.

 
jasonyeo:

OrderSend("EURUSD",OP_SELL, lot, MarketInfo("GBPJPY",MODE_BID), 7, NULL, NULL, NULL, magic, 0, CLR_NONE);

as prefered price for you order on e/u, You use price from GBP/JPY. Probably there can be error.

look for this:

symbol - Symbol for trading.

cmd - Operation type. It can be any of the Trade operation enumeration.

volume - Number of lots.

price - Preferred price of the trade.

slippage - Maximum price slippage for buy or sell orders.

stoploss - Stop loss level.

takeprofit - Take profit level.

comment - Order comment text. Last part of the comment may be changed by server.

magic - Order magic number. May be used as user defined identifier.

expiration - Order expiration time (for pending orders only).

arrow_color - Color of the opening arrow on the chart. If parameter is missing or has CLR_NONE value opening arrow is not drawn on the chart.

 

How to call function with no return value

Here below I have written some code. (the function is not mine, but will do my Job just fine)

However, how do I call this function in my programm? I made a little example code below.

At some point I check my parameters, and if they are ok, it must call the function.

However, the function returns no value, I just want the piece of code inside the function to be executed at this point in my programm.

How can I do that best? Tx in advance - Greetings from Jonkie76

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

//----

if (Price >= PRICE_CLOSE)

call function ; // At this point I'd like to call the function.How do I do that?

else

Alert("Do nothing"); // Price not above, so do nothing

//----

return(0);

}

//+------------------------------------------------------------------+

//===================================================================+

//FUNCTIONS

//===================================================================+

//----------------------- CLOSE ORDER FUNCTION ----------------------+

void subCloseOrder()

{

int

i,

total = 0,

ticket = 0,

err = 0,

c = 0;

total = OrdersTotal();

for(i=total-1;i>=0;i--)

{

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if(OrderSymbol()==Symbol() &&

OrderMagicNumber()==Magic)

{

switch(OrderType())

{

case OP_BUY :

for(c=0;c<NumberOfTries;c++)

{

ticket=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Violet);

err=GetLastError();

if(err==0)

{

if(ticket>0) break;

}

else

{

if(err==0 || err==4 || err==136 || err==137 || err==138 || err==146) //Busy errors

{

Sleep(5000);

continue;

}

else //normal error

{

if(ticket>0) break;

}

}

}

break;

}

}

}

}

Reason: