Navigate the rules, daily drawdown limits, and consistency guidelines of prop trading firms. Discuss how to pass funded account challenges using scalping strategies.
To automatically catch every trade you open and set a Stop Loss, you need an Expert Advisor (EA) rather than a basic Script. A Script only runs once and stops, whereas an EA runs continuously in the background on every price tick, ensuring any manual trade you open is instantly protected.
Here is the complete MQL5 EA code that will automatically assign a 2% Stop Loss to any unprotected trade on the chart you attach it to.
This code calculates 2% of the asset's price (e.g., if Bitcoin is at $100,000, it sets a $2,000 stop loss).
If you are trading Forex (like EUR/USD at 1.1000), a 2% price drop is 220 pips, which is unusually wide for a scalper.
If your goal was instead to risk 2% of your account balance based on lot size, that requires a different calculation using account equity and tick value. If you need balance-based risk rather than price-based distance, let me know.
Would you like to adjust this script to risk 2% of your account balance instead of a 2% asset price move?
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
using System;
using cAlgo.API;
using System.Linq;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class AutoStopLoss2Pct : Robot
{
[Parameter("Stop Loss (%)", DefaultValue = 2.0, MinValue = 0.1)]
public double StopLossPercent { get; set; }
protected override void OnTick()
{
// Find all open positions for the current chart's symbol that do NOT have a Stop Loss
var unprotectedPositions = Positions.FindAll(SymbolName).Where(p => !p.HasStopLoss);
foreach (var position in unprotectedPositions)
{
double slDistance = position.EntryPrice * (StopLossPercent / 100.0);
double newSl = 0.0;
if (position.TradeType == TradeType.Buy)
{
newSl = position.EntryPrice - slDistance;
}
else if (position.TradeType == TradeType.Sell)
{
newSl = position.EntryPrice + slDistance;
}
// Round to the symbol's digits to avoid broker rejection
newSl = Math.Round(newSl, Symbol.Digits);
// Modify the position using the absolute price
ModifyPosition(position, newSl, position.TakeProfit);
}
}
}
}
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
TradingView’s Pine Script works fundamentally differently than MetaTrader or cTrader. Pine Script cannot detect manual trades you place through the TradingView chart UI. It can only manage and apply stop losses to trades that the script itself opens.
To use this, you must write your entry conditions directly into the script. The code below provides the framework: it includes demo entry conditions (moving average crossovers) and the core logic that automatically attaches a 2% Stop Loss to any trade the script executes.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.