Topic: MT4-FST Expert v12-Beta - BreakEven...

MT4-FST Expert v12-Beta is available for download. It is compatible with FST v8.0.0.0 and DLL v0.11.

New features:

1. Break Even stop - Places a Stop Loss at the break even price when the position makes predetermined profit in pips.   

2. Trailing Stop step of change - reduces the frequency of calling OrderModify(). The Trailing Stop moves not at every new high but after predetermined number of pips.   

3. LateStops renamed to Separate_StopLoss_TakeProfit. It has to be set to true for the brokers, which cannot set SL and TP with the initial OrderSend()

4. SetBrokersCompatibility function added. It recognizes the brokers for which we gave to set Separate_StopLoss_TakeProfit = true.


Description of the external parameters:

// Connection_ID serves to identify the expert when multiple copies of Forex Strategy Trader are used.
// It must be a unique number between 0 and 1000.
// The same number has to be entered in Forex Strategy Trader.
extern int  Connection_ID = 0;

// If Separate_StopLoss_TakeProfit is set to true, the expert doesn't set SL and TP together with opening a position but
// modifies the position after that. That is necessary for some brokers as FXCM an FXOpen, which don't allow
// using OrderSend(..) with SL and TP.
extern bool Separate_StopLoss_TakeProfit = false;

// BreakEven_Activating_Distance determines at what profit the Stop Loss will be moved at BreakEven price.
// MarketInfo(symbol, MODE_STOPLEVEL) <= BreakEven_Activating_Distance <= 2000
// If BreakEven_Activating_Distance = 0, the BreakEven is not active.
// If BreakEven_Activating_Distance > 0, the Stop Loss will be placed at BreakEven once the price makes such a move. 
extern int BreakEven_Activating_Distance = 0;

// TrailingStop_Moving_Step determines the step of changing the Trailing Stop.
// 0 <= TrailingStop_Moving_Step <= 2000
// If TrailingStop_Moving_Step = 0, the Trailing Stop trails at every new extreme price in the position's direction.
// If TrailingStop_Moving_Step > 0, the Trailing Stop moves at steps equal to the number of pips chosen.
extern int TrailingStop_Moving_Step = 0;

Installation:
1. Delete (move, rename) the old MT4-FST Expert.mq4
2. Delete MT4-FST Expert.ex4
3. Delete mqlcache.dat
4. Copy the new expert in the MT's expert folder.

Please report bugs and issues.

If you know for other brokers that cannot set SL and TP with the initial OrderSend, tell us the names. We'll include them in the expert for automatic recognition.

Re: MT4-FST Expert v12-Beta - BreakEven...

Break Even realization:

///
/// Sets a BreakEven stop of current positions. 
///
void SetBreakEvenStop(string symbol)
{
    if (SetAggregatePosition(symbol) <= 0)
        return;

    double breakeven = MarketInfo(symbol, MODE_STOPLEVEL);
    if (breakeven < BreakEven_Activating_Distance)
        breakeven = BreakEven_Activating_Distance;
    else if(BreakEven_Activating_Distance > 2000)
        breakeven = 2000;
    
    if (PositionType == OP_BUY)
    {
        double bid = MarketInfo(symbol, MODE_BID);
        if (bid - PositionOpenPrice > Point * breakeven)
            if (PositionStopLoss < bid - Point * breakeven)
                SetStopLossAndTakeProfit(symbol, PositionOpenPrice, PositionTakeProfit);
    }
    else if (PositionType == OP_SELL)
    {
        double ask = MarketInfo(symbol, MODE_ASK);
        if (PositionOpenPrice - ask > Point * breakeven)
            if (PositionStopLoss > ask + Point * breakeven)
                SetStopLossAndTakeProfit(symbol, PositionOpenPrice, PositionTakeProfit);
    }
}

Re: MT4-FST Expert v12-Beta - BreakEven...

Hello,

http://img30.imageshack.us/img30/1486/fst.png

Please give a more information about the "Separate_StopLoss_TakeProfit" true/false ? What does this doing ?

Do I understand correctly that If I'm using "Trailing Stop Limit" (trailing stop=40) in FST and set:

BreakEvenActivating_Distance = 25

then if the position reaches a profit of 25 pips then the FST put Stop-Loss at breakeven. Does it also compatible with trailing stop and the trailing stop also put into the breakeven ?

Re: MT4-FST Expert v12-Beta - BreakEven...

Please give a more information about the "Separate_StopLoss_TakeProfit" true/false ? What does this doing ?

When we want to send an order to the broker via MetaTrader, we normally use OrderSend command.
It has the following parameters:
OrderSend(Symbol, Direction, Lots, OpenPrice, Slippage, StopLoss , TakeProfit, ...)

It opens a position and set its StopLoss and TakeProfit.

The problem is with some brokers like FXCM and FXOpen. They don't allow setting StopLoss and TakeProfit directly with OrderSend.

If we do so, MetaTrader returns an error: Invalid Stop.

To prevent this error, we included an option for separate setting of the StopLoss and TakeProfit.

This option is activated by Separate_StopLoss_TakeProfit parameter. If our broker doesn't support initial setting of SL and TP, we have to set Separate_StopLoss_TakeProfit = True.

Doing so we force MT4-FST Expert to execute two operations:
1. It sends an order without SL and TP.
OrderSend(Symbol, Direction, Lots, OpenPrice, Slippage, 0, 0, ...)
2. After that it modifies the position:
OrderModify(Ticket, OpenPrice, StopLoss, TakeProfit, ...)

In that way we set a position with StopLoss and TakeProfit.

The current version of the expert recognizes FXCM and FXOpen automatically, so it's not necessary to change Separate_StopLoss_TakeProfit  for them.

Re: MT4-FST Expert v12-Beta - BreakEven...

I see a very great and long waited feature that if I specity "Same direction signal = add" then the FST opens several separate orders:

http://img38.imageshack.us/img38/4171/fst3.png

I'm testing this feature. Only thing that I see is that all the 3 orders have separate open levels but have the the same stop-loss levels at 1.62170. The original stop-loss is -250 (e.g. -25 in 4 digit broker)

http://img442.imageshack.us/img442/2389/fst2.png

How the FST manages separate orders or ADD feature, when it will move the stop loss ?

It is not problem for me because I'm currently using different EA for Stop-loss management (i'm testing it now), but I like to understand the logic of the stop-loss management of the current situation.

Re: MT4-FST Expert v12-Beta - BreakEven...

After every trading operation and at every tick the expert calls SetAggregatePosition() function. This function makes an virtual averaged position and report it to FST. FST thinks that only one position exist. 
When FST sends an Add order, the expert opens one new position and resets SL and TP of all existing positions at the levels FST requests. At any time the expert maintains the opened positions with equal SL and TP.

You can see how it works in the MT's Trade tab. When FST sends an order, the expert sets first the new order with its SL and TP. After that it modifies all the opened positions.