Hi, Wolfe - congrats on what you've done and thought these few points might help...
1) you have lots of code replication in v1_3 - you should be able to get a 50% reduction in the number of code lines and do away with the header file in the process - that will also simplify installation/updates for users. If you'd like some help with changing the code then PM me.
2) you don't need to use any global variables at all if you include an open orders checking routine at the beginning of the file - it would actually simplify things and speed up the processing as your routines in the header file are called multiple times during each pass and are replicating the work.
3) you certainly don't need to be changing magic numbers - just check for a combination of magic number and Symbol()
4) to prevent "context busy" issues, you're best to include a wait loop checking for server availability - something like this...
while (!IsTradeAllowed() && !IsStopped())
{
Sleep(1000);
}
if (IsTradeAllowed() && !IsStopped())
{
RefreshRates();
Put order code here.....
}
...and ensure that you use RefreshRates() nearby any order placement command to minimise/prevent requotes
5) your CBM routine will fail if it encounters an order in the order list where no magic numbre was used - some EAs do this and all manually entered orders
6) for any interrogation of the orders list, it's good practice to traverse a known number of entries (use OrdersTotal() - 1 to get the current count)...
...if you are closing / deleting orders then run your loop from the highest to lowest entry. If just reading the information then direction doesn't matter unless your code depends on it for instance, here is some code from one of my other EAs which could be placed at the top of your start() routine and would collect all the information you need in one fell swoop and allow you to dispose of the global variables too...
Orders = OrdersTotal() - 1;
for (Order = 0; Order < Orders; Order++)
{
if (OrderSelect(Order, SELECT_BY_POS))
{
if (OrderMagicNumber() == Reference && OrderSymbol() == Symbol())
{
LastTicket = OrderTicket();
LastPrice = OrderOpenPrice();
LastLots = OrderLots();
Count++;
Profit = Profit + OrderProfit() + OrderSwap() + OrderCommission();
if (OrderType() == OP_BUY)
{
Count_B++;
Profit_B = Profit_B + OrderProfit() + OrderSwap() + OrderCommission();
}
if (OrderType() == OP_SELL)
{
Count_S++;
Profit_S = Profit_S + OrderProfit() + OrderSwap() + OrderCommission();
}
}
}
else
{
Print("Unable to select order in list position: ", Order);
Trade_Allowed = false;
return(0);
}
}
Hope that helps,
Neo
|