Order Management

[Deleted]  

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() = 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,SIGNALCANDLE);

double STOCHOSCSIGNAL = iCustom(NULL,STOCHTIME,"Zerolagstochs",1,SIGNALCANDLE);

double pSTOCHOSCMAIN = iCustom(NULL,STOCHTIME,"Zerolagstochs",0,SIGNALCANDLE+1);

double pSTOCHOSCSIGNAL = iCustom(NULL,STOCHTIME,"Zerolagstochs",1,SIGNALCANDLE+1);

if (STOCHOSCMAIN >= STOCHOSCSIGNAL && pSTOCHOSCMAIN > pSTOCHOSCSIGNAL && STOCHOSCSIGNAL < 50){

EnterOpenBuy();

}

if (STOCHOSCMAIN <= STOCHOSCSIGNAL && pSTOCHOSCMAIN 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)){

EnterOpenSell();

}

if (CCI = (-Cci_Level2)){

EnterOpenSell();

}

if (CCI = (-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

[Deleted]  

also how do you change the color of chart comments ?

sComment = sComment + "Account Profit : $ " + DoubleToStr(AccountProfit(),2) + sNewLine;

I want this to be green when positive and red when neg...

I know it random but ....

[Deleted]  

12 views and no help ??? I thought that this was an EA support community???

[Deleted]  

45 views and still nothing ... How many people here are contributing, and how many are just trolling for free systems?

[Deleted]  

How about Pictures....

Here it is with ManageOrders(); disabled....

Question is why is this code opening multiple orders at the same time ?

void CheckForOpen () {

if (UseStoch){

double STOCHOSCMAIN = iCustom(NULL,STOCHTIME,"Zerolagstochs",0,SIGNALCANDLE);

double STOCHOSCSIGNAL = iCustom(NULL,STOCHTIME,"Zerolagstochs",1,SIGNALCANDLE);

double pSTOCHOSCMAIN = iCustom(NULL,STOCHTIME,"Zerolagstochs",0,SIGNALCANDLE+1);

double pSTOCHOSCSIGNAL = iCustom(NULL,STOCHTIME,"Zerolagstochs",1,SIGNALCANDLE+1);

if (STOCHOSCMAIN >= STOCHOSCSIGNAL && pSTOCHOSCMAIN > pSTOCHOSCSIGNAL && STOCHOSCSIGNAL < 50){

EnterOpenBuy();

}

if (STOCHOSCMAIN <= STOCHOSCSIGNAL && pSTOCHOSCMAIN 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)){

EnterOpenSell();

}

if (CCI = (-Cci_Level2)){

EnterOpenSell();

}

if (CCI = (-Cci_Level3)){

EnterOpenSell();

}

}

}

And here is the EnterOpen() functions...

void EnterOpenBuy(){

GetTrend();

double LongLots = ((AccountFreeMargin()* AccountLeverage()* UpTrend / MarketInfo(Symbol(), MODE_LOTSIZE)) * (RiskPercent/100.0))/MaxOrders;

if (LongLots < 0.1) {LongLots = 0.1;}

OrderSend(Symbol(),OP_BUY,LongLots , Ask, OrderSlippage,Bid-StopLoss*Point,Ask+TakeProfit*Point, "Open Buy", Magic, 0, Green);

Print ("OPEN BUY : ", OrderLots());

return (0);

}

void EnterOpenSell(){

GetTrend();

double ShortLots = ((AccountFreeMargin()* AccountLeverage()* DownTrend / MarketInfo(Symbol(), MODE_LOTSIZE)) * (RiskPercent/100.0))/MaxOrders;

if (ShortLots < 0.1) {ShortLots = 0.1;}

OrderSend(Symbol(), OP_SELL, ShortLots, Bid, OrderSlippage,Ask+StopLoss*Point,Bid-TakeProfit * Point, "Open Sell", Magic, 0, Red);

Print ("OPEN SELL : ", OrderLots());

return (0);

}

Files:
[Deleted]  

And this is what the ManageOrders() function is doing...

Here is the Code...

void ManageOrders(){

for (cnt = OrdersTotal(); cnt >= 0; cnt--) {

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) {

if (OrderType() == OP_BUY) {

if (Bid = TP || Bid > QUICKUPPER3) {

CloseOrders();

}

else if (OrdersTotal() = TP - ((TakeProfit + Pips) * Point)) {

EnterOpenBuy();

}

}

else if (OrderType() == OP_SELL) {

if (Ask >= SL || Ask <= TP || Ask < QUICKLOWER3) {

CloseOrders();

}

else if (OrdersTotal() < MaxOrders && Bid <= TP + ((TakeProfit + Pips) * Point)) {

EnterOpenSell();

}

}

}

}

return (0);

}

Files:
[Deleted]  

I could not post all of the indicators used in the manage order ... too many charactors.

The goal is to have ManageOrders()

1. Manage all open positions as one. cnt --

2. If the Ask/Bid goes against you by n pips, add to the order.

3. close all OP_BUY or OP_SELL orders at the same time.

seems pretty simple but it does not work....I think it has something to do with me allowing multiple trades. but then again i cannot seem to figure it out.

Is there anyone here that can help?

Thanks...

[Deleted]  
Kurka Fund:
How about Pictures....

Here it is with ManageOrders(); disabled....

Question is why is this code opening multiple orders at the same time ?

void CheckForOpen () {

if (UseStoch){

double STOCHOSCMAIN = iCustom(NULL,STOCHTIME,"Zerolagstochs",0,SIGNALCANDLE);

double STOCHOSCSIGNAL = iCustom(NULL,STOCHTIME,"Zerolagstochs",1,SIGNALCANDLE);

double pSTOCHOSCMAIN = iCustom(NULL,STOCHTIME,"Zerolagstochs",0,SIGNALCANDLE+1);

double pSTOCHOSCSIGNAL = iCustom(NULL,STOCHTIME,"Zerolagstochs",1,SIGNALCANDLE+1);

if (STOCHOSCMAIN >= STOCHOSCSIGNAL && pSTOCHOSCMAIN > pSTOCHOSCSIGNAL && STOCHOSCSIGNAL < 50){

EnterOpenBuy();

}

if (STOCHOSCMAIN <= STOCHOSCSIGNAL && pSTOCHOSCMAIN 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)){

EnterOpenSell();

}

if (CCI = (-Cci_Level2)){

EnterOpenSell();

}

if (CCI = (-Cci_Level3)){

EnterOpenSell();

}

}

}

And here is the EnterOpen() functions...

void EnterOpenBuy(){

GetTrend();

double LongLots = ((AccountFreeMargin()* AccountLeverage()* UpTrend / MarketInfo(Symbol(), MODE_LOTSIZE)) * (RiskPercent/100.0))/MaxOrders;

if (LongLots < 0.1) {LongLots = 0.1;}

OrderSend(Symbol(),OP_BUY,LongLots , Ask, OrderSlippage,Bid-StopLoss*Point,Ask+TakeProfit*Point, "Open Buy", Magic, 0, Green);

Print ("OPEN BUY : ", OrderLots());

return (0);

}

void EnterOpenSell(){

GetTrend();

double ShortLots = ((AccountFreeMargin()* AccountLeverage()* DownTrend / MarketInfo(Symbol(), MODE_LOTSIZE)) * (RiskPercent/100.0))/MaxOrders;

if (ShortLots < 0.1) {ShortLots = 0.1;}

OrderSend(Symbol(), OP_SELL, ShortLots, Bid, OrderSlippage,Ask+StopLoss*Point,Bid-TakeProfit * Point, "Open Sell", Magic, 0, Red);

Print ("OPEN SELL : ", OrderLots());

return (0);

}

Why does it open more than one order per bar?

 
Kurka Fund:
Need some Help with Functions:

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

you have to keep track of last orderopen time ..

//this is pseudo code ..

//find the last open order ..

//loop through open orders

lastOpenTime=OrderOpenTime(); //from open

//loop through history

lastCloseTime=OrderCloseTime(); //from History

if((itime(..)-lastOpenTime)>Period()*60 && (itime(..)-lastCloseTime)>Period()*60 )

{

CheckForOpen();

}

at least you are trying .. that's good.

regards

 

Hey KurkaFund

Try using the "Wrap [CODE] tags around selected text" button.

It formats your code so that it looks like . . code.

Trying to read all your stuff 'left justified' is tough.

Sorry I can't help more. It's tough to pick up someone's code when you are new to it and see a problem right away.

Keep banging away at it, posting your thoughts, hopefully we can help you, and by doing that, help ourselves too.

Tross

[Deleted]  

Here it is with the Wrap Code ...

Check for Open

void CheckForOpen () {

if (UseStoch){

double STOCHOSCMAIN = iCustom(NULL,STOCHTIME,"Zerolagstochs",0,SIGNALCANDLE);

double STOCHOSCSIGNAL = iCustom(NULL,STOCHTIME,"Zerolagstochs",1,SIGNALCANDLE);

double pSTOCHOSCMAIN = iCustom(NULL,STOCHTIME,"Zerolagstochs",0,SIGNALCANDLE+1);

double pSTOCHOSCSIGNAL = iCustom(NULL,STOCHTIME,"Zerolagstochs",1,SIGNALCANDLE+1);

if (STOCHOSCMAIN >= STOCHOSCSIGNAL && pSTOCHOSCMAIN > pSTOCHOSCSIGNAL && STOCHOSCSIGNAL < 50){

EnterOpenBuy();

}

if (STOCHOSCMAIN <= STOCHOSCSIGNAL && pSTOCHOSCMAIN 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)){

EnterOpenSell();

}

if (CCI = (-Cci_Level2)){

EnterOpenSell();

}

if (CCI = (-Cci_Level3)){

EnterOpenSell();

}

}

}[/PHP]

And Enter Open

void EnterOpenBuy(){

GetTrend();

double LongLots = ((AccountFreeMargin()* AccountLeverage()* UpTrend / MarketInfo(Symbol(), MODE_LOTSIZE)) * (RiskPercent/100.0))/MaxOrders;

if (LongLots < 0.1) {LongLots = 0.1;}

OrderSend(Symbol(),OP_BUY,LongLots , Ask, OrderSlippage,Bid-StopLoss*Point,Ask+TakeProfit*Point, "Open Buy", Magic, 0, Green);

Print ("OPEN BUY : ", OrderLots());

return (0);

}

void EnterOpenSell(){

GetTrend();

double ShortLots = ((AccountFreeMargin()* AccountLeverage()* DownTrend / MarketInfo(Symbol(), MODE_LOTSIZE)) * (RiskPercent/100.0))/MaxOrders;

if (ShortLots < 0.1) {ShortLots = 0.1;}

OrderSend(Symbol(), OP_SELL, ShortLots, Bid, OrderSlippage,Ask+StopLoss*Point,Bid-TakeProfit * Point, "Open Sell", Magic, 0, Red);

Print ("OPEN SELL : ", OrderLots());

return (0);

}

And Manage Orders ...

[PHP]void ManageOrders(){

for (cnt = OrdersTotal(); cnt >= 0; cnt--) {

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) {

if (OrderType() == OP_BUY) {

if (Bid = TP || Bid > QUICKUPPER3) {

CloseOrders();

}

else if (OrdersTotal() = TP - ((TakeProfit + Pips) * Point)) {

EnterOpenBuy();

}

}

else if (OrderType() == OP_SELL) {

if (Ask >= SL || Ask <= TP || Ask < QUICKLOWER3) {

CloseOrders();

}

else if (OrdersTotal() < MaxOrders && Bid <= TP + ((TakeProfit + Pips) * Point)) {

EnterOpenSell();

}

}

}

}

return (0);

}

Hopefully this helps...

Thanks.