Hi,
I want to write a script for bying or selling as quick as I can. I wrotethis code, but it only works as an EA, not as a script. And as EA, I have the confirmation window, that will waste time.
Can anyone make this code work as a Script?
Or if you have your own, please send it to me.
Here are my values:
Risk = 1% of AccountBalance
SL = 50 pips;
TP = 100 pips;
Lots calculated considering SL and pipvalue
here is my code for the buy order:
void start()
{
double Lots = 0.00; /* If you want to use a static lots value change this value! */
double Risk = 1.0;
int StopLoss = 50; // Number in Pips ie: 50 for 50 pips.
int ProfitTarget = 100; // Number in Pips ie: 50 for 50 pips.
double SL = 10*StopLoss;
double TP = 10*ProfitTarget;
double PipValue = MarketInfo(Symbol(),MODE_TICKVALUE);
Lots = (AccountBalance()*Risk)/(SL*PipValue*100);
Comment ("PipValue = ",PipValue,"\n","Lots = ", (AccountEquity()*Risk)/(SL*PipValue*100),"\n");
Comment( "IBFX - QuickBuy | Placing Long Order, please wait ..." );
if(!IsTradeAllowed())
{
Print("Trade context is busy! Wait until it is free...");
// infinite loop
while(true)
{
// if trade context has become free, terminate the loop and start trading
if(IsTradeAllowed())
{
Print("Trade context has become free!");
break;
}
// if no loop breaking condition has been met, "wait" for 0.1 sec
// and restart checking
Sleep(100);
Print ("Início de Ordem de compra");
int ticketBD=-1;
int T=0;
Print ("TP = ", ProfitTarget, " SL = ",StopLoss);
Print ("Ask - SL*point = ", Ask - SL, "Ask + TP*point = ", Ask + TP);
while (ticketBD < 0)
{
RefreshRates();
ticketBD=OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Ask - SL, Ask + TP, "" ,13052011, 0, NULL);
T++;
if (ticketBD<0)
{
Print("OrderSend failed with error #",GetLastError());
}
if (T>9) break;
}
Print ("Fim de ordem de compra");
}
}
//Fim Compra
Comment("");
return;
}
//+-------------------------------------------------------------------------------+
Thanks for your help,
JFonseca
I want to write a script for bying or selling as quick as I can. I wrotethis code, but it only works as an EA, not as a script. And as EA, I have the confirmation window, that will waste time.
Can anyone make this code work as a Script?
Or if you have your own, please send it to me.
Here are my values:
Risk = 1% of AccountBalance
SL = 50 pips;
TP = 100 pips;
Lots calculated considering SL and pipvalue
here is my code for the buy order:
void start()
{
double Lots = 0.00; /* If you want to use a static lots value change this value! */
double Risk = 1.0;
int StopLoss = 50; // Number in Pips ie: 50 for 50 pips.
int ProfitTarget = 100; // Number in Pips ie: 50 for 50 pips.
double SL = 10*StopLoss;
double TP = 10*ProfitTarget;
double PipValue = MarketInfo(Symbol(),MODE_TICKVALUE);
Lots = (AccountBalance()*Risk)/(SL*PipValue*100);
Comment ("PipValue = ",PipValue,"\n","Lots = ", (AccountEquity()*Risk)/(SL*PipValue*100),"\n");
Comment( "IBFX - QuickBuy | Placing Long Order, please wait ..." );
if(!IsTradeAllowed())
{
Print("Trade context is busy! Wait until it is free...");
// infinite loop
while(true)
{
// if trade context has become free, terminate the loop and start trading
if(IsTradeAllowed())
{
Print("Trade context has become free!");
break;
}
// if no loop breaking condition has been met, "wait" for 0.1 sec
// and restart checking
Sleep(100);
Print ("Início de Ordem de compra");
int ticketBD=-1;
int T=0;
Print ("TP = ", ProfitTarget, " SL = ",StopLoss);
Print ("Ask - SL*point = ", Ask - SL, "Ask + TP*point = ", Ask + TP);
while (ticketBD < 0)
{
RefreshRates();
ticketBD=OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Ask - SL, Ask + TP, "" ,13052011, 0, NULL);
T++;
if (ticketBD<0)
{
Print("OrderSend failed with error #",GetLastError());
}
if (T>9) break;
}
Print ("Fim de ordem de compra");
}
}
//Fim Compra
Comment("");
return;
}
//+-------------------------------------------------------------------------------+
Thanks for your help,
JFonseca