kata Posted June 11, 2010 Report Share Posted June 11, 2010 I'm writing an EA which when it's trading logic is met is supposed to open 2 market orders using the same values. Sometimes both these orders open, and sometimes they dont. For a while I had errors where the second order wouldn't open, and I got an error code. I have fixed that error by using RefreshRates between sending order 1 and 2. However, now I seem to regularly be getting only the second order opening. First I didn't get any error at all, so I went back to the mql4 file and looked at it very carfully, and then moved a bracket around the Else" part of the statement, thinking that was the problem. Today I have come home and discvered the same thing has happened, but this time I have an error message. I looked up the 0 code, only to discover it meant I had no error. So please, if there is no error, why isn't my trade opening??!! It's like it isn't even tryin to open it, but then other times they boh open fine, using exactly eht same lines of code! Does anyone have any idea of why this might be? Quote Link to comment Share on other sites More sharing options...
kennyhubbard Posted June 13, 2010 Report Share Posted June 13, 2010 You are going to have to post the code if you want some help. Quote Link to comment Share on other sites More sharing options...
kata Posted June 13, 2010 Author Report Share Posted June 13, 2010 This is my trade opening logic. I curently always have trailing stop set to higher than 0. { static datetime Time.newBar; bool newBar = (Time[0] > Time.newBar); if (newBar) { // A new bar began. Time.newBar = Time[0]; // Reset static. //... <<<< Any code here is executed only when a new bar appears if ((bflag==false) && (sflag==false)) //No current trades open { //Alert("Check each tick section"); //open buy trade if (buy == true) //buy trade { if (TrailingStop == 0) { tickbuy1=OrderSend(Symbol(),0,Lots,NormalizeDouble(Ask,Digits),NormalizeDouble(5*Point,Digits),NormalizeDouble(Ask-StopLoss*Point,Digits),NormalizeDouble(Ask+TakeProfit*Point,Digits),buycomment1,Magic_no,0,Lime); //tickbuy2=OrderSend(Symbol(),0,Lots/2,NormalizeDouble(Ask,Digits),NormalizeDouble(5*Point,Digits),NormalizeDouble(Ask-StopLoss*Point,Digits),NormalizeDouble(Ask+TakeProfit*Point,Digits),comment,Magic_no,0,Lime); } if (TrailingStop > 0) { tickbuy1=OrderSend(Symbol(),0,Lots/2,NormalizeDouble(Ask,Digits),NormalizeDouble(5*Point,Digits),NormalizeDouble(Ask-StopLoss*Point,Digits),NormalizeDouble(Ask+TakeProfit*Point,Digits),buycomment1,Magic_no,0,Lime); RefreshRates(); tickbuy2=OrderSend(Symbol(),0,Lots/2,NormalizeDouble(Ask,Digits),NormalizeDouble(5*Point,Digits),NormalizeDouble(Ask-StopLoss*Point,Digits),0,buycomment2,Magic_no,0,Lime); } if (tickbuy1>0) { if(OrderSelect(tickbuy1,SELECT_BY_TICKET)) { Print("BUY 1 order opened at: ", OrderOpenPrice()); bflag=true; //Bbeflag = true; } } else { Print("Error opening BUY 1 order : ",GetLastError()); } if (TrailingStop > 0) { if (tickbuy2>0) { if(OrderSelect(tickbuy2,SELECT_BY_TICKET)) { Print("BUY 2 order opened at: ", OrderOpenPrice()); bflag=true; error2 = false; //Bbeflag = true; } } else { Print("Error opening BUY 2 order : ",GetLastError()); error2 = true; } } return(0); } if (sell == true) //sell trade { if (TrailingStop == 0) { ticksell1=OrderSend(Symbol(),1,Lots,NormalizeDouble(Bid,Digits),NormalizeDouble(5*Point,Digits),NormalizeDouble(Bid+StopLoss*Point,Digits),NormalizeDouble(Bid-TakeProfit*Point,Digits),sellcomment1,Magic_no,0,Red); //ticksell2=OrderSend(Symbol(),1,Lots/2,NormalizeDouble(Bid,Digits),NormalizeDouble(5*Point,Digits),NormalizeDouble(Bid+StopLoss*Point,Digits),NormalizeDouble(Bid-TakeProfit*Point,Digits),comment,Magic_no,0,Red); } if (TrailingStop > 0) { ticksell1=OrderSend(Symbol(),1,Lots/2,NormalizeDouble(Bid,Digits),NormalizeDouble(5*Point,Digits),NormalizeDouble(Bid+StopLoss*Point,Digits),NormalizeDouble(Bid-TakeProfit*Point,Digits),sellcomment1,Magic_no,0,Red); RefreshRates(); ticksell2=OrderSend(Symbol(),1,Lots/2,NormalizeDouble(Bid,Digits),NormalizeDouble(5*Point,Digits),NormalizeDouble(Bid+StopLoss*Point,Digits),0,sellcomment2,Magic_no,0,Red); } if (ticksell1>0) { if(OrderSelect(ticksell1,SELECT_BY_TICKET)) { Print("SELL 1 order opened at: ", OrderOpenPrice()); sflag=true; //Sbeflag = true; } } else { Print("Error opening SELL 1 order : ",GetLastError()); } if (TrailingStop > 0) { if (ticksell2>0) { if(OrderSelect(ticksell2,SELECT_BY_TICKET)) { Print("SELL 2 order opened at: ", OrderOpenPrice()); sflag=true; error2 = false; //Sbeflag = true; } } else { Print("Error opening SELL 2 order : ",GetLastError()); error2 = true; } } return(0); } } else if ((bflag == true) && (sflag == true)) { //Alert("Buy and Sell trades already opened."); return(0); } else if ((bflag == true) && (sell == true)) // buy order is open but sell signal is given // check if open orders are in profit { Alert("buy order is open but sell signal is given"); RefreshRates(); if (tickbuy1 > 0) { if(OrderSelect(tickbuy1,SELECT_BY_TICKET)==true) { stoplevel = MarketInfo(Symbol(),MODE_STOPLEVEL); if (OrderProfit() > NormalizeDouble(Ask+(stoplevel*Point),Digits)) { OrderClose(tickbuy1,OrderLots(),Bid,3*Point,Blue); } } } RefreshRates(); if (tickbuy2 > 0) { if(OrderSelect(tickbuy2,SELECT_BY_TICKET)==true) { stoplevel = MarketInfo(Symbol(),MODE_STOPLEVEL); if (OrderProfit() > NormalizeDouble(Ask+(stoplevel*Point),Digits)) { OrderClose(tickbuy2,OrderLots(),Bid,3*Point,Blue); } } } if (TrailingStop == 0) { ticksell1=OrderSend(Symbol(),1,Lots,NormalizeDouble(Bid,Digits),NormalizeDouble(5*Point,Digits),NormalizeDouble(Bid+StopLoss*Point,Digits),NormalizeDouble(Bid-TakeProfit*Point,Digits),sellcomment1,Magic_no,0,Red); //ticksell2=OrderSend(Symbol(),1,Lots/2,NormalizeDouble(Bid,Digits),NormalizeDouble(5*Point,Digits),NormalizeDouble(Bid+StopLoss*Point,Digits),NormalizeDouble(Bid-TakeProfit*Point,Digits),comment,Magic_no,0,Red); } if (TrailingStop > 0) { ticksell1=OrderSend(Symbol(),1,Lots/2,NormalizeDouble(Bid,Digits),NormalizeDouble(5*Point,Digits),NormalizeDouble(Bid+StopLoss*Point,Digits),NormalizeDouble(Bid-TakeProfit*Point,Digits),sellcomment1,Magic_no,0,Red); RefreshRates(); ticksell2=OrderSend(Symbol(),1,Lots/2,NormalizeDouble(Bid,Digits),NormalizeDouble(5*Point,Digits),NormalizeDouble(Bid+StopLoss*Point,Digits),0,sellcomment2,Magic_no,0,Red); } if (ticksell1>0) { if(OrderSelect(ticksell1,SELECT_BY_TICKET)) { Print("SELL 1 order opened at: ", OrderOpenPrice()); sflag=true; //Sbeflag = true; } } else { Print("Error opening SELL 1 order : ",GetLastError()); } if (TrailingStop > 0) { if (ticksell2>0) { if(OrderSelect(ticksell2,SELECT_BY_TICKET)) { Print("SELL 2 order opened at: ", OrderOpenPrice()); sflag=true; error2 = false; //Sbeflag = true; } } else { Print("Error opening SELL 2 order : ",GetLastError()); error2 = true; } } return(0); } Quote Link to comment Share on other sites More sharing options...
kata Posted June 13, 2010 Author Report Share Posted June 13, 2010 else if ((sflag == true) && (buy == true)) // sell order is open but buy signal is given //Alert("sell order is open but buy signal is given"); // check if open orders are in profit { Alert("sell order is open but buy signal is given"); RefreshRates(); if (ticksell1 > 0) { if(OrderSelect(ticksell1,SELECT_BY_TICKET)==true) { stoplevel = MarketInfo(Symbol(),MODE_STOPLEVEL); if (OrderProfit() > NormalizeDouble(Bid+(stoplevel*Point),Digits)) { OrderClose(ticksell1,OrderLots(),Ask,3*Point,Blue); } } } RefreshRates(); if (ticksell2 > 0) { if(OrderSelect(ticksell2,SELECT_BY_TICKET)==true) { stoplevel = MarketInfo(Symbol(),MODE_STOPLEVEL); if (OrderProfit() > NormalizeDouble(Bid+(stoplevel*Point),Digits)) { OrderClose(ticksell2,OrderLots(),Ask,3*Point,Blue); } } } if (TrailingStop == 0) { RefreshRates(); tickbuy1=OrderSend(Symbol(),0,Lots,NormalizeDouble(Ask,Digits),NormalizeDouble(5*Point,Digits),NormalizeDouble(Ask-StopLoss*Point,Digits),NormalizeDouble(Ask+TakeProfit*Point,Digits),buycomment1,Magic_no,0,Lime); //tickbuy2=OrderSend(Symbol(),0,Lots/2,NormalizeDouble(Ask,Digits),NormalizeDouble(5*Point,Digits),NormalizeDouble(Ask-StopLoss*Point,Digits),NormalizeDouble(Ask+TakeProfit*Point,Digits),comment,Magic_no,0,Lime); } if (TrailingStop > 0) { tickbuy1=OrderSend(Symbol(),0,Lots/2,NormalizeDouble(Ask,Digits),NormalizeDouble(5*Point,Digits),NormalizeDouble(Ask-StopLoss*Point,Digits),NormalizeDouble(Ask+TakeProfit*Point,Digits),buycomment1,Magic_no,0,Lime); RefreshRates(); tickbuy2=OrderSend(Symbol(),0,Lots/2,NormalizeDouble(Ask,Digits),NormalizeDouble(5*Point,Digits),NormalizeDouble(Ask-StopLoss*Point,Digits),0,buycomment2,Magic_no,0,Lime); } if (tickbuy1>0) { if(OrderSelect(tickbuy1,SELECT_BY_TICKET)) { Print("BUY 1 order opened at: ", OrderOpenPrice()); bflag=true; //Bbeflag = true; } } else { Print("Error opening BUY 1 order : ",GetLastError()); } if (TrailingStop > 0) { if (tickbuy2>0) { if(OrderSelect(tickbuy2,SELECT_BY_TICKET)) { Print("BUY 2 order opened at: ", OrderOpenPrice()); bflag=true; error2 = false; //Bbeflag = true; } } else { Print("Error opening BUY 2 order : ",GetLastError()); error2 = true; } } return(0); } } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.