How do I change this in the EA to trade actual pips ?
Please advise
Lots and lots and lots has been written about handling 5 digit brokers . . really . . . lots.
Have a look here: http://crum.be/45digit
WHRoeder has suggested some code to tackle this problem: https://www.mql5.com/en/forum/134305
Don't just copy & paste . . . if you want to learn, copy, read, understand & paste instead . . . ;-)
I need about 40hrs of reading time to get mql4 figured out.
It seems to take me sooooo long to understand what I'm reading because most of what I read has not been learned or covered in the lessons at the forex.tsd site.
(my pesky job/business is interfering with my pleasure)
Thanks again - I'll get on this right away.
Seems that when I make the 5 digit changes the first few trades do not close for a long long time even though there is crosses
Also the changes to the 5 digits are not acknowledging as 5 digits and seem to have little effect from what I can tell.
I thought I understood what to do and how it works after reading through the dictionary definitions/book/documentation that would correspond to this.But somehow I'm missing something.
After 6 hours of coding and reading; and making some progress I cannot pin down the problem for what seems like it should be a simple task.
One topic that eludes me is the Slippage.Pips shown in the notes and I feel this could be where I'm missing something.
Does this note actually mean Slippage.Pips with some meaning that I'm not understanding ? Or does this simply mean slippage like this (2*pips2dbl) ?
And I feel I need to use Digit.Pips someplace which I have not done so far//+------------------------------------------------------------------+ //| Dirty_Rat.mq4 | //| Agent86's Dirty Rat Trade | //| http://www.iclbiz.com/joomla | //+------------------------------------------------------------------+ #property copyright "Agent86" #property link "www.iclbiz.com/joomla" //---- input parameters extern double TakeProfit=100.0; extern double Lots=0.1; extern double StopLoss=50.0; //++++ These are adjusted for 5 digit brokers. int pips2points; // slippage 3 pips 3=points 30=points double pips2dbl; // Stoploss 15 pips 0.0015 0.00150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { if (Digits == 5 || Digits == 3) { // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } int Crossed (double line1 , double line2) { static int last_direction = 0; static int current_direction = 0; if(line1>line2)current_direction = 1; //up //might need to add here for second macd agreement if(line1<line2)current_direction = 2; //down if(current_direction != last_direction) //changed { last_direction = current_direction; return (last_direction); } else { return (0); } } int Crossed_2 (double line1 , double line2) //i'll use this later for macd agreement { static int last_direction_2 = 0; static int current_direction_2 = 0; if(line1>line2)current_direction_2 = 1; //up if(line1<line2)current_direction_2 = 2; //down if(current_direction_2 != last_direction_2) //changed { last_direction_2 = current_direction_2; return (last_direction_2); } else { return (0); } } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- int cnt, ticket, total; double faster, slower, faster_2, slower_2; if(Bars<100) { Print("bars less than 100"); return(0); } if(TakeProfit<10) { Print("TakeProfit less than 10"); return(0); // check TakeProfit } faster = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0); //MODE_MAIN slower = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0); //MODE_SIGNAL faster_2 = iMACD(NULL,PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_MAIN,0); //MODE_MAIN slower_2 = iMACD(NULL,PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0); //MODE_SIGNAL int isCrossed = Crossed (faster,slower); int isCrossed_2 = Crossed_2 (faster_2,slower_2); // i'll use this later total = OrdersTotal(); if(total < 1) { if(isCrossed == 1) { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,2*pips2points,Ask-StopLoss*pips2dbl,Ask+TakeProfit*pips2dbl,"Agent86",12345,0,Green); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else Print("Error opening BUY order : ",GetLastError()); return(0); } if(isCrossed == 2) { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,2*pips2points,Ask+StopLoss*pips2dbl,Bid-TakeProfit*pips2dbl,"Agent86",12345,0,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } else Print("Error opening SELL order : ",GetLastError()); return(0); } return(0); } for(cnt=0;cnt<total;cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderType()<=OP_SELL && OrderSymbol()==Symbol()) { if(OrderType()==OP_BUY) // long position is opened { // should it be closed? if(isCrossed == 2) { OrderClose(OrderTicket(),OrderLots(),Bid,2*pips2points,Violet); // close position return(0); // exit } // should it be closed? if(isCrossed == 1) { OrderClose(OrderTicket(),OrderLots(),Ask,2*pips2points,Violet); // close position return(0); // exit } } } } return(0); } //+------------------------------------------------------------------+
This code has issues
Seems that when I make the 5 digit changes the first few trades do not close for a long long time even though there is crosses
Also the changes to the 5 digits are not acknowledging as 5 digits and seem to have little effect from what I can tell.
I thought I understood what to do and how it works after reading through the dictionary definitions/book/documentation that would correspond to this.But somehow I'm missing something.
After 6 hours of coding and reading; and making some progress I cannot pin down the problem for what seems like it should be a simple task.
One topic that eludes me is the Slippage.Pips shown in the notes and I feel this could be where I'm missing something.
Does this note actually mean Slippage.Pips with some meaning that I'm not understanding ? Or does this simply mean slippage like this (2*pips2dbl) ?
And I feel I need to use Digit.Pips someplace which I have not done so farI think that Slippage.Pips is named that way to remind the coder that Slippage.Pips is slippage in terms of Pips not points, so in OrderSend it has to be converted to points, hence it is muliplied by pips2points which strangely converts pips to points ;-)
I found that WHRoeder's code made my head hurt, but only for a while until I grasped what he was doing . . . then my head felt better and I could start smiling ;-)
I mean really noob like 2 weeks. And this is my first real computer language. Although I read python syntax first just to get some basic idea of computer science I never did any programming in python except for a few terminal commands and equations and things with syntax. And I did make one window popup with wXpython.
I found that the original example EA provided in the lessons does the same thing so there is something else wrong and likely not the 5 digit fix
Back to the drawingboard
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Noob here,
From lesson 13 of the forex.tsd site
I toyed with this just to learn to code and make it do different things for practiceAlso changed if from EMA cross to MACD cross
Here is what I have simple macd cross and attempting to make a 5min with 4hr MACD agreement EA just to learn how.
Anyhow I noticed that Oanda and some others have 5 decimal places and so the strategy tester is trading the 5th digit is a pips and not fractional pipshttp://paste.pound-python.org/show/11113/
How do I change this in the EA to trade actual pips ?
Please advise