Automatic Stop Loss

 

Here is my code I took from google and I cannot get this to work. Any idea what I may be doing wrong? First time doing this so it may be something obvious. Thanks in advance!




input int SL = 150; //15 pip



void OnTradeTransaction(const MqlTradeTransaction &txs, const MqlTradeRequest &req, const MqlTradeResult &res)

{

    MqlTradeRequest rq;

    MqlTradeResult tr;

    if (HistoryDealGetInteger(txs.deal, DEAL_ENTRY) == DEAL_ENTRY_IN)

    {

        PositionSelect(txs.symbol);

        rq.action = TRADE_ACTION_SLTP;

        rq.symbol = PositionGetString(POSITION_SYMBOL);

        if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)

            rq.sl = PositionGetDouble(POSITION_PRICE_OPEN) - SL * SymbolInfoDouble(txs.symbol, SYMBOL_POINT);

        else if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)

            rq.sl = PositionGetDouble(POSITION_PRICE_OPEN) + SL * SymbolInfoDouble(txs.symbol, SYMBOL_POINT);

        rq.tp = 15;

        (OrderSend(rq, tr));

    }

}
 
Bhersch2832:Here is my code I took from google and I cannot get this to work. Any idea what I may be doing wrong? First time doing this so it may be something obvious.

TP/SL is a price not an amount.

Reason: