1
0
Derivar 0
MQLArticles/Examples/Get_Sl_by_risk_per_operation_and_lot.mq5

46 linhas
3,6 KiB
MQL5

2025-09-22 12:05:10 -05:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| Get Sl by risk per operation and lot.mq5 |
//| Your name |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Your name"
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property script_show_inputs
#include "..\\RM\\RiskManagement.mqh"
input ENUM_ORDER_TYPE InpOrderType = ORDER_TYPE_BUY; // Order Type:
input double InpEntryPrice = 10.0 ;// Entry price
input double InpRiskPerOperation = 1.0; // Risk per operation in %
input double InpLot = 0.01; // Lot size
input ulong InpDeviation = 0; // Deviation
input ulong InpStopLimit = 0; // StopLimit
//+------------------------------------------------------------------+
//| Main script function |
//+------------------------------------------------------------------+
void OnStart()
{
CGetLote get_lote(_Symbol);
const long calculate_sl = get_lote.CalculateSLWithLot(InpOrderType, InpRiskPerOperation, InpEntryPrice, InpLot, InpDeviation, InpStopLimit);
if(calculate_sl <= 0)
{
//--- Invalid stop loss
Comment("The lot size is too high or the risk per operation is too low. Increase the risk or decrease the lot size.");
}
else
{
//--- Display calculated values
Print("For lot: ", InpLot, ", and risk: ", InpRiskPerOperation, ", the ideal SL is: ", calculate_sl);
Comment("Ideal SL: ", calculate_sl, " Points");
}
Sleep(10000); // Sleep for 10 seconds
Comment(""); // Clean
}
//+------------------------------------------------------------------+