Hello, Dear Coders
Edited: the core issue is how to manually move a line freely like takeprofit stoploss lines in MT4. This line is generated by my EA.
I'm desperately seeking for your help. But the issue might be incredibly simple to you.
Inside my EA, I want to drag an present flat line to a new level X, as well as the new level X might be taken from the EA for later usage. I also require the line staying at the new degree X.
Inside my attached code, the'UpdateDragAlertLvL()' is that the sub that I used to spot the dragging and taking the new degree X.
From the code, I try to use var lt;DragLonglvlgt; to contain'X', and thing lt;LongTickets[0] L-APLgt; would be the present line to be dragged.
I utilized ObjectSet, also ObjectDelete/Create for new degree'X', but if EA really runs, I just cannot make the lineup remain at the new level X, the lineup will jump back into its prior level. The EA won't take the new degree'X' value also.
Truly appreciate if you can help me with this issue, either a suggestion, or even a sample code will be wonderful. I guess my way to ch a drag is first thing going wrong.
The EA's purpose is for a trader to decide on a degree (horizontal line) at lt;AlertLvL4LONGgt;, if price reaches that amount, the EA will do a BE for its existing long positions. What I want is the ability to immediately move that flat line rather than input the values everytime. The logic is very simple.
Inserted Code extern dual AlertLvL4LONG = 0; extern dual AlertLvL4SHOT = 10000; extern dual deftTP = 0; extern dual deftSL = 0; extern int BEoffset = two; extern string SpecRstring = 1,2,3,5,8,13,21,34,55, 90,160,250; // after base level, 12 additional levels! Extern string SpecTPstring = 1,1,2,2,3, 4, 3, 7, 5, 9, 12, 15; extern string OrderCMT =; extern int Slippage = two; extern int SpreadCap = 10; extern string ClearanceNote = must larger than BEoffset; extern int Clearance = 10; extern int ScreenCorner = 1; extern bool UsePresetAlert = false; extern int MagicBase = 100; extern string UserNote = Support MAX 6 Positions; // ------------------------------------------------------------------ //| Internal Variables | // ------------------------------------------------------------------ int MagicNumber, I, pairdigits, NumBuys, NumSels, TotalTrades, StartPos, EnteringDIR; double pairpoint, baseBuyAt, baseSelAt, HiBound, LoBound, allBuyLots, allSelLots, UseLots, NetExposure; double EAPL, DDpeak, EQpeak, BuyPL, SelPL, TPgoal; double LongAPL = 0; //0,0,0,0,0,0; double ShotAPL = 0; //0,0,0,0,0,0; int LongTicketsNumber 91;#93; = 0,0,0,0,0,0; int ShotTickets#91;#93; = 0,0,0,0,0,0; dual BuyPosTP, BuyPosSL, SelPosTP, SelPosSL; // ------------------------------------------------------------------ // ------------------------------------------------------------------ int init() // ------------------------------------------------------------------ // ------------------------------------------------------------------ int start() Count_Pos_Lots(); //Alert(WindowExpertName() 1 LongAPL is LongAPL); NoPosReset(); //Alert(WindowExpertName() two LongAPL is LongAPL); CheckAPL(); //Alert(WindowExpertName() 3 LongAPL is LongAPL); PrintChartComments(); //Alert(WindowExpertName() 4 LongAPL is LongAPL); UpdateDragAlertLvL(); //Alert(WindowExpertName() 5 LongAPL is LongAPL); return(0); // ------------------------------------------------------------------ // Start() finish. All supporting patterns FromBelow. //p ------------------------------------------------------------------ void Count_Pos_Lots() NumBuys = 0; BuyPL = 0.0; allBuyLots = 0.0; NumSels = 0; SelPL = 0.0; allSelLots = 0.0; BuyPosTP = 0; BuyPosSL = 0; SelPosTP = 0; SelPosSL = 0; int m = 0; int n = 0; for (I = 0; I lt; OrdersTotal(); I ) OrderSelect(I,SELECT_BY_POS,MODE_TRADES); if (OrderSymbol() == Symbol() OrderType() == OP_BUY OrderComment() == OrderCMT ) BuyPL = OrderProfit() OrderSwap() OrderCommission(); allBuyLots = OrderLots(); NumBuys ; BuyPosTP = OrderTakeProfit(); BuyPosSL = OrderStopLoss(); LongTicketsNumber 91;m93; = OrderTicket(); m = m 1; ObjectDelete(LongTickets#91;m-1#93; L-APL); if (ObjectCreate(LongTickets#91;m-1#93; L-APL, OBJ_HLINE, 0, 0, LongAPL)) ObjectSet(LongTickets#91;m-1#93; L-APL, OBJPROP_STYLE, STYLE_DASHDOT); ObjectSet(LongTicketsNumber 91;m-1#93; L-APL, OBJPROP_BACK, True); ObjectSet(LongTicketsNumber 91;m-1#93; L-APL, OBJPROP_COLOR, Lime); ObjectSet(LongTicketsNumber 91;m-1#93; L-APL, OBJPROP_WIDTH, 1); else Alert(WindowExpertName() Fail to draw LAPL ); if (OrderSymbol() == Symbol() OrderType() == OP_SELL OrderComment() == OrderCMT) SelPL = OrderProfit() OrderSwap() OrderCommission(); allSelLots = OrderLots(); NumSels ; SelPosTP = OrderTakeProfit(); SelPosSL = OrderStopLoss(); ShotTicketsNumber 91;n#93; = OrderTicket(); n = n 1; ObjectDelete(ShotTickets#91;n-1#93; S-APL); if(ObjectCreate(ShotTickets#91;n-1#93; S-APL, OBJ_HLINE, 0, 0, ShotAPL)) ObjectSet(ShotTickets#91;n-1#93; S-APL, OBJPROP_STYLE, STYLE_DASHDOT); ObjectSet(ShotTicketsNumber 91;n-1#93; S-APL, OBJPROP_BACK, True); ObjectSet(ShotTicketsNumber 91;n-1#93; S-APL, OBJPROP_COLOR, Red); ObjectSet(ShotTicketsNumber 91;n-1#93; S-APL, OBJPROP_WIDTH, 1); else Alert(WindowExpertName() Fail to draw SAPL ); NetExposure = MathAbs(allSelLots - allBuyLots); TotalTrades = NumBuys NumSels; return(0); void CheckAPL() // this sub examine if NOW is great time to start a trading sequence. for (I = 0; I lt; OrdersTotal(); I ) OrderSelect(I,SELECT_BY_POS,MODE_TRADES); if ( OrderType() == OP_BUY MarketInfo(Symbol(), MODE_BID) lt; LongAPL OrderComment() == OrderCMT ) //Alert(WindowExpertName() CHCK LongAPL is LongAPL); //Alert(WindowExpertName() CHCK Bid is MarketInfo(Symbol(), MODE_BID)); JumpTP(); if ( OrderType() == OP_SELL MarketInfo(Symbol(), MODE_BID) gt; ShotAPL OrderComment() == OrderCMT ) JumpTP(); void JumpTP() { bool BE; for(int n=0; nlt;OrdersTotal();n ) { OrderSelect(n, SELECT_BY_POS, MODE_TRADES); if (OrderComment() == OrderCMT OrderSymbol()==Symbol()) { if ( OrderType() == OP_BUY (OrderTakeProfit() gt; (OrderOpenPrice() Clearance * pairpoint) || OrderTakeProfit() == 0) ) BE = OrderModify(OrderTicket(),OrderOpenPrice(),0, NormalizeDouble(OrderOpenPrice() BEoffset*pairpoint, MarketInfo(Symbol(), MODE_DIGITS)), 0,Green); if (BE) Alert(WindowExpertName() BE a Symbol() pos, @ OrderOpenPrice() , @ TimeToStr(TimeCurrent(),TIME_MINUTES)); Print(WindowExpertName() BE a Symbol() pos, @ OrderOpenPrice() , @ TimeToStr(TimeCurrent(),TIME_MINUTES)); else Alert(WindowExpertName() Failed to BE a Symbol() @ OrderOpenPrice() , @ TimeToStr(TimeCurrent(),TIME_MINUTES) because of error GetLastError()); Print(WindowExpertName() Failed to BE a Symbol() @ OrderOpenPrice() , @ TimeToStr(TimeCurrent(),TIME_MINUTES) because of error GetLastError()); if ( OrderType() == OP_SELL (OrderTakeProfit() lt; (OrderOpenPrice() - Clearance * pairpoint) || OrderTakeProfit() == 0) ) { BE = OrderModify(OrderTicket(),OrderOpenPrice(),0,Norma lizeDouble(OrderOpenPrice()-BEoffset*pairpoint, MarketInfo(Symbol(), MODE_DIGITS)), 0,Green); if (BE) Alert(WindowExpertName() BE a Symbol() pos, @ OrderOpenPrice() , @ TimeToStr(TimeCurrent(),TIME_MINUTES)); Print(WindowExpertName() BE a Symbol() pos, @ OrderOpenPrice() , @ TimeToStr(TimeCurrent(),TIME_MINUTES)); else { Alert(WindowExpertName() Failed to BE a Symbol() @ OrderOpenPrice() , @ TimeToStr(TimeCurrent(),TIME_MINUTES) Because of Malfunction GetLastError()); Print(WindowExpertName() Failed to BE a Symbol() @ OrderOpenPrice() , @ TimeToStr(TimeCurrent(),TIME_MINUTES) Because of Malfunction GetLastError()); } } } } } void NoPosReset() // if Not Any Rankings, but variables are used (after Leaving a previous pos), reinit arrays, delete existing Traces if (ArraySize(LongTickets) gt; 0 NumBuys == 0) for (int I = ArraySize(LongTickets)-1;igt;0;I--) ObjectDelete(LongTicketsNumber 91;i-1Number 93; L-APL); ArrayResize(LongTickets,0); if (ArraySize(ShotTickets) gt; 0 NumSels == 0) for (I = ArraySize(ShotTickets)-1;igt;0;I--) ObjectDelete(ShotTicketsNumber 91;i-1Number 93; S-APL); ArrayResize(ShotTickets, 0); return(0); Emptiness UpdateDragAlertLvL() Dual DragLonglvl, DragShotlvl; if (NumBuys gt; 0) for(int I=ArraySize(LongTickets)-1;igt;0;I--) OrderSelect(LongTicketsNumber 91;I#93;,SELECT_BY_TICKET); if (OrderSymbol() == Symbol() OrderType() == OP_BUY OrderComment() == OrderCMT ) DragLonglvl = NormalizeDouble(ObjectGet(LongTicketsNumber 91;I#93; -LONGapl,OBJPROP_PRICE1),MarketInfo(Symbol(), MODE_DIGITS)); if(DragLonglvl!= LongAPL) //ObjectDelete(LongTickets#91;0#93; L-APL); //ObjectCreate(LongTickets#91;0#93; L-APL, OBJ_HLINE, 0, 0, DragLonglvl); ObjectSet(LongTicketsNumber 91;0#93; L-APL, OBJPROP_PRICE1, DragLonglvl); LongAPL = DragLonglvl; if (NumSels gt; 0) for (I=ArraySize(ShotTickets)-1;igt;0;I--) OrderSelect(ShotTicketsNumber 91;I#93;,SELECT_BY_TICKET); should (OrderSymbol() == Symbol() OrderType() == OP_SELL OrderComment() == OrderCMT ) DragShotlvl = NormalizeDouble(ObjectGet(ShotTicketsNumber 91;I#93; -SHOTapl,OBJPROP_PRICE1),MarketInfo(Symbol(), MODE_DIGITS)); if(DragShotlvl! = ShotAPL) ShotAPL = DragShotlvl; return(0); void PrintChartComments() string commentStr; int PipDist2Long, PipDist2Short; should (LongAPL gt; 0) PipDist2Long = (-LongAPL MarketInfo(Symbol(), MODE_BID))/pairpoint; should (ShotAPL gt; 0) PipDist2Short = (ShotAPL - MarketInfo(Symbol(), MODE_BID))/pairpoint; commentStr = Symbol() L: Lot: DoubleToStr(allBuyLots,2) ; APL: DoubleToStr(LongAPL, MarketInfo(Symbol(), MODE_DIGITS)) ; in Bid: PipDist2Long ; TP: DoubleToStr(BuyPosTP,MarketInfo(Symbol(), MODE_DIGITS)) ;; should (NumBuys gt; 0) printComment_l(commentStr, 2, 40, 1); commentStr = Symbol() S: Lot: DoubleToStr(allSelLots,2) ; APL: DoubleToStr(ShotAPL, MarketInfo(Symbol(), MODE_DIGITS)) ; in Bid: PipDist2Short ; TP: DoubleToStr(SelPosTP,MarketInfo(Symbol(), MODE_DIGITS)) ;; should (NumSels gt; 0) printComment_l(commentStr, 3, 65, 3); void printComment_l(string commentStr, int I, int j, int colorcode) ObjectCreate(TradeComment I,OBJ_LABEL,0,0,0); ObjectSet(TradeComment I,OBJPROP_CORNER,ScreenCorner); ObjectSet(TradeComment I,OBJPROP_XDISTANCE,5); ObjectSet(TradeComment I,OBJPROP_YDISTANCE,j); should (colorcode == 1) ObjectSetText(TradeComment I,commentStr,12,Courier New Bold,Lime); should (colorcode == two ) ObjectSetText(TradeComment I,commentStr,12,Courier New Bold,DeepSkyBlue); should (colorcode == 3) ObjectSetText(TradeComment I,commentStr,12,Courier New Bold,DeepPink);