promart
Download scriptThis trading script is designed to automate market entries and manage risk using a combination of technical momentum indicators and a recovery strategy. Below is a detailed breakdown of how the logic operates:
Core Trading Strategy
The script relies on two different MACD (Moving Average Convergence Divergence) indicators. These are used to identify the "momentum" of the market—essentially determining whether the price has enough strength to continue moving in a specific direction.
To enter a trade, the script looks for specific patterns in these indicators:
- Buy Signals: It seeks a specific "V-shape" pattern where the price hits a low point and begins to bounce upward, accompanied by a corresponding shift in the momentum indicators.
- Sell Signals: Conversely, it looks for an inverted pattern where the price reaches a peak and begins to drop, confirmed by a downward shift in the momentum indicators.
Smart Trade Management & Recovery
The logic includes a sophisticated way of handling wins and losses to manage the account balance:
- Profit Tracking: The script reviews your trade history to see how your previous trades performed.
- Conditional Re-entry: If a previous trade resulted in a loss, the script evaluates whether the market is still moving in that same direction or if it has reversed. This helps prevent "revenge trading" and ensures the script doesn't enter a new position against a strong trend.
- Martingale Component: The script utilizes a "Martingale-style" logic. When a trade is opened, it calculates the appropriate lot size based on previous outcomes. This means the system can automatically adjust the volume of its trades to help recover losses from previous unsuccessful positions.
Execution Rules
The script follows strict guidelines to ensure disciplined trading:
- Entry Timing: It only checks for new opportunities when a "tick" occurs that represents a change in market activity, ensuring it doesn't over-trade during stagnant periods.
- Trade Protection: Every trade is automatically armored with two critical safety nets:
- Stop Loss (SL): A predetermined price point where the trade will close automatically to prevent significant capital loss.
- Take Profit (TP): A target price point where the trade will close to secure gains once the desired profit is reached.
- Unique Identification: It uses a "Magic Number" system, which allows it to distinguish its own trades from other manual or automated trades you might have running on the same account.
Summary for the User
In plain terms, this script acts as an automated assistant that watches the charts for specific price "reversals." When it sees a potential move, it opens a trade with a calculated size based on your history. It automatically manages your risk by setting profit targets and safety stops on every trade, aiming to balance the goal of recovering from losses with the objective of capturing steady market momentum.
//+------------------------------------------------------------------+
//| MartGreg_1.mq5 |
//| Copyright 2010, Alf. |
//| http://forum.liteforex.org/showthread.php?p=6210#post6210 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, Alf."
#property link "http://forum.liteforex.org/showthread.php?p=6210#post6210"
#property version "1.00"
#include <OnTesterFunctions.mqh>
#include <Martingail.mqh>
//--- input parameters
input double DML=1000;
input int Ud=1;
input int Stop=500;
input int Tp=1500;
input int Slipage=50;
input int MACD1Fast=5;
input int MACD1Slow=20;
input int MACD2Fast=10;
input int MACD2Slow=15;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int m1=0;
int m2=0;
Martingail lt;
//+------------------------------------------------------------------+
//| Open |
//+------------------------------------------------------------------+
void Open()
{
double t[3];
double k[2];
int poz=0;
if(CopyBuffer(m1,0,1,3,t)<0) return;
if(CopyBuffer(m2,0,1,2,k)<0) return;
MqlTick last_tick;
SymbolInfoTick(_Symbol,last_tick);
MqlTradeResult result;
MqlTradeRequest request;
HistorySelect(0,TimeCurrent());
if(HistoryOrdersTotal()==0)
{
if(t[0]>t[1] && t[1]<t[2] && k[1]>k[0]) poz=1;
if(t[0]<t[1] && t[1]>t[2] && k[1]<k[0]) poz=-1;
}
else
{
double cl=HistoryOrderGetDouble(HistoryOrderGetTicket(HistoryOrdersTotal()-1),ORDER_PRICE_OPEN);
double op=HistoryOrderGetDouble(HistoryOrderGetTicket(HistoryOrdersTotal()-2),ORDER_PRICE_OPEN);
long ot=HistoryOrderGetInteger(HistoryOrderGetTicket(HistoryOrdersTotal()-2),ORDER_TYPE);
if(ot==ORDER_TYPE_BUY)
{
if(cl-op>0)
{
if(t[0]>t[1] && t[1]<t[2] && k[1]>k[0]) poz=1;
if(t[0]<t[1] && t[1]>t[2] && k[1]<k[0]) poz=-1;
}
else poz=-1;
}
else
{
if(op-cl>0)
{
if(t[0]>t[1] && t[1]<t[2] && k[1]>k[0]) poz=1;
if(t[0]<t[1] && t[1]>t[2] && k[1]<k[0]) poz=-1;
}
else poz=1;
}
}
Print("Poz=",poz);
request.symbol=_Symbol;
request.magic=777;
request.deviation=50;
request.action=TRADE_ACTION_DEAL;
request.type_filling=ORDER_FILLING_AON;
if(poz==1)
{
request.volume=lt.Lot();
request.price=last_tick.ask;
request.type=ORDER_TYPE_BUY;
request.sl=last_tick.bid-Stop*Point();
request.tp=last_tick.ask+Tp*Point();
OrderSend(request,result);
}
if(poz==-1)
{
request.volume=lt.Lot();
request.price=last_tick.bid;
request.type=ORDER_TYPE_SELL;
request.sl=last_tick.ask+Stop*Point();
request.tp=last_tick.bid-Tp*Point();
OrderSend(request,result);
}
}
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
m1=iMACD(_Symbol,0,MACD1Fast,MACD1Slow,3,PRICE_MEDIAN);
m2=iMACD(_Symbol,0,MACD2Fast,MACD2Slow,3,PRICE_MEDIAN);
lt.GVarName="PMG_1";
lt.Shape=DML;
lt.DoublingCount=Ud;
lt.GVarGet();
//---
return(0);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
lt.GVarSet();
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
MqlRates rt[1];
if(CopyRates(Symbol(),_Period,0,1,rt)<0) return;
if(rt[0].tick_volume>1) return;
if(!PositionSelect(_Symbol))Open();
}
//+------------------------------------------------------------------+
//| Expert OnTester function |
//+------------------------------------------------------------------+
double OnTester()
{
double p=profitc_divide_lossc();
double s=max_series_loss();
if(Tp<Stop) return 0;
s=s+1;
return p/s;
}
//+------------------------------------------------------------------+
Comments