Page 2 of 3

Re: Prop firms that require a stop loss on every trade

Posted: Sun Nov 08, 2026 12:42 pm
by PTScalper
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.

Code: Select all

//+------------------------------------------------------------------+
//|                                              AutoStopLoss2Pct.mq5|
//+------------------------------------------------------------------+
#property copyright "Auto SL Utility"
#property version   "1.00"

#include <Trade\Trade.mqh>

//--- Input parameters
input double InpStopLossPercent = 2.0; // Stop Loss distance in % of the entry price

CTrade trade;

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   // Loop through all open positions backwards
   for(int i = PositionsTotal() - 1; i >= 0; i--)
     {
      ulong ticket = PositionGetTicket(i);
      
      if(ticket > 0)
        {
         string symbol = PositionGetString(POSITION_SYMBOL);
         
         // Only manage positions for the chart this EA is attached to
         if(symbol != _Symbol) continue; 

         double current_sl = PositionGetDouble(POSITION_SL);
         
         // If Stop Loss is not set (0.0)
         if(current_sl == 0.0)
           {
            double open_price = PositionGetDouble(POSITION_PRICE_OPEN);
            double tp = PositionGetDouble(POSITION_TP);
            long type = PositionGetInteger(POSITION_TYPE);
            
            // Calculate 2% of the entry price
            double sl_distance = open_price * (InpStopLossPercent / 100.0);
            double new_sl = 0.0;
            
            if(type == POSITION_TYPE_BUY)
              {
               new_sl = open_price - sl_distance;
              }
            else if(type == POSITION_TYPE_SELL)
              {
               new_sl = open_price + sl_distance;
              }
              
            // Normalize the price to the symbol's digits to prevent server errors
            int digits = (int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);
            new_sl = NormalizeDouble(new_sl, digits);
            
            // Send the modification request to the server
            if(new_sl > 0.0)
              {
               trade.PositionModify(ticket, new_sl, tp);
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+

Re: Prop firms that require a stop loss on every trade

Posted: Sun Nov 08, 2026 12:43 pm
by PTScalper
How to Install and Use It

1.) Open your MetaTrader 5 terminal and press F4 to open MetaEditor.

2.) In the top left, click New > Expert Advisor (template) > click Next and name it AutoStopLoss2Pct.

3.) Delete the default code, paste the code provided above, and press F7 to compile it.

4.) Go back to MetaTrader 5. Look in your Navigator panel under Expert Advisors, and drag the new EA onto your trading chart.

5.) Ensure the Algo Trading button at the top of MT5 is green (enabled).

Re: Prop firms that require a stop loss on every trade

Posted: Sun Nov 08, 2026 12:43 pm
by PTScalper
A Note on the 2% Calculation

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?

Re: Prop firms that require a stop loss on every trade

Posted: Sun Nov 08, 2026 12:44 pm
by PTScalper
Here are the complete Expert Advisor and cBot codes to automatically apply a 2% Stop Loss to your trades in both MetaTrader 4 and cTrader.

Like the MQL5 version, these will run continuously in the background and instantly assign a Stop Loss to any manual trades you open on that chart.

Re: Prop firms that require a stop loss on every trade

Posted: Sun Nov 08, 2026 12:44 pm
by PTScalper
1. MetaTrader 4 (MQL4) Expert Advisor

MT4 uses slightly older functions than MT5, relying on the OrderSelect() loop rather than the position tracking system.

Code: Select all

//+------------------------------------------------------------------+
//|                                              AutoStopLoss2Pct.mq4|
//+------------------------------------------------------------------+
#property strict

//--- Input parameters
input double InpStopLossPercent = 2.0; // Stop Loss distance in % of the entry price

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   // Loop through all open orders backwards
   for(int i = OrdersTotal() - 1; i >= 0; i--)
     {
      // Select the order
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
         // Only modify trades for the current chart symbol that lack a Stop Loss
         if(OrderSymbol() == Symbol() && OrderStopLoss() == 0.0)
           {
            double open_price = OrderOpenPrice();
            double sl_distance = open_price * (InpStopLossPercent / 100.0);
            double new_sl = 0.0;
            
            if(OrderType() == OP_BUY)
              {
               new_sl = open_price - sl_distance;
              }
            else if(OrderType() == OP_SELL)
              {
               new_sl = open_price + sl_distance;
              }
            else
              {
               continue; // Ignore pending orders like Buy Limits or Sell Stops
              }
              
            // Normalize the price to the symbol's digits to prevent "Invalid Stops" errors
            new_sl = NormalizeDouble(new_sl, Digits);
            
            if(new_sl > 0.0)
              {
               bool success = OrderModify(OrderTicket(), OrderOpenPrice(), new_sl, OrderTakeProfit(), 0, clrNONE);
               if(!success)
                  Print("Error modifying order SL: ", GetLastError());
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+

Re: Prop firms that require a stop loss on every trade

Posted: Sun Nov 08, 2026 12:44 pm
by PTScalper
How to install in MT4:

1.) Press F4 to open MetaEditor.

2.) Click New > Expert Advisor (template) > name it AutoStopLoss2Pct.

3.) Replace the default code with this script, press F7 to compile, and drag it onto your MT4 chart with the AutoTrading button enabled.

Re: Prop firms that require a stop loss on every trade

Posted: Sun Nov 08, 2026 12:45 pm
by PTScalper
2. cTrader (C#) cBot

cTrader uses C# for its algorithms. The cTrader API is very modern, allowing us to easily filter for positions without a Stop Loss using LINQ.

Code: Select all

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);
            }
        }
    }
}

Re: Prop firms that require a stop loss on every trade

Posted: Sun Nov 08, 2026 12:45 pm
by PTScalper
How to install in cTrader:

1.) Open the Automate tab on the left sidebar.

2.) Click New cBot at the top and name it AutoStopLoss2Pct.

3.) Replace the default C# code with the snippet above.

4.) Click the Build button (hammer icon) at the top. Add an instance to your chart and press the Play button to start it.

Re: Prop firms that require a stop loss on every trade

Posted: Sun Nov 08, 2026 12:46 pm
by PTScalper
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.

Re: Prop firms that require a stop loss on every trade

Posted: Sun Nov 08, 2026 12:46 pm
by PTScalper
Pine script:

Code: Select all

//@version=5
strategy("Auto Stop Loss 2%", overlay=true, initial_capital=1000)

// --- Input Parameters ---
slPercent = input.float(2.0, title="Stop Loss (%)", step=0.1)

// --- Placeholder Entry Logic ---
// Replace this with your own scalping entry conditions
fastMA = ta.sma(close, 9)
slowMA = ta.sma(close, 21)

longCondition = ta.crossover(fastMA, slowMA)
shortCondition = ta.crossunder(fastMA, slowMA)

if (longCondition)
    strategy.entry("Long", strategy.long)

if (shortCondition)
    strategy.entry("Short", strategy.short)

// --- Auto Stop Loss Logic ---
// Calculate and apply the SL automatically whenever a position is open
if (strategy.position_size > 0)
    // Long position SL: Entry Price - 2%
    longSL = strategy.position_avg_price * (1 - (slPercent / 100))
    strategy.exit("Exit Long", from_entry="Long", stop=longSL)

if (strategy.position_size < 0)
    // Short position SL: Entry Price + 2%
    shortSL = strategy.position_avg_price * (1 + (slPercent / 100))
    strategy.exit("Exit Short", from_entry="Short", stop=shortSL)