SL, Minstop Level - automated matrix

 

Brothers & Sisters


I have a new challenge which is really confusing my brain out... and I run out of energy.

I also would like to share this code with you - as a reward and showing that MT4 is a truly capable platform.


The issue: SL is not as per definition - at 5 pips. TPs are working fine !!!


double minstoplevel=MarketInfo(ArrSymb[i],MODE_STOPLEVEL);
double Bidy = MarketInfo(ArrSymb[i],MODE_BID);
double Asky = MarketInfo(ArrSymb[i],MODE_ASK);



      if(MarketInfo(SymbolName(i,1),MODE_DIGITS) == 5 || MarketInfo(SymbolName(i,1),MODE_DIGITS) == 3){ 
      Apoint = Apoint*10;

     }

   

     ApointArr[i] = Apoint;

     ArrDigits[i] = MarketInfo(SymbolName(i,1),MODE_DIGITS); // Digits compute per symbol
     ArrPoints[i] = MarketInfo(SymbolName(i,1),MODE_POINT); // Point computer per symbol



     LSL = 5,
     SSL = 5,



double ArrLots1[4] = {0.5,0.5,0.5,0.5};
double ArrTPs1[4]= {15,20,25,30};  



double ArrTPs2[4]= {0.5,0.25,0.25,0.1}; 
double ArrLots2[4] = {15,20,25,30}; 


   double price=NormalizeDouble((Bidy+minstoplevel*LP*ApointArr[i]*ArrPoints[i]),ArrDigits[i]); // 40
   double stoploss=NormalizeDouble((ArrMA20H4[i]-minstoplevel*ArrPoints[i]-LSL*ApointArr[i]*ArrPoints[i]),ArrDigits[i]); // *ApointArr[i]*ArrPoints[i]
   double takeprofit=NormalizeDouble((Bidy+minstoplevel*ArrPoints[i]+ArrTPs[OrderFor]*ApointArr[i]*ArrPoints[i]),ArrDigits[i]); // 200


   price=NormalizeDouble((Asky-minstoplevel*LP*ArrPoints[i]*ApointArr[i]),ArrDigits[i]);//*ApointArr[i]*ArrPoints[i]
   stoploss=NormalizeDouble((ArrMA20H4[i]+minstoplevel*ArrPoints[i]+LSL*ArrPoints[i]*ApointArr[i]),ArrDigits[i]);
   takeprofit=NormalizeDouble((Asky-minstoplevel*ArrPoints[i]-ArrTPs[OrderFor]*ArrPoints[i]*ApointArr[i]),ArrDigits[i]);


ticket=OrderSend(ArrSymb[i],OP_SELL,ArrLots[OrderFor],price,1,stoploss,takeprofit,NULL,0,0,clrNONE); / ticket=OrderSend(ArrSymb[i],OP_BUY,ArrLots[OrderFor],price,1,stoploss,takeprofit,NULL,0,0,clrNONE);

My SL goes actually at 25 pips - instead of 5 pips and i do not think is about the minstoplevel variable... what am I doing wrong ?


Kindly, please advise.

Much appreciated !


Kind regards

C

 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. double price=NormalizeDouble((Bidy+…
    
    double takeprofit=NormalizeDouble((Bidy+…
    You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell orders you pay the spread on close.
    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask. Your SL is shorter by the spread and your TP would be longer. Don't you want the same/specified amount for either direction?
    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25
    3. 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.)

  3. Use the debugger or print out your variables, including _LastError and prices and . Do you really expect us to debug your code for you?

 
William Roeder:
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell orders you pay the spread on close.
    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask. Your SL is shorter by the spread and your TP would be longer. Don't you want the same/specified amount for either direction?
    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25
    3. 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.)

  3. Use the debugger or print out your variables, including _LastError and prices and . Do you really expect us to debug your code for you?


the spread is FAR bigger than ANY kind of spread between Ask and Bid... even if I would deal with major broken house of a market maker.

and not sure if using just the Bid (as I think you try to propose) would help to cut a 20 pip difference between my declared SL and the intended one.


i see no solution in your answer, further more: SL is wrong in both cases for BUY and SELL ! therefore you didn't identified the issue. at all.

about debugging code... i think my code is compiled and working. not working as expected, indeed. 

and this is why I am here. if you can be positive and offer a solution please do it.


note: this happened on EURGBP and GBPUSD on a very reputable ECN trading platform.

the spread between Ask and Bid cannot be 20 pip for these pairs...


I did what you propose to show the Ask line... and the result so far is zero... meaning that I checked the indicated box on Charts from Tools/Options and nothing pops on the screen... (an error maybe ?).


note: i added the orders in the presented code in the Alt+S box... maybe that will clarify further what my position is... 


much appreciated,

C

 
CB:

The issue: SL is not as per definition - at 5 pips. TPs are working fine !!!

You compute your stoploss this:

double stoploss=NormalizeDouble((ArrMA20H4[i]-minstoplevel*ArrPoints[i]-LSL*ApointArr[i]*ArrPoints[i]),ArrDigits[i]);

or 

stoploss=NormalizeDouble((ArrMA20H4[i]+minstoplevel*ArrPoints[i]+LSL*ArrPoints[i]*ApointArr[i]),ArrDigits[i]);

So the key is the value of "ArrMA20H4[i]" right? If it's 100 pips away from your open price, then it'll be 100 pips on top of "minstoplevel*ArrPoints[i]+LSL*ArrPoints[i]*ApointArr[i]".

Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Price Constants
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Calculations of technical indicators require price values and/or values of volumes, on which calculations will be performed. There are 7 predefined identifiers from the ENUM_APPLIED_PRICE enumeration, used to specify the desired price base for calculations. If a technical indicator uses for calculations price data, type of which is set by...
 
Seng Joo Thio:

You compute your stoploss this:

or 

So the key is the value of "ArrMA20H4[i]" right? If it's 100 pips away from your open price, then it'll be 100 pips on top of "minstoplevel*ArrPoints[i]+LSL*ArrPoints[i]*ApointArr[i]".

yes sir - correct. i would guess than that the rest is fine and only that variable would be at fault ? if this is the case i will double check.


thank You Seng !

 
CB:

yes sir - correct. i would guess than that the rest is fine and only that variable would be at fault ? if this is the case i will double check.


thank You Seng !

Yes, that variable should be the only cause of your large stoploss.

Reason: