} } if(dreason==(DEAL_REASON_SL) && dsymbol==Symbol()) //<<--This doesn't work, dreason==(DEAL_REASON_SL) never returns true. {
I figured it out. It was selecting the position before searching for a deal. There is no position when a stop is triggered.
Here's the working code with the change. Thanks for your help!
void TradeProcessor() { ResetLastError(); //--- download trading history from the specified interval to the program cache bool select_pos=pos_info.Select(m_Symbol); ///////removed if(select_pos)<<<-- bool selected=HistorySelect(0,TimeCurrent()); //////changed HistorySelect start time to 0 from pos_info.Time() if(!selected) { PrintFormat("%s. Failed to load history from %s to %s to cache. Error code: %d", __FUNCTION__,TimeToString(pos_info.Time()),TimeToString(TimeCurrent()),GetLastError()); return; } //--- get the current values int deals=HistoryDealsTotal(); string name; //--- for all deals for(int i=deals-1; i>=0 ; i++) { //--- try to get deals ticket if((dticket=HistoryDealGetTicket(i))>0 && dticket!=last_ticket) { //--- get deals properties dtime= (datetime)HistoryDealGetInteger(dticket,DEAL_TIME); dsymbol= HistoryDealGetString(dticket,DEAL_SYMBOL); dreason= (int)HistoryDealGetInteger(dticket,DEAL_REASON); dmagic= HistoryDealGetInteger(dticket,DEAL_MAGIC); dcom= HistoryDealGetDouble(dticket,DEAL_COMMISSION); dprice= HistoryDealGetDouble(dticket,DEAL_PRICE); dvolume= HistoryDealGetDouble(dticket,DEAL_VOLUME); //--- only for current symbol if(dreason==(DEAL_REASON_EXPERT) && dsymbol==m_Symbol) { name="Ticket #_"+string(dticket); Print("Expert deal: ",pos_info.Comment(),"\n",name,"); } if(dreason==(DEAL_REASON_CLIENT) && dsymbol==m_Symbol) { rebootresume(dcom,dticket,dprice,dtime,1); } if(dreason==(DEAL_REASON_SL) && dsymbol==m_Symbol) { PlaySound("alert2.wav"); } } } return; }
datetime day[1]; day[0]=-1; CopyTime(Symbol(),PERIOD_D1,1,1,day); ResetLastError(); //--- download trading history from the specified interval to the program cache bool select_pos=pos_info.Select(m_Symbol); bool selected=HistorySelect(day[0],TimeCurrent());
int deals=HistoryDealsTotal(); string name; datetime dtime; string dsymbol; int dreason; double dprofit; //--- for all deals for(int i=deals-1; i<=deals ; i++)
But is the loop even necessary if I just want the most recent deal info?
Either way, this dramatically sped up the program. I went back over other for loops in my code and realized this is a recurring problem of loops being limited by break statements but still sometimes searching through history unnecessarily. I thought maybe this is what was causing my debugger to freeze and sure enough, that is working again too. Thanks for the help. Improving my coding skills everyday!
for(int cnt = NULL; (cnt < max) && !_StopFlag; cnt++)
while( (x < y)
&& (!_StopFlag) )
static datetime last_processed = NULL;
int cnt = NULL;
while( (last_processed < orders[cnt].open_time)
&& (!_StopFlag))
{
cnt++;
}
last_processed = orders[0].open_time;
I have a function for finding the price and reason for the last deal to have taken place. I made a change, it stopped working, so I changed it back...and it still wasn't working. I reverted to an older version and it STILL IS NOT WORKING. How is this possible? Oh yeah and backtesting on history data keeps freezing now, even on previous, untouched stable versions.
New version (works for everything except dreason==DEAL_REASON_SL is never triggered):
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have a function for finding the price and reason for the last deal to have taken place. I made a change, it stopped working, so I changed it back...and it still wasn't working. I reverted to an older version and it STILL IS NOT WORKING. How is this possible? Oh yeah and backtesting on history data keeps freezing now, even on previous, untouched stable versions.
New version (works for everything except dreason==DEAL_REASON_SL is never triggered):