Rejoindre la communauté
banner_forum
Devenez membre de la plus grande
communauté francophone sur le Forex
Partagez, échangez et apprenez en gagnant des crédits sur votre compte de trading

Une Robot "A mes Yeux" IDEAL..

  • arka3579

    Bonsoir..

    Peut-on programmer cette idée en E.A ?

    Si A.T.R. à la hausse ou a la baisse sur M30 + D1 + W1 (les 3 en accords)
    alors, ouverture BK HighLow "20" Si prix au dessus / en dessous de E.M.A. (Expo) "20" (réglable)
    Stop-Loss sur Trailing.S - A.T.R. (réglable)
    Ouverture sur %Equity.

    LA SUITE EN PRIVE..

    J'ai l'indicateur MQL4 pour le BreakOut (pour les éventuelles copier / coller)
    J'ai l'indicateur MQL4 pour TRIO A.T.R. (pour les éventuelles copier / coller)
    J'ai l'indicateur MQL4 pour S.L.. T.S. (pour les éventuelles copier / coller)

    Si tu maitrises, et si c'est possible, on en parle.
    Avec mes remerciements.

    "Prenons nos rêves.. pour des réalités"..
    Yohan.
    Modifié le 2021-06-17 18:42:45 par arka3579
  • arka3579

    En image..
    arka3579 a joint une image
    une-robot-a-mes-yeux-ideal-13557
  • arka3579

    Voici un ensemble de code devant être compiler pour un "Tout en Un"

    Le EA ouverture/fermeture croisement SMA / EMA : (fonctionnel)

    //+------------------------------------------------------------------+
    //| MACross.mq4 |
    //| Copyright 2020, Signal Forex |
    //| https://signalforex.id |
    //+------------------------------------------------------------------+

    #property version "1.00"
    #property strict

    //--- input parameters
    input int period_ma_fast = 4; //Period Fast MA
    input int FasterMode = 3; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma
    input int period_ma_slow = 18; //Period Slow MA
    input int SlowerMode = 0; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma

    input double takeProfit = 987654321; //Take Profit (pips)
    input double stopLoss = 1; //Stop Loss (pips)

    input double lotSize = 0.01; //Lot Size
    input double minEquity = 10.0; //Min. Equity ($)

    input int Slippage = 3; //Slippage
    input int MagicNumber = 5; //Magic Number

    //Variabel Global
    double myPoint = 0.0;
    int mySlippage = 0;
    int BuyTicket = 0;
    int SellTicket = 0;

    //+------------------------------------------------------------------+
    //| Expert initialization function |
    //+------------------------------------------------------------------+
    int OnInit()
    {
    //validasi input, sebaiknya kita selalu melakukan validasi pada initialisasi data input
    if (period_ma_fast >= period_ma_slow || takeProfit < 0.0 || stopLoss < 0.0 || lotSize < 0.01 || minEquity < 10){
    Alert("WARNING - Input data inisial tidak valid";);
    return (INIT_PARAMETERS_INCORRECT);
    }

    double min_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
    if(lotSize<min_volume)
    {
    string pesan =StringFormat("Volume lebih kecil dari batas yang dibolehkan yaitu %.2f",min_volume);
    Alert (pesan);
    return(INIT_PARAMETERS_INCORRECT);
    }

    myPoint = GetPipPoint(Symbol());
    mySlippage = GetSlippage(Symbol(),Slippage);

    return(INIT_SUCCEEDED);
    }

    //+------------------------------------------------------------------+
    //| Expert deinitialization function |
    //+------------------------------------------------------------------+
    void OnDeinit(const int reason)
    {
    Print ("EA telah diberhentikan";);
    }

    //+------------------------------------------------------------------+
    //| Expert tick function |
    //+------------------------------------------------------------------+
    void OnTick()
    {
    if (cekMinEquity()){


    int signal = -1;
    bool isNewCandle = NewCandle(Period(), Symbol());

    signal = getSignal(isNewCandle);
    transaction(isNewCandle, signal);


    }else{
    //Stop trading, karena equity tidak cukup
    Print ("Vérifier Equity";);
    }
    }

    void transaction(bool isNewCandle, int signal){
    if (isNewCandle==false) return;

    int tOrder = 0;
    int tOrderBuy = 0, tOrderSell = 0;
    string strMN = "", pair = "";
    int tiketBuy = 0, tiketSell = 0;
    double lotBuy = 0.0, lotSell = 0.0;

    pair = Symbol();

    tOrder = OrdersTotal();
    for (int i=tOrder-1; i>=0; i--){
    bool hrsSelect = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
    strMN = IntegerToString(OrderMagicNumber());
    if (StringFind(strMN, IntegerToString(MagicNumber), 0) == 0 && StringFind(OrderSymbol(), pair, 0) == 0 ){
    if (OrderType() == OP_BUY){
    tOrderBuy++;
    tiketBuy = OrderTicket();
    lotBuy = OrderLots();
    }
    if (OrderType() == OP_SELL){
    tOrderSell++;
    tiketSell = OrderTicket();
    lotSell = OrderLots();
    }

    }//end if magic number && pair

    }//end for

    double lot = 0.0;
    double hargaOP = 0.0;
    double sl = 0.0, tp = 0.0;
    int tiket = 0;
    int orderType = -1;

    //Open pertama kali
    if (signal == OP_BUY && tOrderBuy == 0){
    lot = getLotSize();
    orderType = signal;
    hargaOP = Ask;
    tiket = OrderSend(Symbol(), orderType, lot, hargaOP, mySlippage, sl, tp, "OP BUY M5", MagicNumber, 0, clrBlue);
    if (tiketSell > 0){
    if (OrderClose(tiketSell, lotSell, Ask, mySlippage, clrRed)){
    Print ("Close successful";);
    }
    }
    }else if (signal == OP_SELL && tOrderSell == 0){
    lot = getLotSize();
    orderType = signal;
    hargaOP = Bid;
    tiket = OrderSend(Symbol(), orderType, lot, hargaOP, mySlippage, sl, tp, "OP SELL M5", MagicNumber, 0, clrRed);
    if (tiketBuy > 0){
    if (OrderClose(tiketBuy, lotBuy, Bid, mySlippage, clrRed)){
    Print ("Close successful";);
    }
    }
    }

    }

    int getSignal(bool isNewCandle){
    int signal = -1;

    if (isNewCandle==true){
    //Moving Averages
    double maFast1 = iMA(NULL, 0, period_ma_fast, 0, FasterMode, 0, 1);
    double maSlow1 = iMA(NULL, 0, period_ma_slow, 0, SlowerMode, 0, 1);
    double maFast2 = iMA(NULL, 0, period_ma_fast, 0, FasterMode, 0, 2);
    double maSlow2 = iMA(NULL, 0, period_ma_slow, 0, SlowerMode, 0, 2);

    if(maFast2 <= maSlow2 && maFast1 > maSlow1){
    signal = OP_BUY;
    }else if(maFast2 >= maSlow2 && maFast1 < maSlow1){
    signal = OP_SELL;
    }
    }

    return (signal);
    }

    double getLotSize(){
    double lot = 0.0;
    lot = NormalizeDouble(lotSize, 2);
    return (lot);
    }

    //fungsi tambahan untuk cek equity minimum
    bool cekMinEquity(){
    bool valid = false;
    double equity = 0.0;
    equity = AccountEquity();

    if (equity > minEquity){
    valid = true;
    }
    return (valid);
    }

    // Fungsi GetPipPoint
    double GetPipPoint(string pair)
    {
    double point= 0.0;
    int digits = (int) MarketInfo(pair, MODE_DIGITS);
    if(digits == 2 || digits== 3) point= 0.01;
    else if(digits== 4 || digits== 5) point= 0.0001;
    return(point);
    }

    // Fungsi GetSlippage
    int GetSlippage(string pair, int SlippagePips)
    {
    int slippage = 0;
    int digit = (int) MarketInfo(pair,MODE_DIGITS);
    if(digit == 2 || digit == 4) slippage = SlippagePips;
    else if(digit == 3 || digit == 5) slippage = SlippagePips * 10;
    return(slippage );
    }

    bool NewCandle(int tf, string pair = "" ){
    bool isNewCS = false;
    static datetime prevTime = TimeCurrent();
    if (pair == "";) pair = Symbol();
    if (prevTime < iTime(pair, tf, 0)){
    isNewCS = true;
    prevTime = iTime(pair, tf, 0);
    }
    return isNewCS;
    }
  • arka3579

    Le E.A. ouverture/fermeture sur A.T.R. : (Fonctionnel)

    //+------------------------------------------------------------------+
    //| EarnForex.com |
    //| https://www.earnforex.com |
    //| 2011-2021 |
    //+------------------------------------------------------------------+
    #property copyright "www.EarnForex.com, 2011-2021"
    #property version "1.05"
    #property link "https://www.earnforex.com/metatrader-expert-advisors/ATR-Trailer/"

    // Plain trailing stop EA with ATR-based stop-loss.

    #define LONG 1
    #define SHORT 2

    extern int ATR_Period = 14;
    extern int ATR_Multiplier = 3;
    extern int StartWith = 1; // 1 - Short, 2 - Long
    extern int Slippage = 3; // Tolerated slippage in pips
    extern double Lots = 0.01;
    extern bool ECN_Mode = true; // Set to true if stop-loss should be added only after Position Open
    extern int TakeProfit = 998877665544; // In your broker's pips

    extern int Magic = 1;

    // Global variables
    bool HaveLongPosition;
    bool HaveShortPosition;

    int LastPosition = 0;

    int init()
    {
    LastPosition = 3 - StartWith;
    return(0);
    }

    //+------------------------------------------------------------------+
    //| Expert Every Tick Function |
    //+------------------------------------------------------------------+
    int start()
    {
    double SL = 0, TP = 0;

    if (IsTradeAllowed() == false) return(0);

    // Getting the ATR values
    double ATR = iATR(NULL, 0, ATR_Period, 0);
    ATR *= ATR_Multiplier;

    if (ATR <= (MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD)) * Point) ATR = (MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD)) * Point;

    // Check what position is currently open
    GetPositionStates();

    // Adjust SL and TP of the current position
    if ((HaveLongPosition) || (HaveShortPosition)) AdjustSLTP(ATR);
    else
    {
    // Buy condition
    if (LastPosition == SHORT)
    {
    for (int i = 0; i < 10; i++)
    {
    RefreshRates();
    // Bid and Ask are swapped to preserve the probabilities and decrease/increase profit/loss size
    if (!ECN_Mode)
    {
    SL = NormalizeDouble(Bid - ATR, Digits);
    if (TakeProfit > 0) TP = NormalizeDouble(Bid + TakeProfit * Point, Digits);
    }
    int result = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, SL, TP, "ATR-Trader", Magic, 0, Blue);
    Sleep(1000);
    if (result == -1)
    {
    int e = GetLastError();
    Print(e);
    }
    else return(0);
    }
    }
    // Sell condition
    else if (LastPosition == LONG)
    {
    for (i = 0; i < 10; i++)
    {
    RefreshRates();
    // Bid and Ask are swapped to preserve the probabilities and decrease/increase profit/loss size
    if (!ECN_Mode)
    {
    SL = NormalizeDouble(Ask + ATR, Digits);
    if (TakeProfit > 0) TP = NormalizeDouble(Ask - TakeProfit * Point, Digits);
    }
    result = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, SL, TP, "ATR-Trader", Magic, 0, Red);
    Sleep(1000);
    if (result == -1)
    {
    e = GetLastError();
    Print(e);
    }
    else return(0);
    }
    }
    }

    return(0);
    }

    //+------------------------------------------------------------------+
    //| Check What Position is Currently Open |
    //+------------------------------------------------------------------+
    void GetPositionStates()
    {
    int total = OrdersTotal();
    for (int cnt = 0; cnt < total; cnt++)
    {
    if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) == false) continue;
    if (OrderMagicNumber() != Magic) continue;
    if (OrderSymbol() != Symbol()) continue;

    if (OrderType() == OP_BUY)
    {
    HaveLongPosition = true;
    HaveShortPosition = false;
    }
    else if (OrderType() == OP_SELL)
    {
    HaveLongPosition = false;
    HaveShortPosition = true;
    }
    if (HaveLongPosition) LastPosition = LONG;
    else if (HaveShortPosition) LastPosition = SHORT;
    return;
    }

    HaveLongPosition = false;
    HaveShortPosition = false;
    }

    //+------------------------------------------------------------------+
    //| Adjust Stop-Loss and TakeProfit of the Open Position |
    //+------------------------------------------------------------------+
    void AdjustSLTP(double SLparam)
    {
    double TP = 0;

    int total = OrdersTotal();
    for (int cnt = 0; cnt < total; cnt++)
    {
    if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) == false) continue;
    if (OrderMagicNumber() != Magic) continue;
    if (OrderSymbol() != Symbol()) continue;

    if (OrderType() == OP_BUY)
    {
    RefreshRates();
    double SL = NormalizeDouble(Bid - SLparam, Digits);
    if (TakeProfit > 0) TP = NormalizeDouble(Bid + TakeProfit * Point, Digits);
    if (OrderTakeProfit() != 0) TP = NormalizeDouble(OrderTakeProfit(), Digits); // TP already set, no need to trail it.
    if ((SL > NormalizeDouble(OrderStopLoss(), Digits)) || (NormalizeDouble(OrderStopLoss(), Digits) == 0) || ((TP > 0) && (NormalizeDouble(OrderTakeProfit(), Digits) == 0)))
    {
    for (int i = 0; i < 10; i++)
    {
    bool result = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0);
    if (result) return;
    }
    }
    }
    else if (OrderType() == OP_SELL)
    {
    RefreshRates();
    SL = NormalizeDouble(Ask + SLparam, Digits);
    if (TakeProfit > 0) TP = NormalizeDouble(Ask - TakeProfit * Point, Digits);
    if (OrderTakeProfit() != 0) TP = NormalizeDouble(OrderTakeProfit(), Digits); // TP already set, no need to trail it.
    if ((SL < NormalizeDouble(OrderStopLoss(), Digits)) || (NormalizeDouble(OrderStopLoss(), Digits) == 0) || ((TP > 0) && (NormalizeDouble(OrderTakeProfit(), Digits) == 0)))
    {
    for (i = 0; i < 10; i++)
    {
    result = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0);
    if (result) return;
    }
    }
    }
    }
    }
    //+------------------------------------------------------------------+
  • arka3579

    Si besoin du code "SuperTrend ATR" je le fournirais a la personne qui se penche sur le sujet si elle estime en avoir besoin.

    On combine tout ca. Et on en parle en privé si t'acceptes de te pencher dessus.

    Merci.
  • arka3579 — en réponse à arka3579 dans son message #124606

    Ce robot présente un défaut..
    Il ouvre automatiquement en sens inverse après avoir fermer sur ATR.
    Cela, même si la vague continue ! (C'est pour ca qu'il est nul) NUL = A perte
    S'il attendait le changement A.T.R. pour ré-ouvrir, je pense qu'il y aurai plus de résultat.
  • phvdweid — en réponse à arka3579 dans son message #124603

    Bonjour,
    Je viens de lire ton post sur cette stratégie à programmer. Est-ce toujours d'actualité ?
    Philippe