Please remember that we cannot read your mind, nor see your computer. Such a vague explanation does not make it clear what your issue may be.
Only by showing your code, log files results, some screenshots, etc. can we begin to understand some of your explanation.
However, given that you did not code it yourself and may lack some coding knowledge, any answers we give, may not be totally understandable to you. Please be aware of that possibility.
Please remember that we cannot read your mind, nor see your computer. Such a vague explanation does not make it clear what your issue may be.
Only by showing your code, log files results, some screenshots, etc. can we begin to understand some of your explanation.
However, given that you did not code it yourself and may lack some coding knowledge, any answers we give, may not be totally understandable to you. Please be aware of that possibility.
Here's the code:
//+------------------------------------------------------------------+ //| PSAR-PSAR.mq5 | //| Copyright 2023, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2023, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" //+------------------------------------------------------------------+ //| Include | //+------------------------------------------------------------------+ #include <Expert\Expert.mqh> //--- available signals #include <Expert\Signal\SignalSAR.mqh> //--- available trailing #include <Expert\Trailing\TrailingParabolicSAR.mqh> //--- available money management #include <Expert\Money\MoneyFixedLot.mqh> //+------------------------------------------------------------------+ //| Inputs | //+------------------------------------------------------------------+ //--- inputs for expert input string Expert_Title ="PSAR-PSAR"; // Document name ulong Expert_MagicNumber =27294; // bool Expert_EveryTick =false; // //--- inputs for main signal input int Signal_ThresholdOpen =10; // Signal threshold value to open [0...100] input int Signal_ThresholdClose =10; // Signal threshold value to close [0...100] input double Signal_PriceLevel =0.0; // Price level to execute a deal input double Signal_StopLevel =50.0; // Stop Loss level (in points) input double Signal_TakeLevel =50.0; // Take Profit level (in points) input int Signal_Expiration =4; // Expiration of pending orders (in bars) input double Signal_SAR_Step =0.02; // Parabolic SAR(0.02,0.2) Speed increment input double Signal_SAR_Maximum =0.2; // Parabolic SAR(0.02,0.2) Maximum rate input double Signal_SAR_Weight =1.0; // Parabolic SAR(0.02,0.2) Weight [0...1.0] //--- inputs for trailing input double Trailing_ParabolicSAR_Step =0.02; // Speed increment input double Trailing_ParabolicSAR_Maximum=0.2; // Maximum rate //--- inputs for money //input double Money_FixLot_Percent =10.0; // Percent input double Money_FixLot_Lots =0.1; // Fixed volume //+------------------------------------------------------------------+ //| Global expert object | //+------------------------------------------------------------------+ CExpert ExtExpert; //+------------------------------------------------------------------+ //| Initialization function of the expert | //+------------------------------------------------------------------+ int OnInit() { //--- Initializing expert if(!ExtExpert.Init(Symbol(),Period(),Expert_EveryTick,Expert_MagicNumber)) { //--- failed printf(__FUNCTION__+": error initializing expert"); ExtExpert.Deinit(); return(INIT_FAILED); } //--- Creating signal CExpertSignal *signal=new CExpertSignal; if(signal==NULL) { //--- failed printf(__FUNCTION__+": error creating signal"); ExtExpert.Deinit(); return(INIT_FAILED); } //--- ExtExpert.InitSignal(signal); signal.ThresholdOpen(Signal_ThresholdOpen); signal.ThresholdClose(Signal_ThresholdClose); signal.PriceLevel(Signal_PriceLevel); signal.StopLevel(Signal_StopLevel); signal.TakeLevel(Signal_TakeLevel); signal.Expiration(Signal_Expiration); //--- Creating filter CSignalSAR CSignalSAR *filter0=new CSignalSAR; if(filter0==NULL) { //--- failed printf(__FUNCTION__+": error creating filter0"); ExtExpert.Deinit(); return(INIT_FAILED); } signal.AddFilter(filter0); //--- Set filter parameters filter0.Step(Signal_SAR_Step); filter0.Maximum(Signal_SAR_Maximum); filter0.Weight(Signal_SAR_Weight); //--- Creation of trailing object CTrailingPSAR *trailing=new CTrailingPSAR; if(trailing==NULL) { //--- failed printf(__FUNCTION__+": error creating trailing"); ExtExpert.Deinit(); return(INIT_FAILED); } //--- Add trailing to expert (will be deleted automatically)) if(!ExtExpert.InitTrailing(trailing)) { //--- failed printf(__FUNCTION__+": error initializing trailing"); ExtExpert.Deinit(); return(INIT_FAILED); } //--- Set trailing parameters trailing.Step(Trailing_ParabolicSAR_Step); trailing.Maximum(Trailing_ParabolicSAR_Maximum); //--- Creation of money object CMoneyFixedLot *money=new CMoneyFixedLot; if(money==NULL) { //--- failed printf(__FUNCTION__+": error creating money"); ExtExpert.Deinit(); return(INIT_FAILED); } //--- Add money to expert (will be deleted automatically)) if(!ExtExpert.InitMoney(money)) { //--- failed printf(__FUNCTION__+": error initializing money"); ExtExpert.Deinit(); return(INIT_FAILED); } //--- Set money parameters // money.Percent(Money_FixLot_Percent); money.Lots(Money_FixLot_Lots); //--- Check all trading objects parameters if(!ExtExpert.ValidationSettings()) { //--- failed ExtExpert.Deinit(); return(INIT_FAILED); } //--- Tuning of all necessary indicators if(!ExtExpert.InitIndicators()) { //--- failed printf(__FUNCTION__+": error initializing indicators"); ExtExpert.Deinit(); return(INIT_FAILED); } //--- ok return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Deinitialization function of the expert | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { ExtExpert.Deinit(); } //+------------------------------------------------------------------+ //| "Tick" event handler function | //+------------------------------------------------------------------+ void OnTick() { ExtExpert.OnTick(); } //+------------------------------------------------------------------+ //| "Trade" event handler function | //+------------------------------------------------------------------+ void OnTrade() { ExtExpert.OnTrade(); } //+------------------------------------------------------------------+ //| "Timer" event handler function | //+------------------------------------------------------------------+ void OnTimer() { ExtExpert.OnTimer(); } //+------------------------------------------------------------------+
Input variables:
Backtest results with SL set to 0:
There seems to be a range effect up to 55000 (see attached file).
As far as what happens above that, I think I figured that out. Above 800,000 points, it starts killing long trades. My best guess is that it's hitting the point that some of those are invalid stop loss values on long trades, i.e., they'd be below 0. The backtest period is going back 2+ years, so that makes sense, so never mind about that issue.
But what doesn't make sense is why adding a stop loss of, say, 800,000 points would cut the profitability in half vs. no stop loss.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have an MQL5 EA I built using the wizard, but I'm kind of stumped on something. It uses a PSAR trailing stop. If I set no manual stop loss, I get 2794 trades within the test period with a profit of Recovery Factor of 4.04, profit of 9510.91. If I set any initial stop loss (I've tried everything from 1 point up to a million), it increases the number of trades (range effect up to a max of 2877), drops the RF (range effect from 1.94 at best on down to losses), and cuts the profit (5633.36 at best on down to losing). Adding a manual stop loss larger than any trade ever hits shouldn't affect the profitability, right?
In fact, this is weird - if I set the stop loss to something ridiculous, like, say, 10 million points, it kills all the long trades (turns them into losses).