|
Please help with simple generic script.
Hi
Can some1 help me please with simple script.
Here is what i need.
Very generic script that can be used on any symbol that will place 3-4 orders for SELL_STOP and BUY_STOP
Let's say i want to place a buy_stop 20 points above current price, second order 40 points above current price, 3d 80 points and so on.
Same thing for Sell_Stop
I kinda was trying to assemble the script based on some examples but since i am not familiar with C language i am having some problems.
"""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""" """"// improved.mq4
int start()
{
int ticket,i;
int cnt=1;
int Dist_SL =10; // Preset SL (pt)
int Dist_TP =100; // Preset TP (pt)
string Symb=Symbol(); // Symbol
RefreshRates();
double bid =MarketInfo(Symb,MODE_BID);
double ask =MarketInfo(Symb,MODE_ASK);
double point =MarketInfo(Symb,MODE_POINT);
int Min_Dist=MarketInfo(Symb,MODE_STOPLEVEL);
if (Dist_TP < Min_Dist) // If it is less than allowed
{
Dist_TP=Min_Dist; // Set the allowed
Alert(" Increased the distance of TakeP = ",Dist_TP," pt");
}
//-------------------------------------------------------------------- 6 --
Alert("The request was sent to the server. Waiting for reply..");
for(i=100;i<400;i=i+100)
{
double TP=(ask+i*Point) + Dist_TP*Point; // Requested price of TP
ticket=OrderSend(Symb,OP_BUYSTOP,0.1,ask+i*Point,1 ,(ask+i*Point)-Dist_SL*Point,TP);
Sleep(500);
int Error=GetLastError(); // Failed :(
switch(Error) // Overcomable errors
{
case 130:Alert("The SL is wrong. Retrying..");
RefreshRates(); // Update data
if (Dist_SL < Min_Dist) // If it is less than allowed
{
Dist_SL=Min_Dist; // Set the allowed
Alert(" Increased the distance of SL = ",Dist_SL," pt");
}
i=i-50;
Alert (i);
Alert (Dist_SL);
cnt=cnt+1;
Alert (cnt);
if (cnt==3)break;
continue; // At the next iteration
case 135:Alert("The price has changed. Retrying..");
RefreshRates(); // Update data
continue; // At the next iteration
case 136:Alert("No prices. Waiting for a new tick..");
while(RefreshRates()==false) // Up to a new tick
Sleep(1); // Cycle delay
continue; // At the next iteration
case 146:Alert("Trading subsystem is busy. Retrying..");
Sleep(500); // Simple solution
RefreshRates(); // Update data
continue; // At the next iteration
}
switch(Error) // Critical errors
{
case 2 : Alert("Common error.");
break; // Exit 'switch'
case 5 : Alert("Outdated version of the client terminal.");
break; // Exit 'switch'
case 64: Alert("The account is blocked.");
break; // Exit 'switch'
case 133:Alert("Trading forbidden");
break; // Exit 'switch'
default: Alert("Occurred error ",Error);// Other alternatives
}
//break;
}
//-------------------------------------------------------------------------- 9 --
Alert ("The script has completed its operations ---------------------------");
return; // Exit start()
}
"""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""""""""
It kinda of works but many times i am having problem with stop loss.
Last edited by Linuxser; 12-19-2008 at 01:24 AM.
|