Creare funzioni in AlgoWizard
3 risposte
Trading mirato
6 mesi fa #288569
Salve,
I’m an experienced MQL5 developer and am trying to code our EA into SQX for back testing. We already successfully coded our indicators in .java using code editor, but I’m not seeing an option to create a strategy in Code Editor. Am I seeing this correctly? We’re not allowed to code strategies in Code Editor?
If so, how would I code in my custom functions using AlgoWizard as I’m not seeing the options I need in the fixed dropdowns? I tried the “Custom Functions” where I put a function in the .mq5 in “C:\StrategyQuantX138\user\extend\Code\MetaTrader5\CustomFunctions” but it did not seem to recognize this for back testing.
For example, one of the more simplistic functions we have is to assign the Average Price for Buys into a variable, how would I do this with AlgoWizard? or is there a way to code a strategy in Code Editor similar to how we code indicators in .java?
Below is a sample function I’d like to code.
Thank you for your help in advance.
[code]double Average_Price_BUY(ulong magicNumber,string symbol,int s){
double Total_Price = 0;
double Total_Size = 0;
double bAverage_Price;
for(int i = PositionsTotal() – 1; i >= 0; i–){
string CurrencyPair = PositionGetSymbol(i);
double PositionOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
double PositionSize = PositionGetDouble(POSITION_VOLUME);
long PositionDirection = PositionGetInteger(POSITION_TYPE);
long PositionMagicNumber = PositionGetInteger(POSITION_MAGIC);
if (symbol == CurrencyPair && PositionDirection == POSITION_TYPE_BUY && PositionMagicNumber == magicNumber){
Total_Size += PositionSize;
Total_Price += PositionOpenPrice * PositionSize;
}
}
if (Total_Size != 0) {
bAverage_Price = Total_Price / Total_Size;
} else {
bAverage_Price = 0.0;
}
if(inpCommissionAccount==false){return bAverage_Price;}
else{return bAverage_Price+(sym[s].CommPointsToAdd*SymbolPoint(symbol));}
}[/codice]

tomas262
6 mesi fa #288574
Ciao,
that is correct. You cannot use CodeEditor to create strategies directly.
CustomFunctions can only used in sim / real not in backtesting. You cannot simply get the average price. In MT4/5 hedging mode each position is being treated as independent. You cannot as well directly reference “position average price”
Trading mirato
6 mesi fa #288582
Okay thank you for your answer.
Is there any way to write anything custom in AlgoWizard or are we limited to the fixed dropdowns?
Bartosz
4 mesi fa #289168
1. I’m also interested in using CUST Custom Function. Description says we can use it to put our custom MQL code, but doesn’t mention we can’t use it in the retester etc. So, what’s its intended usage?
Stai visualizzando 3 risposte - da 1 a 3 (di 3 totali)