Reply

Lets share SQ’s custom MQL4 functions here!

10 replies

Karish

Customer, bbp_participant, community, sq-ultimate, 444 replies.

Visit profile

8 years ago #114883

Hi there fellow SQ users,

because few of us come from MQL4 programming prospective we have our own ideas how to improve the original SQ’s MQL4 functionalities,

so.., i wanted to share some of mine “add-ons” that i’ve implemented into the original SQ’s MQL4 files..

plus i want that everyone that had their SQ’s MQL4 files somehow modified to share their modifications here with everyone also 🙂

 

ill start by sharing some of mine.. have fun!:

 

 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

¢ BACKTEST MUCH MORE FASTER WHEN USING MT4 (WITHOUT VISUAL MODE):

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Open your “Main.tpl” file and insert the following code line somewhere under the “int start() {” and above the “drawStats();”:

if(IsTesting()&&IsVisualMode()==false){ObjectsDeleteAll();} //Deletes all objects for faster MT4 backtesting..

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

 

 

 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

¢ SPREAD LIMITER:

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Search for “MaxSlippage = 3;” inside the “PrintParameters.inc” file, then under that line insert the following code line:

extern double MaxSpread = 1.5; // << enter your maximum spread in PIPs here

Search for “void openPosition” inside the “MT4Functions.inc” file, then under the “if(sqIsTradeAllowed() == 1) {” insert the following peace of code:

         string OrderTypeString;
         if(orderType==OP_BUY)       OrderTypeString="#BUY";
         if(orderType==OP_SELL)      OrderTypeString="#SELL";
         if(orderType==OP_BUYLIMIT)  OrderTypeString="#BUY_LIMIT";
         if(orderType==OP_SELLLIMIT) OrderTypeString="#SELL_LIMIT";
         if(orderType==OP_BUYSTOP)   OrderTypeString="#BUY_STOP";
         if(orderType==OP_SELLSTOP)  OrderTypeString="#SELL_STOP";
         //
         int orderStartPointInTime = GetTickCount();
         if(orderType==OP_BUY||orderType==OP_SELL){if(DoubleToStr((Ask - Bid)*gPointPow, 1)>DoubleToStr(MaxSpread, 1)){Log("#ERROR!: Order's ("+OrderTypeString+") Spread was too high, - (Current Spread: ("+DoubleToStr((Ask - Bid)*gPointPow, 1)+")>("+DoubleToStr(MaxSpread, 1)+" Maximum), Delayed.");Sleep(500);return(0);}}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

 

 

 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

¢ Determine if order closed by Stoploss/Takeprofit LOG NOTIFIER:

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Open your “Main.tpl” file and insert the following code line somewhere under the “int start() {” and above the “drawStats();”:

Order_Closure_OfSLTP_Notifier();

Open your “CustomCodeMT4,mq4” file and insert the following peace of code somewhere under the rest of the existing code that is already there..:

void Order_Closure_OfSLTP_Notifier()
{
   for(int i=OrdersHistoryTotal()-1;i>=0;i--){
   if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true&&OrderSymbol()==Symbol()){
   if(OrderMagicNumber()==MagicNumber){
   if(TimeCurrent()-OrderCloseTime()==0) //<< (ANTI LOOP FLOOD!)
   //
      //________________________________________________________
      //#Determine if order closed by Stoploss/Takeprofit:
      if(OrderTakeProfit()!=0||OrderStopLoss()!=0){
         string OrderTypeString;
         if(OrderType()==OP_BUY)       OrderTypeString="#BUY";
         if(OrderType()==OP_SELL)      OrderTypeString="#SELL";
         if(OrderType()==OP_BUYLIMIT)  OrderTypeString="#BUY_LIMIT";
         if(OrderType()==OP_SELLLIMIT) OrderTypeString="#SELL_LIMIT";
         if(OrderType()==OP_BUYSTOP)   OrderTypeString="#BUY_STOP";
         if(OrderType()==OP_SELLSTOP)  OrderTypeString="#SELL_STOP";
         //--
            if(OrderType()==OP_BUY&&OrderClosePrice()>=OrderTakeProfit()){Log("#Order: ("+OrderTypeString+" [Ticket: "+OrderTicket()+"]) was Closed By TP.");}
            if(OrderType()==OP_BUY&&OrderClosePrice()<=OrderStopLoss()){Log("#Order: ("+OrderTypeString+" [Ticket: "+OrderTicket()+"]) was Closed By SL.");}
            //
            if(OrderType()==OP_SELL&&OrderClosePrice()<=OrderTakeProfit()){Log("#Order: ("+OrderTypeString+" [Ticket: "+OrderTicket()+"]) was Closed By TP.");}
            if(OrderType()==OP_SELL&&OrderClosePrice()>=OrderStopLoss()){Log("#Order: ("+OrderTypeString+" [Ticket: "+OrderTicket()+"]) was Closed By SL.");}
         //
      //________________________________________________________         
   }}}}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

 

0

Karish

Customer, bbp_participant, community, sq-ultimate, 444 replies.

Visit profile

8 years ago #135833

Please if any one got a BreakEven & TrailingStop by TICKS please share..,

thank you..

0

Karish

Customer, bbp_participant, community, sq-ultimate, 444 replies.

Visit profile

8 years ago #135874

Please if any one got a BreakEven & TrailingStop by TICKS please share..,

thank you..

Somebody?..

0

stearno

Customer, bbp_participant, community, 379 replies.

Visit profile

8 years ago #135903

Karish,

I am sorry for such a simple question.  Where is the “Main.tpl?”  

0

Karish

Customer, bbp_participant, community, sq-ultimate, 444 replies.

Visit profile

8 years ago #135904

Karish,

I am sorry for such a simple question.  Where is the “Main.tpl?”  

All files located inside the “SQ\code” folder,

the “Main.tpl” located inside the “SQ\code\Mql_MT4” folder.

 

there is a Main.tpl inside the “SQ\code\Mql_MT4_BarOpen” folder also, but i don’t use the “BarOpen” feature.., only Tick based, so referee to the “SQ\code\Mql_MT4” folder.

0

stearno

Customer, bbp_participant, community, 379 replies.

Visit profile

8 years ago #135905

Thanks!

0

hankeys

Customer, bbp_participant, community, sq-ultimate, 487 replies.

Visit profile

7 years ago #141012

has anyone done modifications to the MQL4 code from SQ to get past through the validation process on MQL Market? I am stuck on this problem https://www.mql5.com/en/articles/2555#invalid_lot

You want to be a profitable algotrader? We started using StrateQuant software in early 2014. For now we have a very big knowhow for building EAs for every possible types of markets. We share this knowhow, apps, tools and also all final strategies with real traders. If you want to join us, fill in the FORM.

0

daveng

Customer, bbp_participant, community, 94 replies.

Visit profile

7 years ago #141066

Yes, it is part of MQL requirement to check the lot size to ensure it stays within the minimum and maximum lot size range of the broker. And the lot step needs to be checked as well.

You can use the following code (for MT4) which I’ve modified from the original MQL’s code:

============================================================================

bool CheckLotSizeValue(double volume)
{
//— minimal allowed volume for trade operations
   if(volume<min_volume)
   {
      Print(“Lot Size volume is less than the minimal allowed. Minimum allowed lot size is “,min_volume);
      return(false);
   }

//— maximal allowed volume of trade operations
   if(volume>max_volume)
   {
      Print(“Lot Size volume is greater than the maximum allowed. Maximum allowed lot size is “,max_volume);
      return(false);
   }

//— get minimal step of volume changing
   int ratio=(int)MathRound(volume/volume_step);
   if(MathAbs(ratio*volume_step-volume)>0.0000001)
   {
      PrintFormat(“Lot Size volume is not a multiple of the minimal step SYMBOL_VOLUME_STEP=%.2f, the closest correct volume is %.2f”,volume_step,ratio*volume_step);
      return(false);
   }
   
   return(true);
}

 

========================================================

 

And than insert these into your “Init” section:

 

min_volume=MarketInfo(Symbol(),MODE_MINLOT);
max_volume=MarketInfo(Symbol(),MODE_MAXLOT);
volume_step=MarketInfo(Symbol(),MODE_LOTSTEP);

 

========================================================

 

And also insert the function call command into your “start” section:

 

   if(!CheckLotSizeValue(LotSize))return;

 

Usually you will need to insert this right at the start so that your EA checks the lot size first before going to the rest of the codes…

=========================================================

 

And this is just one of the checks, there are quite a number of other checks that MQL admin would expect you to put in as well which includes free margin check, stop level check, freeze level check, pending order limit check, lot volume limit check, and Ordermodify error 1 check. Basically all these are mentioned in the MQL article.

Also not forgetting all your extern parameters need to have a check function to check each parameter value so that when a user keys in invalid value, your EA will automatically prompt an error in journal to alert the user and stop the EA.

 

Regards,

Dave

 

0

hankeys

Customer, bbp_participant, community, sq-ultimate, 487 replies.

Visit profile

6 years ago #143499

is anyone capable of doing custom MQL modification of MQ4 code to the SQ, so the approriate lotsize is going right from SQ to the strategy code? So if i have in SQ lotsize 0.08 it will put this size right after i click generate MQ4 code? if i need to change this in 100+ strs its very upsetting

You want to be a profitable algotrader? We started using StrateQuant software in early 2014. For now we have a very big knowhow for building EAs for every possible types of markets. We share this knowhow, apps, tools and also all final strategies with real traders. If you want to join us, fill in the FORM.

0

daveng

Customer, bbp_participant, community, 94 replies.

Visit profile

6 years ago #143502

is anyone capable of doing custom MQL modification of MQ4 code to the SQ, so the approriate lotsize is going right from SQ to the strategy code? So if i have in SQ lotsize 0.08 it will put this size right after i click generate MQ4 code? if i need to change this in 100+ strs its very upsetting

If you’re implying to manually change the default value of the lot size in the codes, that’s easy.

In the codes, look for “extern double Lots = 0.1;” which is usually located at the top part of the codes, then manually change the value to “0.08”.

Save it, and then every time when you run the EA it will be using a default lot size of “0.08”.

But if you’ve 100 EAs, you’ll need to do this manually for every EA. I don’t know if there’s any easy way to mass change this.

 

Regards,

Dave

0

hankeys

Customer, bbp_participant, community, sq-ultimate, 487 replies.

Visit profile

6 years ago #143503

This advice is useless, i know how to do it manually, i know how to do it together for 100+ strs in one click if the lotsize is the same value – but for me every strategy trading different lotsize, which is already used in SQ and is stored in STR file. and i want simple way how to put this exact value right to the MQL code

 

if we cant write samething like this discussed – custom MQL funkction

 

we can run some script (R, python, what so ever) – which will look for lotsize in STR file and put it automatically to the MQ4 file

You want to be a profitable algotrader? We started using StrateQuant software in early 2014. For now we have a very big knowhow for building EAs for every possible types of markets. We share this knowhow, apps, tools and also all final strategies with real traders. If you want to join us, fill in the FORM.

0

Viewing 10 replies - 1 through 10 (of 10 total)