Download MetaTrader 5

Experts: Autotrade

To add comments, please log in or register
Have you found an interesting application? Publish it in Code Base - millions of traders will appreciate that!
MetaQuotes Software Corp.
Moderator
181142
MetaQuotes Software Corp. 2008.04.07 07:36 

Autotrade:

Adviser Autotrade.

Author: John Smith

MQL4 Comments
16319
MQL4 Comments 2008.04.22 14:25  
Which pair and time frame was used for the avove test? Any recommendations on settings? Thanks your for explaining.
loh yoke wah
64
loh yoke wah 2008.08.25 01:34  
//+------------------------------------------------------------------+
//|                                                    AutoTrade.mq4 |
//|                      Copyright ? 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2006, Popular:-)"
#property link      "scrivimi@mail.ru"
extern int Level_Warrants=20;
extern int Level_Profit=-2;
extern int End_minutes=20;
extern int unconditional_fixation=30;
extern int stabilization_items=25;
extern double lots=0.1;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   double pip=MarketInfo(Symbol(),MODE_TICKSIZE);
//----
   if (OrdersTotal()==0)
     {
      double buy= Ask+Level_Warrants*pip;
      double sell= Bid-Level_Warrants*pip;
      int ticket1=OrderSend(Symbol(),OP_BUYSTOP,lots,buy,3,0,0,"buy",16384,CurTime()+End_minutes*60,Green);
      int ticket2=OrderSend(Symbol(),OP_SELLSTOP,lots,sell,3,0,0,"buy",16384,CurTime()+End_minutes*60,Green);
     }
   if (OrdersTotal()>0)
     {
      for(int i=0;i<=OrdersTotal();i++)
        {
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
//----
         ticket1=OrderTicket();
         double profit1=OrderProfit();
         double price1=OrderOpenPrice();
         if(OrderType()==OP_BUY)
           {
            OrderSelect(i+1,SELECT_BY_POS,MODE_TRADES);
            ticket2=OrderTicket();
            if(OrderType()==OP_SELLSTOP)//---test closure on profit NO:1
              {
               OrderModify(OrderTicket(),OrderOpenPrice(),0,0,0,CLR_NONE);
               if(profit1>Level_Profit&&MathAbs(Close[1]-Open[1])<=stabilization_items*pip)
                 {
                  OrderClose(ticket1,lots,Bid,3,CLR_NONE);
                  OrderDelete(ticket2);
                 }
               if(MathAbs(Close[1]-Open[1])<=stabilization_items*pip&&MathAbs(Close[2]-Open[2])<=stabilization_items*pip)
                 {
                  OrderClose(ticket1,lots,Bid,3,CLR_NONE);
                  OrderDelete(ticket2);
                 }
               if(profit1>=unconditional_fixation)
                 {
                  OrderClose(ticket1,lots,Bid,3,CLR_NONE);
                  OrderDelete(ticket2);
                 }
              }
            if(OrderType()==OP_SELL)
              {//---immediately the closure of both
               OrderClose(ticket1,lots,Bid,3,CLR_NONE);
               OrderClose(ticket2,lots,Ask,3,CLR_NONE);
              }
           }
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderType()==OP_BUYSTOP)
           {
            OrderSelect(i+1,SELECT_BY_POS,MODE_TRADES);
            ticket2=OrderTicket();
            if(OrderType()==OP_SELL)//---verification closure on profits NO:2
              {
               OrderModify(ticket1,price1,0,0,0,CLR_NONE);
               double profit2=OrderProfit();
               if(profit2>Level_Profit&&MathAbs(Open[1]-Close[1])<=stabilization_items*pip)
                 {
                  OrderClose(ticket2,lots,Bid,3,CLR_NONE);
                  OrderDelete(ticket1);
                 }
               if(MathAbs(Open[1]-Close[1])<=stabilization_items*pip&&MathAbs(Open[2]-Close[2])<=stabilization_items*pip)
                 {
                  OrderClose(ticket2,lots,Bid,3,CLR_NONE);
                  OrderDelete(ticket1);
                 }
               if(profit2>=unconditional_fixation)
                 {
                  OrderClose(ticket2,lots,Bid,3,CLR_NONE);
                  OrderDelete(ticket1);
                 }
              }
           }
        }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
loh yoke wah
64
loh yoke wah 2008.08.25 01:36  
247817:
Which pair and time frame was used for the avove test? Any recommendations on settings? Thanks your for explaining.
the above was translated, try your best to understand.
To add comments, please log in or register