Problème avec un script...

 
J'ai des problèmes avec un script, j'aimerais recevoir de l'aide svp


//+------------------------------------------------------------------+
//|                                       RISK_2_REWARD_SIMULATOR.mq5 |
//|                        Copyright 2024, MetaQuotes Software Corp. |
//|                                       https://www.mql5.com      |
//+------------------------------------------------------------------+
#property copyright "2024"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_buffers 0
#property indicator_plots   0

//--- input parameters
input color RiskLineColor = clrRed;
input color RewardLineColor = clrLime;
input color LabelColor = clrWhite;
input int LineWidth = 3;
input int LineStyle = STYLE_DOT;
input int LabelFontSize = 14;
input string LabelFont = "Tahoma";
input int MaxInstances = 10;
input int LineLength = 150; // Length of lines in points

//--- internal variables
int instanceCounter = 0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   // Initialization code
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
void OnTick()
  {
   // Prevent exceeding the maximum number of instances
   if (ObjectsTotal() >= MaxInstances * 6) // Increase limit for buttons and labels
     {
      Print("Maximum number of instances reached.");
      return;
     }

   // Generate a unique ID for this instance
   string id = "Instance_" + IntegerToString(instanceCounter++);

   // Example data for demonstration
   datetime startTime = TimeCurrent() - 3600; // 1 hour ago
   datetime endTime = TimeCurrent();
   double entryPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID);
   double riskLevel = entryPrice - LineLength * _Point;
   double rewardLevel = entryPrice + LineLength * _Point;

   // Draw Risk Line
   if (!ObjectCreate(0, id + "_RiskLine", OBJ_TREND, 0, startTime, riskLevel, endTime, riskLevel))
     {
      Print("Error creating RiskLine: ", GetLastError());
      return;
     }
   ObjectSetInteger(0, id + "_RiskLine", OBJPROP_COLOR, RiskLineColor);
   ObjectSetInteger(0, id + "_RiskLine", OBJPROP_WIDTH, LineWidth);
   ObjectSetInteger(0, id + "_RiskLine", OBJPROP_STYLE, LineStyle);
   ObjectSetString(0, id + "_RiskLine", OBJPROP_TEXT, "Risk Level");

   // Draw Reward Line
   if (!ObjectCreate(0, id + "_RewardLine", OBJ_TREND, 0, startTime, rewardLevel, endTime, rewardLevel))
     {
      Print("Error creating RewardLine: ", GetLastError());
      return;
     }
   ObjectSetInteger(0, id + "_RewardLine", OBJPROP_COLOR, RewardLineColor);
   ObjectSetInteger(0, id + "_RewardLine", OBJPROP_WIDTH, LineWidth);
   ObjectSetInteger(0, id + "_RewardLine", OBJPROP_STYLE, LineStyle);
   ObjectSetString(0, id + "_RewardLine", OBJPROP_TEXT, "Reward Level");

   // Calculate Risk/Reward Ratio
   double risk = MathAbs(rewardLevel - riskLevel);
   double reward = MathAbs(rewardLevel - entryPrice);
   double ratio = reward / risk;
   string ratioText = StringFormat("Risk/Reward: %.2f", ratio);

   // Draw Ratio Label
   if (!ObjectCreate(0, id + "_RatioLabel", OBJ_LABEL, 0, 0, 0))
     {
      Print("Error creating RatioLabel: ", GetLastError());
      return;
     }
   ObjectSetText(id + "_RatioLabel", ratioText, LabelFontSize, LabelFont, LabelColor);
   ObjectSetInteger(0, id + "_RatioLabel", OBJPROP_XDISTANCE, 20);
   ObjectSetInteger(0, id + "_RatioLabel", OBJPROP_YDISTANCE, 40);
   ObjectSetInteger(0, id + "_RatioLabel", OBJPROP_COLOR, LabelColor);
   ObjectSetInteger(0, id + "_RatioLabel", OBJPROP_FONTSIZE, LabelFontSize);

   // Draw Interactive Buttons
   DrawButtons(id, startTime, riskLevel, rewardLevel);
  }

//+------------------------------------------------------------------+
//| Function to draw interactive buttons                            |
//+------------------------------------------------------------------+
void DrawButtons(string id, datetime startTime, double riskLevel, double rewardLevel)
  {
   // Draw Increase Risk Button
   string increaseRiskBtn = id + "_IncreaseRiskBtn";
   if (!ObjectCreate(0, increaseRiskBtn, OBJ_BUTTON, 0, 0, 0))
     {
      Print("Error creating Increase Risk Button: ", GetLastError());
      return;
     }
   ObjectSetString(0, increaseRiskBtn, OBJPROP_TEXT, "Increase Risk");
   ObjectSetInteger(0, increaseRiskBtn, OBJPROP_COLOR, clrYellow);
   ObjectSetInteger(0, increaseRiskBtn, OBJPROP_XSIZE, 120);
   ObjectSetInteger(0, increaseRiskBtn, OBJPROP_YSIZE, 20);
   ObjectSetInteger(0, increaseRiskBtn, OBJPROP_XDISTANCE, 10);
   ObjectSetInteger(0, increaseRiskBtn, OBJPROP_YDISTANCE, 10);

   // Draw Decrease Risk Button
   string decreaseRiskBtn = id + "_DecreaseRiskBtn";
   if (!ObjectCreate(0, decreaseRiskBtn, OBJ_BUTTON, 0, 0, 0))
     {
      Print("Error creating Decrease Risk Button: ", GetLastError());
      return;
     }
   ObjectSetString(0, decreaseRiskBtn, OBJPROP_TEXT, "Decrease Risk");
   ObjectSetInteger(0, decreaseRiskBtn, OBJPROP_COLOR, clrOrange);
   ObjectSetInteger(0, decreaseRiskBtn, OBJPROP_XSIZE, 120);
   ObjectSetInteger(0, decreaseRiskBtn, OBJPROP_YSIZE, 20);
   ObjectSetInteger(0, decreaseRiskBtn, OBJPROP_XDISTANCE, 10);
   ObjectSetInteger(0, decreaseRiskBtn, OBJPROP_YDISTANCE, 40);

   // Draw Update Button
   string updateBtn = id + "_UpdateBtn";
   if (!ObjectCreate(0, updateBtn, OBJ_BUTTON, 0, 0, 0))
     {
      Print("Error creating Update Button: ", GetLastError());
      return;
     }
   ObjectSetString(0, updateBtn, OBJPROP_TEXT, "Update");
   ObjectSetInteger(0, updateBtn, OBJPROP_COLOR, clrAqua);
   ObjectSetInteger(0, updateBtn, OBJPROP_XSIZE, 120);
   ObjectSetInteger(0, updateBtn, OBJPROP_YSIZE, 20);
   ObjectSetInteger(0, updateBtn, OBJPROP_XDISTANCE, 10);
   ObjectSetInteger(0, updateBtn, OBJPROP_YDISTANCE, 70);
  }

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   // Remove all objects when the script is removed
   for (int i = 0; i < MaxInstances; i++)
     {
      string id = "Instance_" + IntegerToString(i);
      ObjectDelete(id + "_RiskLine");
      ObjectDelete(id + "_RewardLine");
      ObjectDelete(id + "_RatioLabel");
      ObjectDelete(id + "_IncreaseRiskBtn");
      ObjectDelete(id + "_DecreaseRiskBtn");
      ObjectDelete(id + "_UpdateBtn");
     }
  }

Les erreurs:

'RISK_2_REWARD_SIMULATOR.mq5' RISK_2_REWARD_SIMULATOR.mq5 1 1
'ObjectsTotal' - wrong parameters count RISK_2_REWARD_SIMULATOR.mq5 41 8
   built-in: int ObjectsTotal(long,int,int) RISK_2_REWARD_SIMULATOR.mq5 41 8
'ObjectSetText' - undeclared identifier RISK_2_REWARD_SIMULATOR.mq5 91 4
',' - unexpected token RISK_2_REWARD_SIMULATOR.mq5 91 36
'+' - some operator expected RISK_2_REWARD_SIMULATOR.mq5 91 21
',' - unexpected token RISK_2_REWARD_SIMULATOR.mq5 91 47
',' - unexpected token RISK_2_REWARD_SIMULATOR.mq5 91 62
expression has no effect RISK_2_REWARD_SIMULATOR.mq5 91 49
',' - unexpected token RISK_2_REWARD_SIMULATOR.mq5 91 73
expression has no effect RISK_2_REWARD_SIMULATOR.mq5 91 64
')' - unexpected token RISK_2_REWARD_SIMULATOR.mq5 91 85
expression has no effect RISK_2_REWARD_SIMULATOR.mq5 91 75
'ObjectDelete' - wrong parameters count RISK_2_REWARD_SIMULATOR.mq5 158 7
   built-in: bool ObjectDelete(long,const string) RISK_2_REWARD_SIMULATOR.mq5 158 7
'ObjectDelete' - wrong parameters count RISK_2_REWARD_SIMULATOR.mq5 159 7
   built-in: bool ObjectDelete(long,const string) RISK_2_REWARD_SIMULATOR.mq5 159 7
'ObjectDelete' - wrong parameters count RISK_2_REWARD_SIMULATOR.mq5 160 7
   built-in: bool ObjectDelete(long,const string) RISK_2_REWARD_SIMULATOR.mq5 160 7
'ObjectDelete' - wrong parameters count RISK_2_REWARD_SIMULATOR.mq5 161 7
   built-in: bool ObjectDelete(long,const string) RISK_2_REWARD_SIMULATOR.mq5 161 7
'ObjectDelete' - wrong parameters count RISK_2_REWARD_SIMULATOR.mq5 162 7
   built-in: bool ObjectDelete(long,const string) RISK_2_REWARD_SIMULATOR.mq5 162 7
'ObjectDelete' - wrong parameters count RISK_2_REWARD_SIMULATOR.mq5 163 7
   built-in: bool ObjectDelete(long,const string) RISK_2_REWARD_SIMULATOR.mq5 163 7
14 errors, 3 warnings 15 4


Découvrez de nouvelles opportunités MetaTrader 5 avec la communauté et les services MQL5
Découvrez de nouvelles opportunités MetaTrader 5 avec la communauté et les services MQL5
  • 2024.07.22
  • www.mql5.com
MQL5 : langage de stratégies de trading intégré à la plateforme de trading MetaTrader 5, permet d'écrire vos propres robots de trading, indicateurs techniques, scripts et bibliothèques de fonctions