MQL4 Learning - page 82

 

Roger09,

Thank you !

 

symbols.raw, symgroups.raw and symbols.sel structure

Hi,

Could someone provide us the full structure of symbols.raw, symgroups.raw and symbols.sel structure files?

Regards,

 

Need help coding. Can't get the program to do what i want

Hi!

I have a problem in my code it works fine till the part signed as the error 1 that little part is supposed to create orders when a specific order has a profit higher than a certain number.

Here's the code

extern double LOT = 2.0;

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

//| expert initialization function |

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

int init()

{

//----

//----

return(0);

}

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

//| expert deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| expert start function |

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

int start()

{

int Tot, Ticket;

double M_G0, M_G1, S_R0, S_R1,

MA_0, MA_1,

RSI_G0, RSI_R0, RSI_G1, RSI_R1,

MOM_0, MOM_1,

Ord_Prof;

//------------------- Momentum ------------------------

MOM_0 = iMomentum(NULL,0,8,PRICE_CLOSE,0); // 0 bar

MOM_1 = iMomentum(NULL,0,8,PRICE_CLOSE,1); // 1st bar

//---------------------- RSI --------------------------

RSI_G0 = iRSI(NULL,0,13,PRICE_CLOSE,0); // 0 Bar

RSI_G1 = iRSI(NULL,0,13,PRICE_CLOSE,1); // 1st Bar

RSI_R0 = iRSI(NULL,0,3,PRICE_CLOSE,0); // 0 Bar

RSI_R1 = iRSI(NULL,0,3,PRICE_CLOSE,1); // 1st Bar

//---------------------- MA ---------------------------

MA_0 = iMA(NULL,0,13,0,MODE_SMA,PRICE_CLOSE,0); // 0 bar

MA_1 = iMA(NULL,0,13,0,MODE_SMA,PRICE_CLOSE,1); // 1st bar

//------------------ Stochastic -----------------------

M_G0 = iStochastic(NULL,0,8,3,3,MODE_SMA,0,MODE_MAIN, 0); // 0 bar

M_G1 = iStochastic(NULL,0,8,3,3,MODE_SMA,0,MODE_MAIN, 1); // 1st bar

S_R0 = iStochastic(NULL,0,8,3,3,MODE_SMA,0,MODE_SIGNAL,0); // 0 bar

S_R1 = iStochastic(NULL,0,8,3,3,MODE_SMA,0,MODE_SIGNAL,1); // 1st bar

//------------- Operation sell --------------------

Tot=OrdersTotal();

if(Tot<1)

{

if ( MOM_1>100 && MOM_0S_R1 && M_G0RSI_G1 && RSI_R0Bid)

Ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,Ask+100*Point,Ask-500*Point);

}

//-------------- Error #1 --------------------------

//--- this part here is supposed to creat new orders when ------

//--- "ticket" order has an order profit > 130, 160, etc... ---

if(OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES)==true)

{

Ord_Prof=OrderProfit();

}

if(Tot==1 && Ord_Prof> 130 && Ord_Prof<159)

{

OrderSend(Symbol(),OP_SELL,LOT,Bid,3,Ask+100*Point,Ask-370*Point);

}

if(Tot==2 && Ord_Prof> 160 && Ord_Prof<189)

OrderSend(Symbol(),OP_SELL,LOT,Bid,3,Ask+100*Point,Ask-340*Point);

if(Tot==3 && Ord_Prof> 190 && Ord_Prof<219)

OrderSend(Symbol(),OP_SELL,LOT,Bid,3,Ask+100*Point,Ask-310*Point);

if(Tot==4 && Ord_Prof> 220 && Ord_Prof<249)

OrderSend(Symbol(),OP_SELL,LOT,Bid,3,Ask+100*Point,Ask-280*Point);

if(Tot==5 && Ord_Prof> 250 && Ord_Prof<279)

OrderSend(Symbol(),OP_SELL,LOT,Bid,3,Ask+100*Point,Ask-250*Point);

if(Tot==6 && Ord_Prof> 280 && Ord_Prof<309)

OrderSend(Symbol(),OP_SELL,LOT,Bid,3,Ask+100*Point,Ask-220*Point);

if(Tot==7 && Ord_Prof> 310 && Ord_Prof<339)

OrderSend(Symbol(),OP_SELL,LOT,Bid,3,Ask+100*Point,Ask-190*Point);

if(Tot==8 && Ord_Prof> 340 && Ord_Prof<379)

OrderSend(Symbol(),OP_SELL,LOT,Bid,3,Ask+100*Point,Ask-160*Point);

if(Tot==9 && Ord_Prof> 370 && Ord_Prof<409)

OrderSend(Symbol(),OP_SELL,LOT,Bid,3,Ask+100*Point,Ask-130*Point);

if(Tot==10 && Ord_Prof> 400 && Ord_Prof<439)

OrderSend(Symbol(),OP_SELL,LOT,Bid,3,Ask+100*Point,Ask-100*Point);

//----------------------------------------------------------------------

return(0);

}

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

Hope you can help me. Thank You

 

Make your variable int Ticket as static:

static int Ticket;

 
Roger09:
Make your variable int Ticket as static: static int Ticket;

Hi! First of all thank's for your answer.

The script isn't working.

Probably the orderselect(...) and ORD_PROF=orderprofit() have some kind mistake i don't know

 

I don't know how you tested, but in my tester it's good. Example - EURUSD from 23 Sep.

1 2009.09.23 21:20 sell 1 0.10 1.47697 1.48715 1.42715 0.00 10000.00

2 2009.09.24 19:50 sell 2 2.00 1.46347 1.47365 1.42665 0.00 10000.00

3 2009.09.28 03:45 sell 3 2.00 1.45946 1.46964 1.42564 0.00 10000.00

4 2009.09.28 03:50 sell 4 2.00 1.45729 1.46747 1.42647 0.00 10000.00

5 2009.09.28 18:16 s/l 4 2.00 1.46747 1.46747 1.42647 -2036.00 7964.00

6 2009.09.29 09:50 sell 5 2.00 1.45675 1.46693 1.42593 0.00 7964.00

7 2009.09.29 12:50 sell 6 2.00 1.45360 1.46378 1.42578 0.00 7964.00

8 2009.09.30 08:02 s/l 6 2.00 1.46378 1.46378 1.42578 -2039.20 5924.80

9 2009.09.30 11:20 s/l 5 2.00 1.46693 1.46693 1.42593 -2039.20 3885.60

10 2009.09.30 16:07 sell 7 2.00 1.45752 1.46770 1.42670 0.00 3885.60

11 2009.09.30 18:32 close at stop 7 2.00 1.46629 1.46770 1.42670 -1754.00 2131.60

12 2009.09.30 18:32 close at stop 3 2.00 1.46629 1.46964 1.42564 -1372.40 759.20

13 2009.09.30 18:32 close at stop 2 2.00 1.46629 1.47365 1.42665 -576.80 182.40

14 2009.09.30 18:32 close at stop 1 0.10 1.46629 1.48715 1.42715 105.68 288.08
 
 

HELP - want simple code for sl / tp

hi everyone

does anybody have a simple piece of code that I can insert into my EA that will:

1. scan all open positions

2.determine if trade has reach predefined sl / tp

3. close trade accordingly

btw, Im a ex cobol programmer and still new to mql4

thanks

 

Quick Question or a bug maybe?

Hi People,

I am wanting the highest high for the last 10 days and I have been using this line.. Now I find it is not giving me the highest high. It gives me yesterdays close for some reason.

Can someone tell me why please.

double HighTrendVal= High;

Print ("High Trend Value is",(HighTrendVal));

thanks

 
buju357:
hi everyone

does anybody have a simple piece of code that I can insert into my EA that will:

1. scan all open positions

2.determine if trade has reach predefined sl / tp

3. close trade accordingly

thanks

This is a start.. you can adjust it how you want.. you will need to look up close because glorderclose will not work for you

[code ]

if(ordersTotal() !=0) // if total orders are not zero

{

total = OrdersTotal(); // the word total represents total orders

for(i = total - 1; i >= 0; i--)// count each order backwards

{

OrderSelect(i, SELECT_BY_POS, MODE_TRADES); //select each order by postiton

if(OrderSymbol() != Symbol()) continue; //if it is not equal to our symbol, skip it

if((OrderType() == OP_BUY) || (OrderType() == OP_SELL))

{

if ((OrderStopLoss()==0) && (((OrderProfit())+ 0.0003) > OrderOpenPrice()))// change this to suit your requirement.

{

if(PrintComments) Print(" closed trades!");

glOrderClose();

}

}

}

}

[/code]