AK-47 Scalper EA: Die perfekte Handelssoftware für MetaTrader 4

Mike 2023.01.14 02:49 53 0 0
Anhang

1. Eingabeparameter

#define ExtBotName "AK-47 Scalper EA" //Bot Name
#define Version "1.00"

//--- Eingabeparameter
extern string EASettings = "---------------------------------------------"; //-------- <EA Einstellungen> --------
input int InpMagicNumber = 124656; //Magic Number

extern string TradingSettings = "---------------------------------------------"; //-------- <Handelseinstellungen> --------
input double Inpuser_lot = 0.01; //Lots
input double InpSL_Pips = 3.5; //Stoploss (in Pips)
input double InpMax_spread = 0.5; //Maximal erlaubter Spread (in Pips) (0 = floating)

extern string MoneySettings = "---------------------------------------------"; //-------- <Geldmanagement> --------
input bool isVolume_Percent = true; //Erlauben Sie Volumen in Prozent
input double InpRisk = 3; //Risikoanteil des Kontostands (%)

input string TimeSettings = "---------------------------------------------"; //-------- <Handelszeit Einstellungen> --------
input bool InpTimeFilter = true; //Handelszeit Filter
input int InpStartHour = 2; //Startstunde
input int InpStartMinute = 30; //Startminute
input int InpEndHour = 21; //Endstunde
input int InpEndMinute = 0; //Endminute

2. Initialisierung der lokalen Variablen

//--- Variablen
int Pips2Points; // Slippage 3 Pips
double Pips2Double; // Stoploss 15 Pips
int InpMax_slippage = 3; // Maximal erlaubte Slippage
bool isOrder = false; // nur 1 Order öffnen
int slippage;
string strComment = "";

3. Hauptcode

a/ Initialisierungsfunktion des EAs

int OnInit()
{
    //---  
    // 3 oder 5 Ziffern erkennen
    // Pip und Punkt
    if (Digits % 2 == 1)
    {
        Pips2Double = _Point * 10; 
        Pips2Points = 10;
        slippage = 10 * InpMax_slippage;
    } 
    else
    {
        Pips2Double = _Point;
        Pips2Points = 1;
        slippage = InpMax_slippage;
    }
    
    //---
    return(INIT_SUCCEEDED);
}

b/ Tick-Funktion des EAs

void OnTick() { //--- if(IsTradeAllowed() == false) { Comment("AK-47 EA\nHandel nicht erlaubt."); return; } MqlDateTime structTime; TimeCurrent(structTime); structTime.sec = 0; //Startzeit setzen structTime.hour = InpStartHour; structTime.min = InpStartMinute; datetime timeStart = StructToTime(structTime); //Endzeit setzen structTime.hour = InpEndHour; structTime.min = InpEndMinute; datetime timeEnd = StructToTime(structTime); double acSpread = MarketInfo(Symbol(), MODE_SPREAD); StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL); strComment = "\n" + ExtBotName + " - v." + (string)Version; strComment += "\nGMT Zeit = " + TimeToString(TimeGMT(),TIME_DATE|TIME_SECONDS); strComment += "\nHandelszeit = [" + (string)InpStartHour + "h" + (string)InpStartMinute + " --> " + (string)InpEndHour + "h" + (string)InpEndMinute + "]"; strComment += "\nAktueller Spread = " + (string)acSpread + " Punkte"; strComment += "\nAktueller Stopp-Level = " + (string)StopLevel + " Punkte"; Comment(strComment); //Werte aktualisieren UpdateOrders(); TrailingStop(); //Handelszeit überprüfen if(InpTimeFilter) { if(TimeCurrent() >= timeStart && TimeCurrent() 

3.1 Signal zur Ordereröffnung berechnen

void OpenOrder(){
    double TP = 0;
    double SL = 0;
    string comment = ExtBotName;

    //Lots berechnen
    double lot1 = CalculateVolume();
    
    double OpenPrice = NormalizeDouble(Bid - (StopLevel * _Point) - (InpSL_Pips/2) * Pips2Double, Digits);
    SL = NormalizeDouble(Ask + StopLevel * _Point + InpSL_Pips/2 * Pips2Double, Digits);
    
    if(CheckSpreadAllow()) //Spread überprüfen
    {
        if(!OrderSend(_Symbol, OP_SELLSTOP, lot1, OpenPrice, slippage, SL, TP, comment, InpMagicNumber, 0, clrRed))
            Print(__FUNCTION__,"--> OrderSend Fehler ", GetLastError());
    }
}

3.2 Volumen berechnen

double CalculateVolume() { double LotSize = 0; if(isVolume_Percent == false) { LotSize = Inpuser_lot; } else { LotSize = (InpRisk) * AccountFreeMargin(); LotSize = LotSize / 100000; double n = MathFloor(LotSize/Inpuser_lot); LotSize = n * Inpuser_lot; if(LotSize MarketInfo(Symbol(),MODE_MAXLOT)) LotSize = MarketInfo(Symbol(),MODE_MAXLOT); if(LotSize 

3.3 Der EA hat eine "Trailing Stop"-Funktion, SL wird jedes Mal angepasst, wenn sich der Preis ändert (nach unten)

void TrailingStop()
{
    for(int i = OrdersTotal() - 1; i >= 0; i--)
    {
        if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
            if((OrderMagicNumber() == InpMagicNumber) && (OrderSymbol() == Symbol()))
            {
                //Für Verkaufsorder
                if(OrderType() == OP_SELL)
                {
                    double SL_in_Pip = NormalizeDouble(OrderStopLoss() - (StopLevel * _Point) - Ask, Digits) / Pips2Double;
                    if(SL_in_Pip > InpSL_Pips){
                        double newSL = NormalizeDouble(Ask + (StopLevel * _Point) + InpSL_Pips * Pips2Double, Digits);
                        if(!OrderModify(OrderTicket(), OrderOpenPrice(), newSL, OrderTakeProfit(), 0, clrRed))
                        {
                            Print(__FUNCTION__,"--> OrderModify Fehler ", GetLastError());
                            continue;
                        }
                    }
                }
                //Für Verkaufs-Stopp-Order
                else if(OrderType() == OP_SELLSTOP)
                {
                    double SL_in_Pip = NormalizeDouble(OrderStopLoss() - (StopLevel * _Point) - Ask, Digits) / Pips2Double;
                    if(SL_in_Pip  Modify PendingOrder Fehler!", GetLastError());
                            continue;
                        }
                    }
                }
            }
        }
    }
}


Liste
Kommentar 0