This is for MT5.
It will look for two lines on the chart.
One line is Limit Order
The other is Stop Loss
I'm still trying to figure out how to create an object since it is market close.
It works both ways for buy or sell orders
It will look for two lines on the chart.
One line is Limit Order
The other is Stop Loss
I'm still trying to figure out how to create an object since it is market close.
It works both ways for buy or sell orders
Inserted Code
//+------------------------------------------------------------------+ //| LotSizeCalc.mq5| //| Copyright 2023, MetaQuotes Ltd.| //| https://www.mql5.com| //+------------------------------------------------------------------+ #property copyright "MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #property script_show_inputs //--- input parameters input string BuyOrderLabel = "Limit Order"; // Label name for the buy order line input string StopLossLabel = "Stop Loss"; // Label name for the stop loss line input double RiskPercentage = 1.0; // Risk percentage per trade //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { // Find the lines on the chart by their labels int buyLine = ObjectFind(0, BuyOrderLabel); int slLine = ObjectFind(0, StopLossLabel); if (buyLine < 0 || slLine < 0) { MessageBox("Lines not found. Please draw the 'Buy Order' and 'Stop Loss' lines on the chart."); return; } // Get the price values of the lines double buyPrice = ObjectGetDouble(0, BuyOrderLabel, OBJPROP_PRICE); double slPrice = ObjectGetDouble(0, StopLossLabel, OBJPROP_PRICE); // Calculate the distance between the lines in points double pointSize = SymbolInfoDouble(_Symbol, SYMBOL_POINT); double distanceInPoints = MathAbs(buyPrice - slPrice) / pointSize; // Calculate the lot size based on the risk percentage and account balance double accountBalance = AccountInfoDouble(ACCOUNT_BALANCE); double lotSize = accountBalance * RiskPercentage / distanceInPoints; // Calculate the amount of money loss at the Stop Loss level double stopLossAmount = lotSize * distanceInPoints * pointSize; double printLotSize = DoubleToString(lotSize/100, 2); Alert("Distance in points: ", DoubleToString(distanceInPoints, 2)); Alert("Lot Size: ", printLotSize); Alert("Amount Loss at Stop Loss Level: ", DoubleToString(stopLossAmount, 2)); Alert("Stop Loss Level: ", DoubleToString(slPrice, SymbolInfoInteger(_Symbol, SYMBOL_DIGITS))); }
You're going to pay a price for every bloody thing you do and don't do