magft wrote:Thats is Empty4 for you!! Here is a new version that fixes that (i didnt want anyone trying it on a live account yet but i'll turn that off)and the atr filter issue, you need M1 data for the period of interest at the mo. I have changed this so that it is user specifiable the update interval so for backtesting set to same or previous tf in minutes.
This is still a demo version until we are sure the trade context bit is fixed.
I'm going bed now, have fun.
Mike
I think you may be allowing too long of a wait for making the trades. For example, looking at the modify section of the BreakEvenStopLoss():
Code: Select all
if (modify)
{
//RetryCount is declared as 10 in the Trading variables section at the top of this file
for (int cc = 0; cc < RetryCount; cc++)
{
for (int d = 0; (d < RetryCount) && TradeIsBusy()<0; d++) Sleep(100);
result = OrderModify(OrderTicket(), OrderOpenPrice(), NewStop, OrderTakeProfit(), OrderExpiration(), CLR_NONE);
if (!result) ReportError();
}
// set the trade context free
TradeIsNotBusy();
}//if (modify)
TradeIsBusy() will already wait 30 seconds for the semaphore to be available. You have it waiting for a considerably longer period (I got tired multiplying

). No doubt that would never happen, but I think this is sufficient:
Code: Select all
if (modify)
{
//try to lock the trading thread for our use
if (TradeIsBusy()<0) {
Alert("Unable to modify stop loss, wait time exceeded.");
return;
}
//ok, we can trade now
for (int cc = 0; cc < RetryCount; cc++)
{
RefreshRates(); //make sure we have updated info
result = OrderModify(OrderTicket(), OrderOpenPrice(), NewStop, OrderTakeProfit(), OrderExpiration(), CLR_NONE);
if (!result) ReportError();
}
// set the trade context free
TradeIsNotBusy();
}//if (modify)
The pattern should be:
Lock Resource
Use Resource
Unlock Resource
In this case that's
TradeIsBusy() == 1
{ do some trading -- but do it quickly}
TradeIsNotBusy()
The names aren't very descriptive. What the author means is SetTradeIsBusyFlag() and ClearTradeIsBusyFlag(). It would be better if they were called LockTradingThread() and UnlockTradingThread() or something similar.
I also think you'll want to place a call to TradeIsNotBusy() in deinit().
George