Author: Copyright 2010, Alf.
Profit factor:
0.00

This automated trading script is designed to manage and execute trades on the financial markets by analyzing price trends and momentum. It uses a combination of technical indicators and a progressive betting strategy to navigate market movements.

Core Trading Logic

The system operates by monitoring two specific moving averages (referred to as Fast and Slow). By comparing these indicators, the script identifies shifts in the market's direction.

  • Buy Signals: The script looks for a specific pattern where the price shows a "bottoming out" motion followed by an upward confirmation. If the trend indicators align to suggest that momentum is turning bullish, the system automatically opens a purchase (Buy) order.
  • Sell Signals: Conversely, the script watches for a "peaking" motion where prices appear to hit a ceiling before potentially dropping. If the momentum indicators confirm a downward shift, the system executes a sale (Sell) order.

Trade Management and Execution

To ensure high-quality execution, the script follows several strict rules:

  • Entry Precision: It uses a "slippage" setting to ensure that trades are executed at prices as close to the desired market value as possible, protecting the user from unfavorable price gaps during high volatility.
  • Risk Control: Every trade is automatically equipped with a Stop Loss (SL) and a Take Profit (TP) level. This ensures that even if a trade moves against the expected direction, the potential loss is capped at a pre-defined limit, while winning trades are closed automatically once they reach a target profit level.
  • Order Filtering: The script includes a safety check to ensure it only acts on "fresh" price changes (tick volume), preventing it from reacting unnecessarily to minor vibrations in the market data.

Advanced Strategy Components

Beyond simple trend following, the script incorporates two sophisticated financial mechanics:

  1. Martingale Strategy: The system utilizes a "Martingale" approach for trade sizing. This means that if a trade results in a loss, the script is configured to adjust the volume of the subsequent trade based on a predefined doubling logic. The goal is to recover previous losses more quickly once a winning trade occurs.
  2. Single Position Management: The script is programmed to monitor active trades. It will generally wait for an existing position to be closed before looking for new entries, preventing the account from becoming over-leveraged with too many simultaneous positions on a single instrument.

Summary for the User

Essentially, this tool acts as an automated floor trader that waits for the market to show signs of a reversal. Once it detects a shift in momentum, it enters a trade with a calculated risk profile and uses a progressive volume strategy to manage the balance between winning and losing cycles.

Price Data Components
Series array that contains open prices of each bar
Orders Execution
It automatically opens orders when conditions are reached
16 Views
0 Downloads
0 Favorites
tootrix_v1
//+------------------------------------------------------------------+
//|                                                         Ichi.mq5 |
//|                        Copyright 2010, Alf.                      |
//|        http://forum.liteforex.org/showthread.php?p=6517#post6517 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, Alf."
#property link      "http://forum.liteforex.org/showthread.php?p=6517#post6517"
#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      Fast=9;
input int      Slow=9;

int m1=0;
int m2=0;

Martingail lt;
//+------------------------------------------------------------------+
//| Open                                                             |
//+------------------------------------------------------------------+
void Open()
  {
   double t[3];
   double k[2];

   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;
   
   ZeroMemory(result);
   ZeroMemory(request);

   request.symbol=_Symbol;
   request.magic=777;
   request.deviation=Slipage;
   request.action=TRADE_ACTION_DEAL;
   request.type_filling=ORDER_FILLING_FOK;
   if(t[0]>t[1] && t[1]<t[2] && k[1]>k[0])
     {
      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(t[0]<t[1] && t[1]>t[2] && k[1]<k[0])
     {
      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=iTriX(_Symbol,0,Fast,PRICE_MEDIAN);
   m2=iTriX(_Symbol,0,Slow,PRICE_MEDIAN);
   lt.GVarName="MG_2";
   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