Skip to content

Instantly share code, notes, and snippets.

@ybagheri
Created September 21, 2022 06:44
Show Gist options
  • Save ybagheri/243cc5a50ecb73101d40bce616eb1d54 to your computer and use it in GitHub Desktop.
Save ybagheri/243cc5a50ecb73101d40bce616eb1d54 to your computer and use it in GitHub Desktop.
Create dynamic mq4 file with php
<?php
$ea[0]=array("magic"=>"14001","pipstep"=>"50","numoftrade"=>"2","tp"=>"10,5","sl"=>"30,10");
$ea[1]=array("magic"=>"14002","pipstep"=>"50","numoftrade"=>"2","tp"=>"15,5","sl"=>"35,20");
$ea[2]=array("magic"=>"14003","pipstep"=>"50","numoftrade"=>"2","tp"=>"20,5","sl"=>"40,20");
$ea[3]=array("magic"=>"14004","pipstep"=>"50","numoftrade"=>"2","tp"=>"25,5","sl"=>"40,21");
$ea[4]=array("magic"=>"14005","pipstep"=>"50","numoftrade"=>"2","tp"=>"30,5","sl"=>"40,22");
$ea[5]=array("magic"=>"14006","pipstep"=>"50","numoftrade"=>"2","tp"=>"40,5","sl"=>"40,23");
$ea[6]=array("magic"=>"14007","pipstep"=>"50","numoftrade"=>"2","tp"=>"50,5","sl"=>"40,24");
$ea[7]=array("magic"=>"14008","pipstep"=>"50","numoftrade"=>"2","tp"=>"60,5","sl"=>"50,30");
for ($i = 0; $i <= 7; $i++) {
$txt="
//+------------------------------------------------------------------+
//| 2008 Ilan1.4 |
//+------------------------------------------------------------------+
//v 1.7 add setup strategy TEMAWithHigherEMA
//v 1.6 use refreshrade for sure open position
//v 1.5 tp sl depend on number of trades
//v 1.4 atr target for tp or multiply lot
//v 1.3 add LotExponent For Align WithTrend, update fGetLots function
//v 1.2 add pipstep for adding in positive position
//ver 1.1 add in positive
#property copyright \"Yousef Bagheri\"
#property link \"https://t.me/...\"
#property version \"1.2\"
#property strict
enum EA_Setting {TEMAWithHigherEMA,MACD,TEMA,CrossMA3MA20,CrossPriceMALine,FourCandleFlowReverse,Random,MA3Cross,MA3CrossReverse,BreakLowHighAgainst,BreakLowHighFollow,Manual, RSI_MTF};
enum DirectionOfOpenOrder {BUY,SELL,NONE};
extern DirectionOfOpenOrder Dir=SELL;
extern bool TradeOnlyInPreSetDirection=false;
extern bool UseAtrTPSLPipStep=false;
//----
sinput string TradeSettings; // ** EA SETTINGS **
input EA_Setting EA_Mode= TEMAWithHigherEMA;
extern bool TradeOnCandleStartOnly=false;
extern bool TradeStartManually=true;
sinput string TradeSettingMACD; // ** MACD SETTINGS **
extern int SleepOnSLMinutes=0;
extern int _fastEMAPeriod=12;
extern int _slowEMAPeriod=26;
extern int _signalPeriod=9;
extern bool _useStoch=false;
sinput string TradeSettingRSI; // ** RSI SETTINGS **
input int RSIPeriod = 14; // RSI Period
input double OverboughtLevel = 70; //Over-bought level
input double OversoldLevel = 30; // Over-sold level
input bool UseM1Timeframe = true; // Use M1 Timeframe?
input bool UseM5Timeframe = false; // Use M5 Timeframe?
input bool UseM15Timeframe = false; // Use M15 Timeframe?
input bool UseM30Timeframe = false; // Use M30 Timeframe?
input bool UseH1Timeframe = false; // Use H1 Timeframe?
input bool UseH4Timeframe = false; // Use H4 Timeframe?
input bool UseDailyTimeframe = false; // Use Daily Timeframe?
input bool UseWeeklyTimeframe = false; // Use Weekly Timeframe?
input bool UseMonthlyTimeframe = false; // Use Monthly Timeframe?
sinput string OtherSettings; // ** OTHER Setting **
input double Commission_eurusd_3_5_gold_6 = 6.1;
input double Commission_inPointForTrailCalculation=4;
extern int BrokerMaxLot=20;
extern int MMType=2; // MM type: 0-Lots, 1-as it was in 1.2, 2-martingale (LotExponent coefficient)
extern bool UseClose=false; // closing at a loss PipStep. recommended false
extern bool UseAdd=true; // reopening with a new lot. lot to be reopened is calculated by LotExponent regardless of MMType recommended = true
extern bool AddOnDirection=false;
extern double LotExponent=2; //1.21 old multiplying lots in a series exponentially to break even. first lot 0.1, series: 0.16, 0.26, 0.43 ...
extern double LotExponentForAlignWithTrend=0.85;
extern double Slippage=10; // allowable price slippage in pips
extern double Lots=0.01; // now you can also microlots 0.01, while if it is 0.1, then the next lot in the series will be 0.16
extern double LotsDigits=2; // 2 - micro lots 0.01, 1 - mini lots 0.1, 0 - normal lots 1.0
double TakeProfit=70; // Profit level in pipsaz from the opening price.
extern string TrailTp =\"".$ea[$i]["tp"]."\";
double Stoploss=1000;
extern string SLString=\"".$ea[$i]["sl"]."\";
double TrailStart=30;
extern string TrailStartString=\"7\";//\"140,120,100,80,60,40,30,20,10,8\";
double TrailStop=20;
extern string TrailStopString=\"100,100,100,100,100,100,100,100,100,100,100,50,50,50,50\";
extern bool TrailFistPosition=false;
extern int Trail=100; //distance from Price For Trail (points)
extern double PipStep=".$ea[$i]["pipstep"]."; // the distance in pips of loss at which the next knee order is opened.
extern double PipStepForAlignWithTrend=0;//PipStepForAlignWithTrend = 0 means don't use it
extern int MaxTrades=".$ea[$i]["numoftrade"].";
extern bool UseEquityStop=false;
extern double TotalEquityRisk=4.9; //loss as a percentage of equity
extern bool UseTrailingStop=false;
extern bool UseTimeOut=false;
extern double MaxTradeOpenHours=48;
extern int MagicNumber=" . $ea[$i]["magic"] .";
sinput string Visuals; // ** VISUALS **
input int Panel_X = 40; // Panel X coordinate.
input int Panel_Y = 40; // Panel Y coordinate.
input color Panel_Color = clrBlack; // Panel background colour.
input color Panel_Lable_Color = clrWhite; // Panel lable text color.
//----
//+------------------------------------------------------------------+
//| Global variable and indicators |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
// your code .....
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert Shutdown function |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// your code .....
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
// your code .....
}
//+------------------------------------------------------------------+
";
$myfile = fopen($ea[$i]["magic"].".mq4", "w") or die("Unable to open file!");
fwrite($myfile, $txt);
fclose($myfile);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment