Dear Steve and all experts,
Currently I am using a EA to trade range. However I need to close my Long OR Short trade individually. Is there any script to close all trades for Long OR Short only?(including an option to close "Profit for Long" or "Profit for Loss")
Once I find the market breaks out, I want to close all my Long or Short trades and leave others floating. (e.g. i have 2 long 2 short open trades, when it breaks out, I close 2 long and leave 2 short trades alone, my EA will continue to close 2 short, however it may continue to open another long. How do I stop EA to continue opening long trades but keeps it on to close my short?
Regards,
RC
Script
-
forex.rapheal
- Trader
- Posts: 46
- Joined: Mon Feb 13, 2012 6:46 am
- gaheitman
- Trader
- Posts: 655
- Joined: Tue Nov 15, 2011 10:55 pm
- Location: Richmond, VA, US
Re: Script
If your EA is likely to open more trades in the direction you don't want, you really need to put all the logic in the EA to both close trades you don't want and to prevent it from opening new ones. Do you have the source to your EA?forex.rapheal wrote:Dear Steve and all experts,
Currently I am using a EA to trade range. However I need to close my Long OR Short trade individually. Is there any script to close all trades for Long OR Short only?(including an option to close "Profit for Long" or "Profit for Loss")
Once I find the market breaks out, I want to close all my Long or Short trades and leave others floating. (e.g. i have 2 long 2 short open trades, when it breaks out, I close 2 long and leave 2 short trades alone, my EA will continue to close 2 short, however it may continue to open another long. How do I stop EA to continue opening long trades but keeps it on to close my short?
Regards,
RC
George
- SteveHopwood
- Owner
- Posts: 9904
- Joined: Tue Nov 15, 2011 8:43 am
- Location: Misterton - an insignificant village in England. Very pleasant to live in.
Re: Script
You are trying to use an EA for a purpose for which it is not designed. EA's do what they are programmed to do, not what a user wishes them to do. From your description, your EA is coded to trade a range, so that is what it does. It is not coded to recognise the breakout from the range.

Read the effing manual, ok?
Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.
I still suffer from OCCD. Good thing, really.
Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.
To see The Weekly Roundup of stuff you guys might have missed Click here
My special thanks to Thomas (tomele) for all the incredible work he does here.
Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.
I still suffer from OCCD. Good thing, really.
Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.
To see The Weekly Roundup of stuff you guys might have missed Click here
My special thanks to Thomas (tomele) for all the incredible work he does here.
-
forex.rapheal
- Trader
- Posts: 46
- Joined: Mon Feb 13, 2012 6:46 am
Re: Script
Hi Steve and George,
Yes you are right as I am the one who decide the direction. I guess the only way is to close all and start it again. Thanks for the advice.
Yes you are right as I am the one who decide the direction. I guess the only way is to close all and start it again. Thanks for the advice.
-
thlmobile
Re: Script
It is not coded to recognise the breakout from the range.
________________________________________________
Thl ThL Smart Phone
________________________________________________
Thl ThL Smart Phone
-
dietcoke
- Trader
- Posts: 162
- Joined: Tue Nov 15, 2011 9:59 pm
Re: Script
Try using global variables.forex.rapheal wrote:Dear Steve and all experts,
Currently I am using a EA to trade range. However I need to close my Long OR Short trade individually. Is there any script to close all trades for Long OR Short only?(including an option to close "Profit for Long" or "Profit for Loss")
Once I find the market breaks out, I want to close all my Long or Short trades and leave others floating. (e.g. i have 2 long 2 short open trades, when it breaks out, I close 2 long and leave 2 short trades alone, my EA will continue to close 2 short, however it may continue to open another long. How do I stop EA to continue opening long trades but keeps it on to close my short?
Regards,
RC
Create two GV's called TRADE_LONG and TRADE_SHORT give them value of 1 (true)
In your EA. in the code which decides whether to trade, run the following check(pseudocode alert)
if ( Buy condition met && GlobalVariableGet(TRADE_LONG) == 1)
BUY
else
Dont buy
if ( Sell condition met && GlobalVariableGet(TRADE_SHORT) == 1)
SELL
else
Dont Sell
Create the GV in your init function (using GlobalVariableSet) and then in your code when you close trades , you can update the GV
eg
void closeorders()
if(close Long trades)
Globalvariableset(TRADE_LONG,0);
if(close short orders)
Globalvariableset(TRADE_SHORT,0);
When you close out a poition completely, you will then need to reset the GV's back to 1.
the beauty of this is that you can manually change the values in the Globals while the EA is running if you want to.