Sorry Hop it look OK now.
int start() { //---- // -- Check if there is already open position with that Symbol if(OrderSelect(NULL,SELECT_BY_TICKET)==true) { if(OrderSymbol() == Symbol()) { CheckForTrailStop(); } } //-- Open Long if (LastUpperBolinger <= LastUpperKeltner) { if (Close[1]>UpperBolinger) { if (UpperBolinger > UpperKeltner) { if (MACD_M > MACD_S) { OpenLongPosition(); } } } } //-- Open Short if (LastLowerBolinger >= LastLowerKeltner) { if (Close[1]<LowerBolinger) { if (LowerBolinger < LowerKeltner) { if (MACD_M < MACD_S) { OpenShortPosition(); } } } } //---- return(0); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Open Long Order Procedure | //+------------------------------------------------------------------+ int OpenLongPosition () { double LowPrice = iLowest(Symbol(),0,MODE_LOWER,10,0); if (OrderSelect(NULL,SELECT_BY_TICKET)== true) { if (OrderSymbol() == Symbol()) { Alert ("Cannot Open Position - Already have Opened Position"); CheckForTrailStop(); } else OrderSend(Symbol(),OP_BUY, 0.1, Ask, 3, LowPrice, 0, NULL, 0, 0, Green); } //---- return(0); } //+------------------------------------------------------------------+ //| Open Short Order Procedure | //+------------------------------------------------------------------+ int OpenShortPosition () { double HighPrice = iHighest(Symbol(),0,MODE_UPPER,10,0); if (OrderSelect(NULL,SELECT_BY_TICKET)== true) { if (OrderSymbol() == Symbol()) { Alert ("Cannot Open Position - Already have Opened Position"); CheckForTrailStop(); } else OrderSend(Symbol(),OP_SELL, 0.1, Bid, 3, HighPrice, 0, NULL, 0, 0, Blue); } //---- return(0); } //+------------------------------------------------------------------+ //| Trailing Stop Procedure | //+------------------------------------------------------------------+ int CheckForTrailStop() { if(OrderSelect(NULL,SELECT_BY_TICKET)==true) { if(OrderSymbol() == Symbol()) { if (OrderType() == OP_BUY) { if (Bid > OrderOpenPrice() + 100*Point) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid-100*Point,OrderTakeProfit(),0,Green); } } if (OrderType() == OP_SELL) { if(Ask < OrderOpenPrice() - 100*Point) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask-100*Point,OrderTakeProfit(),0,Blue); } } } } //---- return(0);
vaknineyal:
What error# and message does it give you?
Hi All,
I cannot understand why this code not open any order and also it doesn't give any error.
Update - I Added the code down on this topic.
Thanks A lot.
ubzen:
What error# and message does it give you?
What error# and message does it give you?
No error just not open any position.
vaknineyal: No error just not open any position.
Check out the Book OrderSelect_Loop.
vaknineyal: Sorry Hop it look OK now.
- Why didn't you edit your original post as requested?
if(OrderSelect(NULL,SELECT_BY_TICKET)==true)
NULL is not a valid ticket number, this if never executeselse OrderSend(Symbol(),OP_SELL, 0.1, Bid, 3, HighPrice, 0, NULL, 0, 0, Blue);
What are Function return values ? How do I use them ? - MQL4 forum
vaknineyal:
Ohhh not sure about that, I am tring to find if there is any open order and if yes check if the order is the same symbol as I want to open.
So how should I write it ?
You have to do: if(OrdersTatal() > 0) { ... }
I change the code to look like that ... but it still doesn't open any order
int start() { //---- if(OrderSelect(12345,SELECT_BY_TICKET)==true) { if(OrderSymbol() == Symbol()) { CheckForTrailStop(); } } //-- Open Long if (LastUpperBolinger <= LastUpperKeltner) { if (Close[1]>UpperBolinger) { if (UpperBolinger > UpperKeltner) { if (MACD_M > MACD_S) { OpenLongPosition(); } } } } //-- Open Short if (LastLowerBolinger >= LastLowerKeltner) { if (Close[1]<LowerBolinger) { if (LowerBolinger < LowerKeltner) { if (MACD_M < MACD_S) { OpenShortPosition(); } } } } //---- return(0); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Open Long Order Procedure | //+------------------------------------------------------------------+ int OpenLongPosition () { double LowPrice = iLowest(Symbol(),0,MODE_LOWER,10,0); if (OrderSelect(12345,SELECT_BY_TICKET)==true) { if (OrderSymbol() == Symbol()) { Alert ("Cannot Open Position - Already have Opened Position"); CheckForTrailStop(); } } if (OrderSelect(12345,SELECT_BY_TICKET)==false) { OrderSend(Symbol(),OP_BUY, 0.1, Ask, 3, LowPrice, 0, NULL, 12345, 0, Green); } } //---- return(0); //+------------------------------------------------------------------+ //| Open Short Order Procedure | //+------------------------------------------------------------------+ int OpenShortPosition () { double HighPrice = iHighest(Symbol(),0,MODE_UPPER,10,0); if (OrderSelect(12345,SELECT_BY_TICKET)==true) { if (OrderSymbol() == Symbol()) { Alert ("Cannot Open Position - Already have Opened Position"); CheckForTrailStop(); } if (OrderSelect(12345,SELECT_BY_TICKET)==false) { OrderSend(Symbol(),OP_SELL, 0.1, Bid, 3, HighPrice, 0, NULL, 0, 0, Blue); } } } //---- //+------------------------------------------------------------------+ //| Trailing Stop Procedure | //+------------------------------------------------------------------+ int CheckForTrailStop() { if(OrderSelect(12345,SELECT_BY_TICKET)==true) { if(OrderSymbol() == Symbol()) { if (OrderType() == OP_BUY) { if (Bid > OrderOpenPrice() + 100*Point) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid-100*Point,OrderTakeProfit(),0,Green); } } if (OrderType() == OP_SELL) { if(Ask < OrderOpenPrice() - 100*Point) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask-100*Point,OrderTakeProfit(),0,Blue); } } } } //---- return(0); }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi All,
I cannot understand why this code not open any order and also it doesn't give any error.
Update - I Added the code down on this topic.
Thanks A lot.