How do I change the code to automatically correct for an issue of 5digit v 3 digit

 

Hello,

I am still learning and am writing an EA. The simple format of the trade logic is if the absolute value of Open[1] - Close[1] is greater than a defined minimum value open an order. I don't use this in isolation - there are other filter conditions. My big problem is it works fine until I have a pair involving JPY because the magnitude of the difference is 100 times greater due to the 3 digit versus 5 digit issue.

I have tried to work this out and read the forum discussion at https://forum.mql4.com/30672 but am still very unsure about how to progress.

I trade only in Forex pairs and my broker has no prefix or suffix. All Symbols are 5 digit except the xxxJPY which are 3 digits

int init()

NDigits = Digits;

and below works fine for all trade functions like Stop Loss, Take Profit etc.

int start()

......

void OnEveryTick()
{
    if (DetectBrokerDigits == false && true) PipValue = 10;
    if (DetectBrokerDigits && (NDigits == 3 || NDigits == 5)) PipValue = 10;
    
    WeekdayFilter();
        
}


My code to detect a minimum candle body height is:

if (MathAbs(Open[1] - Close[1]) > MinUpCandle)

For a "regular" pair it will be (say) 1.31585 - 1.31685 = (Abs) 0.0010 = 10 pips so if MinUpCandle value is 0.0008, the condition is met.

But if it is a pair involving JPY the numbers might be 106.505 - 106.605 = (Abs) 0.100 = 10 Pips so I have to define the MinUpCandle value as 0.1000 instead of 0.0010

I am managing this by having a set file for regular pairs and a different set file for JPY pairs but think there must be a way to manage this.

Can any kind person tell me how I can detect the 3 digits and divide the Abs value by 100 (or multiply MinUpCandle by 100) if Symbol is xxxJPY?


 

include

double THE_POINT ()
  {
  if (Digits == 5 || Digits == 3)
     {return (Point*10);}
      else
     {return  (Point);}
  }
 
You must adjust TP, SL, AND slippage
//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){                                                     OptParameters();
     if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
//---- These are adjusted for 5 digit brokers.
    /* On ECN brokers you must open first and THEN set stops
    int ticket = OrderSend(..., 0,0,...)
    if (ticket < 0)
       Alert("OrderSend failed: ", GetLastError());
    else if (!OrderSelect(ticket, SELECT_BY_TICKET))
       Alert("OrderSelect failed: ", GetLastError());
    else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0)
       Alert("OrderModify failed: ", GetLastError());
     */
 

Thank you onewithzachy and WHRoeder - I will try both solutions.

I take it I am to delete / comment out the NDigits = digits in int init() and replace the suggested alernatives in the int Start() section?

 
onewithzach's NDigits, does not handle SLIPPAGE.The function call is inefficient since nothing there will ever change between init() calls.
 

I have not been able to get any of these solutions to work. I feel bad about this. I'm sure it was because I needed to do things in int start() and/or int init() but whatever I tried, there were errors.

I tried a different approach and it seems to be working. This might be useful for others so I'm feeding it back. Also, this is my first creative attempt to achieve this and I may find there are unanticipated errors. So I am asking if this appears a sound approach or it is wrong and may have unintended consequences.

In Variables: I declared string symbole;

In int start() I added the code below

symbole = Symbol();

if(StringSubstr(symbole,3,3)=="JPY") {MinUpCandle1 = MinUpCandle*100; } else { MinUpCandle1 = MinUpCandle; }
 

Sorry for lazy reply (not :| ). I never use, actually rarely use

Point

I replace that and use variable, say YOUR_POINT, and it's value we're taken from my include THE_POINT() function I told you above. I call that function on top of the int (), and start(), so the value of YOUR_POINT is updated. Like this :

YOUR_POINT = THE_POINT ();

Say we have 5 digits pair. Point value will be 0.00001, YOUR_POINT value will be 0.0001. Say for example, 1.23456 - 1.23356 = 0.00100. Then we divide this 0.00100 with YOUR_POINT, the result is 10.

Say we have 3 digits pair. Point value will be 0.00100, YOUR_POINT value will be 0.0100, Say for example, 123.456 - 123.356 = 0.10000. Then we divide this 0.10000 with YOUR_POINT, the result is 10.

Now do your own calculation if we have 4 digits and 2 digits pair, and if you still don't get it,

Print ();

them.

And leave me alone

:|

Files:
 
Thanks for clarification and attachment onewithzachy, it is appreciated.
 
NewtonLeo:
Thanks for clarification and attachment onewithzachy, it is appreciated.

The reasons why you get lazy reply is because you're asking for an ancient topic. MQL4.com is full of that 3 - 5 digits topics.

Hope you don't mind, some of us become boring and lazy replying because the answer is simple.

 
I am always genuinely grateful to anyone taking the time to answer anything I post. On this issue, I did search here and quoted a link that had seemed most relevant to my question; I also looked closely at two MQ4 language e-books I have but could not find any info specific to this need; certainly nothing that I could compile without errors :-(. But I have now learned a new thing and was sincere in posting the solution that worked for me so others might benefit. I was well intentioned and admit I am still learning. Thanks again.
 
NewtonLeo:

I have not been able to get any of these solutions to work. I feel bad about this. I'm sure it was because I needed to do things in int start() and/or int init() but whatever I tried, there were errors.

I tried a different approach and it seems to be working. This might be useful for others so I'm feeding it back. Also, this is my first creative attempt to achieve this and I may find there are unanticipated errors. So I am asking if this appears a sound approach or it is wrong and may have unintended consequences.

In Variables: I declared string symbole;

In int start() I added the code below

Then you haven't any idea what you are doing Time to Study

What if your symbole is not an JPY pair what is it then doing

Take this example of the method from WHRoeder

//+------------------------------------------------------------------+
//|                                                Digitnotation.mq4 |
//|                                      Copyright © 2012,  WHRoeder |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012,  WHRoeder"
#property link      "https://forum.mql4.com"








//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   if (Digits % 2 == 1)  // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
     {pips2dbl = Point*10; pips2points = 10;   Digits.pips = 1;}
     else {pips2dbl = Point;    pips2points =  1;   Digits.pips = 0;}
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl     
//---- These are adjusted for 5 digit brokers.
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
Reason: