an impossible problem? - page 2

 

my script open 50s orders. i dont know how you used my script in your EA but i guess you have copied my lines in you EA and go trough it every tick.

this is not a forum where you get every code you want. if you would like to lern how to code it yourself, your at the right place, an i think we gave you all the information you need.

you could post your code, so maybe we understand what you would like to do.

try searching for the functions i wrote in the posts bevor. there is everything you need. if you make some logic mistakes i will help you find them. but i am not going to write this script for you. unless you a willing to pay. thats the way i see this community.

 
 

sorry guys i was unable to post earlier, anyway this is my code slightly trimmed down, ive only trimmed down the ordersends as its the same concept just over and over, firstly i want to mention that i DID try your suggestions on magic numbers with a collaboration of orderselect and geterrors but it also came out wrong and only made orders get sent once until they are filled

double Lots = 0.1;
double StopLoss = 500; 
double TakeProfit = 50;


int start() {

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

OrderSend(Symbol(),OP_BUY,Lots,94.000,3,94.000-StopLoss*Point,94.000+TakeProfit*Point,"buy",0,CLR_NONE);

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

OrderSend(Symbol(),OP_BUY,Lots,94.100,3,94.100-StopLoss*Point,94.100+TakeProfit*Point,"buy",0,CLR_NONE);

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

OrderSend(Symbol(),OP_BUY,Lots,94.200,3,94.200-StopLoss*Point,94.200+TakeProfit*Point,"buy",0,CLR_NONE);

return;
}

second of all if you input this code into mt4 and run a test you will see what the problems is. that it runs the same ordersend several times on the set price. as i mentioned earlier in the post im trying to find a way to make the script run each of the:

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

OrderSend(Symbol(),OP_BUY,Lots,94.000,3,94.000-StopLoss*Point,94.000+TakeProfit*Point,"buy",0,CLR_NONE);

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

OrderSend(Symbol(),OP_BUY,Lots,94.100,3,94.100-StopLoss*Point,94.100+TakeProfit*Point,"buy",0,CLR_NONE);

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

OrderSend(Symbol(),OP_BUY,Lots,94.200,3,94.200-StopLoss*Point,94.200+TakeProfit*Point,"buy",0,CLR_NONE);

once and only once until it reaches a stoploss or a takeprofit then it can reopen again. example:


open

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

is order open? if yes -----> then go to next order if no -----> then open order then -----> go to next order, etc.

it really seems like the simplest of problems but i just cant find a solution for it anywhere ive even tried using "logical" values and "string" values. ive tried different functions (pretty much anything begginig with "order" ive tried different em all i really and truely and honestly have exhausted the knowledgebase!


and for that ive tried inputing magic numbers instead of the "buy" and "sell" and using those unique numbers in a orderselect. within order select ive also tried to use other methods but to no use, ive changed the script many many many many times and ive tried all your recommendations and came up with unhelpful outcomes. thats why i put here the script in its origional format to minimize errors i might have added to it. and please do not call me lazy because i have done what i can and if you cannot help thanks anyway.

 

Ok before I go any further, first question.... are you trying to write a script (which by definition will only run once) or an EA (which by definition will run every tick)?


Second question, are you trying to set up a grid of "PENDING" orders (that by definition sit and wait to be triggered if and when the price action reaches that level) or send instant market orders (which by definition will immediately open a trade at the current price.. (And top viffer tip, if it's pending orders, and you post market orders one more time, I think I will scream)

And just to be crystal. This... with OP_SELL

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

is a market order. It will FAIL unless the Bid is exactly the same as the price you typed.


This... with OP_SELLSTOP


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

is a pending order. It will hang around until the price action reaches the price you typed. Whilst the price may never trigger the order, the program will have succeded.


So please answer those two questions first and then I will move on.

V

 

no im trying to write an EA so it runs continually.

Well i got the same problem with both types (pending and market) orders, the pending orders will continually keep placing pending orders on the same position so when they finally get "opened" i would have more than 1 order on the same price open (e.g. 12 SELLLIMIT's on 93.950). so ive countered the same problem in both cases.... so i decided to go back to (please dont scream or kill me).... market orders.... :/

 
and about the grid of pending orders, yes i am setting up a grid but its not a grid type youve seen before its a new idea, it opens on specific prices not just starting at a random ask or bid price and doing the same thing every 5 pips... just trust me on the idea... its the coding thats driving me crazy... im starting to see mql in my dreams!
 

this is irrelevant but these are the pages that im currently viewing:

https://book.mql4.com/operators/if

https://docs.mql4.com/trading/OrderOpenPrice

https://book.mql4.com/trading/ordersend

https://docs.mql4.com/basis/operations/rules

https://docs.mql4.com/trading

 
nayef:

no im trying to write an EA so it runs continually.

Ok, lets refer to it as an EA from now on. Scripts are different and are programmed differently



nayef wrote >>

Well i got the same problem with both types (pending and market) orders, the pending orders will continually keep placing pending orders on the same position so when they finally get "opened" i would have more than 1 order on the same price open (e.g. 12 SELLLIMIT's on 93.950). so ive countered the same problem in both cases.... so i decided to go back to (please dont scream or kill me).... market orders.... :/

Good, so a grid of pending orders...it is not the order type that is your problem but your activation criteria. So post pending orders only please! :)


OK, moving on... when you launch the EA, what criteria do you have (if any) that you would want to start sending the orders? Is the starting point for the grid just whatever the current price or does where you first start matter. ie, is it at the opening of a bar, or have 2 ma's crossed or an oscillator at a certain level. (you don't have to have anyything like that though).


Second, is the spacing between orders constant?


Third, what is the rational behind opening 50 orders? is this significant? If we open two then keep adding as the price moves up and triggers our orders is that OK?


V

 
nayef:
and about the grid of pending orders, yes i am setting up a grid but its not a grid type youve seen before its a new idea, it opens on specific prices not just starting at a random ask or bid price and doing the same thing every 5 pips... just trust me on the idea... its the coding thats driving me crazy... im starting to see mql in my dreams!
Our posts crossed, when you say specific prices, you have something already that determins the start point. and is the spacing of orders constant?
 

ok EA.

criteria:

1. buy and sell at the same pre-determind set price (i know there will be a time lag in most cases and other cases the buy or sell might not be fulfilled because of fluctations or other reason but its a risk ill take

2. as an example im working on a tp of 50 and a sl of 250 points on both the buyorders and sellorders.

3. if im using a sl of 250 and a tp of 50 and using the predetermined prices of pending orders then ill always have 10 open orders, if my sl is 500 ill have 20 open orders etc.

4. the script is as simple as ive written above theres nothing more to it, no ma's no fibonaccis nothing!


its kind of a grid with pending orders, however if i use pending orders ill have to use all 4 types... selllimits,sellstops,buylimits,buystops in 1 EA otherwise if i use just sellstops and buylimits ill have to wait for the price to rebound so more orders can be "pending", thats why i still prefer going back to and trying to make the market orders work.


and thats it... all i need is the missing link in all this... im sure you know exactly whats missing.. as youve seen the code... you read the strategy and you know whats missing.

i had to write this twice because of stupid internet connection

Reason: