How To Capture Mouse Dragging of a Line
Page 1 of 842 12 LastLast
Results 1 to 10 of 13

Thread: How To Capture Mouse Dragging of a Line

  1. #1
    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);

  2. #2
    Hey, Nub:

    Glad you found it here.

    Yes, I'm aware both igt;=0and hardcode array, these 2 issues aren't the motive prevented me from dragging my horizontal line. I made them the way intentionally to just examine the 1st position(line)

    the logic is in fact very simple:

    for a long position, I'll manually draw a line below the price, if price reaches there, I'll move the TP for my entrance. In other words, the price is against me, I want to depart my long near my entrance price (if price drops a bit).

    But my current code can't allow me to drag the horizontal line. I do not know what function to use for that purpose (objectcreate? or objectmove? Or objectset...)

    still, many thanks for your time, mate!

    Quote Originally Posted by ;
    I do not follow any of this shit anymore, however with that said... for(int I=ArraySize(LongTickets)-1;igt;0;I--) Assess your loops. i gt; 0 ? That should be gt; -1 or gt;= 0And in which you remove an item from your arrays does not appear correct to me, but I'm not certain on that. You're also trying to hard-cod your own arrays for some reason. Simply make them lively, however use a constant to dictate how large they could get. Start off them completely vacant, then add to them. You spelled short wrong (ShotAPL). I'm not really following the code correctly,...

  3. #3
    Oh right. Ok.

    Wait, your difficulty isn't that you aren't first double-clicking the line to ensure it is moveable, is it? I'd have to things about setting up your code on my machine to figure-out what you're doing, and I just can't... so it's all guesses from the dark from me.

  4. #4
    No,

    the EA will generate a flat line, then I double-click, pick it and move to a new level X. however the problem is that the line won't stay at X. it'll jump back to its initial level. My objective is to earn the line stay at the new level X (transfer the line anytime, anywhere, like I can move tp, sl lines in MT4 now).

    Quote Originally Posted by ;
    Oh directly. Okay. Wait, your problem isn't that you are not first double-clicking the line to ensure it is moveable, is it? I'd have to stuff about setting up your code on my machine to figure-out what you are doing, and that I simply can't... so it is all guesses in the dark out of me.

  5. #5
    jTorSess
    Guest
    That is my understanding:User sets AlertLvl4Long; The aforementioned is assigned to LongApl in Init(); Start() calls Count_Pos_lots(), whicheletes the line if it is, then; generates the line with LongApl value;
    Start() calls UpdateDragAlert() to find the price value of this lineup, and compare to LongApl. Now, the price will match LongApl since the lineup is becoming deleted and recreated on each call to Start(), and directly into the price level fixed by the consumer at 1 .

    Thus, even if you move the line between calls, step 3 will delete it and recreate the line in the value given in step 1.

    Does that make sense? ...

    Regards

    OD

  6. #6
    Damn, thanks a lot, OD! I guess you hit it right on!

    I'll go test it now

    btw, I read your thread online along with your posts. They're pretty helpful to my prior coding!

    Quote Originally Posted by ;
    That is my perception: User places AlertLvl4Long; The preceding is assigned to LongApl in Init(); Start() calls Count_Pos_lots(), which: deletes the line when it is, then; generates the line using LongApl value; Start() calls UpdateDragAlert() to get the price value of this line, and compare to LongApl. At this point, the price will fit LongApl as the line is becoming deleted and recreated on each call to Start(), and reverting to the price level fixed by the user at 1 above. So, even in the event that you move the line between calls, step 3 will delete it and recreate...

  7. #7
    Hi, One Day!

    I fixed a problem by remove that unnecessary ObjectDelete, now I can transfer the line to a new level.

    But the EA cannot get the price of the new level.

    I use [DragLonglvl = NormalizeDouble(ObjectGet(LongTickets[I] -LONGapl,OBJPROP_PRICE1),MarketInfo(Symbol(), MODE_DIGITS)); ] to put the new level price into variable DragLonglvl. Nonetheless, it returns 0. What could go wrong here?

    Many thanks for your precious time and help! I attach the entire code here.

    Quote Originally Posted by ;
    Start() calls UpdateDragAlert() to get the price value of this lineup, and compare to LongApl. At this point, the price will fit LongApl since the lineup is getting deleted and recreated on each call to Start(), and reverting to the price level fixed by the user at 1 . So, even in the event that you move the line between calls, step 3 will delete it and recreate the lineup in the value given in step 1. Does that make sense? ... Regards OD
    https://www.forexforum.co.za/attachm...1775024935.mq4

  8. #8
    Quote Originally Posted by ;
    Hello, 1 Day! I fixed one problem by remove that unnecessary ObjectDelete, today I can transfer the line to a new level. However, the EA cannot obtain the price of the new level. I utilize [DragLonglvl = NormalizeDouble(ObjectGet(LongTickets[I] -LONGapl,OBJPROP_PRICE1),MarketInfo(Symbol(), MODE_DIGITS)); ] to place the new level price into factor DragLonglvl. But it returns 0. What could go wrong here? Thanks for your precious time and help! I attach the code here. quote document
    When did you begin calling your items together with the LONGapl suffix rather than the l-apl or whatever it was called? And why not just use a constant to prevent this whole issue?

  9. #9
    cesyogaCwz
    Guest
    Hello Charvo,

    I do Not have access to my terminal for now, but in Stark terms, I'd approach it as follows:Loop through orders and check if there is a line object prefixed with the corresponding order number; Otherwise, then make one and delegate it's price level to a variable eg line1_oldprice; On subsequent calls;Check if any orders have been closed and if so, delete the corresponding line object, Loop through each line object;Compare it is new price to it's old price; When it has changed, then upgrade the old price variable to coincide with the new and use ordermodify to change the relevant order take profit level.

    You should also be aware that at a fast market, you could have numerous incoming ticks whilst going the line. As such you could end up modifying the order whilst you're moving online - only a point to be aware of...

    In case it helps, I could knock up a fundamental indior to demone moving a line, but it may not be until tomorrow....

    OD

  10. #10
    Sorry, Nub, that is what I want! You've got a pair of eyes!

    Damn, I would like to hit my head on walls. Such a stupid error. Thank you, mate!

    Quote Originally Posted by ;
    quote When did you start calling your items together with the LONGapl suffix rather than the l-apl or whatever it was called? And why not just use a constant to avoid this whole matter?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.