| / | Forum |
|
Fishtank
2006.01.16 02:10
Hi, I have my system placing it's stop order's in the correct places, however I
am having trouble writing the code to control how many and what type are placed.
I have some specific paramters that are hanging me up.
-It can never have more that 2 orders, pending or open. It could have 1 open/1pending (stop or limit), or it could have 2 pending, or 2 open orders...but never needs to have more. -If the previous order is a OP_BUY/STOP/LIMIT the 2nd order can only be a SELL/LIMIT/STOP, and the opposite is true as well, if the previous order is a SELL only a BUY can be set. I know I need to use OrderSelect() with the OrderType()...but having trouble thinking it through. Should I run a For loop to find the trades and their type from 1-2? Can the FOR loop distinguish between Symbols, as this advisor will be running on more than one chart at a time. Anyway if someone has some time, or has some idea's or some code already created I would be very gratefull, thanks in advance!! |
|
This article will be interesting first of all for programmers both beginners and professionals working in MQL environment. Also it would be useful if this article were read by MQL environment developers and ideologists, because questions that are analyzed here may become projects for future implementation of MetaTrader and MQL. |
|
Roets
2006.01.19 18:23
Hope the code below can help.
int start() { //---- double cnt=0; // Set Indicators to zero double MAFast=0; // 13 double MASlow=0; // 2 double STDDEV=0; int ticket, total; // 8-period and 34-period EXPONENTIAL moving average on CLOSE of Bar[1] MAFast=iMA(NULL,0,Fast,0,MODE_EMA,PRICE_CLOSE,0); MASlow=iMA(NULL,0,Slow,0,MODE_EMA,PRICE_CLOSE,0); STDDEV=iStdDev(NULL,0,15,MODE_EMA,0,PRICE_CLOSE,0); total = OrdersTotal(); if(total < 1) { if(MASlow<MAFast && STDDEV>DevLine) { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,0,"AfricanWarrior",200512090750, 0,Yellow); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else Print("Error opening BUY order : ",GetLastError()); return(0); } if(MASlow>MAFast && STDDEV>DevLine) { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,1,0,0,"AfricanWarrior",200512090750, 0,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); Sleep(600000); } else Print("Error opening SELL order : ",GetLastError()); return(0); } return(0); } //---- for (cnt=0; cnt<OrdersTotal(); cnt++) { if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) { if (OrderType()==OP_BUY) { if ((MASlow-(Pips/10000))>MAFast) { OrderClose(OrderTicket(),OrderLots(),Bid,0,White); Print("Buy Close: " + "SL+5: "+ (MASlow+(Pips/10000)) + " " + "SL: " + MASlow + " " + "Fst: " + MAFast + " B: " + ((MASlow+(Pips/10000))>MAFast)+ " C: " + ((MASlow+(Pips/10000))<MAFast)); } return(0); } if (OrderType()==OP_SELL) { if ((MASlow+(Pips/10000))<MAFast) { OrderClose(OrderTicket(),OrderLots(),Ask,0,Aqua); Print("Sell Close: " + "SL+5: "+ (MASlow+(Pips/10000)) + " " + "SL: " + MASlow + " " + "Fst: " + MAFast + " C: " + ((MASlow+(Pips/10000))<MAFast)+ " B: " + ((MASlow+(Pips/10000))>MAFast)); } return(0); } } } //*/ return(0); } |
|
Fishtank
2006.01.24 20:43
thanks alot! it did infact help with some issues, there are some things in there
I can relate to my code.
|