TrueScalperProfitLock_v1

Download script
Author: Copyright � 2005, International Federation of Red Cross.
Profit factor:
0.49

Strategy Overview

This script is an automated trading tool designed to manage market entries, risk levels, and trade protection. It combines technical indicators—specifically Moving Averages and the Relative Strength Index (RSI)—with advanced management features like automated "Break-Even" locks and time-based exit strategies.

Core Trading Logic

The system identifies opportunities by comparing two different types of moving averages. It looks for specific momentum shifts where a short-term average crosses over or under a longer-term average, while simultaneously validating the market's strength using an RSI indicator.

Depending on the settings chosen, the script can interpret these signals in two ways:

  • Method A: Looks for a specific "cross" or transition in the RSI values.
  • Method B: Simply checks if the RSI is currently above or below a set threshold.

When both the moving average conditions and the RSI requirements are met, the script triggers an entry signal to either "Buy" (going long) or "Sell" (going short).

Risk and Money Management

The script includes built-in safeguards to ensure responsible trading:

  • Automated Lot Sizing: Instead of always trading a fixed amount, the system can automatically calculate your trade size based on a percentage of your current account balance. It ensures that the volume remains within safe limits and adjusts automatically for different types of accounts (like "Mini" accounts).
  • Margin Protection: The tool checks your available funds before opening a trade to ensure you have enough margin to cover the position.

Trade Protection Features

One of the primary functions of this script is its ability to manage a trade once it is already open:

  • Profit Lock (Break-Even): This feature monitors active trades in real-time. If a trade moves into profit by a specific amount (the "Trigger"), the script automatically moves the Stop Loss to the entry price plus a small profit buffer. This ensures that if the market reverses, you exit the trade without losing your initial investment.
  • Abandon Methods: These are time-based safety nets. If a trade remains open for a specific number of bars (candles) without reaching its target, the script can intervene:
    • It can force a "Hedge" by closing the current position and immediately opening an opposing one.
    • Alternatively, it can simply close the losing position to prevent further exposure.

Customization and Optimization

The script is designed to be adaptable. It includes specific settings that automatically adjust profit targets, stop losses, and time limits for certain high-volume currency pairs (like GBPUSD), ensuring the logic is tailored to the specific volatility of different markets.

Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategyIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
Moving average indicatorRelative strength index
15 Views
0 Downloads
0 Favorites
TrueScalperProfitLock_v1
//+------------------------------------------------------------------+
//|                                        TrueScalperProfitLock.mq4 |
//|         Copyright © 2005, International Federation of Red Cross. |
//|                                             http://www.ifrc.org/ |
//|                                         Please donate some pips  |
//+------------------------------------------------------------------+
//+-----------------------------------------------------------------------------------------+
//|  Modifications                                                                          |
//|  -------------                                                                          |
//|  1)  Jacob Yego and Ron Thompson: Original version                                      |
//|                                                                                         |
//|  2)  Reworked by Roger. This MT4 version is now identical to                            |
//|                    Roger's earlier MT3 version TrueScalperProfitLock.mql.               |
//|                    Both these versions now include optional RSI validation, optional    |
//|                    Abandon method, MoneyManagement and ProfitLock system.               |
//|                                                                                         |
//| Original Theory of operation (See TrueScalperProfitLock.mql MT3 version for more UPDATED|
//| and DETAILED descriptions)                                                              |
//+-----------------------------------------------------------------------------------------+
#property copyright "Copyright © 2005, International Federation of Red Cross."
#property link      "http://www.ifrc.org/"
// generic user input
extern double Lots=1.0;
extern int    TakeProfit=44;
extern int    StopLoss=90;
extern bool   RSIMethodA=false;
extern bool   RSIMethodB=true;
extern int    RSIValue=50;
extern bool   AbandonMethodA=true;
extern bool   AbandonMethodB=false;
extern int    Abandon=101;
extern bool   MoneyManagement=true;
extern int    Risk=2;
extern int    Slippage=3;
extern bool   UseProfitLock=true;
extern int    BreakEvenTrigger=25;
extern int    BreakEven=3;
extern bool   LiveTrading=false;
extern bool   AccountIsMini=false;
extern int    maxTradesPerPair=1;
extern int    MagicNumber=5432;
//----
double lotMM;
bool BuySignal=false;
bool SetBuy=false;
bool SellSignal=false;
bool SetSell=false;
// Bar handling
datetime bartime=0;
int      bartick=0;
int      TradeBars=0;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   if (UseProfitLock) ProfitLockStop();
   if (AbandonMethodA || AbandonMethodB)
     {
      RunAbandonCheck();
      RunAbandonMethods();
     }
   if (!SetLotsMM()) return(0);
   RunOrderTriggerCalculations();
   RunPairSpesificSettings();
   RunNewOrderManagement();
//----
   return(0);
  }
//  SetLotsMM - By Robert Cochran http://autoforex.biz
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool SetLotsMM()
  {
   double MarginCutoff;
//----
   if(!AccountIsMini) MarginCutoff=1000;
   if(AccountIsMini) MarginCutoff=100;
   if(AccountFreeMargin() < MarginCutoff) return(false);
   if(MoneyManagement)
     {
      lotMM=MathCeil(AccountBalance() * Risk/10000)/10;
//----
      if(lotMM < 0.1) lotMM=Lots;
      if(lotMM > 1.0) lotMM=MathCeil(lotMM);
      // Enforce lot size boundaries
      if(LiveTrading)
        {
         if(AccountIsMini)               lotMM=lotMM * 10;
         if(!AccountIsMini && lotMM < 1.0) lotMM=1.0;
        }
      if(lotMM > 100) lotMM=100;
     }
   else
     {
      lotMM=Lots; // Change MoneyManagement to 0 if you want the Lots parameter to be in effect
     }
   return(true);
  }
//+------------------------------------------------------------------+
//|  RunOrderTriggerCalculations                                     |
//+------------------------------------------------------------------+
bool RunOrderTriggerCalculations()
  {
   bool    RSIPOS=false;
   bool    RSINEG=false;
   // 3-period moving average on Bar[1]
   double bullMA3=iMA(Symbol(),0,3,0,MODE_EMA,PRICE_CLOSE,1);
   // 7-period moving average on Bar[1]
   double bearMA7=iMA(Symbol(),0,7,0,MODE_EMA,PRICE_CLOSE,1);
   // 2-period moving average on Bar[2]
   double RSI=iRSI(Symbol(),0,2,PRICE_CLOSE,2);
   double RSI2=iRSI(Symbol(),0,2,PRICE_CLOSE,1);
   // Determine what polarity RSI is in
   if (RSIMethodA)
     {
      if(RSI>RSIValue && RSI2<RSIValue)
        {
         RSIPOS=true;
         RSINEG=false;
        }
      else RSIPOS=false;
      if(RSI<RSIValue && RSI2>RSIValue)
        {
         RSIPOS=false;
         RSINEG=true;
        }
      else RSINEG=false;
     }
   if (RSIMethodB)
     {
      if(RSI>RSIValue)
        {
         RSIPOS=true;
         RSINEG=false;
        }
      if(RSI<RSIValue)
        {
         RSIPOS=false;
         RSINEG=true;
        }
     }
   if ((bullMA3 > (bearMA7+Point)) && RSINEG)
     {
      BuySignal=true;
     }
   else BuySignal=false;
   if ((bullMA3 < (bearMA7-Point)) && RSIPOS)
     {
      SellSignal=true;
     }
   else SellSignal=false;
   return(true);
  }
// OpenOrdersBySymbolAndComment
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OpenOrdersForThisEA()
  {
   int ofts=0;
   for(int x=0;x<OrdersTotal();x++)
     {
      OrderSelect(x, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
        {
         ofts++;
        }
     }
   return(ofts);
  }
// PROFIT LOCK - By Robert Cochran - http://autoforex.biz
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool ProfitLockStop()
  {
   if(OpenOrdersForThisEA() > 0 )
     {
        for( int i=0; i < OrdersTotal(); i++){
         OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
         //--- LONG TRADES
         if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()== MagicNumber)
           {
            if (Bid>=OrderOpenPrice() + BreakEvenTrigger*Point &&
                OrderOpenPrice() > OrderStopLoss())
              {
               OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + BreakEven * Point, OrderTakeProfit(), Green);
              }
           }
         //--- SHORT TRADES
         if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
           {
            if (Ask <=OrderOpenPrice() - BreakEvenTrigger*Point &&
                OrderOpenPrice() < OrderStopLoss())
              {
               OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice() - BreakEven * Point, OrderTakeProfit(), Blue);
              }
           }
        }
     }
  }
// ABANDON CHECK
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool RunAbandonCheck()
  {
   if(OpenOrdersForThisEA() > 0 )
     {
      if (TradeBars==0 && bartick==0)
        {
         for(int i=0; i < OrdersTotal(); i++)
           {
            if (OrderSymbol()==Symbol())
              {
               TradeBars=MathFloor(CurTime() - OrderOpenTime())/60/Period();
               bartime=Time[0];
               bartick=TradeBars;
              }
           }
        }
      if(bartime!=Time[0])
        {
         bartime=Time[0];
         bartick++;
        }
     }
   return(true);
  }
// RunAbandonMethods
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool RunAbandonMethods()
  {
   if(OpenOrdersForThisEA() > 0 )
     {
      for(int i=0; i < OrdersTotal(); i++)
        {
         OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
         if (AbandonMethodA && bartick==Abandon)//Force "HEDGE" after abandon
           {
            // LONG TRADES
            if (OrderType()==OP_BUY && OrderSymbol()==Symbol() &&
            OrderMagicNumber()==MagicNumber)
              {
               OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue);
               SetSell=true;
               continue;
              }
            // SHORT TRADES
            if (OrderType()==OP_SELL && OrderSymbol()==Symbol() &&
            OrderMagicNumber()==MagicNumber)
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Blue);
               SetBuy=true;
               continue;
              }
           }
         if (AbandonMethodB && bartick==Abandon)//Indicators decide direction after abandon
           {
            // LONG TRADES
            if (OrderType()==OP_BUY && OrderSymbol()==Symbol() &&
            OrderMagicNumber()==MagicNumber)
              {
               OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,White);
               continue;
              }
            // SHORT TRADES
            if (OrderType()==OP_SELL && OrderSymbol()==Symbol() &&
            OrderMagicNumber()==MagicNumber)
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,White);
               continue;
              }
           }
        }
     }
   return(true);
  }
// RunPairSpesificSettings
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool RunPairSpesificSettings()
  {
   // set up the symbol optimizations
   if (Symbol()=="GBPUSD")
     {
      TakeProfit=55; StopLoss=100; Abandon=69;
     }
   return(true);
  }
// RunNewOrderManagement
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool RunNewOrderManagement()
  {
   double  TP,SL;
//----
   if(OpenOrdersForThisEA() < maxTradesPerPair )
     {
      //ENTRY Ask(buy, long) 
      if (BuySignal || SetBuy)
        {
         SL=Ask - StopLoss*Point;
         TP=Ask + TakeProfit*Point;
         OrderSend(Symbol(),OP_BUY,lotMM,Ask,Slippage,SL,TP,"TS-ProfitLock - "+Symbol()+" - Long",MagicNumber,0,White);
         bartick=0;
         if (SetBuy) SetBuy=false;
         return(true);
        }
      //ENTRY Bid (sell, short)
      if (SellSignal || SetSell)
        {
         SL=Bid + StopLoss*Point;
         TP=Bid - TakeProfit*Point;
         OrderSend(Symbol(),OP_SELL,lotMM,Bid,Slippage,SL,TP,"TS-ProfitLock - "+Symbol()+" - Short",MagicNumber,0,Red);
         bartick=0;
         if (SetSell) SetSell=false;
         return(true);
        }
     }
   return(true);
  }
//+------------------------------------------------------------------+

Profitability Reports

PERFORMANCE BY SYMBOL

Expected payoff

Average expected payoff across the available backtests for each symbol.

Positive Negative
2 reports
GBP/USD Oct 2024 - Jan 2025
0.50
Total Trades 1393
Won Trades 880
Lost trades 513
Win Rate 63.17 %
Expected payoff -3.62
Gross Profit 5100.90
Gross Loss -10150.00
Total Net Profit -5049.10
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
0.48
Total Trades 803
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -3.55
Gross Profit 2646.40
Gross Loss -5499.00
Total Net Profit -2852.60
-100%
-50%
0%
50%
100%

Comments