an impossible problem?

 
i need to make sure that each order is only opened once, the layout of the script is very specific to what the ask or bid price is so theres over 50 pending orders in the script all followed by each other like so:


OrderSend(Symbol(),OP_SELL,Lots,86.200,3,86.200+StopLoss*Point,86.200-TakeProfit*Point,"sell",0,CLR_NONE);

OrderSend(Symbol(),OP_SELL,Lots,86.250,3,86.250+StopLoss*Point,86.250-TakeProfit*Point,"sell",0,CLR_NONE); 

OrderSend(Symbol(),OP_SELL,Lots,86.300,3,86.300+StopLoss*Point,86.300-TakeProfit*Point,"sell",0,CLR_NONE); 

OrderSend(Symbol(),OP_SELL,Lots,86.350,3,86.350+StopLoss*Point,86.350-TakeProfit*Point,"sell",0,CLR_NONE); 

OrderSend(Symbol(),OP_SELL,Lots,86.400,3,86.400+StopLoss*Point,86.400-TakeProfit*Point,"sell",0,CLR_NONE); 


therefore i probably will need an "if" and "else" command maybe something like


if (orderstotal()>1) {OrderSend(Symbol(),OP_SELL,Lots,86.200,3,86.200+StopLoss*Point,86.200-TakeProfit*Point,"sell",0,CLR_NONE);} else { next op_sell} else { next op_sell) 


however that doesnt seem to work because it will only excute 1 order in the entire script and stop all orders until that single order is fulfilled and thats not what i need... i need it to open just the order itself once until its fulfilled and continue with the rest of the orders in the script in the same way (opening them once each until they are closed). thats why i dont think magic numbers would work here because its all one script.

also ive tried it with historytotal and its useless too because i cannot edit the history tab to show only the last 10 trades or so (that would be very useful) but it shows all the trades in the last day,week,month etc and because the order would be there it would mean the order wount be placed unless the history is deleted.

also ive tried an (int ticket and gave each sell and each buy operation its unique number from 1 to 5... but it also seemed to have ignored it, it still opened the same order several times... i thought if i changed the slippage to 0 it might make a difference but still it totally ignored slippage being at 0 and opened several orders of the same unique order a few times (note: it was only opened 3 or 4 or 5 times and rarley once depending on how many times the price crossed the ordersend line) which was a bit of an improvment as the basic script opened 10's of the same order within milliseconds of eachother.. i didnt even know the server could handle that many!

ive also tried other methods but they all were less useful than the above mentioned. this is really a hurdle that i simply do not have the adequate knowledge to jump over, so im looking for help from the pros on this one. thanks

 

this is now your 4rt thread on the same problem.

if you want to learn coding you own scripts/ea's. you have to READ READ READ as much as you can. try coding it yourself, and when you have a specific problem you will get the help you need. but if you want to get a script made for you without dooing anything. well, pay for it.

reguarding your problem:

i don't know if i understand your tradingsystem, you want to open a grid of pending orders, each 50pips above the last one.

first of all, you have to use !!!PENDING ORDERS!!! http://lmgtfy.com/?q=ordersend+pending+order

second. use a for() loop to create your order. read the documentation. there are all the informations you need.

third, you should maybe check also how to write a valid if() {}else{} statement.

sorry for the hard tone, but for me it seems that you didn't even try it

 
And use Print and getlasterror liberally
 
i have tried and failed many times using many different formats and functions, what i am trying to achieve has come a long way with the help of likes of u guys, but honestly i only post on something that i cannot find a solution to and ive been reading all the relevant material before asking, anyway for the grid system im implementing pending orders are too slow, because of the size of the script one pending order might have been called and closed before it is sent as a stop or limit order again. your telling me i didnt even try but ive spent on average 13 hours a day for the past 2 weeks trying to put it together, i do have good knowledge in forex but my knowledge in MQL4 is primary level and im learning and im only asking on the same issue because i cannot find a solution to it myself and i blieve thats what forums are for " to form helpful communities". thank you
 

But you can understand our frustration, 4 times now we have said you need to use pending orders and yet you post code that still shows incorrect use of market orders. a couple of times we have said you need to use a for loop and given you links and you post code saying how you are trying if statements. We suggest using get last error and don't see anything incorporated in your code that gives us any hint that the support we are giving is sinking in. My suggestion.. focus on the for loop and get it executing all the orders you need and then once that is working, focus on managing those orders.

I am also at a loss at why your orders are growing so much, we started with 2, then 4, 8, 10 and now 50. What you are trying to achieve is not an impossible problem, It's quite staright forward actually. This is a helpful community, but you need to understand it's a two way street. We are not going to help if what we are saying appears to fall on deaf ears. And it's very difficult to offer advice when we only get half the story.

 
//+------------------------------------------------------------------+
//|                                                         Grid.mq4 |
//|                                                               Z. |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Z."
#property link      ""

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
extern int size=50;
extern int step=50;
extern int slInPips=100;
extern int tpInPips=200;
extern double lotsize=1;
extern int slippage=30;
int start()
  {
//----
   for(int i=0;i<size;i++){
      double openPrice=NormalizeDouble(Ask-((step+(step*i))*Point),Digits);
      double sl=NormalizeDouble(openPrice+(slInPips*Point),Digits);
      double tp=NormalizeDouble(openPrice-(tpInPips*Point),Digits);
      OrderSend(Symbol(),OP_SELLSTOP,lotsize,openPrice,slippage,sl,tp,"",0,0,CLR_NONE);
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

here you have a example code how to open a grid of pending sell orders. i strongly recommand to not use it on live accounts as it contains no errorhandling ecc.

this example open 50 pending sell orders with specific SL and TP every 50Points.

 

i understand an i am sorry for the frustration V.


zzuegg this is what i mean, the script you posted is good but once your run it, it will keep opening constantly every 50 pips and theres nothin in the scrip that stops it from running the same pending order on the same level twice. and thats what im basically stuck on. not being able to limit one single pending/order from sending the order only ONCE until its fulfilled and closed by a sl or a tp and then opening again on the same position. anyway ill take it as a personal challenge to find a soultion myself if you guys cant help me further and again i do apologize if ive offended/annoyed/been a nuisance/(anything else) you. :)

 

well per definition a script run's only once.once dropped it over the chart the script will open the pendings and then quits. in my example exactly 50 pending orders are opended. none less none more. of cource if you drop it again it would again open 50 pending orders. if you would like to avoid this you have to traverse all pending orders and watch if there is already a order with the same price.

you have to write a function which returns a boolean value.

functions you might have to use are: OrdersTotal() OrderSelect() OrderOpenPrice() OrderSymbol() OrderType()

a working for() loop you see in my example.

a valid if() statement you will find in the doc.

i think this is all you will need for writing this function. read about them in the Documentation and the book.

//Z

 

thats very odd, because i just ran youre script a few times and in a matter of a few seconds (backtesting of 1-5 hours) it opened more than 13000 pending orders:



and this is exactly what my poblem is.... why does it do that?!?!?!?

 

the script i wrote for you is a example how to open !50! pending orders every time you drop/call it. i don't know your trading strategy so i can't say more to this. this only was ment to show you how to open a gird of pending orders. try to understand EACH LINE of this very very very very very (very) small and simple script.


also in my pervious post i have written how you maybe could avoid this reoping of orders

 
ok what you saying makes sense, but if it is possible to open "just 50" and its quite simple to do why didnt you just put it in your script? are you telling me your script opens just 50 pending orders? and my mt4 is having an issue?
Reason: