Forex



Go Back   Forex Trading > Discussion Areas > General Discussion
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 08-21-2006, 12:01 AM
jpsdyb's Avatar
Member
 
Join Date: Dec 2005
Posts: 74
jpsdyb is on a distinguished road
How to creat equity trail stop

Looking for a way my EA can use a trailing stop based on equity for all trades via magic number EA.

I would like it to work something like this:
If equity profit = + 200, set equity stop (or equity trailing stop) at +100, target profit = +500.

So if I do not hit my profit target of 500 cause market retraced, at least I can guarantee that all trades will be closed out with +100 to my equity/balance.

Thank you
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 09-09-2006, 08:16 PM
jpsdyb's Avatar
Member
 
Join Date: Dec 2005
Posts: 74
jpsdyb is on a distinguished road
any smart people that can help code this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 09-10-2006, 10:12 AM
phoenix's Avatar
Senior Member
 
Join Date: May 2006
Posts: 319
phoenix is on a distinguished road
  1. creat a function to defind how much you can get from 1 pip , due to your entry lotsize
  2. creat another function to defind how many pips you gain or loss from your equity
  3. and that by your pips-gain-from-equity function you will know how many pips far from current price to mark as a new sl
but this will more difficult if you trade more than 1 order at a time

hope this idea helps you
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 06-07-2008, 10:07 PM
Member
 
Join Date: Jul 2006
Location: Denver, Colorado
Posts: 51
AirforceMook is on a distinguished road
Red face

This would be extremely difficult to code if you're actually trying to set the stoploss values on the orders. If you can leave your EA running at all times, as I would think you do, then it's not too difficult.

Please see the attached code. I haven't had time to test it, so be sure to look at it prior to use.

Settings:
equity_lock How much you want to ensure you keep, once lock_start has been hit.
equity_lock_start At what profit do we start locking in equity?
equity_target At this amount of profit we close all orders

Example:
100,130,500 - If we get to $130 profit, then we'll lock in $100. If we get to $500 profit, we close all orders.

Realize that because this is a stand-alone EA, it's not very friendly. It ignores magic numbers and manual orders and will take everything into account.
Attached Files
File Type: mq4 EquityWatch.mq4 (2.8 KB, 121 views)
File Type: ex4 EquityWatch.ex4 (2.8 KB, 34 views)
__________________
//AirforceMook//
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #5 (permalink)  
Old 06-07-2008, 11:48 PM
Senior Member
 
Join Date: Oct 2005
Location: Porto/Portugal
Posts: 333
hellkas is on a distinguished road
Quote:
Originally Posted by AirforceMook View Post
This would be extremely difficult to code if you're actually trying to set the stoploss values on the orders. If you can leave your EA running at all times, as I would think you do, then it's not too difficult.

Please see the attached code. I haven't had time to test it, so be sure to look at it prior to use.

Settings:
equity_lock How much you want to ensure you keep, once lock_start has been hit.
equity_lock_start At what profit do we start locking in equity?
equity_target At this amount of profit we close all orders

Example:
100,130,500 - If we get to $130 profit, then we'll lock in $100. If we get to $500 profit, we close all orders.

Realize that because this is a stand-alone EA, it's not very friendly. It ignores magic numbers and manual orders and will take everything into account.
Very nice idea.. I'll try it..

Thank you
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #6 (permalink)  
Old 06-08-2008, 03:45 AM
Senior Member
 
Join Date: Feb 2007
Posts: 986
FerruFx is on a distinguished road
I give as a bonus with my differents offers a CloseAll with global $ amount. One of the features is a global trailing stop in $ amount. In other words, it works exactly like the standard MT4 trailing stop but this one is in $ and for a global profit (all order at the same time).

All targets are in $ and are hidden.

Not sure that is what you need.

FerruFx
__________________
FerruFx / www.ervent.net - Professional Coding Services (EAs/Indicators/Alerts)

BBVPS.com - Reliable Windows VPS For MT4 Hosting
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #7 (permalink)  
Old 06-08-2008, 05:25 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 818
wolfe is on a distinguished road
I did something like this. Keep track of all orders via $ amount. Assuming all your orders have the same magic number, first you have to figure your total profit by magic number. I created a function to do this:

PHP Code:
double OPBM(int intMagic)//OrderProfitByMagic
{
double dblProfit=0;
int intPOS=0;
bool boolTerm=false;
while(
boolTerm==false)
{
if(
OrderSelect(intPOS,SELECT_BY_POS))
{
if(
OrderMagicNumber()==intMagicdblProfit=dblProfit+OrderProfit();
intPOS++;
}
else
boolTerm=true;
}
return(
dblProfit);

Insert this piece of code after the last ending bracket of your EA. Then anytime you need to get the total value of all open orders with a specific magic number simply call the function. Ex.

PHP Code:
OPBM(Your_Magic_Number_Here
Next create a few external variables:

PHP Code:
extern bool    Use_Trailing_Stop=true;//select true to use a trailing stop based on total $amount
extern double  Trail_Start=10;//TS will start after this $Profit amount is reached
extern double  TSLoss_Percent=50;//%Percentage of your HIGHEST profit you can lose before close all is performed 
After your Trail_Start value is hit, you will need to keep track of your highest achieved profit value, and an allowed loss value, and store those values. I stored them as a Global Variables.

PHP Code:
Total_Profit=OPBM(Your_Magic_Number_Here);

if ((
Use_Trailing_Stop==true) && (OPBM(Your_Magic_Number_Here)>Trail_Start))  
{
 
Highest_Profit=GlobalVariableGet(TFX_Highest_Profit);
 if (
Total_Profit Highest_Profit)
  {
   
Highest_Profit=GlobalVariableSet(TFX_Highest_Profit,Total_Profit);
   
Highest_Profit=GlobalVariableGet(TFX_Highest_Profit);
   
Loss_Percent=TSLoss_Percent*0.01;
   Print(
"                                                                                                 Loss percent = ",Loss_Percent);
   
Allowed_Loss=GlobalVariableGet(TFX_Highest_Profit)*Loss_Percent;
   
Allowed_Loss=GlobalVariableSet(TFX_Allowed_Loss,Allowed_Loss);
   
Allowed_Loss=GlobalVariableGet(TFX_Allowed_Loss);
   
Trail_Engaged=true;
   Print(
"                                                                                      Highest Profit = ",Highest_Profit);
   Print(
"                                                                                        Allowed Loss = ",Allowed_Loss);
  }

Then you need code to close orders when you fall below your allowed loss value, maybe something like this:

PHP Code:
if ((Use_Trailing_Stop==true) && (Trail_Engaged==true)) 
{
 if (
OPBM(Your_Magic_Number_Here) <= ((GlobalVariableGet(TFX_Highest_Profit))-(GlobalVariableGet(TFX_Allowed_Loss))))
  {
    
CBM(Your_Magic_Number_Here);
  } 
The CBM() is a Close By Magic function I made:
PHP Code:
int CBM(int intMagic)//CloseByMagic
{
int intOffset=0;
int Count OTBM(intMagic);

while(
OTBM(intMagic)>&& Count 0)
{
OrderSelect(intOffset,SELECT_BY_POS);
if(
OrderMagicNumber()==intMagic)
{
if(
OrderType()==OP_BUYOrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),999,Red);
else if(
OrderType()==OP_SELLOrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),999,Orange);
Count--;
}
else {
intOffset++;
}
}
return(
0);

To use the CBM function, you also will need this function:

PHP Code:
int OTBM(int intMagic)//OrdersTotalByMagic
{
int intCount=0;
int intPOS=0;
bool boolTerm=false;
while(
boolTerm==false)
{
if(
OrderSelect(intPOS,SELECT_BY_POS))
{
if(
OrderMagicNumber()==intMagicintCount++;
intPOS++;
}
else
boolTerm=true;
}
return(
intCount);

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #8 (permalink)  
Old 06-26-2009, 09:54 PM
Junior Member
 
Join Date: Aug 2008
Posts: 12
Grigoriy is on a distinguished road
Quote:
Originally Posted by hellkas View Post
Very nice idea.. I'll try it..
Did you test the EquityWatch (have it locked the profit), hellkas ?
I try for some times, but no effects..
Anyone tested it ?(or am I doing smth wrong)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
trail SL EA jonas Expert Advisors - Metatrader 4 2 09-22-2007 10:13 AM
Trailing EQUITY STOP FEATURE? tyger01 Metatrader 4 1 12-21-2006 04:25 PM
If the current day equity is more than the repvious equity babarmughal Expert Advisors - Metatrader 4 6 12-18-2006 12:48 AM
Account equity percentage stop loss...help! faifarni Expert Advisors - Metatrader 4 3 08-08-2006 06:36 AM


All times are GMT. The time now is 08:34 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.