Monitoring trailing stop

 

Hi All,

My broker has the option for a trailing stop. However many times the trailing stop doesn't work. Does anybody know a simple way to monitor the trailing stop on all open orders and close the open positions which hit the trailing stop? The open orders are placed manually.

Thanks in advance!

Calmar

 

Unless all open orders have the same trailing stop you are going to have some work to do to open orders using scripts to make them identifiable by MAGICNUMBER.

There is no simple one line fix for this problem, it is a full blown EA which you would need to understand and code.

 

I could use the same trailing stop for all long positions and the same for all short positions. Would this be possible with a one line fix?

If I would use your suggestion to make them identifiable by Magicnumber, would you know a simple EA example which I could use as basis? I'm quite new here and don't really know where to start.

Thanks!

 
Calmar:
I could use the same trailing stop for all long positions and the same for all short positions. Would this be possible with a one line fix?
What part of
There is no simple one line fix for this problem, it is a full blown EA
didn't you understand?
Calmar:
My broker has the option for a trailing stop. However many times the trailing stop doesn't work.
The mql4 trailing stop works just fine for manual trading. It is per order only. YOU must activate it for every order (and keep the terminal running at all times.)
 
WHRoeder:
What part of didn't you understand?
The mql4 trailing stop works just fine for manual trading. It is per order only. YOU must activate it for every order (and keep the terminal running at all times.)


Hi WHRoeder,

I don´t understand your "What part of "There is no simple one line fix for this problem, it is a full blown EA" didn't you understand" because when I read Dabblers answer well, he writes that I will have some work using scripts UNLESS all open orders have the same trailing stop. I confirmed that I can use the same trailing stop, was not quite sure about the difference between long and short positions. But apparantly I misunderstood him.

Anyway thanks for the second part of your answer, but I trade at the moment with Alpari and in the practice I can see that I don't always get my trailing stop on all positions (even when the trailing stop is activated and the terminal is running). And with not getting the stop I don't mean that there are a few points difference with the expected stop, but that the position simple stays open.....

 
Calmar:


Anyway thanks for the second part of your answer, but I trade at the moment with Alpari and in the practice I can see that I don't always get my trailing stop on all positions (even when the trailing stop is activated and the terminal is running). And with not getting the stop I don't mean that there are a few points difference with the expected stop, but that the position simple stays open.....

Wow that really sucks. I'm also with Alpari and I haven't seen that problem (although I seldom use trailing stops in the terminal).

So we have two sorts of stops: server side stops and EA/terminal stops. If the terminal goes down or you lose the connection then your terminal/EA stops go missing. That's seriously bad. Server side stops are much safer. So, can an EA be written that takes all open orders and tweaks the server side stops (or just closes orders which exceed their pre-defined stops). Yes.

I'm sorry my earlier post was mis-leading. There is no such thing as a "one line" EA. This one would be a few dozen lines at least. Give it a try.

 
Calmar:

Anyway thanks for the second part of your answer, but I trade at the moment with Alpari and in the practice I can see that I don't always get my trailing stop on all positions (even when the trailing stop is activated and the terminal is running). And with not getting the stop I don't mean that there are a few points difference with the expected stop, but that the position simple stays open.....

Are you using the build in trailing stoploss of MT4 or does your EA/Script adjust the stoploss for you? I've been using Alpari for a while and never missed a stoploss, but all my stoplosses are adjusted by EA or scripts. Example:


// Trailing stoploss with fixed number of pips ------------------------
void TrailingStoplossFixedPips( string Location, int TicketNum, double TrailStop )
{

double NewStopLoss;
string AdjustStopLoss = "N";

// Select ticket
OrderSelect( TicketNum, SELECT_BY_TICKET );
int TypePos = OrderType();
double OpenStopLoss = OrderStopLoss();

// Force new price information
RefreshRates();

// Calculate new stoploss in case of open buy
if( TypePos == OP_BUY )
{
NewStopLoss = NormalizeDouble( Ask - ( TrailStop * PipPoint ), Digits ); // Stoploss includes spread
if( NewStopLoss > OpenStopLoss ) AdjustStopLoss = "Y";
}

// Calculate new stoploss in case of open sell
if( TypePos == OP_SELL )
{
NewStopLoss = NormalizeDouble( Bid + ( TrailStop * PipPoint ), Digits ); // Stoploss includes spread
if( NewStopLoss < OpenStopLoss ) AdjustStopLoss = "Y";
}

// Adjust the stoploss
if( AdjustStopLoss == "Y" )
{
int OrderReturn = OrderModify( TicketNum, OrderOpenPrice(), NewStopLoss, OrderTakeProfit(), 0, CLR_NONE );
if( OrderReturn == false )
{
string DumpString = StringConcatenate( " / TicketNum = ", TicketNum,
" / OrderOpenPrice = ", OrderOpenPrice(),
" / NewStopLoss = ", NewStopLoss,
" / OrderTakeProfit = ", OrderTakeProfit()
);
OrderErrorHandling( Location, DumpString );
}

}

}

You will still have to do some leg work because this function uses some of my standard functions for error handling and such. So dabbler is right that there is not a simple one-line fix.

Oh Damn... I just noticed I forgot the TradeContext... back to the drawing board...

 

Oh... and all the indentations dissappear when you paste code into the "code block". That's handy.... not :-/

 
burgie:

Oh... and all the indentations dissappear when you paste code into the "code block". That's handy.... not :-/

No they don't if you use the SRC correctly. Check out other posters contributions. Since yours isn't syntax coloured you did something wrong!
 
burgie:

Are you using the build in trailing stoploss of MT4 or does your EA/Script adjust the stoploss for you? I've been using Alpari for a while and never missed a stoploss, but all my stoplosses are adjusted by EA or scripts. Example:


// Trailing stoploss with fixed number of pips ------------------------
void TrailingStoplossFixedPips( string Location, int TicketNum, double TrailStop )
{

double NewStopLoss;
string AdjustStopLoss = "N";

// Select ticket
OrderSelect( TicketNum, SELECT_BY_TICKET );



This first OrderSelect is a disaster waiting to happen. You really must check it to see that it worked or your EA could get you into serious trouble.
 
dabbler:
No they don't if you use the SRC correctly. Check out other posters contributions. Since yours isn't syntax coloured you did something wrong!
I pasted my code, highlighted it and set the text to "code". But now I see that you can also insert code by clicking on "SRC". Will do that next time.
Reason: