|
Order Management
Need some Help with Functions:
Here is my Start :
int start() {
int TotalOrders = OrdersTotal();
if ( TotalOrders <= MaxOrders) { CheckForOpen(); }
if ( TotalOrders > 0) { ManageOrders(); }
ChartComment();
return(0);
}
for some reason ManageOrders () is opening and closing a ton of orders at the same time....
for (cnt = OrdersTotal(); cnt >= 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) {
if (OrderType() == OP_BUY) {
if (//---Closing Conditions---) {
CloseOrders();
}
else if (OrdersTotal() < MaxOrders && Ask >= TP - ((TakeProfit + Pips) * Point)) {
EnterOpenBuy();
}
}
else if (OrderType() == OP_SELL) {
if (//---Closing Conditions----) {
CloseOrders();
}
else if (OrdersTotal() < MaxOrders && Bid <= TP + ((TakeProfit + Pips) * Point)) {
EnterOpenSell();
}
}
}
}
return (0);
}
And CheckForOpen() opens multiple orders on the same bar, And ReOpens orders when TP or SL is hit.....
void CheckForOpen () {
if (UseStoch){
double STOCHOSCMAIN = iCustom(NULL,STOCHTIME,"Zerolagstochs",0,SIGNALCAN DLE);
double STOCHOSCSIGNAL = iCustom(NULL,STOCHTIME,"Zerolagstochs",1,SIGNALCAN DLE);
double pSTOCHOSCMAIN = iCustom(NULL,STOCHTIME,"Zerolagstochs",0,SIGNALCAN DLE+1);
double pSTOCHOSCSIGNAL = iCustom(NULL,STOCHTIME,"Zerolagstochs",1,SIGNALCAN DLE+1);
if (STOCHOSCMAIN >= STOCHOSCSIGNAL && pSTOCHOSCMAIN > pSTOCHOSCSIGNAL && STOCHOSCSIGNAL < 50){
EnterOpenBuy();
}
if (STOCHOSCMAIN <= STOCHOSCSIGNAL && pSTOCHOSCMAIN < pSTOCHOSCSIGNAL && STOCHOSCSIGNAL > 50){
EnterOpenSell();
}
}
if (UseCCI){
double CCI = iCCI(NULL,0,CciPer,PRICE_MEDIAN,SIGNALCANDLE);
double CCIPrevious = iCCI(NULL,0,CciPer,PRICE_MEDIAN,SIGNALCANDLE+1);
if (CCI > Cci_Level1 && CCIPrevious <= Cci_Level1){
EnterOpenBuy();
}
if (CCI > Cci_Level2 && CCIPrevious <= Cci_Level2){
EnterOpenBuy();
}
if (CCI > Cci_Level3 && CCIPrevious <= Cci_Level3){
EnterOpenBuy();
}
if (CCI < Cci_Level1 && CCIPrevious >= (-Cci_Level1)){
EnterOpenSell();
}
if (CCI < Cci_Level2 && CCIPrevious >= (-Cci_Level2)){
EnterOpenSell();
}
if (CCI < Cci_Level3 && CCIPrevious >= (-Cci_Level3)){
EnterOpenSell();
}
}
}
How do I
Get CheckForOpen() to open only one position per bar?
Stop Opening of a position once it has been closed ?
Thanks For you Help
|