-
Code fails on JPY and metals.
PIP, Point, or Tick are all different in general.
What is a TICK? - MQL4 programming forum 2014.08.03Unless you manually adjust your SL/TP for each separate symbol, using Point means code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points), and metals. Compute what a PIP is and use it, not points.
How to manage JPY pairs with parameters? - MQL4 programming forum 2017.02.09
Slippage defined in index points - Expert Advisors and Automated Trading - MQL5 programming forum 2018.01.15 -
Code checks if the last buy is 100 points above the market. It will always be false when in profit.
-
Code fails on JPY and metals.
PIP, Point, or Tick are all different in general.
What is a TICK? - MQL4 programming forum 2014.08.03Unless you manually adjust your SL/TP for each separate symbol, using Point means code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points), and metals. Compute what a PIP is and use it, not points.
How to manage JPY pairs with parameters? - MQL4 programming forum 2017.02.09
Slippage defined in index points - Expert Advisors and Automated Trading - MQL5 programming forum 2018.01.15 -
Code checks if the last buy is 100 points above the market. It will always be false when in profit.
Hello ِDear William
Thank you very much for your response
1. This expert is only used in dollar-euro currency
I did not put the complete code related to this section, so maybe the subject is not understood correctly
With this code, when the last position of 10 pips is lost, the next position is allowed to open (so far it is correct and it works properly)
But I want the next position to be opened if the last position was 10 pips in profit and there was a buy position
extern int Distance = 100 ; // Position Distance 1 //+-----------------------------------------------\\ disbuy=Distance; //+-----------------------------------------------\\ if (FindLastBuyPrice () - Ask > disbuy * Point ){ Comment(string( FindLastBuyPrice () - Ask) + " "+ DoubleToStr(disbuy * Point)); ticket=OrderSend("GBPUSD",OP_BUY,0.10,Ask,slippage,0,FindFirsBuyTP(),"AbdullRahim",Magic3,Blue); //+-----------------------------------------------\\ double FindLastBuyPrice() { double oldorderopenprice=0; int oldticketnumber; double unused=0; int ticketnumber=0; for(int i=OrdersTotal()-1; i>=0; i--) { unused=OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderSymbol()!="GBPUSD" || OrderMagicNumber()!=Magic3) continue; if(OrderSymbol()=="GBPUSD" && OrderMagicNumber()==Magic3 && OrderType()==OP_BUY) { oldticketnumber=OrderTicket(); if(oldticketnumber>ticketnumber) { oldorderopenprice=OrderOpenPrice(); ticketnumber=oldticketnumber; } } } return (oldorderopenprice); } //+------------------------------------------------------------------+I am very happy to have your masterful guidance in solving this problem
Hello ِDear William
Thank you very much for your response
1. This expert is only used in dollar-euro currency
I did not put the complete code related to this section, so maybe the subject is not understood correctly
With this code, when the last position of 10 pips is lost, the next position is allowed to open (so far it is correct and it works properly)
But I want the next position to be opened if the last position was 10 pips in profit and there was a buy position
I am very happy to have your masterful guidance in solving this problem
I want to make something like this so that it is not 10 pip away from the last position and the new position does not open.
Hi
I wrote this code but still could not get the desired result which was 10 pips distance between all positions
I can know the opinion of the professors
Where am I going wrong?
GlobalVariableSet("price"); } if(Ask>=(GlobalVariableGet("price")+100*MathPow(10,-Digits))|| Ask<(GlobalVariableGet("price")+100*MathPow(10,-Digits))) { if(GlobalVariableCheck("price")==true) { GlobalVariableDel("price"); }
Terminal variables (GV) are for interprocess communication (EAs and indicators) and persistent storage (global variables w/flush).
No need for them, just use static or global variables. Using "price" means the code can not run on multiple charts.
MathPow(10,-Digits) is the same thing as _Point.
Don't find the last buy price, just find the lowest.
Dear William Roeder,
I should first state I am willing to pay for solving my problem. My problem appears only in Real Time, not in Back Testing.
My EA works fine with currencies.
I am using PCSv9 to set the StopLoss.
When trading the DAX my EA moves the SL to 7 digits difference to Bid or Ask (e.g. if Short SL 15007, BID price 15000), as soon as the profit is > ~€7.50 for one contract. Its lot * 7.50, i.e. for 3 contracts the profit must be > ~€ 23 before the EA moves the SL. It behaves then like a trailing stop.
I have stripped my code to the minimum and created manual Buy/Sell buttons.
I have no idea what could cause this behavior in my code and thought it must happen in CTrade. I am not using POINTs or PIPS in the code.
PCSv9 value and manual opening of a position:
double iCal(int hnd,int j,int k) { double values[]; CopyBuffer(hnd,j,k,1,values); return(values[0]); } double sigPCS(int i) { if(iCal(PCS,1,i)<iCal(PCS,0,i)) return(-iCal(PCS,1,i)); else return(iCal(PCS,0,i)); }
{ double SLM=sigPCS(0); double tp=0; string ClickedObjectName=sparam; if(StopType==0 && sigPCS(0)<0) // PCSv9 SLM=SymbolInfoDouble(NULL,SYMBOL_ASK)-mSL*SymbolInfoDouble(NULL,SYMBOL_POINT); if(StopType==2 && sigs2(0)<0) SLM=SymbolInfoDouble(NULL,SYMBOL_ASK)-mSL*SymbolInfoDouble(NULL,SYMBOL_POINT); if(id==CHARTEVENT_OBJECT_CLICK && sparam=="BuyButton") Pool.Buy(lot,NULL,SymbolInfoDouble(_Symbol,SYMBOL_ASK),SLM,tp,"Man BUY="+MathAbs(sigPCS(0))); Comment(sparam+" was pressed"); } { double SLM=-sigPCS(0); double tp=0; string ClickedObjectName=sparam; if(orOpen(1,_Symbol)==0) if(StopType==0 && sigPCS(0)>0) SLM=SymbolInfoDouble(NULL,SYMBOL_BID)+mSL*SymbolInfoDouble(NULL,SYMBOL_POINT); if(StopType==2 && sigs2(0)>0) SLM=SymbolInfoDouble(NULL,SYMBOL_BID)+mSL*SymbolInfoDouble(NULL,SYMBOL_POINT); if(id==CHARTEVENT_OBJECT_CLICK && sparam=="SellButton") Pool.Sell(lot,NULL,SymbolInfoDouble(_Symbol,SYMBOL_BID),SLM,tp,"Man Sell="+MathAbs(sigPCS(0))); Comment(sparam+" was pressed"); } }
Thank you!
That is your problem.
Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
Code debugging - Developing programs - MetaEditor Help
Error Handling and Logging in MQL5 - MQL5 Articles (2015)
Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)
Dear William Roeder,
I should first state I am willing to pay for solving my problem. My problem appears only in Real Time, not in Back Testing.
My EA works fine with currencies.
I am using PCSv9 to set the StopLoss.
When trading the DAX my EA moves the SL to 7 digits difference to Bid or Ask (e.g. if Short SL 15007, BID price 15000), as soon as the profit is > ~€7.50 for one contract. Its lot * 7.50, i.e. for 3 contracts the profit must be > ~€ 23 before the EA moves the SL. It behaves then like a trailing stop.
I have stripped my code to the minimum and created manual Buy/Sell buttons.
I have no idea what could cause this behavior in my code and thought it must happen in CTrade. I am not using POINTs or PIPS in the code.
PCSv9 value and manual opening of a position:
Thank you!
What is PCSv9 ?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello to all professors
I want a distance of 10 pips on the last position
That is, when the last position is taken, if it goes to profit, no new position will be opened for another 10 pips
And if the last position goes to the loss, the new position will not open in the same way for another 10 pips.
With this code, I was able to lose the new position when it goes to the last position in 10 pips
But I could not open the next position in the same way when 10 pips went into profit.