Forex



Go Back   Forex Trading > Downloads > Expert Advisors - Metatrader 4






Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 12-05-2006, 10:33 PM
Kurka Fund's Avatar
Senior Member
 
Join Date: Sep 2006
Location: San Diego
Posts: 138
Kurka Fund is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 12-05-2006, 10:39 PM
Kurka Fund's Avatar
Senior Member
 
Join Date: Sep 2006
Location: San Diego
Posts: 138
Kurka Fund is on a distinguished road
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 ....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 12-05-2006, 11:17 PM
Kurka Fund's Avatar
Senior Member
 
Join Date: Sep 2006
Location: San Diego
Posts: 138
Kurka Fund is on a distinguished road
12 views and no help ??? I thought that this was an EA support community???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 12-06-2006, 03:01 AM
Kurka Fund's Avatar
Senior Member
 
Join Date: Sep 2006
Location: San Diego
Posts: 138
Kurka Fund is on a distinguished road
45 views and still nothing ... How many people here are contributing, and how many are just trolling for free systems?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #5 (permalink)  
Old 12-06-2006, 03:42 AM
Kurka Fund's Avatar
Senior Member
 
Join Date: Sep 2006
Location: San Diego
Posts: 138
Kurka Fund is on a distinguished road
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);
}
Attached Images
File Type: bmp TheBigProvider Snapshot.bmp (1.71 MB, 263 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #6 (permalink)  
Old 12-06-2006, 03:45 AM
Kurka Fund's Avatar
Senior Member
 
Join Date: Sep 2006
Location: San Diego
Posts: 138
Kurka Fund is on a distinguished road
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);
}
Attached Images
File Type: bmp TBP Manage Orders.bmp (1.75 MB, 238 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #7 (permalink)  
Old 12-06-2006, 03:50 AM
Kurka Fund's Avatar
Senior Member
 
Join Date: Sep 2006
Location: San Diego
Posts: 138
Kurka Fund is on a distinguished road
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...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #8 (permalink)  
Old 12-06-2006, 03:51 AM
Kurka Fund's Avatar
Senior Member
 
Join Date: Sep 2006
Location: San Diego
Posts: 138
Kurka Fund is on a distinguished road
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #9 (permalink)  
Old 12-06-2006, 03:56 AM
auto's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Tokyo
Posts: 237
auto is on a distinguished road
Exclamation

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #10 (permalink)  
Old 12-06-2006, 03:58 AM
Senior Member
 
Join Date: Oct 2006
Posts: 127
Tross is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
Zerolagstochs

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Swiss Army EA (Automatic order management) ryanklefas Expert Advisors - Metatrader 4 344 11-02-2009 02:44 PM


All times are GMT. The time now is 10:56 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.