Hi RR.
OK I found the coding. In this case, they created a separate function called OpenBuy() and OpenSell() but you get the picture. MaxLoop was previously defined at 25.
//ENTRY LONG (buy, Ask)
void OpenBuy()
{
int gle=0; //Get Last Error
int ticket=0;
double SL=0;
double TP=0;
int loopcount;
// PLACE order is independent of MODIFY order.
// This is mandatory for ECNs and acceptable for retail brokers
loopcount=0;
while(true)
{
// place order - NO TP OR SL
ticket=OrderSend(Symbol(),OP_BUY,lotsi,Ask,Slippage,0,0,TradeComment,MagicNumber,White);
gle=GetLastError();
if(gle==0)
{
logwrite(TradeComment,"BUY PLACED Ticket="+ticket+" Ask="+Ask+" Lots="+lotsi);
break;
}
else
{
logwrite(TradeComment,"-----ERROR----- Placing BUY order: Lots="+lotsi+" Bid="+Bid+" Ask="+Ask+" ticket="+ticket+" Err="+gle+" "+ErrorDescription(gle));
RefreshRates();
Sleep(500);
// give up after loopcount tries
loopcount++;
if(loopcount>maxloop)
{
logwrite(TradeComment,"-----ERROR----- Giving up on placing BUY order");
return(gle);
}
}
}//while - place order
// modify the order for users TP & SL
loopcount=0;
while(true)
{
// don't set TP and SL both to zero, they're already there
if(LossLimit==0 && ProfitMade==0) break;
if(LossLimit ==0) SL=0;
if(ProfitMade ==0) TP=0;
if(LossLimit >0) SL=Ask-((LossLimit)*myPoint );
if(ProfitMade >0) TP=Ask+((ProfitMade)*myPoint );
OrderModify(ticket,OrderOpenPrice(),SL,TP,0,White);
gle=GetLastError();
if(gle==0)
{
logwrite(TradeComment,"BUY MODIFIED Ticket="+ticket+" Ask="+Ask+" Lots="+lotsi+" SL="+SL+" TP="+TP);
break;
}
else
{
logwrite(TradeComment,"-----ERROR----- Modifying BUY order: Lots="+lotsi+" SL="+SL+" TP="+TP+" Bid="+Bid+" Ask="+Ask+" ticket="+ticket+" Err="+gle+" "+ErrorDescription(gle));
RefreshRates();
Sleep(500);
loopcount++;
if(loopcount>maxloop)
{
logwrite(TradeComment,"-----ERROR----- Giving up on modifying BUY order");
return(gle);
}
}
}//while - modify order
}//BUYme
Dave R.
OK I found the coding. In this case, they created a separate function called OpenBuy() and OpenSell() but you get the picture. MaxLoop was previously defined at 25.
//ENTRY LONG (buy, Ask)
void OpenBuy()
{
int gle=0; //Get Last Error
int ticket=0;
double SL=0;
double TP=0;
int loopcount;
// PLACE order is independent of MODIFY order.
// This is mandatory for ECNs and acceptable for retail brokers
loopcount=0;
while(true)
{
// place order - NO TP OR SL
ticket=OrderSend(Symbol(),OP_BUY,lotsi,Ask,Slippage,0,0,TradeComment,MagicNumber,White);
gle=GetLastError();
if(gle==0)
{
logwrite(TradeComment,"BUY PLACED Ticket="+ticket+" Ask="+Ask+" Lots="+lotsi);
break;
}
else
{
logwrite(TradeComment,"-----ERROR----- Placing BUY order: Lots="+lotsi+" Bid="+Bid+" Ask="+Ask+" ticket="+ticket+" Err="+gle+" "+ErrorDescription(gle));
RefreshRates();
Sleep(500);
// give up after loopcount tries
loopcount++;
if(loopcount>maxloop)
{
logwrite(TradeComment,"-----ERROR----- Giving up on placing BUY order");
return(gle);
}
}
}//while - place order
// modify the order for users TP & SL
loopcount=0;
while(true)
{
// don't set TP and SL both to zero, they're already there
if(LossLimit==0 && ProfitMade==0) break;
if(LossLimit ==0) SL=0;
if(ProfitMade ==0) TP=0;
if(LossLimit >0) SL=Ask-((LossLimit)*myPoint );
if(ProfitMade >0) TP=Ask+((ProfitMade)*myPoint );
OrderModify(ticket,OrderOpenPrice(),SL,TP,0,White);
gle=GetLastError();
if(gle==0)
{
logwrite(TradeComment,"BUY MODIFIED Ticket="+ticket+" Ask="+Ask+" Lots="+lotsi+" SL="+SL+" TP="+TP);
break;
}
else
{
logwrite(TradeComment,"-----ERROR----- Modifying BUY order: Lots="+lotsi+" SL="+SL+" TP="+TP+" Bid="+Bid+" Ask="+Ask+" ticket="+ticket+" Err="+gle+" "+ErrorDescription(gle));
RefreshRates();
Sleep(500);
loopcount++;
if(loopcount>maxloop)
{
logwrite(TradeComment,"-----ERROR----- Giving up on modifying BUY order");
return(gle);
}
}
}//while - modify order
}//BUYme
Dave R.