Lavoro terminato
Specifiche
I have an EA which is supposed to place a pending order with the push of a button, & an execution price at the open of the current bar.
The button functions works perfectly, the parameters within the pending order work flawlessly, the dynamic pricing displayed in button which changed on every tick is perfect.
However, when I push the button to initiate a pending order, sometimes nothing happens. It prints a "success" message into the Journal, but no Pending order appears in the ledger. Other times, it places a pending order with no problem.
Whenever I use this on a new chart, the prices are not updated either. The execution prices is some random price. I even changed the chart from the EURUSD to the EURJPY - completely different pricing structure, and it as telling me that the entry price on the pending order for the EURJPY was a price formatted to a 5 decimal place price. I have tried refresh rates, but to no avail. See illustration for case in point.
Here is my coding, and I have also attached the files if you wanted to recreate this as well.
I need someone who can alter the code to ensure that I do not get sporadic prices, and that it actually places a pending order every time, and not just it feels like it.
//+------------------------------------------------------------------+ //| manStat.mqh | //| Copyright 2022, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2022, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property strict #include <global_declarations.mqh> void manualStaticButtons(){ currentBid = Bid; currentAsk = Ask; currentSpread = sqrt(MathPow((currentBid - currentAsk)/Point,2)); ObjectCreate(0,"manBuy",OBJ_BUTTON,0,0,0); ObjectSetInteger(0,"manBuy",OBJPROP_XDISTANCE,880); ObjectSetInteger(0,"manBuy",OBJPROP_YDISTANCE,580); ObjectSetInteger(0,"manBuy", OBJPROP_YSIZE, 40); ObjectSetInteger(0,"manBuy", OBJPROP_XSIZE, 200); ObjectSetInteger(0,"manBuy", OBJPROP_CORNER,CORNER_LEFT_UPPER); ObjectSetInteger(0,"manBuy", OBJPROP_COLOR,clrWhite); ObjectSetInteger(0,"manBuy", OBJPROP_FONTSIZE,10); ObjectSetInteger(0,"manBuy", OBJPROP_BGCOLOR,clrGreen); ObjectSetString(0,"manBuy", OBJPROP_TEXT,"Market Order "+DoubleToString(currentBid,Digits)); ObjectSetInteger(0,"manBuy",OBJPROP_STATE,false); ObjectCreate(0,"manSell",OBJ_BUTTON,0,0,0); ObjectSetInteger(0,"manSell",OBJPROP_XDISTANCE,1150); ObjectSetInteger(0,"manSell",OBJPROP_YDISTANCE,580); ObjectSetInteger(0,"manSell", OBJPROP_YSIZE, 40); ObjectSetInteger(0,"manSell", OBJPROP_XSIZE, 200); ObjectSetInteger(0,"manSell", OBJPROP_CORNER,CORNER_LEFT_UPPER); ObjectSetInteger(0,"manSell", OBJPROP_COLOR,clrWhite); ObjectSetInteger(0,"manSell", OBJPROP_FONTSIZE,10); ObjectSetInteger(0,"manSell", OBJPROP_BGCOLOR,clrRed); ObjectSetString(0,"manSell", OBJPROP_TEXT,"Market Order "+DoubleToString(currentAsk,Digits)); ObjectSetInteger(0,"manSell",OBJPROP_STATE,false); ObjectCreate(0,"spread",OBJ_LABEL,0,0,0); ObjectSetInteger(0,"spread",OBJPROP_XDISTANCE,1105); ObjectSetInteger(0,"spread",OBJPROP_YDISTANCE,585); ObjectSetInteger(0,"spread", OBJPROP_YSIZE, 40); ObjectSetInteger(0,"spread", OBJPROP_XSIZE, 60); ObjectSetInteger(0,"spread", OBJPROP_CORNER,CORNER_LEFT_UPPER); ObjectSetInteger(0,"spread", OBJPROP_COLOR,clrBlack); ObjectSetInteger(0,"spread", OBJPROP_FONTSIZE,20); ObjectSetString(0,"spread", OBJPROP_TEXT,DoubleToString(currentSpread,0)); }
//+------------------------------------------------------------------+ //| demo.mq4 | //| Copyright 2022, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2022, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict #include <manStat.mqh> //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int pendingExpiration = Period() * 60; double candleOpenPrice = iOpen(NULL,0,0); double pendingOrderExecPrice = NormalizeDouble(candleOpenPrice,Digits); datetime candleOpenTime = Time[0]; string pendingError = IntegerToString(GetLastError(),0); int OnInit() { return(INIT_SUCCEEDED); } void OnTick() { manualStaticButtons(); } void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam){ lastErrorCode = IntegerToString(GetLastError()); if(id == CHARTEVENT_OBJECT_CLICK){ if(sparam == "manBuy"){ RefreshRates(); if(!OrderSend(Symbol(),OP_BUYSTOP,1,pendingOrderExecPrice,0,0,0,NULL,1,candleOpenTime + pendingExpiration,clrNONE)){ Print("Error "+pendingError); } else { Print("Success"); } } if(sparam == "manSell"){ RefreshRates(); if(!OrderSend(Symbol(),OP_SELLSTOP,LotSize,pendingOrderExecPrice,0,0,0,NULL,1,candleOpenTime + pendingExpiration,clrNONE)){ Print("Error "+pendingError); } else { Print("Success"); } } } }