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

655 pips (les sexy, pas les pipettes) en 4 mois sans aucun indic.

  • MisterM

    Moii :) :D
    mais pas ton mail non plus

    [email protected]
  • NYKOES

    Si ya encore une place, je suis preneur évidemment ! :)
  • PHIL670

    alors cela donne quoi les tests?
  • furynick

    Je balance le code de l'EA tel qu'il est, il y a certainement des bugs mais je n'aurais pas l'occasion de m'y repencher avant un petit moment vu le projet que j'ai attaqué.

    Cool, on a les smileys qui s'affichent !!

    Code
    //+------------------------------------------------------------------+ //| FuRyXfirstBar.mq4 | //| Tous droits réservés, Nicolas Tuffier (2011) | //| http://www.furyweb.fr/forex/ | //+------------------------------------------------------------------+ #property copyright "Tous droits réservés, Nicolas Tuffier (2011)" #property link "http://www.furyweb.fr/forex/" #import "kernel32.dll" int GetTimeZoneInformation(int& a[]); #import "stdlib.ex4" string ErrorDescription(int error_code); #import #include <stderror.mqh> #define NAME "firstBar" #define VERSION "1.0" //---- input parameters extern double marginRisk = 0.2; extern double maxMarginRisk = 2.0; extern int takeProfit1 = 20; extern int takeProfit2 = 30; extern int takeProfit3 = 35; extern color buyColor = DodgerBlue; extern color sellColor = Crimson; extern int slippage = 2; int prd; // optimal selected period in minutes int prdIndex; // index in periods array int prdSize; // size of periods array int win; // winning trades count in loop of initialization int los; // loosing trades count in loop of initialization int logFile; // log file handle int bar2check; // current bar number being checked within 24h from 1 to PERIOD_D1 / Period() int limitCheck; // last bar id to be checked int initCheck; // number of bars to be checked int broker2gmt; // time offset from broker time to gmt in seconds int magicNumber; // magic number of trades int lotPrecision; // digits of minimal lot size bool openOnNextBar; // trade opening flag bool buySignal; // buy signal bool sellSignal; // sell signal bool initialization; // initialization period, find best bar for direction check bool breakeven; // breakeven flag double ratio; // winning ratio of current initialization loop double minSize; // size of minimal lots size double lotSize; // size of lot double stepSize; // size of minimal step size double savedVolume; // last volume information for new bar detection double pip2point; // conversion factor from pips to points ; 20 pips on 4/5 digits instrument = 0.002 points and 0.2 points on 2/3 digits instrument double activeTrailingStop;// level of current trailing stop, EMPTY_VALUE if not in use string periodName; // readable name of period string symb; // name of current Symbol double profitPoints[3]; // array of converted take profit levels double loss; // sum of previous trades loss in currency string checkBarAt; // optimal hour found for direction check int periods[4] = {PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4}; string prdNames[4] = {"M15", "M30", "H1", "H4"}; //+------------------------------------------------------------------+ //| detect new bar formed | //+------------------------------------------------------------------+ bool newBarFormed() { double vol = iVolume(symb, prd, 0); bool ret = vol < savedVolume; if (ret) Print("New bar detected"); savedVolume = vol; return(ret); } //+------------------------------------------------------------------+ //| normalize and convert double to string | //+------------------------------------------------------------------+ string d2s (double v, int p = -1) { if (p == -1) return (DoubleToStr(NormalizeDouble(v, Digits), Digits)); return (DoubleToStr(NormalizeDouble(v, p), p)); } //+------------------------------------------------------------------+ //| log messages to distinct files | //+------------------------------------------------------------------+ void msgLog(string msg) { Print(msg); msg=TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS)+" "+msg+"\r\n"; FileWriteString(logFile, msg, StringLen(msg)); } //+------------------------------------------------------------------+ //| reads or creates magic number for trades identification | //+------------------------------------------------------------------+ void readMagicNumber() { string fileName = NAME+".magic"; int hMagic = FileOpen(fileName, FILE_BIN|FILE_READ); if (hMagic < 0) { //---- initializing magic number MathSrand(TimeLocal()); magicNumber = MathRand(); hMagic = FileOpen(fileName, FILE_BIN|FILE_WRITE); FileWriteInteger(hMagic, magicNumber, SHORT_VALUE); msgLog("Magic number saved : " + magicNumber); } else { //---- loading existing magic number magicNumber = FileReadInteger(hMagic, SHORT_VALUE); msgLog("Magic number read : " + magicNumber); } FileClose(hMagic); } //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- int tzdata[172]; int tzinfo = GetTimeZoneInformation(tzdata); string barTime; initialization = true; activeTrailingStop = 0; bar2check = 0; openOnNextBar = false; symb = Symbol(); prdSize = ArraySize(periods); ratio = 0; pip2point = Point * MathPow(10, Digits % 2); minSize = MarketInfo(symb, MODE_MINLOT); lotSize = MarketInfo(Symbol(), MODE_LOTSIZE); stepSize = MarketInfo(Symbol(), MODE_LOTSTEP); profitPoints[0] = takeProfit1 * pip2point; profitPoints[1] = takeProfit2 * pip2point; profitPoints[2] = takeProfit3 * pip2point; broker2gmt = (3600.0 * MathRound((TimeLocal() - TimeCurrent()) / 3600)) + (60 * tzdata[0] - 3600 * (1 - tzinfo % 2)); for (lotPrecision = 0; lotPrecision < 5; lotPrecision++) if (MathFloor(stepSize * MathPow(10, lotPrecision)) > 0) break; logFile = FileOpen(NAME+"_"+VERSION+"_"+Symbol()+".log", FILE_BIN | FILE_READ | FILE_WRITE); FileSeek(logFile, 0, SEEK_END); readMagicNumber(); //---- check history data Comment("Initializing : checking history data of 60 last days"); // warning : need at least 5760 bars in M15 for (prdIndex = 0; prdIndex < prdSize; prdIndex++) if (iClose(symb, periods[prdIndex], 60 * PERIOD_D1 / periods[prdIndex]) == 0) { Comment("Data unavailable for " + prdNames[prdIndex]); return(-1); } msgLog("All history data were verified"); prdIndex = 0; while (prdIndex < prdSize) { if (bar2check == 0) { msgLog("initialization : check for period " + prdNames[prdIndex]); bar2check = iBars(symb, periods[prdIndex]) - 1; initCheck = PERIOD_D1 / periods[prdIndex]; limitCheck = bar2check - initCheck; win = 0; los = 0; } if (bar2check > limitCheck) { barTime = TimeToStr(iTime(symb, periods[prdIndex], bar2check), TIME_MINUTES); Comment("Initializing : searching for best ratio on ", prdNames[prdIndex], " with bars at ", barTime, " (", NormalizeDouble(100 * (prdIndex + (1.0 - ((1.0 * bar2check - limitCheck) / initCheck))) / prdSize, 1), "%)"); for (int n = bar2check; n > 0; n -= initCheck) { if (iClose(symb, periods[prdIndex], n) > iOpen(symb, periods[prdIndex], n)) { if (iHigh(symb, periods[prdIndex], iHighest(symb, periods[prdIndex], MODE_HIGH, initCheck, n - initCheck)) > iClose(symb, periods[prdIndex], n) + profitPoints[0]) win++; else los++; } else { if (iLow(symb, periods[prdIndex], iLowest(symb, periods[prdIndex], MODE_LOW, initCheck, n - initCheck)) < iClose(symb, periods[prdIndex], n) - profitPoints[0]) win++; else los++; } } if (1.0 * win / los > ratio) { ratio = 1.0 * win / los; prd = periods[prdIndex]; checkBarAt = barTime; msgLog("ratio on " + prdNames[prdIndex] + " with bars at " + barTime + " = " + ratio); } bar2check--; } else { bar2check = 0; prdIndex++; } } /*/ debug checkBarAt="15:35"; prd=5; //*/ switch (prd) { case PERIOD_M1: periodName = "M1"; break; case PERIOD_M5: periodName = "M5"; break; case PERIOD_M15: periodName = "M15"; break; case PERIOD_M30: periodName = "M30"; break; case PERIOD_H1: periodName = "H1"; break; case PERIOD_H4: periodName = "H4"; break; case PERIOD_D1: periodName = "D1"; break; case PERIOD_W1: periodName = "W1"; break; case PERIOD_MN1: periodName = "MN1"; break; default: periodName = "xx"; break; } initialization = false; Comment("Best ratio of " + d2s(ratio, 2) + " found on " + periodName + " at " + checkBarAt); //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- int i, n, step, error, total, ticket, tickets[4]; bool opened = false; bool newBar = newBarFormed(); double price, lotSize, pipValue, ts; color col, targets[3] = {Red, Orange, Yellow}; string msg, name, prefix[3] = {"TP2", "TP3", "TS"}; if (initialization) return(0); //---- close order if already open total = OrdersTotal(); if (StringFind(TimeToStr(TimeCurrent()), checkBarAt) >= 0) { for (i = 0; i < total; i++) if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) if (OrderMagicNumber() == magicNumber && OrderSymbol() == symb) { opened = true; if (OrderType() == OP_BUY) { price = Bid; col = buyColor; } if (OrderType() == OP_SELL) { price = Ask; col = sellColor; } name = TimeYear(TimeCurrent()) + TimeDayOfYear(TimeCurrent()); ObjectCreate(name, OBJ_RECTANGLE, 0, OrderOpenTime(), OrderOpenPrice(), Time[0], price); if (OrderProfit() > 0) ObjectSet(name, OBJPROP_COLOR, Lime); else ObjectSet(name, OBJPROP_COLOR, Red); msgLog("closing trade #" + OrderTicket() + " on trading window end"); OrderClose(OrderTicket(), OrderLots(), price, slippage, col); } if (opened) return(0); } //---- manage opened orders ticket = 0; step = -1; for (i = 0; i < total; i++) if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) if (OrderMagicNumber() == magicNumber && OrderSymbol() == symb) { opened = true; if (StringFind(OrderComment(), "TP") == 0) { // check fixed targets step = StrToInteger(StringSubstr(OrderComment(), 2, 1)); if (step == 1) break; if (OrderType() == OP_BUY) { if (OrderStopLoss() == 0) { // set breakeven stop msgLog("Setting breakeven stop to order #" + OrderTicket()); OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), 0); error = GetLastError(); if (error != ERR_NO_ERROR) msgLog("Error setting SL on order #" + OrderTicket() + " : " + ErrorDescription(error)); else breakeven = true; } } else if (OrderType() == OP_SELL) { if (OrderStopLoss() == 0) { // set breakeven stop msgLog("Setting breakeven stop to order #" + OrderTicket()); OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), 0); error = GetLastError(); if (error != ERR_NO_ERROR) msgLog("Error setting SL on order #" + OrderTicket() + " : " + ErrorDescription(error)); else breakeven = true; } } } else { // manage trailing stop, ts value vary between profitPoints[2] and profitPoints[2] - profitPoints[1] from OpenTime to OpenTime + 86400 (1 day) if (OrderType() == OP_BUY) { if (OrderStopLoss() == 0) { // set breakeven stop msgLog("Setting breakeven stop to order #" + OrderTicket()); OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), 0); error = GetLastError(); if (error != ERR_NO_ERROR) msgLog("Error setting SL on order #" + OrderTicket() + " : " + ErrorDescription(error)); else breakeven = true; } if (step == -1) { ts = Bid - ((profitPoints[2] - profitPoints[1]) + (profitPoints[1] * (86400 - TimeCurrent() + OrderOpenTime()) / 86400)); if (activeTrailingStop == EMPTY_VALUE || activeTrailingStop < ts) activeTrailingStop = ts; if (Bid <= activeTrailingStop) { msgLog("Buy trailing stop hit"); OrderClose(OrderTicket(), OrderLots(), Bid, slippage, buyColor); error = GetLastError(); if (error != ERR_NO_ERROR) msgLog("Error closing order #" + OrderTicket() + " : " + ErrorDescription(error)); else activeTrailingStop = EMPTY_VALUE; } } } else if (OrderType() == OP_SELL) { if (OrderStopLoss() == 0) { // set breakeven stop msgLog("Setting breakeven stop to order #" + OrderTicket()); OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), 0); error = GetLastError(); if (error != ERR_NO_ERROR) msgLog("Error setting SL on order #" + OrderTicket() + " : " + ErrorDescription(error)); else breakeven = true; } if (step == -1) { ts = Ask + ((profitPoints[2] - profitPoints[1]) + (profitPoints[1] * (86400 - TimeCurrent() + OrderOpenTime()) / 86400)); if (activeTrailingStop == EMPTY_VALUE || activeTrailingStop > ts) activeTrailingStop = ts; if (Ask >= activeTrailingStop) { msgLog("Sell trailing stop hit"); OrderClose(OrderTicket(), OrderLots(), Ask, slippage, sellColor); error = GetLastError(); if (error != ERR_NO_ERROR) msgLog("Error closing order #" + OrderTicket() + " : " + ErrorDescription(error)); else activeTrailingStop = EMPTY_VALUE; } } } } } //---- open new trade pipValue = MarketInfo(symb, MODE_TICKVALUE); if (newBar && openOnNextBar) { msgLog("Opening new orders"); if (iClose(symb, prd, 1) > iOpen(symb, prd, 1)) { msgLog("Last bar is bullish, open buy order"); lotSize = MathFloor((AccountFreeMargin() * marginRisk / 100) / MathAbs(AccountFreeMargin() - AccountFreeMarginCheck(symb, OP_BUY, 1.0)) / 4 / minSize) * minSize; if (loss > 0) lotSize = MathMin(lotSize * loss / (pipValue * takeProfit1), lotSize * maxMarginRisk / marginRisk); ticket = OrderSend(symb, OP_BUY, lotSize, Ask, slippage, 0, 0, "TP1 "+NAME + " " + VERSION, magicNumber, 0, buyColor); error = GetLastError(); if (error == ERR_NO_ERROR) for (i = 0 ; i < 3 ; i++) { OrderModify(ticket, Ask, 0, Ask + profitPoints[i], 0); error = GetLastError(); if (error != 0) msgLog("Error modifying order #" + ticket + " : " + ErrorDescription(error)); ObjectCreate(ticket+" TP"+i, OBJ_TREND, 0, Time[0], Ask + profitPoints[i], Time[0] + 86400, Ask + profitPoints[i]); ObjectSet(ticket+" TP"+i, OBJPROP_COLOR, targets[i]); ObjectSet(ticket+" TP"+i, OBJPROP_RAY, false); RefreshRates(); ticket = OrderSend(symb, OP_BUY, lotSize, Ask, slippage, 0, 0, prefix[i] + " " + NAME + " " + VERSION, magicNumber, 0, buyColor); error = GetLastError(); if (error != ERR_NO_ERROR) msgLog("Error opening trade " + prefix[i] + " : " + ErrorDescription(error)); } else msgLog("Error opening initial trade : " + ErrorDescription(error)); } else { msgLog("Last bar is bearish, open sell order"); lotSize = MathFloor((AccountFreeMargin() * marginRisk / 100) / MathAbs(AccountFreeMargin() - AccountFreeMarginCheck(symb, OP_SELL, 1.0)) / 4 / minSize) * minSize; if (loss > 0) lotSize = MathMin(lotSize * loss / (pipValue * takeProfit1), lotSize * maxMarginRisk / marginRisk); ticket = OrderSend(symb, OP_SELL, lotSize, Bid, slippage, 0, 0, "TP1 " + NAME + " " + VERSION, magicNumber, 0, sellColor); error = GetLastError(); if (error == 0) for (i = 0 ; i < 3 ; i++) { OrderModify(ticket, Bid, 0, Bid - profitPoints[i], 0); error = GetLastError(); if (error != ERR_NO_ERROR) msgLog("Error modifying order #" + ticket + " : " + ErrorDescription(error)); ObjectCreate(ticket+" TP"+i, OBJ_TREND, 0, Time[0], Bid - profitPoints[i], Time[0] + 86400, Bid - profitPoints[i]); ObjectSet(ticket+" TP"+i, OBJPROP_COLOR, targets[i]); ObjectSet(ticket+" TP"+i, OBJPROP_RAY, false); RefreshRates(); ticket = OrderSend(symb, OP_SELL, lotSize, Bid, slippage, 0, 0, prefix[i] + " " + NAME + " " + VERSION, magicNumber, 0, sellColor); error = GetLastError(); if (error != ERR_NO_ERROR) msgLog("Error opening trade " + prefix[i] + " : " + ErrorDescription(error)); } else msgLog("Error opening initial trade : " + ErrorDescription(error)); } openOnNextBar = false; return(0); } //---- verify if current time match check time if (StringFind(TimeToStr(TimeCurrent()), checkBarAt) >= 0 && !openOnNextBar && !opened) { msgLog("Current bar will be checked on opening of next one"); openOnNextBar = true; n=0; loss = 0; int cnt = OrdersHistoryTotal(); for (i = 0; i < cnt; i++) if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) if (OrderSymbol() == symb && OrderMagicNumber() == magicNumber) loss -= OrderProfit(); } //---- print informations if (lotSize == 0) lotSize = MathFloor((AccountFreeMargin() * marginRisk / 100) / MathAbs(AccountFreeMargin() - AccountFreeMarginCheck(symb, OP_BUY, 1.0)) / 4 / minSize) * minSize * 4.0; msg = "Best ratio of " + d2s(ratio, 2) + " found on " + periodName + " at " + checkBarAt + "\nAccount free margin=" + d2s(AccountFreeMargin(), 2) + "\nAccount leverage=" + AccountLeverage() + ":1\nLot size=" + d2s(lotSize, lotPrecision) + "\nPip value=" + d2s(pipValue * lotSize, 2) + AccountCurrency(); if (openOnNextBar) msg = msg + "\nOrders will be opened on next bar"; if (opened) msg = msg + "\nOrders are opened"; else breakeven = false; if (breakeven) msg = msg + "\nBreakeven enabled"; if (step == -1 && opened) msg = msg + "\nTrailing stop enabled : " + d2s(ts); Comment(msg); //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- FileClose(logFile); //---- return(0); } //+------------------------------------------------------------------+
  • furynick

    Par contre, c'est moins cool d'avoir les smilies qui s'affichent dans le code ... je signale le bug.
  • NYKOES

    En effet, mais on rectifiera de nous même ! Merci Fury pour l'investissement. BABS m'a flatté les merveilles de ton nouvel EA, bravo !!
  • furynick

    Du coup je n'ai même pas eu le temps de le mettre en test et de voir s'il arrive à faire du bénef :/
  • babs

    Afin de compléter le fil je poste le lien vers le journal du robot que j'ai lancé en démo.

    http://babs06fury.mt4stats.com/

    Quel projet furynick? professionnel?
  • furynick

    Professionnel et commercial ... donc confidentiel :)
Page 6