stupid program,i hate error 130,help!

 

can anybody tell me what's going on with my stupid program?

if((MacdPPrevious-SignalPPrevious)*(MacdPrevious-SignalPrevious)<0 )
ticket=OrderSend(Symbol(),OP_BUY,Lots,ask,3,NormalizeDouble(ask-StopLoss*point,digits), NormalizeDouble(ask+TakeProfit*point,digits),"try2 sample",10009,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());

as show,this stupid program has no problem in backward testing,but when i use it in forward testing,the order opening error 130 always appeared.i can't find reason.pls help to solve this problem..thanks a lot...thank you

 
What is volume of ask, point, StopLoss, TakeProfit and digits?
 
wang wrote >>

can anybody tell me what's going on with my stupid program?

if((MacdPPrevious-SignalPPrevious)*(MacdPrevious-SignalPrevious)<0 )
ticket=OrderSend(Symbol(),OP_BUY,Lots,ask,3,NormalizeDouble(ask-StopLoss*point,digits), NormalizeDouble(ask+TakeProfit*point,digits),"try2 sample",10009,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());

as show,this stupid program has no problem in backward testing,but when i use it in forward testing,the order opening error 130 always appeared.i can't find reason.pls help to solve this problem..thanks a lot...thank you

1. you may be using a broker that requires that you enter order first, then modify the order afterwards.

2. you may not have a sufficient distance from the Ask or Bid to the stop loss or take profit.

Attempt a manual trade, don't complete it, just right click chart and select trade. Then look at the values set by your broker. This will help you to determine issue #2.

Seperate the OrderSend and the stop loss and Take profit. Put the stop loss and take profit in a modifyOrder call.

 
wang wrote >>

can anybody tell me what's going on with my stupid program?

if((MacdPPrevious-SignalPPrevious)*(MacdPrevious-SignalPrevious)<0 )
ticket=OrderSend(Symbol(),OP_BUY,Lots,ask,3,NormalizeDouble(ask-StopLoss*point,digits), NormalizeDouble(ask+TakeProfit*point,digits),"try2 sample",10009,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());

as show,this stupid program has no problem in backward testing,but when i use it in forward testing,the order opening error 130 always appeared.i can't find reason.pls help to solve this problem..thanks a lot...thank you

First of all, always put OrderSend() in a retry loop. If you want to retry 5 times, loop 5 times but exit the loop with "break;" as soon as ticket is not -1. Make sure to use RefreshRates() inside that loop and re-update your SL/TP as the loop continues.

Second, you need to check the MarketInfo() function for STOPLEVEL and make sure that you are not inside that range -- this will return points.. 50 points on a 5 digit broker is 5 pips.

Third, in backtesting, it is an ideal world situation. Imagine that the whole world stops for you when you send an order. That just isn't the case in real live trading so it is necessary to try to catch up to the ticks with a retry loop if the market moved too much since you started analysing the entry.

Fourth, LEHayes could be right and you might need to place an order with 0 SL/TP then on the next tick, check any open orders with 0 SL/TP to change it to the wanted values.

Hope this helps,

Jon

 
Roger wrote >>
What is volume of ask, point, StopLoss, TakeProfit and digits?

hi roger

thank you .

extern int TakeProfit=500;
extern double Lots=0.1;
extern int StopLoss=250;

int start()
{
double MacdCurrent,SignalCurrent;
double SignalPrevious,MacdPrevious;
int cnt, ticket, total;
double diff, dea, Bar;
double MacdPPrevious,SignalPPrevious;
double OpenTime, CloseTime;
double bid =MarketInfo("EURUSD",MODE_BID); // Request for the value of Bid
double ask =MarketInfo("EURUSD",MODE_ASK); // Request for the value of Ask
double point =MarketInfo("EURUSD",MODE_POINT);//Request for Point
double open=iOpen(NULL,PERIOD_M5,0);
int digits=MarketInfo("EURUSD",MODE_DIGITS);
int Spread=MarketInfo("EURUSD",MODE_SPREAD);

currently,i using fxcm mt4 platform,so the price of euro vs usd is 1.44021 /1.44049,I check STOPLEVEL is zero and i know that 500 points on 5 digit broker is 50pips.so i don't think i have any mistake on this StopLoss setting.do you have any idea about my program?thanks

 
Try this simple and very reliable example just to be sure:
if((MacdPPrevious-SignalPPrevious)*(MacdPrevious-SignalPrevious)<0 )
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,30,Ask-250*Point,Ask+500*Point,"try2 sample",10009,0,Green);
etcetera
and let me know.
 
Archael wrote >>

First of all, always put OrderSend() in a retry loop. If you want to retry 5 times, loop 5 times but exit the loop with "break;" as soon as ticket is not -1. Make sure to use RefreshRates() inside that loop and re-update your SL/TP as the loop continues.

Second, you need to check the MarketInfo() function for STOPLEVEL and make sure that you are not inside that range -- this will return points.. 50 points on a 5 digit broker is 5 pips.

Third, in backtesting, it is an ideal world situation. Imagine that the whole world stops for you when you send an order. That just isn't the case in real live trading so it is necessary to try to catch up to the ticks with a retry loop if the market moved too much since you started analysing the entry.

Fourth, LEHayes could be right and you might need to place an order with 0 SL/TP then on the next tick, check any open orders with 0 SL/TP to change it to the wanted values.

Hope this helps,

Jon

thank you john

i've tried many methodes to solve this problem,as LEHayes said that i changed SL/TP to zero.it seems work.so can i write my program as following:

if((MacdPPrevious-SignalPPrevious)*(MacdPrevious-SignalPrevious)<0 )
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,ask,3,0,0,"try2 sample",10009,0,Green);
if(ticket<0)
{refreshrate()}

if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(ask-StopLoss*point,digits),NormalizeDouble(ask+TakeProfit*point,digits),0,Green);
}
}

else Print("Error opening BUY order : ",GetLastError());
return(0);

}

 
Roger wrote >>
Try this simple and very reliable example just to be sure:
if((MacdPPrevious-SignalPPrevious)*(MacdPrevious-SignalPrevious)<0 )
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,30,Ask-250*Point,Ask+500*Point,"try2 sample",10009,0,Green);
etcetera
and let me know.

hi roger

there is a same error appeared.it seems doesn't work .but if i put T/ P and S/L in zero,it's working...

 
wang wrote >>

thank you john

i've tried many methodes to solve this problem,as LEHayes said that i changed SL/TP to zero.it seems work.so can i write my program as following:

if((MacdPPrevious-SignalPPrevious)*(MacdPrevious-SignalPrevious)<0 )
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,ask,3,0,0,"try2 sample",10009,0,Green);
if(ticket<0)
{refreshrate()}

if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(ask-StopLoss*point,digits),NormalizeDouble(ask+TakeProfit*point,digits),0,Green);
}
}

else Print("Error opening BUY order : ",GetLastError());
return(0);

}

Glad you got it working!

As for anyone else with a similar problem that would like to test and make sure, here's what to do:

The best way to test is to open up a demo account and open up a trade right away. If you cannot set a SL/TP at order time manually, you won't be able to inside the EA. In this case, the right way to proceed is to send the order then modify it with the SL/TP of the open order on the next tick.

 
Cool, that one drove me nuts for about 3 weeks. I am glad I could spare someone the same headache.
Reason: