Run once a script

 

Dear all, I just started learning MQL4 language to support my trades but I have a little question on how to run this very very simple script:  

 

//+------------------------------------------------------------------+
//| OrderBuy Scripts      by ***NicoMax***                           |
//|                                                                  |
//| Set a New Order Buy with Predefined Lots,SL,TP                   |
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
  int ticket,iSlipPage,iSLPips,iTPPips;
  double dStopLoss, dTakeProfit,dLots;
  string sText,sArrow;
  iSLPips=100;        //Stop Loss in Pips
  iTPPips=50;        //Take Profit in Pips
  dLots=0.01;           //Amount of Lots
  iSlipPage=3;
  sText="My Order";  //Order Text
  sArrow=CLR_NONE;   //Order Arrow Color
  
  dStopLoss=Bid-NormalizeDouble(iSLPips*Point,MarketInfo(Symbol(),MODE_DIGITS));
  dTakeProfit=Ask + NormalizeDouble(iTPPips*Point,MarketInfo(Symbol(),MODE_DIGITS));  
  ticket=OrderSend(Symbol(),OP_BUY,dLots, Ask,iSlipPage,dStopLoss, dTakeProfit,sText,000,0,sArrow);
     if(ticket<0)
       {
        Print("OrderSend failed with error #",GetLastError());
       }

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

The purpose of the script is to place a market order and set SL and TP. 

My problem is that I attached it to a chart and it starter sending orders, it didn't stop after firtst run and it executes 12 order on my real account before I stopped it!!! 

How can I run it only once? 

Thank you in advance,

Marco 

 
apone:

Dear all, I just started learning MQL4 language to support my trades but I have a little question on how to run this very very simple script:  


The purpose of the script is to place a market order and set SL and TP. 

My problem is that I attached it to a chart and it starter sending orders, it didn't stop after firtst run and it executes 12 order on my real account before I stopped it!!! 

How can I run it only once? 

Thank you in advance,

Marco 


Probably you compiled it as an Expert Advisor. All the scripts run only once. It only can open several orders if you send them inside a loop, but in that code there's no any loop. Therefore, the only option is that you compiled it as an Expert.

Please go to MetaEditor, and click on New, and then choose Script. Then copy that code and click on Compile. It should appear at Scripts folder inside MT4 Explorer.

Then, attach it to a chart.

Regards.

 
Jose Francisco Casado Fernandez:


Probably you compiled it as an Expert Advisor. All the scripts run only once. It only can open several orders if you send them inside a loop, but in that code there's no any loop. Therefore, the only option is that you compiled it as an Expert.

Please go to MetaEditor, and click on New, and then choose Script. Then copy that code and click on Compile. It should appear at Scripts folder inside MT4 Explorer.

Then, attach it to a chart.

Regards.

Thank you very very much!

The first time I opened the file and compiled directly.

Now I created a NEW SCRIPT file, cut & paste code inside it, then compiled and it works as expected!

 
apone:

Thank you very very much!

The first time I opened the file and compiled directly.

Now I created a NEW SCRIPT file, cut & paste code inside it, then compiled and it works as expected!

I'm glad everything was fine. Regards.
Reason: