Udoskonalenie ea na warunki prawdziwe

MQL5 Experts

Job finished

Execution time 30 days

Specification

witam wszystkich programistów prosze o ulepszenie do warunków realnych zeby bot działał na demo działa dobrze ale na warunkach prawdziwych juz nie 



//+------------------------------------------------------------------+

//|    GoldPendingEA_Professional_v17.1_PRO.mq4                      |

//|    Autor: Kamil                        |

//|    XAU/USD: AutoLot skokowy + Cele USD ~ lot, Trailing, Panel    |

//|    BuyStop/SellStop, SL->profit, filtr spreadu, auto-reset       |

//+------------------------------------------------------------------+

#property strict

#property indicator_chart_window


//=================== Parametry handlowe ===================//

input int    DistancePoints        = 100;   // odległość pendingów od ceny (punkty)

input int    SL_Points             = 200;   // SL w punktach

input int    TP_Points             = 200;   // TP w punktach

input int    Slippage              = 10;

input int    Magic                 = 777;

input int    MaxAllowedSpread      = 10;    // max spread (punkty)


// Trailing

input int    TrailingGap           = 80;    // odległość SL od ceny (punkty)

input int    TrailingStep          = 10;    // minimalny krok aktualizacji (punkty)


// Przesunięcie SL w zysk po progu USD

input bool   EnableMoveSLtoProfit  = true;

input double MoveSLProfitTrigger   = 50.0;  // łączny zysk EA (USD), po którym SL idzie w zysk

input double MoveSL_OffsetPoints   = 100;   // o ile punktów ponad cenę wejścia (BUY) / poniżej (SELL)


//=================== AutoLot i cele USD ===================//

input bool   EnableAutoLot         = true;

input double LotStepUSDPer01       = 100.0; // co ile USD salda dodajemy 0.01 lot

input double MinLot                = 0.01;  // min lot

input double MaxLot                = 50.0;  // max lot


input double ProfitPerLotUSD       = 240.0; // zysk docelowy na 1.00 lot

input double LossPerLotUSD         = 30.0;  // strata maks. na 1.00 lot

input bool   RecalcTargetsOnTick   = false;


//=================== Kolory panelu ===================//

input color  PanelBackgroundColor  = clrDarkSlateGray;

input color  PanelTextColor        = clrWhite;

input color  PanelBorderColor      = clrDimGray;

input color  PanelTitleColor       = clrGold;


//=================== Zmienne globalne ===================//

double gPoint, gStopLevel;

double gLot = 0.01;

double gCloseAtProfitUSD = 0.0;

double gCloseAtLossUSD   = 0.0;

bool   gSessionActive    = false;

bool   gMovedToProfit    = false;


//=================== Deklaracje ===================//

void   CalculateLotAndTargets();

void   OpenPendings();

void   ManageOrders();

void   LiveTrailing();

bool   MoveSLtoProfitZone();

bool   CloseAllEAOrders(string reason);

void   AutoResetIfAllClosed();

void   DeletePending(int type);

void   DeleteAllPendings();

double CurrentEAProfitUSD();

void   CreatePanel();

void   UpdatePanel();


//+------------------------------------------------------------------+

//| OnInit                                                           |

//+------------------------------------------------------------------+

int OnInit()

{

   gPoint    = MarketInfo(Symbol(), MODE_POINT);

   gStopLevel= MarketInfo(Symbol(), MODE_STOPLEVEL) * gPoint;


   CalculateLotAndTargets();

   OpenPendings();

   gSessionActive = true;

   CreatePanel();

   return(INIT_SUCCEEDED);

}


//+------------------------------------------------------------------+

//| OnTick                                                           |

//+------------------------------------------------------------------+

void OnTick()

{

   if(RecalcTargetsOnTick) CalculateLotAndTargets();


   ManageOrders();

   MoveSLtoProfitZone();

   LiveTrailing();


   double pnl = CurrentEAProfitUSD();

   if(pnl >= gCloseAtProfitUSD)

   {

      if(CloseAllEAOrders("TargetProfit")) gSessionActive=false;

   }

   else if(pnl <= gCloseAtLossUSD)

   {

      if(CloseAllEAOrders("MaxLoss")) gSessionActive=false;

   }


   AutoResetIfAllClosed();

   UpdatePanel();

}


//+------------------------------------------------------------------+

//| Obliczenia lota i celów USD                                      |

//+------------------------------------------------------------------+

void CalculateLotAndTargets()

{

   double balance = AccountBalance();


   if(EnableAutoLot)

   {

      double steps = balance / MathMax(LotStepUSDPer01, 1.0);

      gLot = 0.01 * MathFloor(steps + 1e-9);

      if(gLot < MinLot) gLot = MinLot;

      if(gLot > MaxLot) gLot = MaxLot;

      gLot = NormalizeDouble(gLot, 2);

   }


   gCloseAtProfitUSD = NormalizeDouble(gLot * ProfitPerLotUSD, 2);

   gCloseAtLossUSD   = NormalizeDouble(-gLot * LossPerLotUSD, 2);


   Print("AutoLot=", DoubleToString(gLot,2),

         " | TargetProfit=", DoubleToString(gCloseAtProfitUSD,2),

         " | MaxLoss=", DoubleToString(gCloseAtLossUSD,2));

}


//+------------------------------------------------------------------+

//| Aktualny P/L (USD) dla zleceń EA                                 |

//+------------------------------------------------------------------+

double CurrentEAProfitUSD()

{

   double sum=0;

   for(int i=0;i<OrdersTotal();i++)

   {

      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;

      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;

      int t=OrderType();

      if(t==OP_BUY || t==OP_SELL)

         sum += OrderProfit()+OrderSwap()+OrderCommission();

   }

   return(sum);

}


//+------------------------------------------------------------------+

//| Przesunięcie SL w zysk po progu USD                              |

//+------------------------------------------------------------------+

bool MoveSLtoProfitZone()

{

   if(!EnableMoveSLtoProfit) return(false);

   if(CurrentEAProfitUSD() < MoveSLProfitTrigger) return(false);


   bool changed=false;

   RefreshRates();


   for(int i=0;i<OrdersTotal();i++)

   {

      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;

      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;


      double open=OrderOpenPrice(), tp=OrderTakeProfit(), sl=OrderStopLoss();

      double newSL;

      if(OrderType()==OP_BUY)

      {

         newSL = NormalizeDouble(open + MoveSL_OffsetPoints*gPoint, Digits);

         if(Bid>newSL && newSL>sl)

         {

            if(!OrderModify(OrderTicket(), open, newSL, tp, 0, clrAqua))

               Print("OrderModify BUY error ", GetLastError());

            else { changed=true; gMovedToProfit=true; }

         }

      }

      else if(OrderType()==OP_SELL)

      {

         newSL = NormalizeDouble(open - MoveSL_OffsetPoints*gPoint, Digits);

         if(Ask<newSL && (sl==0 || newSL<sl))

         {

            if(!OrderModify(OrderTicket(), open, newSL, tp, 0, clrAqua))

               Print("OrderModify SELL error ", GetLastError());

            else { changed=true; gMovedToProfit=true; }

         }

      }

   }

   return(changed);

}


//+------------------------------------------------------------------+

//| Otwieranie pendingów z filtrem spreadu                           |

//+------------------------------------------------------------------+

void OpenPendings()

{

   RefreshRates();

   double ask=MarketInfo(Symbol(), MODE_ASK);

   double bid=MarketInfo(Symbol(), MODE_BID);

   double spread=MarketInfo(Symbol(), MODE_SPREAD);


   if(spread > MaxAllowedSpread)

   {

      Print("Spread zbyt wysoki (", spread, " pkt) – nie otwieram zleceń.");

      return;

   }


   DeleteAllPendings();


   double buyPrice  = NormalizeDouble(ask + DistancePoints*gPoint, Digits);

   double sellPrice = NormalizeDouble(bid - DistancePoints*gPoint, Digits);


   double buySL  = NormalizeDouble(buyPrice  - SL_Points*gPoint, Digits);

   double buyTP  = NormalizeDouble(buyPrice  + TP_Points*gPoint, Digits);

   double sellSL = NormalizeDouble(sellPrice + SL_Points*gPoint, Digits);

   double sellTP = NormalizeDouble(sellPrice - TP_Points*gPoint, Digits);


   int bt = OrderSend(Symbol(), OP_BUYSTOP, gLot, buyPrice, Slippage, buySL, buyTP, "BuyStop",  Magic, 0, clrBlue);

   if(bt<0) Print("BuyStop error ", GetLastError());


   int st = OrderSend(Symbol(), OP_SELLSTOP, gLot, sellPrice, Slippage, sellSL, sellTP, "SellStop", Magic, 0, clrRed);

   if(st<0) Print("SellStop error ", GetLastError());

}


//+------------------------------------------------------------------+

//| Gdy aktywuje się BUY/SELL – usuń przeciwny pending               |

//+------------------------------------------------------------------+

void ManageOrders()

{

   bool hasBuy=false, hasSell=false;

   for(int i=0;i<OrdersTotal();i++)

   {

      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;

      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;

      if(OrderType()==OP_BUY)  hasBuy=true;

      if(OrderType()==OP_SELL) hasSell=true;

   }

   if(hasBuy)  DeletePending(OP_SELLSTOP);

   if(hasSell) DeletePending(OP_BUYSTOP);

}


//+------------------------------------------------------------------+

//| Trailing stop                                                    |

//+------------------------------------------------------------------+

void LiveTrailing()

{

   RefreshRates();

   for(int i=0;i<OrdersTotal();i++)

   {

      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;

      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;


      double open=OrderOpenPrice(), sl=OrderStopLoss(), tp=OrderTakeProfit();


      if(OrderType()==OP_BUY)

      {

         double newSL=NormalizeDouble(Bid - TrailingGap*gPoint, Digits);

         if(Bid>open && newSL > sl + TrailingStep*gPoint)

         {

            if(!OrderModify(OrderTicket(), open, newSL, tp, 0, clrLime))

               Print("Trailing BUY error ", GetLastError());

         }

      }

      else if(OrderType()==OP_SELL)

      {

         double newSL=NormalizeDouble(Ask + TrailingGap*gPoint, Digits);

         if(Ask<open && newSL < sl - TrailingStep*gPoint)

         {

            if(!OrderModify(OrderTicket(), open, newSL, tp, 0, clrLime))

               Print("Trailing SELL error ", GetLastError());

         }

      }

   }

}


//+------------------------------------------------------------------+

//| Zamknij wszystko                                                 |

//+------------------------------------------------------------------+

bool CloseAllEAOrders(string reason)

{

   RefreshRates();

   Print("CloseAll [", reason, "]");

   bool okAll=true;


   for(int i=OrdersTotal()-1;i>=0;i--)

   {

      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;

      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;


      bool ok=true;

      int t=OrderType();

      if(t==OP_BUY)  ok=OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, clrRed);

      if(t==OP_SELL) ok=OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, clrRed);

      if(t==OP_BUYSTOP || t==OP_SELLSTOP) ok=OrderDelete(OrderTicket());

      if(!ok){ Print("Close error ", GetLastError()); okAll=false; }

   }

   return(okAll);

}


//+------------------------------------------------------------------+

//| Auto reset po całkowitym zamknięciu                              |

//+------------------------------------------------------------------+

void AutoResetIfAllClosed()

{

   int active=0;

   for(int i=0;i<OrdersTotal();i++)

   {

      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;

      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;

      active++;

   }


   if(active==0)

   {

      if(!gSessionActive)

      {

         CalculateLotAndTargets();

         OpenPendings();

         gSessionActive=true;

         gMovedToProfit=false;

      }

   }

   else

   {

      gSessionActive=false;

   }

}


//+------------------------------------------------------------------+

//| Usuń pendingi danego typu                                        |

//+------------------------------------------------------------------+

void DeletePending(int type)

{

   for(int i=OrdersTotal()-1;i>=0;i--)

   {

      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;

      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;

      if(OrderType()!=type) continue;


      if(!OrderDelete(OrderTicket()))

         Print("DeletePending error ", GetLastError());

   }

}


//+------------------------------------------------------------------+

//| Usuń wszystkie pendingi EA                                       |

//+------------------------------------------------------------------+

void DeleteAllPendings()

{

   for(int i=OrdersTotal()-1;i>=0;i--)

   {

      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;

      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;

      int t=OrderType();

      if(t==OP_BUYSTOP || t==OP_SELLSTOP)

      {

         if(!OrderDelete(OrderTicket()))

            Print("DeleteAll error ", GetLastError());

      }

   }

}


//+------------------------------------------------------------------+

//| Stylowy panel informacyjny EA                                    |

//+------------------------------------------------------------------+

void CreatePanel()

{

   string bg="EA_BG";

   if(ObjectFind(0,bg)==-1)

   {

      ObjectCreate(0,bg,OBJ_RECTANGLE_LABEL,0,0,0);

      ObjectSet(bg,OBJPROP_CORNER,0);

      ObjectSet(bg,OBJPROP_XDISTANCE,8);

      ObjectSet(bg,OBJPROP_YDISTANCE,20);

      ObjectSet(bg,OBJPROP_XSIZE,340);

      ObjectSet(bg,OBJPROP_YSIZE,230);

      ObjectSet(bg,OBJPROP_BGCOLOR,PanelBackgroundColor);

      ObjectSet(bg,OBJPROP_COLOR,PanelBorderColor);

      ObjectSetInteger(0,bg,OBJPROP_CORNER,CORNER_LEFT_UPPER);

      ObjectSetInteger(0,bg,OBJPROP_BACK,true);

   }


   string lbls[]={"EA_Title","EA_Line1","EA_Line2","EA_Line3",

                  "EA_Line4","EA_Line5","EA_Line6","EA_Line7"};

   for(int i=0;i<ArraySize(lbls);i++)

   {

      if(ObjectFind(0,lbls[i])==-1)

      {

         ObjectCreate(0,lbls[i],OBJ_LABEL,0,0,0);

         ObjectSet(lbls[i],OBJPROP_CORNER,0);

         ObjectSet(lbls[i],OBJPROP_XDISTANCE,20);

         ObjectSet(lbls[i],OBJPROP_YDISTANCE,30+(i*25));

         ObjectSetText(lbls[i],"",10,"Segoe UI",PanelTextColor);

      }

   }

}


//+------------------------------------------------------------------+

//| Aktualizacja panelu                                              |

//+------------------------------------------------------------------+

void UpdatePanel()

{

   RefreshRates();

   double ask=MarketInfo(Symbol(), MODE_ASK);

   double bid=MarketInfo(Symbol(), MODE_BID);

   double spread=MarketInfo(Symbol(), MODE_SPREAD);

   double pnl=CurrentEAProfitUSD();

   double bal=AccountBalance();


   string statusIcon=gSessionActive ? "🟢" : "🔄";

   color pnlColor = pnl>=0 ? clrLime : clrTomato;

   color spreadColor = spread>MaxAllowedSpread ? clrRed : clrWhite;


   ObjectSetText("EA_Title","💎 GoldPendingEA v17.1 PRO",12,"Segoe UI Bold",PanelTitleColor);

   ObjectSetText("EA_Line1",statusIcon+"  Status: "+(gSessionActive?"Aktywny":"Reset"),10,"Segoe UI",clrWhite);

   ObjectSetText("EA_Line2","📉 Spread: "+DoubleToString(spread,0)+" pkt",10,"Segoe UI",spreadColor);

   ObjectSetText("EA_Line3","💰 Saldo: "+DoubleToString(bal,2)+" USD",10,"Segoe UI",clrYellow);

   ObjectSetText("EA_Line4","⚖️ Lot: "+DoubleToString(gLot,2),10,"Segoe UI",clrAqua);

   ObjectSetText("EA_Line5","🎯 Cele: TP "+DoubleToString(gCloseAtProfitUSD,2)+" $  |  SL "+DoubleToString(gCloseAtLossUSD,2)+" $",10,"Segoe UI",clrOrange);

   ObjectSetText("EA_Line6","📊 P/L: "+DoubleToString(pnl,2)+" $",10,"Segoe UI",pnlColor);

   ObjectSetText("EA_Line7","💹 Bid: "+DoubleToString(bid,Digits)+" | Ask: "+DoubleToString(ask,Digits),10,"Segoe UI",clrSilver);

}

//+------------------------------------------------------------------+


Responded

1
Developer 1
Rating
(252)
Projects
462
26%
Arbitration
139
20% / 60%
Overdue
100
22%
Free
2
Developer 2
Rating
(1)
Projects
1
0%
Arbitration
1
0% / 0%
Overdue
0
Free
3
Developer 3
Rating
(1)
Projects
1
0%
Arbitration
0
Overdue
0
Free
Similar orders
We are seeking an experienced MQL4/MQL5 programmer to develop a high-performance, fully automated Expert Advisor (EA). The bot must execute a sophisticated multi-currency hedging strategy across correlated forex pairs. Key Responsibilities Develop Multi-Currency Logic : Build an EA capable of scanning and trading multiple currency pairs simultaneously from a single chart or setup. Implement Hedging Strategy : Code
I am seeking an elite, top-tier quantitative programmer to engineer a professional multi-strategy software suite for XAU/USD (Gold). This project will be executed under a single contract workspace, cleanly structured across sequential development milestones: Milestone 1: (M30/H1/H4 Swing Architecture) 2: (M1/M5/M15 High-Frequency Velocity Architecture) 3: (Integration Phase):(Unified All-In-One Parent Class Execution
Hi I want a trade copier for my ninja Trader 1. It should support at least 50 followers accounts. 2. Each follower should have its own configurable quantity/risk. 3. Copier should replicate entries, stops, and take profit, order medications, and order cancellations, ect. 4. It should copy both manual and strategy trades. (As long as the follower accounts are selected to follow, it should do the exact same as the
Infinity 30+ USD
Gold Guardian EA (MT5) Entry Strategy Trade only XAUUSD. Default timeframe: M5. Buy when: 20 EMA crosses above 50 EMA. RSI (14) is above 55. ADX (14) is above 25 (strong trend). Sell when: 20 EMA crosses below 50 EMA. RSI (14) is below 45. ADX (14) is above 25. Only one open trade at a time. Risk Management Risk 1% of account balance per trade (adjustable). Automatic lot size based on stop-loss distance. Daily loss
I am looking for an experienced MetaTrader 5 expert. I already have 3 MT5 trading accounts. I need someone to: 1. Help me choose a reliable Windows VPS. 2. Connect to my VPS remotely (AnyDesk or TeamViewer). 3. Install 3 MetaTrader 5 terminals. 4. Configure: - 1 Master Account - 2 Slave Accounts 5. Install and configure a professional Trade Copier. 6. Copy all trades from the Master account to both Slave
Project: Fib Grid Entry — Automated Trading Strategy (Sierra Chart / ACSIL, C++) I need a Sierra Chart custom study (Advanced Custom Study, C++/ACSIL) that automates a Fibonacci-based split-entry strategy. The core idea: I draw a Fibonacci Retracement on the chart by hand using Sierra Chart's own Price Retracement tool (Tools → Price Retracement), and the strategy should read that drawing's two anchor points
Online Ordering System para sa Milk Tea Shop* *1. Layunin ng Project* Gumawa ng website at mobile app kung saan makaka-order ang mga customer ng milk tea online. Para hindi na pumila at para mas madali i-track yung mga orders. *2. Mga Kailangan / Features* - *Para sa Customer:* - Mag-register at mag-login gamit ang email at number - Makita ang menu na may picture, presyo, at description - Makapag-customize ng
I am looking for a highly experienced developer to build a professional, commercial-grade trading indicator for MT4/MT5. I am not looking for a basic indicator or a modified public script. I need a custom solution based on real market logic with high-quality coding standards. Requirements 100% Non-Repainting indicator. Accurate Entry signals. Automatic Stop Loss placement based on real market structure. Automatic
I need a custom MT5 Expert Advisor (MQL5) for XAUUSD. Strategy: 1. Trend Filter (H1) - EMA 20, EMA 50 and EMA 200. - Buy only when EMA20 > EMA50 > EMA200 and price is above EMA200. - Sell only when EMA20 < EMA50 < EMA200 and price is below EMA200. 2. Confirmation (M15) - M15 trend must confirm the H1 trend before taking any trade. 3. Entry (M5) - Wait for price to pull back to EMA20 only. - After touching EMA20, wait
Mac200 50+ USD
I need a Trend following Bot. Here we took entries by looking at two indicator which are 200 period ema and 12 26 9 MacD. Rules for entry exit are: Buy trade: When market is above 200 ema and MacD Line cross over the signal line and this cross over happened below the zero line of MacD indicator. We simply put Buy trade. Sell trade: When market is below 200 ema and MacD line crosses below the signal line and this

Project information

Budget
30+ USD
Deadline
to 1 day(s)