Schau, wie man Roboter kostenlos herunterladen kann
Finden Sie uns auf Twitter!
und werden Sie Mitglied unserer Fangruppe
Interessantes Skript?
Veröffentliche einen Link auf das Skript, damit die anderen ihn auch nutzen können
Hat Ihnen das Skript gefallen?
Bewerten Sie es im Terminal MetaTrader 5
Skripte

Trailing Function - Skript für den MetaTrader 4

Kailash Bai Mina
Veröffentlicht:
Kailash Bai Mina
Ansichten:
6431
Rating:
(25)
Veröffentlicht:
2021.11.09 00:49
Aktualisiert:
2022.03.03 08:12
Function.mq4 (5.11 KB) ansehen
MQL5 Freelance Benötigen Sie einen Roboter oder Indikator, der auf diesem Code basiert? Bestellen Sie ihn im Freelance-Bereich Zum Freelance
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Trailing(double trailingStartPips, double _trailingPips, double initialStopLossInPips=0, bool useSymbol=false, bool useMagicNumber=false, int _magicNumber=0, bool initialStopLossWillBeDone=true) {
    for(int i=OrdersTotal()-1; i>=0; i--) {
        if(OrderSelect(i,SELECT_BY_POS)) {
            bool magic = (useMagicNumber) ? (OrderMagicNumber()==_magicNumber) : true;
            bool symbol = (useSymbol) ? (OrderSymbol()==Symbol()) : true;
            if(!magic || !symbol) continue;
            if(OrderType() == OP_BUY) {
                if(OrderStopLoss() >= NormalizeDouble(OrderOpenPrice() + initialStopLossInPips*_Point*10,_Digits) && OrderStopLoss() != 0) {//OrderStopLoss() != 0 is not necessary here cause in Buy NULL SL is Zero and 0 Will never be grater than Order Open Price + Jobhi hai
                    if(Bid - OrderStopLoss() > _trailingPips * Point() * 10) {
                        if(NormalizeDouble(OrderStopLoss(),_Digits) != NormalizeDouble(Bid - (_trailingPips * Point() * 10),_Digits)) {
                            ResetLastError();
                            if(!OrderModify(OrderTicket(), OrderOpenPrice(), Bid - _trailingPips * Point() * 10, OrderTakeProfit(), 0)) {
                                Print("ERROR:"," Order Modify Failed: ",_LastError,"  ||  Function Name: ",__FUNCTION__,"  ||  Line Number: ",__LINE__);
                            }
                        }
                    }
                } else if(initialStopLossWillBeDone && OrderStopLoss() < NormalizeDouble(OrderOpenPrice() + initialStopLossInPips*_Point*10,_Digits)){
                    if(Bid - OrderOpenPrice() >= trailingStartPips * Point() * 10) {
                        if(OrderStopLoss() != NormalizeDouble(OrderOpenPrice() + initialStopLossInPips*_Point*10,_Digits)) {
                            ResetLastError();
                            if(!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(OrderOpenPrice() + initialStopLossInPips*_Point*10,_Digits), OrderTakeProfit(), 0)) {
                                Print("ERROR:"," Order Modify Failed: ",_LastError,"  ||  Function Name: ",__FUNCTION__,"  ||  Line Number: ",__LINE__);
                            }
                        }
                    }
                }
            }
            if(OrderType() == OP_SELL) {
                if(OrderStopLoss() <= NormalizeDouble(OrderOpenPrice() - initialStopLossInPips*_Point*10,_Digits) && OrderStopLoss() != 0) {//OrderStopLoss() != 0 is necessary here cause in Sell NULL SL is Zero and 0 Will Always be Lower than Order Open Price - Jobhi hai
                    if(OrderStopLoss() - Bid > _trailingPips * Point() * 10) {
                        if(NormalizeDouble(OrderStopLoss(),_Digits) != NormalizeDouble((_trailingPips * Point() * 10) + Bid,_Digits)) {
                            ResetLastError();
                            if(!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble((_trailingPips * Point() * 10) + Bid,_Digits), OrderTakeProfit(), 0)) {
                                Print("ERROR:"," Order Modify Failed: ",_LastError,"  ||  Function Name: ",__FUNCTION__,"  ||  Line Number: ",__LINE__);
                            }
                        }
                    }
                } else if(initialStopLossWillBeDone && (OrderStopLoss() > NormalizeDouble(OrderOpenPrice() - initialStopLossInPips*_Point*10,_Digits) || OrderStopLoss()==0)) {
                    if(OrderOpenPrice() - Bid >= trailingStartPips * Point() * 10) {
                        if(OrderStopLoss() != NormalizeDouble(OrderOpenPrice() - Bid >= _trailingPips * Point() * 10,_Digits)) {
                            ResetLastError();
                            if(!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(OrderOpenPrice() - initialStopLossInPips*_Point*10,_Digits), OrderTakeProfit(), 0)) {
                                Print("ERROR:"," Order Modify Failed: ",_LastError,"  ||  Function Name: ",__FUNCTION__,"  ||  Line Number: ",__LINE__);
                            }
                        }
                    }
                }
            }
        }
    }
}
    Correlation Calculator Panel Correlation Calculator Panel

    Calculator

    MyRsi with NET MyRsi with NET

    MyRsi with Noise Elimination Technology - by John Ehlers : metatrader 4 version

    Trailing Step Function Trailing Step Function

    This Is Just A Normal Trailing Step Function.

    DMH DMH

    Directional Movement using Hann windowing - metatrader 4 version