Author: �����
Profit factor:
0.00

This automated trading script is designed to manage market positions by simultaneously executing opposing trades and monitoring specific profit milestones. Below is a non-technical breakdown of how the logic functions:

Core Trading Mechanism

The script operates on a dual-action strategy where it opens both a Buy position and a Sell position at the same time. To ensure these trades are managed correctly, the script attaches a specific price target (Take Profit) to each order based on a pre-defined point value.

Dynamic Lot Management

One of the key features of this logic is its approach to trade volume. Every time a new pair of Buy and Sell orders is successfully opened, the script automatically reduces the trading size (lot size) for the next cycle by a small increment. This suggests a systematic way of scaling down exposure as the trading session progresses.

Profit Monitoring and Reset Logic

The script continuously tracks the "Equity" of the account (the current value of your money plus open profits/losses) compared to your starting balance. It looks for two specific triggers to conclude a trading cycle:

  1. Target Achievement: If the total profit reaches a user-defined amount, the script considers its job finished for that session.
  2. System Alerts: It also monitors for specific internal errors that might signal the end of a sequence.

Automated Position Clearing

Once the target profit is reached or the work flag is deactivated, the script moves into a "cleanup" mode. It automatically scans all currently open positions and closes them immediately. After successfully clearing the market, the script resets its internal variables—including the lot size and balance tracking—to prepare for a fresh start in the next cycle.

Operational Flow Summary

  • Step 1: Check if the system is ready to trade.
  • Step 2: Open a Buy and a Sell order simultaneously with reduced volume.
  • Step 3: Monitor the live profit of the account.
  • Step 4: If the target profit is hit, close all active trades instantly.
  • Step 5: Reset all settings and repeat the process.
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
14 Views
0 Downloads
0 Favorites
qf1
//+------------------------------------------------------------------+
//|                                                           õ1.mq4 |
//|                                                            ÅÂÃÅÍ |
//|                                                  z_e_e_d@mail.ru |
//+------------------------------------------------------------------+
#property copyright "ÅÂÃÅÍ"
#property link      "z_e_e_d@mail.ru"
extern double my_profit=27.00;
extern double order_profit=150.00;

  int max_buy,max_sell,buy,sell,pos,tiket1,tiket2;
  double balans,my_lot;
  bool work,go;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
  balans=0;
  work=true;
  go=false;
  tiket1=0;
  tiket2=0;
  my_lot=0.1;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
int total=OrdersTotal(); 
//----------- 
 if(balans==0)
  balans=AccountBalance();
//------------------------------------------------------------------- 
  double profit=AccountEquity()- balans;
  if(my_lot==0)
  my_lot=0.1;
//----------- 
if(total!=0) 
{
if (OrderSelect(tiket1, SELECT_BY_TICKET, MODE_TRADES) == true)
         {
         if (OrderCloseTime()!=0)
             go=true; 
                      
             }
       else
           Print("Îøèáêà ", GetLastError(), " ïðè âûáîðå îðäåðà tiket ", tiket1);
           
if (OrderSelect(tiket2, SELECT_BY_TICKET, MODE_TRADES) == true)
         {
         if (OrderCloseTime()!=0)
             go=true;          
             }
       else
           Print("Îøèáêà ", GetLastError(), " ïðè âûáîðå îðäåðà tiket ", tiket2);           
           
}             
//-----------
   if(work==true && (total==0 ||go==true))
   {
   tiket1 = OrderSend(Symbol(),OP_BUY,my_lot,Ask,3,0,Ask+order_profit*Point,NULL,0,0,CLR_NONE);
   if(tiket1>0)
   Print("tiket1=",tiket1);
   else
   {
   Print("tiket1<0-ÏÐÎÈÇÎØËÀ ÎØÈÁÊÀ-",GetLastError());
   return(0);
   }
//-----------   
   tiket2 = OrderSend(Symbol(),OP_SELL,my_lot,Bid,3,0,Bid-order_profit*Point,NULL,0,0,CLR_NONE);
   if(tiket2>0)
   {
   Print("tiket2=",tiket2);
   go=false;
   my_lot=my_lot-0.01;
   }
   else
   {
   Print("tiket2<0-ÏÐÎÈÇÎØËÀ ÎØÈÁÊÀ-",GetLastError());
   return(0);
   }
   }
//-----------------------------------------------------
if(profit>=my_profit||GetLastError()==148)
work=false;
//-----------------------------------------------------  
   if(work==false)
     { 
    for ( pos = 0; pos<total; pos++ )
     {
       if (OrderSelect(pos, SELECT_BY_POS, MODE_TRADES) == true)
         {
         double price;
         if (OrderType()==OP_SELL) 
             price = MarketInfo(OrderSymbol(), MODE_ASK);
         else
             price = MarketInfo(OrderSymbol(), MODE_BID);     
         if (OrderClose(OrderTicket(), OrderLots(), price, 3)==true)
          Print("çàêðûòà ïîçèöèÿ", OrderTicket());
          else
          Print("Îøèáêà ", GetLastError()," ïðè çàêðûòèè ïîçèöèè ", OrderTicket());         
          }
       else
           Print("Îøèáêà ", GetLastError(), " ïðè âûáîðå îðäåðà íîìåð ", pos);
           }
  balans=0;
  tiket1=0;
  tiket2=0; 
  go=false;
  my_lot=0.1;
   }
   if(work==false && total==0)
   work=true;
   Print(" profit=",profit);
   Print("my_lot=",my_lot);
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments