j3rrbk6ha3w6vjk9k6s6f67f

Download script
Author: FEELING , TL��13530409376:
Profit factor:
0.00

This automated trading script is designed to manage market positions by identifying trend shifts and managing risk through specific entry, exit, and recovery rules. Below is a detailed breakdown of its logic:

Core Strategy Mechanism

The script primarily uses two Moving Averages (MA) as its signal source. It monitors the relationship between a fast-moving average (7 periods) and a slow-moving average (26 periods).

  • Trend Detection: The system looks for "crossovers." When the fast average crosses over or under the slow average, it signals a change in market momentum.
  • Simultaneous Entry: Unlike many bots that only take one direction at a time, this script is designed to open both Buy and Sell positions simultaneously when a crossover occurs (provided there are fewer than two active orders). This suggests a strategy of "hedging" or capturing volatility from both sides of the market.

Trade Management Logic

The script continuously monitors open trades based on their distance from the entry price:

  • Profit Taking: It evaluates whether a trade has reached a specific point threshold (defined by the user as the profit target). If a position meets this criteria, the script automatically closes it.
  • Dynamic Re-entry: If a trade is closed due to reaching a target, the script checks the current market status. Depending on the direction of the last closed trade and the available "slots," it may immediately open a new position to maintain market presence.

Risk Mitigation & Error Handling

The script includes specific safety features to manage losing trades and technical issues:

  • Maximum Loss Protection: The logic contains a specialized routine to monitor trades that are moving against the intended direction. If multiple positions are losing, it identifies the one with the worst performance (the "maximum loss") and closes it specifically. This is a proactive way to prune the worst-performing part of a hedge or a trade cluster.
  • Execution Reliability: To ensure the script doesn't get stuck in a loop if a trade fails to close due to market conditions, it includes a retry counter. If a closing order fails more than five times, it will trigger an alert notification to inform the user that the operation is being bypassed to prevent system hanging.
  • Time Delays: The script incorporates "Sleep" intervals based on the selected timeframe. This prevents the bot from spamming orders and ensures it waits a designated amount of time before attempting the next logic cycle, which helps in stabilizing execution during high volatility.

Summary of Behavior

Essentially, the bot acts as an automated trend-follower that enters both directions at once upon seeing a moving average crossover. It manages these positions by automatically taking profits when targets are hit and aggressively pruning the most significant losing trades to protect the overall account balance.

Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
Moving average indicator
Miscellaneous
It issuies visual alerts to the screen
12 Views
0 Downloads
0 Favorites
j3rrbk6ha3w6vjk9k6s6f67f

#property copyright "FEELING ,  TL£º13530409376:"
#property link      "²âÊÔÖ¸±ê"
#define QQ 450459237

extern int restM=0;  //ÐÝϢʱ¼ä
extern double mylots=0.1;
extern int myslippage=7; //»¬µãÊý

extern int mx=0 ; //Ó¦ÓÃÓÚͼ±íµÄʱ¼äÖÜÆÚ



extern int maf=7 ; //maÖÜÆÚ
extern int mas=26 ; //maÖÜÆÚ



extern int howgetclose=10;//ÖÁÉÙ»ñÀû¶àÉÙ¸öµã²Å¿ÉÒÔÆ½²Ö
extern int howlossclose=-100;//ƽ»ñÀûµ¥µÄͬʱƽµô¿÷Ë𳬹ýijֵµÄ×î´óµ¥

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
int closeadd=0;  
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
int restmm=0; 
int ifdoubletrade=0;
int ifbuytrade=0;
int ifsaletrade=0;
//+------------------------------------------------------------------+
int start()
  {
//----
   
   if(restM==0)  
   restmm=Period();
   else
   restmm=restM;
   
   
   if (ifdoubletrade==1)
   {
      if(ifbuytrade==1)           
      send_buyorder();
      if(ifsaletrade==1)
      send_saleorder();
      if(ifbuytrade==0 && ifsaletrade==0)
      {
         ifdoubletrade=0;
         Sleep(restmm*120*1000); 
      }
   }
   
   
    if(ifbuytrade==1)     
    {      
      send_buyorder();
      Sleep(restmm*120*1000);       
    }
    if(ifsaletrade==1)
    {
      send_saleorder();
      Sleep(restmm*120*1000); 
    }
   
   
   double ma7=iMA(NULL,mx,maf,0,MODE_SMA,PRICE_CLOSE,0 );
   double ma26=iMA(NULL,mx,mas,0,MODE_SMA,PRICE_CLOSE,0 );
   double ma71=iMA(NULL,mx,maf,0,MODE_SMA,PRICE_CLOSE,1 );
   double ma261=iMA(NULL,mx,mas,0,MODE_SMA,PRICE_CLOSE,1 );
   

   
   if(ma7>ma26 && ma71<ma261  )
   {
      if(OrdersTotal()<2)
      {
      
      ifdoubletrade=1;
      ifbuytrade=1;
      ifsaletrade=1;
      send_saleorder();
      send_buyorder();            
      
      }
   }
   
    if(ma7<ma26 && ma71>ma261  )
   {
      if(OrdersTotal()<2)
      {
      ifdoubletrade=1;
      ifbuytrade=1;
      ifsaletrade=1;
      send_saleorder();   
      send_buyorder();      
     
      }
   }
   
   int ifclose=0;
   int ifclosetype=0;
   
   
   if(ma7>ma26 && ma71<ma261 )
   {
       ifclose=0;
       ifclosetype=0;
      for(int i=0;i<OrdersTotal();i++)      
      {
            if(OrderSelect(i, SELECT_BY_POS,MODE_TRADES)==true)
               {     
                  if(OrderType()==OP_BUY )
                  {
                        if((Bid-OrderOpenPrice())/Point>howgetclose )
                        {
                           send_orderclose(OrderTicket(),Bid,myslippage,Red)  ;     
                           close_lossMaxOrder(OrderType(),howlossclose)     ;    
                           ifclose=1;
                           ifclosetype=1;
                           
                        }
                  }
                  
                  if(OrderType()==OP_SELL )
                  {
                        if((OrderOpenPrice()-Ask)/Point>howgetclose )
                        {                 
                            send_orderclose(OrderTicket(),Ask,myslippage,Green)   ; 
                            close_lossMaxOrder(OrderType(),howlossclose)     ;
                            ifclose=1;
                           ifclosetype=-1;
                        }
                  }
                  
               }              
               
               
               
               
      } //over for
        ////////////////////////////////////
                             
   }
   
   
   
   
   if(ma7<ma26 && ma71>ma261 )
   {
        ifclose=0;
        ifclosetype=0;
      for( i=0;i<OrdersTotal();i++)      
      {
            if(OrderSelect(i, SELECT_BY_POS,MODE_TRADES)==true)
               {     
                  if(OrderType()==OP_BUY )
                  {
                        if((Bid-OrderOpenPrice())/Point>howgetclose )
                        {
                           send_orderclose(OrderTicket(),Bid,myslippage,Red)  ;     
                           close_lossMaxOrder(OrderType(),howlossclose)     ;    
                           ifclose=1;
                           ifclosetype=1;
                        }
                  }
                  
                  if(OrderType()==OP_SELL )
                  {
                        if((OrderOpenPrice()-Ask)/Point>howgetclose )
                        {                 
                            send_orderclose(OrderTicket(),Ask,myslippage,Green)   ; 
                            close_lossMaxOrder(OrderType(),howlossclose)     ;
                            ifclose=1;
                           ifclosetype=-1;
                        }
                  }
                  
               }              
               
               
               
               
      } //over for


      if(ifclose==1)
      {
      if(OrdersTotal()<2)
         {
            ifdoubletrade=1;
            ifbuytrade=1;
            ifsaletrade=1;
            send_saleorder();
            send_buyorder();                            
         }
         else
         {
            if(ifclosetype==1)
            {
               ifbuytrade=1;            
               send_buyorder();  
            }

            if(ifclosetype==-1)
            {
                ifsaletrade=1; 
                send_saleorder();
            }

         }

       }       
      
      
   }
   
   
   
   
   
   
   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+




int maxloss=0 ;

void close_lossMaxOrder(int ordertp,int howloss) 
{

     
    for(int i=0;i<OrdersTotal();i++)      
      {
            if(OrderSelect(i, SELECT_BY_POS,MODE_TRADES)==true)
               {
                  if(OrderType()==ordertp && ordertp==0 ) 
                  {
                     if((Bid-OrderOpenPrice())/Point<howloss )
                     {
                        if(maxloss>(Bid-OrderOpenPrice())/Point )
                        {
                           maxloss=(Bid-OrderOpenPrice())/Point;
                        }
                     }
                  }
                  
                   if(OrderType()==ordertp && ordertp==1 ) 
                   {
                     if((OrderOpenPrice()-Ask)/Point<howloss )
                     {
                        if(maxloss>(OrderOpenPrice()-Ask)/Point )
                        {
                           maxloss=(OrderOpenPrice()-Ask)/Point;
                        }
                     }
                   }
               }
               
      } 
       
     
      
      
      
    
       for( i=0;i<OrdersTotal();i++)      
      {
            if(OrderSelect(i, SELECT_BY_POS,MODE_TRADES)==true)
               {
                  if(OrderType()==ordertp && ordertp==0 ) 
                  {
                     if((Bid-OrderOpenPrice())/Point<howloss )
                     {
                        if(maxloss==(Bid-OrderOpenPrice())/Point )
                        {
                           send_orderclose(OrderTicket(),Bid,myslippage,Red)  ;    
                        }
                     }
                  }
                  
                   if(OrderType()==ordertp && ordertp==1 ) 
                   {
                     if((OrderOpenPrice()-Ask)/Point<howloss )
                     {
                        if(maxloss==(OrderOpenPrice()-Ask)/Point )
                        {
                            send_orderclose(OrderTicket(),Ask,myslippage,Green)   ; 
                        }
                     }
                   }
               }
               
      } 
      
      
      

}


  
void send_orderclose(int closeorder_id,double closeorderprice,int closeorderslippage,color setcolor)
 {
      
      bool backorderclose;     
      OrderSelect(closeorder_id, SELECT_BY_TICKET) ;
      backorderclose=OrderClose(closeorder_id,OrderLots(),closeorderprice,closeorderslippage,setcolor);          
      
     if(backorderclose==true) closeadd=0;
     
      if(backorderclose==false)
      {     
      closeadd++ ;
      if(closeadd>5) 
         {
            Alert("×Ô¶¯Æ½²Ö±àºÅΪ"+closeorder_id+"µÄ¶©µ¥£¬¿ÉÄÜ´æÔÚÍøÂç»ò·þÎñÆ÷ÎÊÌ⣬ÒÑÆ½²Ö¶à´Îʧ°Ü¡£ÇëÊÖ¶¯Æ½²Ö¡£");          
         }
      }
 }
 
 
      

 void send_buyorder()   
 {
          int i;     
          
          i=OrderSend(Symbol(),OP_BUY,mylots,Ask,3,0,0,"",QQ,0,Red );  
           
          if(i>0)  
               {                     
               
                  Print("ÂòÈë³É¹¦"+i);    
                        ifbuytrade=0;                                                   
                
               }
          else 
               {                  
                  Print("ÂòÈëʧ°Ü: "+ GetLastError()) ;
               }
 }      
 
 
 
 
 void send_saleorder() 
 {
       int i;         
              
          i=OrderSend(Symbol(),OP_SELL,mylots,Bid,3,0,0,"",QQ,0,Green);  
         
          if(i>0)  
               { 
               
                  Print("¹Áµ¥Èë³É¹¦"+i);     
                  ifsaletrade=0;
                              
               }
          else  
               {                  
                  Print("¹Áµ¥Èëʧ°Ü: "+ GetLastError()) ;
               }
 } 
 
  
 

Comments