Proffessor_v5_2011_4digits

Author: Copyright � 2011, MetaQuotes Software Corp.
Profit factor:
0.00

Okay, here's a breakdown of what this MetaTrader script does, explained in a way that avoids technical jargon and focuses on the core logic:

Overall Purpose:

The script, named "Professor_v5_2011," is designed to automatically trade on the MetaTrader platform. It analyzes market conditions and opens/manages orders (buy or sell positions) based on a set of rules. It can be operated manually or automatically.

Initial Setup:

  • Customizable Settings: The script has several adjustable parameters that you, as the user, can modify to influence its trading behavior. These include:
    • manual: Enables manual operation.
    • lot: Initial trading size.
    • znak: The number of decimal places the broker is using.
    • MAX_Lines: How many pending orders in each direction can be created at once.
    • klot: Increase of each lot size.
    • pluslot: Adds a extra value to each lot size.
    • plusDelta: Adjusts the distance between pending orders.
    • variant: Method for initial stop orders.
    • Delta1: The distance for the first stop order from the market price.
    • Delta: The spacing between pending orders.
    • TP: How much profit to target on the initial trade.
    • tral: Activates a trailing stop.
    • step: Step size for the trailing stop.
    • Profit: Profit in points to adjust all orders.
    • f: ADX values to trigger trade.
    • bar: Time shift for ADX values.
    • st: Overbought/oversold value.
    • st_r: Stochastic line difference to trade.
    • timeframe: Which timeframe to base indicator on.
    • magic: A unique ID for the script's trades.
    • StartHour/EndHour: Sets specific trading hours.
    • Fr_Stop: Stop trading on fridays.
  • Initialization: When the script starts, it displays a comment with its name on the chart.

Trading Logic:

  1. Time Check: The script first makes sure that trading is allowed for the current hour and that it is not Friday (if configured that way).
  2. Order Check: The script verify if there are no orders on the market.
  3. Manual Trading: If manual is enabled, a series of dialog boxes appear allowing you to make desicions:
    • Flat or Trending market.
    • Buy or Sell. It then opens trades as selected.
  4. Automatic Trading: If manual is disabled, the script enters automatic mode:
    • Market Analysis: The script uses technical indicators to assess the market situation:
      • ADX (Average Directional Index): This indicator helps determine if the market is trending or ranging (flat). It looks at the strength of a trend.
      • Stochastic Oscillator: This indicator helps identify overbought and oversold conditions, potentially signaling when prices might reverse.
    • Trading Decisions:
      • If the ADX indicates a flat market: The script looks to buy when the price is expected to go up and sell when the price is expected to go down.
      • If the ADX indicates a trending market: The script will consider buying when the market has a trend upwards and selling when the market has a trend downwards.
    • Order Placement: Based on the analysis, the script will:
      • Open an initial "market order" (buy or sell at the current price).
      • Place a series of "pending orders" (buy limit, sell limit, buy stop, sell stop) around the current price. These are essentially instructions to buy or sell if the price reaches a certain level in the future. The number of pending orders is controlled by MAX_Lines.
      • Set a "take profit" level for the initial trade, which automatically closes the trade when a specific profit is reached.

Order Management:

  • Closing All Orders: The script has a safety feature: If the trade direction ever changes, it first closes all open orders (both the initial trade and any pending orders).
  • Trailing Stop: If the initial trade becomes profitable, a "trailing stop" is activated. This feature automatically adjusts the stop-loss order (an order that limits potential losses) as the price moves in a favorable direction.
  • Profit Adjustment: If multiple orders have been placed then the robot averages the total profits and places all the take profits equal distances from the average position.

Important Considerations:

  • Risk: This script, like all automated trading systems, carries risk. It is essential to understand the parameters and how they influence the script's behavior.
  • Backtesting: Before using this script with real money, it is crucial to test it on historical data ("backtesting") to get an idea of its potential performance.
  • Monitoring: Even with automated systems, it's important to monitor the trades and be prepared to intervene if necessary.
  • Broker Settings: This script depends on your broker. If your broker needs 5 values to be correct you need to set the znak setting to 5.

In short, this script aims to automate trading by analyzing market conditions, opening a series of orders, and managing them with features like take profit and trailing stop.

Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategy
Indicators Used
Movement directional indexStochastic oscillator
Miscellaneous
It opens Message Boxes to the user
4 Views
0 Downloads
1 Favorites
Proffessor_v5_2011_4digits
//+------------------------------------------------------------------+
//|                                           Proffessor_v5_2011.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#include <WinUser32.mqh>
extern bool manual =false;   //åñëè èñòèíà, òî ïåðâûé îðäåð ðó÷êàìè
extern double lot=0.02;
extern int znak=4;            //åñëè 5, òî ïÿòèçíàêîâûé äèëöåíòð
extern int MAX_Lines       = 10;     //ìàêñèìàëüíîå êîëëè÷åñòâî îòëîæåííûõ îðäåðîâ êàæäîãî íàïðàâëåíèÿ  
extern double klot           = 1;      //êîýôôèöèåíò óìíîæåíèÿ ëîòîâ ïðè óäàëåíèè îò öåíû  
extern double pluslot      =0.01;      //êîýôôèöèåíò äîëèâêè ëîòà ïðè óäàëåíèè îò öåíû
extern int plusDelta     =0;        //êîýôôèöèåíò óâåëè÷åíèÿ ðàññòîÿíèÿ ìåæäó îòëîæåííûìè îðäåðàìè
                                    //åñëè çíà÷åíèå îòðèöàòåëüíîå, òî ðàññòîÿíèå óìåíüøàåòñÿ íà äàííîå êîë-âî ïóíêòîâ
extern int variant  =2; //âàðèàíò äëÿ âòîðîãî îðäåðà
                        //0 - ñòîïîâûé îðäåð â ñèììåòðè÷íîì ëîêå
                        //1 - ñòîïîâûé îðäåð â àññèìåòðè÷íîì ëîêå
                        //2 - ñèììåòðè÷íûé ïî èíäèêàòîðó ADX
extern double Delta1       =80;     //ïåðâàÿ äåëüòà îò öåíû äëÿ ñòîïîâîãî îðäåðà
extern int Delta           = 60;        //ðàññòîÿíèå ìåæäó îòëîæåííûìè îðäåðàìè  
extern int TP              =25;  //òåéê ïðîôèò â ïóíêòàõ äëÿ ïåðâîé ñäåëêè
extern int tral               =10;//òðåéëèíã ñòîï â ïóíêòàõ äëÿ ïåðâîãî îðäåðà
extern int step               =1;//øàã òðåéëèíãà â ïóíêòàõ
extern int Profit             =10;//ïðîôèò â ïóíêòàõ äëÿ ïà÷êè îðäåðîâ
extern double f            =40;  //ïàðàìåòð ãðàíèöû ôëåòà ïî ADX
extern double bar        = 2;   //ñäâèã ïî áàðàì ADX
extern double st        =25;//óðîâåíü ïåðåêóïëåííîñòè/ïåðåïðîäàííîñòè
extern double st_r      =20;//ðàçíèöà ìåæäó ëèíèÿìè ñòîõàñòèêà, êîãäà ìîæíî ñòàâèòü ñòîïîâèêè
//extern double hl        =150;//ðàçíèöà ìåæäó õàé è ëîó îäèí áàð íàçàä
extern double timeframe  = 1;  //òàéìôðåéì äëÿ èíäèêàòîðà ADX 0-òåêóùèé,1-1ìèíóòà, 2-5ìèíóò, 3-15ìèíóò, 4-30ìèíóò, 5-1÷àñ
                             //6-4÷àñà, 7-äåíü, 8-íåäåëÿ, 9-ìåñÿö
extern int magic           = 12345; 
extern int StartHour=0;       //÷àñ íà÷àëà ðàáîòû ñîâåòíèêà
extern int EndHour=24;     //÷àñ îêîí÷àíèÿ ðàáîòû ñîâåòíèêà
extern bool Fr_Stop=true; //åñëè true, òî â ïÿòíèöó íå òîðãóåì 
extern int pop=3;//êîëè÷åñòâî ïîïûòîê çàêðûòü îðäåð
bool ticket, closed;
double Lots;
int x,q,i,own,trals;
bool trade=false;
double iflet,ibuy,isell,stoh,stoh_sign;
int _timeframe;
int init() {
      Comment("ProfessorSoft_v5_2011");
      return (0);
  
}

int deinit() {
      Comment("");
      return (0);
}

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----

if(timeframe==1)_timeframe=1;
else if(timeframe==0)_timeframe=0;
else if(timeframe==2)_timeframe=5;
else if(timeframe==3)_timeframe=15;
else if(timeframe==4)_timeframe=30;
else if(timeframe==5)_timeframe=60;
else if(timeframe==6)_timeframe=240;
else if(timeframe==7)_timeframe=1440;
else if(timeframe==8)_timeframe=10080;
else _timeframe=43200;

if(OrdersTotal()==0 && time()==true)
{
if(manual==true)
{
bool flet,buy;
   int a=MessageBox("Íàæìèòå Äà äëÿ ëèìèòíîé ñåòêè èëè Íåò äëÿ ñòîïîâîé","Ìîæíî òîðãîâàòü",MB_YESNOCANCEL);
if(a==IDYES) flet=true;
if(a==IDNO) flet=false;
if(a==IDCANCEL) return(0);
 int b=MessageBox("Íàæìèòå Äà ÷òîáû êóïèòü èëè Íåò ÷òîáû ïðîäàòü","Ìîæíî òîðãîâàòü",MB_YESNOCANCEL);
if(b==IDYES) buy=true;
if(b==IDNO) buy=false;
if(b==IDCANCEL) return(0);
   if(flet==true && buy==true)//óñëîâèå äëÿ ïîêóïêè è îïðåäåëåíèå ôëåòà
      {
               Lots=lot;
               ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TP*Point,"",magic,0,Blue);
                if(ticket==-1)return(0);
               if(variant==2)OrderSend(Symbol(),OP_BUYLIMIT,Lots,Ask-Delta1*Point,3,0,0,"",magic,0,Blue);
               else if (variant==1) OrderSend(Symbol(),OP_SELLSTOP,NormalizeDouble(Lots*klot,2)+pluslot,Bid-Delta1*Point,3,0,0,"",magic,0,Red);
               else  OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-Delta1*Point,3,0,0,"",magic,0,Red);
                for(x=1;x<=MAX_Lines;x++)
               {
                Lots=NormalizeDouble(Lots*klot,2)+pluslot;
                  OrderSend(Symbol(),OP_BUYLIMIT,Lots,Ask-(Delta1+x*NormalizeDouble(Delta+plusDelta*x/2,0))*Point,3,0,0,"",magic,0,Blue);
                  OrderSend(Symbol(),OP_SELLLIMIT,Lots,Bid+x*NormalizeDouble(Delta+plusDelta*x/2,0)*Point,3,0,0,"",magic,0,Red);     
               }
      
      
      }
      else if(flet==true && buy==false)//óñëîâèå äëÿ ïðîäàæè è îïðåäåëåíèå ôëåòà
      {
                  Lots=lot;
                  ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TP*Point,"",magic,0,Red); 
                   if(ticket==-1)return(0);
                   if(variant==2) OrderSend(Symbol(),OP_SELLLIMIT,Lots,Bid+Delta1*Point,3,0,0,"",magic,0,Red);
                   else if (variant==1) OrderSend(Symbol(),OP_BUYSTOP,NormalizeDouble(Lots*klot,2)+pluslot,Ask+Delta1*Point,3,0,0,"",magic,0,Blue);
                  else  OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Delta1*Point,3,0,0,"",magic,0,Blue);
                 
                    for(x=1;x<=MAX_Lines;x++)
                  {
                     Lots=NormalizeDouble(Lots*klot,2)+pluslot;
                     OrderSend(Symbol(),OP_BUYLIMIT,Lots,Ask-x*NormalizeDouble(Delta+plusDelta*x/2,0)*Point,3,0,0,"",magic,0,Blue);
                     OrderSend(Symbol(),OP_SELLLIMIT,Lots,Bid+(Delta1+x*NormalizeDouble(Delta+plusDelta*x/2,0))*Point,3,0,0,"",magic,0,Red);     
                  }
      }
       else if(flet==false && buy==true)//óñëîâèå äëÿ ïîêóïêè è îïðåäåëåíèå òðåíäà
      {
                   Lots=lot;
                   ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TP*Point,"",magic,0,Blue);
                    if(ticket==-1)return(0);
                     if(variant==2)  OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-Delta1*Point,3,0,0,"",magic,0,Red);
                   else if (variant==1) OrderSend(Symbol(),OP_SELLSTOP,NormalizeDouble(Lots*klot,2)+pluslot,Bid-Delta1*Point,3,0,0,"",magic,0,Red);
                  else  OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-Delta1*Point,3,0,0,"",magic,0,Red);
                  
       
                    for(x=1;x<=MAX_Lines;x++)
                   {
                    Lots=NormalizeDouble(Lots*klot,2)+pluslot;
                      OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-(Delta1+x*NormalizeDouble(Delta+plusDelta*x/2,0))*Point,3,0,0,"",magic,0,Blue);
                      OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+x*NormalizeDouble(Delta+plusDelta*x/2,0)*Point,3,0,0,"",magic,0,Red);     
                   }
      }
       else if(flet==false && buy==false)//óñëîâèå äëÿ ïðîäàæè è îïðåäåëåíèå òðåíäà
      {
                  Lots=lot;
                  ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TP*Point,"",magic,0,Red); 
                   if(ticket==-1)return(0);
                    if(variant==2)  OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Delta1*Point,3,0,0,"",magic,0,Blue);
                   else if (variant==1)OrderSend(Symbol(),OP_BUYSTOP,NormalizeDouble(Lots*klot,2)+pluslot,Ask+Delta1*Point,3,0,0,"",magic,0,Blue);
                  else OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Delta1*Point,3,0,0,"",magic,0,Blue);
                 
                    for(x=1;x<=MAX_Lines;x++)
                  {
                     Lots=NormalizeDouble(Lots*klot,2)+pluslot;
                     OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-x*NormalizeDouble(Delta+plusDelta*x/2,0)*Point,3,0,0,"",magic,0,Blue);
                     OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+(Delta1+x*NormalizeDouble(Delta+plusDelta*x/2,0))*Point,3,0,0,"",magic,0,Red);     
                  }
      }
      else return(0);
      }



   else
   {
   ticket=-1;
    iflet=iADX( Symbol(), _timeframe, 14, PRICE_CLOSE,MODE_MAIN, bar); 
    ibuy=iADX( Symbol(), _timeframe, 14, PRICE_CLOSE,MODE_PLUSDI, bar); 
    isell=iADX(  Symbol(), _timeframe, 14, PRICE_CLOSE,MODE_MINUSDI, bar); 
    stoh=iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,0);
    stoh_sign=iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);
   // double hl0=(High[0]-Low[0]);
   // double hl1=(High[1]-Low[1]); 
   // Print("ýòî 0",hl0,"ýòî 1 ",hl1,"ýòî èñõîäíûé ",hl*Point);
    //if(hl0>=hl*Point || hl1>=hl*Point || DayOfWeek()==5)return(0);
    if(Fr_Stop==true) if(DayOfWeek()==5)return(0);
      if(iflet<f && ibuy>isell && stoh>stoh_sign)//óñëîâèå äëÿ ïîêóïêè è îïðåäåëåíèå ôëåòà
      {
               Lots=lot;
               ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TP*Point,"",magic,0,Blue);
                if(ticket==-1)return(0);
               if(variant==2)OrderSend(Symbol(),OP_BUYLIMIT,Lots,Ask-Delta1*Point,3,0,0,"",magic,0,Blue);
               else if (variant==1) OrderSend(Symbol(),OP_SELLSTOP,NormalizeDouble(Lots*klot,2)+pluslot,Bid-Delta1*Point,3,0,0,"",magic,0,Red);
               else  OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-Delta1*Point,3,0,0,"",magic,0,Red);
       
                for(x=1;x<=MAX_Lines;x++)
               {
                Lots=NormalizeDouble(Lots*klot,2)+pluslot;
                  OrderSend(Symbol(),OP_BUYLIMIT,Lots,Ask-(Delta1+x*NormalizeDouble(Delta+plusDelta*x/2,0))*Point,3,0,0,"",magic,0,Blue);
                  OrderSend(Symbol(),OP_SELLLIMIT,Lots,Bid+x*NormalizeDouble(Delta+plusDelta*x/2,0)*Point,3,0,0,"",magic,0,Red);     
               }
      
      
      }
      else if(iflet<f && ibuy<isell && stoh<stoh_sign)//óñëîâèå äëÿ ïðîäàæè è îïðåäåëåíèå ôëåòà
      {
                  Lots=lot;
                  ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TP*Point,"",magic,0,Red); 
                   if(ticket==-1)return(0);
                 if(variant==2) OrderSend(Symbol(),OP_SELLLIMIT,Lots,Bid+Delta1*Point,3,0,0,"",magic,0,Red);
                   else if (variant==1) OrderSend(Symbol(),OP_BUYSTOP,NormalizeDouble(Lots*klot,2)+pluslot,Ask+Delta1*Point,3,0,0,"",magic,0,Blue);
                  else  OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Delta1*Point,3,0,0,"",magic,0,Blue);
                    for(x=1;x<=MAX_Lines;x++)
                  {
                     Lots=NormalizeDouble(Lots*klot,2)+pluslot;
                     OrderSend(Symbol(),OP_BUYLIMIT,Lots,Ask-x*NormalizeDouble(Delta+plusDelta*x/2,0)*Point,3,0,0,"",magic,0,Blue);
                     OrderSend(Symbol(),OP_SELLLIMIT,Lots,Bid+(Delta1+x*NormalizeDouble(Delta+plusDelta*x/2,0))*Point,3,0,0,"",magic,0,Red);     
                  }
      }
       else if(iflet>f && ibuy>isell && stoh>st && stoh<100-st && stoh>stoh_sign && stoh-stoh_sign>st_r)//óñëîâèå äëÿ ïîêóïêè è îïðåäåëåíèå òðåíäà
      {
                   Lots=lot;
                   ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TP*Point,"",magic,0,Blue);
                    if(ticket==-1)return(0);
                  if(variant==2) OrderSend(Symbol(),OP_BUYLIMIT,Lots,Ask-Delta1*Point,3,0,0,"",magic,0,Red); 
                  //OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-Delta1*Point,3,0,0,"",magic,0,Red);
                   else if (variant==1) OrderSend(Symbol(),OP_SELLSTOP,NormalizeDouble(Lots*klot,2)+pluslot,Bid-Delta1*Point,3,0,0,"",magic,0,Red);
                  else  OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-Delta1*Point,3,0,0,"",magic,0,Red);
       
                    for(x=1;x<=MAX_Lines;x++)
                   {
                    Lots=NormalizeDouble(Lots*klot,2)+pluslot;
                      OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-(Delta1+x*NormalizeDouble(Delta+plusDelta*x/2,0))*Point,3,0,0,"",magic,0,Blue);
                      OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+x*NormalizeDouble(Delta+plusDelta*x/2,0)*Point,3,0,0,"",magic,0,Red);     
                   }
      }
       else if(iflet>f && ibuy<isell && stoh>st && stoh<100-st && stoh<stoh_sign && stoh_sign-stoh>st_r)//óñëîâèå äëÿ ïðîäàæè è îïðåäåëåíèå òðåíäà
      {
                  Lots=lot;
                  ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TP*Point,"",magic,0,Red); 
                   if(ticket==-1)return(0);
                  if(variant==2)OrderSend(Symbol(),OP_SELLLIMIT,Lots,Bid+Delta1*Point,3,0,0,"",magic,0,Blue); 
                  // OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Delta1*Point,3,0,0,"",magic,0,Blue);
                   else if (variant==1)OrderSend(Symbol(),OP_BUYSTOP,NormalizeDouble(Lots*klot,2)+pluslot,Ask+Delta1*Point,3,0,0,"",magic,0,Blue);
                  else OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Delta1*Point,3,0,0,"",magic,0,Blue);
                    for(x=1;x<=MAX_Lines;x++)
                  {
                     Lots=NormalizeDouble(Lots*klot,2)+pluslot;
                     OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-x*NormalizeDouble(Delta+plusDelta*x/2,0)*Point,3,0,0,"",magic,0,Blue);
                     OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+(Delta1+x*NormalizeDouble(Delta+plusDelta*x/2,0))*Point,3,0,0,"",magic,0,Red);     
                  }
      }
      else return(0);
     
   }
  }
  
      
      if(OrdersTotal()>0)
    {
     Comment("          Balance  ",AccountBalance(),"\n          Equity  ",AccountEquity(),"\n          Profit  ",OrdersProfit());
      own=0;
         for (i=OrdersTotal()-1;i>=0;i--)
         {
            OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
            if(OrderType()<2)own=own+1;
         }
         if (own==0)
         {
           for (i=OrdersTotal()-1;i>=0;i--)
           {          
                     for(q=0;q<pop;q++)
                     {
                     closed=false;
                     closed=OrderDelete(OrderTicket());
                     if(closed==true)q=pop;
                     }
           }  
         }
        if(own>1)
        {
          
          int k=0,u=0;
          int pipsZero=0;
          double pipsPrice=0;
           for (i=OrdersTotal()-1;i>=0;i--)
         {
            OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
            if(OrderStopLoss()!=0 || OrderTakeProfit()!=0)u=u+1;
         }
         if(u==own)return(0);
          for (i=OrdersTotal()-1;i>=0;i--)
         {
            OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
            if(OrderType()==OP_BUY) k=k+OrderLots()/lot;
            if(OrderType()==OP_SELL)k=k-OrderLots()/lot;
         }
 //        Print("êîåôôèöèåíò ðàâåí ",k);
        pipsPrice=k*lot/0.1;
 //       Print("Öåíà ïóíêòà ",pipsPrice);
        if(znak==5)pipsZero=10*(-NormalizeDouble(OrdersProfit()/pipsPrice,0));
        else pipsZero=(-NormalizeDouble(OrdersProfit()/pipsPrice,0)); 
  //      Print("Ïóíêòîâ äî íóëÿ", pipsZero);
        if(pipsPrice>0)
        {
         for (i=OrdersTotal()-1;i>=0;i--)
         {
            OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
            if(OrderType()==OP_BUY)  OrderModify(OrderTicket(), OrderOpenPrice(), 0,Bid+pipsZero*Point+Profit*Point, 0, Blue);
           // Print ("TP äëÿ îðäåðà ",OrderTicket()," ðàâåí ",Bid+pipsZero*Point);
            if(OrderType()==OP_SELL) OrderModify(OrderTicket(), OrderOpenPrice(), Ask+pipsZero*Point+Profit*Point,0, 0, Red);
           // Print ("SL äëÿ îðäåðà ",OrderTicket()," ðàâåí ",Ask+pipsZero*Point);  
         }
        }
        if(pipsPrice<0)
        {
         for (i=OrdersTotal()-1;i>=0;i--)
         {
            OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
            if(OrderType()==OP_BUY)  OrderModify(OrderTicket(), OrderOpenPrice(), Bid+pipsZero*Point-Profit*Point,0, 0, Blue); 
           // Print ("SL äëÿ îðäåðà buy",OrderTicket()," ðàâåí ",Bid-pipsZero*Point);  
            if(OrderType()==OP_SELL) OrderModify(OrderTicket(), OrderOpenPrice(), 0,Ask+pipsZero*Point-Profit*Point, 0, Red);  
            // Print ("TP äëÿ îðäåðà sell ",OrderTicket()," ðàâåí ",Ask-pipsZero*Point);
         }
        }
        } 
         
         
       
      if(OrdersProfit()>=tral*lot*10)
      {
         
         if(own==1)
         {
                  for (i=OrdersTotal()-1;i>=0;i--)
                  {
                     OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
                     if(OrderType()<2 && OrderProfit()>=tral*OrderLots()*10)TrailPositions();   
                  }
         }
        
            
            Sleep(1000);
            if(OrderType()>1 ) 
             for(q=0;q<pop;q++)
                  {
                  closed=false;
                  closed=OrderDelete(OrderTicket());
                  if(closed==true)q=pop;
                  }          
      }
    }
   
   
//----
   return(0);
  }
  
//+------------------------------------------------------------------+

   bool time()
 {
   if (StartHour<EndHour) 
      {if (Hour()>=StartHour && Hour()<EndHour) return(true); else return(false);}
   if (StartHour>EndHour) 
      {if (Hour()>=EndHour && Hour()<StartHour) return(false); else return(true);}
 }
 
double OrdersProfit()
{
   
  double rezultSymb=0;
  string SMB=Symbol();
  int i;
  for (i=OrdersTotal()-1;i>=0;i--)
   {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true)
     {
      if(OrderSymbol()!= SMB) continue;
      if(OrderType()==OP_BUY || OrderType()==OP_SELL)
       {
        rezultSymb+=OrderProfit();
       } 
     }
   }
  return(rezultSymb);


}

 void TrailPositions() // ôóíêöèÿ òðåéëèíã ñòîï
{
  int Orders = OrdersTotal();
  for (int i=0; i<Orders; i++) {
    if (!(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))) continue;
    if (OrderSymbol() != Symbol()) continue;
        
     if (OrderType() == OP_BUY )  {
      if (Bid-OrderOpenPrice() > tral*Point) {
        if (OrderStopLoss() < Bid-(tral+step-1)*Point) {
          OrderModify(OrderTicket(), OrderOpenPrice(), Bid-tral*Point,
                                                     OrderTakeProfit(), 0, Blue);
        }      }    }
    if (OrderType() == OP_SELL)  {
      if (OrderOpenPrice()-Ask >tral*Point) {
        if (OrderStopLoss() > Ask+(tral+step-1)*Point 
                                                       || OrderStopLoss() == 0) {
          OrderModify(OrderTicket(), OrderOpenPrice(), Ask+tral*Point,
                                                      OrderTakeProfit(), 0, Blue);
          }   }    }   }  }
          

Comments