ISMA BeatZ:
J'ai des problèmes avec un script, j'aimerais recevoir de l'aide svp
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:
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
//+------------------------------------------------------------------+ //| 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(0, 0, -1) >= MaxInstances * 6) // Corrected parameters for ObjectsTotal { 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); // 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); // 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; } ObjectSetString(0, id + "_RatioLabel", OBJPROP_TEXT, ratioText); 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(0, id + "_RiskLine"); // Corrected parameters for ObjectDelete ObjectDelete(0, id + "_RewardLine"); ObjectDelete(0, id + "_RatioLabel"); ObjectDelete(0, id + "_IncreaseRiskBtn"); ObjectDelete(0, id + "_DecreaseRiskBtn"); ObjectDelete(0, id + "_UpdateBtn"); } } //essaye ça

Vous manquez des opportunités de trading :
- Applications de trading gratuites
- Plus de 8 000 signaux à copier
- Actualités économiques pour explorer les marchés financiers
Inscription
Se connecter
Vous acceptez la politique du site Web et les conditions d'utilisation
Si vous n'avez pas de compte, veuillez vous inscrire
Les erreurs: