How to set a var price and wait for it fitness carry out instantbuy or sell

 

Hi , guys , I am new for this ,and i want to write  a script  about how to   set a var price and wait for it fitness carry out  instant-buy or instant-sell 

and it does not work  totoally !

help me !

 

//+------------------------------------------------------------------+
//|                                                  OrderIntime.mq4 |
//|                                         Copyright 2014, Jarshi`s |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, Jarshi`sQQ:89588391"
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict
//--- input parameters
 
extern int waiting_time=15;
extern double lot_vol=0.1;   
extern double price_wanted;
extern int acting_mode;   //0卖,1是买 
extern int magic=405215;
 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   DrawLabel("will1","www.zhinngiaoi.com,QQ:2756892070",2,13,"宋体",9,Aqua,0);
//---
   return(INIT_SUCCEEDED);
  }
  int start()
  {
      
      int if_doit=0; 
          while(if_doit==0)
          {
             if(instantDoit(lot_vol,acting_mode,price_wanted, TimeLocal()+waiting_time*60)>0)
               {
                  if_doit=1;
               }
             
              Sleep(100);
          }
       return(0);    
  }
    
   
  //执行立即买入
  int instantDoit(double lots,int mode ,double priceat,datetime exptime)
  {
   int ticket=0;
   if(mode==1)
   {  
      if(priceat<=Bid)
      {
         ticket=OrderSend(Symbol( ) ,OP_BUY,lots,priceat,0,0,0,Symbol()+"buy",magic,exptime,White); 
      }
      
   }
   else
   {
      if(priceat>=Ask)
      {
         ticket=OrderSend(Symbol( ) ,OP_SELL,lots,priceat,0,0,0,Symbol()+"sell",magic,exptime,White); 
      }
      
   }
    if(ticket<0)
     {
      Print("OrderSend failed with error #",GetLastError());
     }
   else
      Print("OrderSend placed successfully");
    
      
      return(ticket);  
  }
 void DrawLabel(string name,string text,int X,int Y,string FontName,int FontSize,color FontColor,int zhongxin)
{
   if(ObjectFind(name)!=0)
   {
    ObjectDelete(name);
    ObjectCreate(name,OBJ_LABEL,0,0,0);
      ObjectSet(name,OBJPROP_CORNER,zhongxin);
      ObjectSet(name,OBJPROP_XDISTANCE,X);
      ObjectSet(name,OBJPROP_YDISTANCE,Y);
    }  
   ObjectSetText(name,text,FontSize,FontName,FontColor);
   WindowRedraw();
}
 
 

Forum on trading, automated trading systems and testing trading strategies


Hello,

This forum is about MT5/mql5, please post your question about MT4/mql4 on mql4.com forum.

  • They are more people who can answer there.
  • They are more people who can have similar problem there.
  • A forum is not only to get help but to share with the community, mql4/MT4 community isn't the same as mql5/MT5 community.