12-05-2006, 10:33 PM
Senior Member
Join Date: Sep 2006
Location: San Diego
Posts: 138
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
12-05-2006, 10:39 PM
Senior Member
Join Date: Sep 2006
Location: San Diego
Posts: 138
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 ....
12-05-2006, 11:17 PM
Senior Member
Join Date: Sep 2006
Location: San Diego
Posts: 138
12 views and no help ??? I thought that this was an EA support community???
12-06-2006, 03:01 AM
Senior Member
Join Date: Sep 2006
Location: San Diego
Posts: 138
45 views and still nothing ... How many people here are contributing, and how many are just trolling for free systems?
12-06-2006, 03:42 AM
Senior Member
Join Date: Sep 2006
Location: San Diego
Posts: 138
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,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();
}
}
}
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);
}
12-06-2006, 03:45 AM
Senior Member
Join Date: Sep 2006
Location: San Diego
Posts: 138
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 <= SL || Bid >= TP || Bid > QUICKUPPER3) {
CloseOrders();
}
else if (OrdersTotal() < MaxOrders && Ask >= 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);
}
12-06-2006, 03:50 AM
Senior Member
Join Date: Sep 2006
Location: San Diego
Posts: 138
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...
12-06-2006, 03:51 AM
Senior Member
Join Date: Sep 2006
Location: San Diego
Posts: 138
Quote:
Originally Posted by 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,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();
}
}
}
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?
12-06-2006, 03:56 AM
Senior Member
Join Date: Jan 2006
Location: Tokyo
Posts: 237
Quote:
Originally Posted by 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
12-06-2006, 03:58 AM
Senior Member
Join Date: Oct 2006
Posts: 127
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
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT. The time now is 10:56 AM .