Help with writing a script

 

Greetings everyone,

I have an idea for a script that would help me tremendously with my trading strategy but, I am not sure if it can be written and if so, I know that I don’t posses enough programming skills to accomplish it without help from wiser people than me. So, I come here seeking advise and knowledge from any who care to help.

What I need is a script that will close all open buy orders except the one that has the lowest opening price and move the stop loss on it to break even. If there are 2 orders that have the same lowest price, it should close one of them (along with any other open buys that have a higher opening price) and move the stop loss on the other to break even.

Example: I have buys opened at 1.3242, 1.3242, 1.3256, and 1.3268. The script will close all but one of the 1.3242’s and move the stop loss on it to break even.

Another script would handle all open sell orders by leaving the highest open price sell open (moving the stop loss on it to break even) and closing all the rest.

Is it possible to write a script that can do this? Can anyone give me some help or ideas on how it would need to be written? Thanks in advance for any help offered.

Ron

 
rwb181 wrote >>

Greetings everyone,

I have an idea for a script that would help me tremendously with my trading strategy but, I am not sure if it can be written and if so, I know that I don’t posses enough programming skills to accomplish it without help from wiser people than me. So, I come here seeking advise and knowledge from any who care to help.

What I need is a script that will close all open buy orders except the one that has the lowest opening price and move the stop loss on it to break even. If there are 2 orders that have the same lowest price, it should close one of them (along with any other open buys that have a higher opening price) and move the stop loss on the other to break even.

Example: I have buys opened at 1.3242, 1.3242, 1.3256, and 1.3268. The script will close all but one of the 1.3242’s and move the stop loss on it to break even.

Another script would handle all open sell orders by leaving the highest open price sell open (moving the stop loss on it to break even) and closing all the rest.

Is it possible to write a script that can do this? Can anyone give me some help or ideas on how it would need to be written? Thanks in advance for any help offered.

Ron


Script in MT4 runs only once when it is loaded. Waht you need is an EA. I can help you write the EA for this. Let me know your email and I will respond.

ForexWatchman
 
ForexWatchman:


Script in MT4 runs only once when it is loaded. Waht you need is an EA. I can help you write the EA for this. Let me know your email and I will respond.

ForexWatchman

That is what I want, for it to run only once when I attach it to the chart. I have a script that will delete all open sell orders. I want to modify it to leave the highest one (for sells) open and close the rest. If also having it modify the stop loss on the remaining open order requires it to become an EA, then that doesn't need to be included. I already have a script that will modify the stop loss or take profit of an open order. I was just hoping to try and get as many tasks done as possible with just one drag and drop.

I am trying to shorten the time it takes to close each order except the one I want left open.

I'm pretty sure this can be done with a script. It's just a matter of the script recognizing the highest (or lowest) open order price and ignoring it if there is only one and closing one if there are 2.

 
rwb181 wrote >>

That is what I want, for it to run only once when I attach it to the chart. I have a script that will delete all open sell orders. I want to modify it to leave the highest one (for sells) open and close the rest. If also having it modify the stop loss on the remaining open order requires it to become an EA, then that doesn't need to be included. I already have a script that will modify the stop loss or take profit of an open order. I was just hoping to try and get as many tasks done as possible with just one drag and drop.

I am trying to shorten the time it takes to close each order except the one I want left open.

I'm pretty sure this can be done with a script. It's just a matter of the script recognizing the highest (or lowest) open order price and ignoring it if there is only one and closing one if there are 2.



Ok. I thought you want to monitor that on an ongoing basis.
If you don't need help in writing EA or Script thats fine.

ForexWatchman
 
ForexWatchman:


Ok. I thought you want to monitor that on an ongoing basis.
If you don't need help in writing EA or Script thats fine.

ForexWatchman

Yes, I do need help with writing the script. I know what I want the script to do but, I don't know how to write the programming. It is beyond my current capabilities.

If someone could show me programming that can do something similar, I can probably modify it for my particular needs using reverse engineering.

Here is another idea for a script that might prove very useful to traders (I know it would be useful to me);

One that will calculate the break even price for all open buys, then set the stop losses on each to a value that locks in a certain number of total pips in regards to the number of orders open.

Example: I open equal size buys at 1.5042, 1.5030, 1.5005, and 1.4989. I want 50 pips total. The break even point is at 1.50165 and since I have 4 equal size trades open, each one needs to make 12 ½ pips to make 50 total. So, the place I would want my stop loss to be is at 1.5029 (1.50165 +. 00125). If that price is hit, trades are closed and I bank 50 pips.

Another one that would be a little more complicated but I think doable is doing the above but, instead of closing all open trades, leave the bottom one open, do the calcs for your small profit with only the upper open trades, move their stop losses to the right spot and move the stop loss on the bottom one to break even.

With the above example of orders, the break even point would be 1.50257 and the 3 trades would need to each make 16.7 pips to get 50 total. So, the stop losses on the upper 3 orders would be moved to 1.5042 (1.50257 +. 00167 normalized) and the stop loss on the bottom order would be moved to 1.4989 (break even). If hit, I bank 49 pips and have a free trade going.

These are all things I look to do while trading and a script would make it much quicker, one drag and drop instead of very many clicks and time needed to do the calcs.

Any chance of those be created?

Ron

 
Well, I was able to find an indicator that calc's the break even point of all open orders and I morphed it into a script that moves the stop losses and take profits (whichever the case may be) on all open orders to a point that gives me a profit I am looking for. With it, I can see how the looping action is done and I am confident that I can modify it to do the other things (ideas) I had posted here. It is just a matter of identifying the order I want left open and excluding it from the ones that are used in the calc's.

I want to thank everyone that helped me out on this project. I came looking for help and received what I expected. When I came here with this idea, I didn't posses the skills to write the scripts but, I am happy to say that I now do. Once again, thank you to all that helped. If any of the members that helped me need help of their own, please don't hesitate to ask.