-
The very first thing is finding out what event has occurred. You are assuming that it is a button click.
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam){ if( id == CHARTEVENT_KEYDOWN){ ⋮ } // CHARTEVENT_KEYDOWN else if(id == CHARTEVENT_MOUSE_MOVE){ // Check for dragging levels. ⋮ } // Mouse move. else if(direction == 0) // GUI not visible; Ignore clicks, return; // Including a double click on order button. else if(id == CHARTEVENT_OBJECT_CLICK){ if( sparam == "MMGT_RiskSizeButtonPlus"){ ⋮ } // CHARTEVENT_OBJECT_CLICK else if(id == CHARTEVENT_OBJECT_CREATE){ ⋮
-
if(!OrderSend(Symbol(),0,LotSize,Ask,100,Ask-Sl*Point,Ask+Tp*Point,NULL,(int)magicnum)) if(!OrderSend(Symbol(),1,LotSize,Ask,100,Bid+Sl*Point,Ask-Tp*Point,NULL,(int)magicnum))
You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.
-
Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?
-
Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25 -
The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
My GBPJPY shows average spread = 26 points, average maximum spread = 134.
My EURCHF shows average spread = 18 points, average maximum spread = 106.
(your broker will be similar).
Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)
-
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
here is what the code looks like :
I have tried to recreate the issue , but I have no Idea what causes this problem , and which way I should go to solve this , I know some thing is wrong with my approach , but if some one can point out what I am doing wrong I will really appreciate it