"Strategy Tester", stoploss, takeprofit. How to assign values

 

Please help me understand

I use mql5 :)

How should I do to make the stoploss values and takeprofit of my EA are used in the "Strategy Tester"
No matter the values that exist in my text "ea.ml5"
. They will be ignored.
Whenever I run the "Strategy Tester" values used are always those who are on the "Inputs"

What should I do so that the "Strategy Tester" always use the values stated in my "ea.mq5"?

Thanks in advance

 
as I don't know whether you have mt4 or mt5 and I don't know much about mt5 please find here anything you need I  guess!
 
Carl Schreiber:
as I don't know whether you have mt4 or mt5 and I don't know much about mt5 please find here anything you need I  guess!

I use MQL5

Thanks for your time, but I also already searched this page but did not find documentation on this subject.

I have done numerous tests and find no solution.

Please, anyone have this problem?
How you guys use the SL and TP with the "Strategy Tester"?
 
Sergio Gelli:

I use MQL5

Thanks for your time, but I also already searched this page but did not find documentation on this subject.

I have done numerous tests and find no solution.

Please, anyone have this problem?
How you guys use the SL and TP with the "Strategy Tester"?
Please show your code if you need coding help.
 
Sergio Gelli:

I use MQL5

Thanks for your time, but I also already searched this page but did not find documentation on this subject.

I have done numerous tests and find no solution.

Please, anyone have this problem?
How you guys use the SL and TP with the "Strategy Tester"?

Typically the SL and TP values are specified as input to an EA as a guideline for your EA.  Meaning, when you open your position you specify those values to the current Bid or Ask (depending if short or long).  So for example, if you specify a SL of 50 pips and a TP of 100 pips you would so something like this (or similar)

if(Type == LONG_POSITION) Price = Ask; else Price = Bid;
TP = (Type == LONG_POSITION ? Price + TakeProfit : Price - TakeProfit);
HardStop = (Type == LONG_POSITION ? Price - StopLoss : Price + StopLoss);
Result = OrderSend(NULL, (Type == LONG_POSITION ? OP_BUY : OP_SELL), Lots, Price, 0, HardStop, TP, CommentMsg, MagicNumber, NULL, NULL);
 
Alain Verleyen:
Please show your code if you need coding help.
This code has been done to illustrate the problem with the "Strategy Tester".
Please do not criticize the utility.

Just look at if you makes alterations in TKP and STL values, you will see that there will be no change in the result.

Only there will be changes in the results if you make changes in the "Input" tab of the "Strategy Tester"

I look for a solution to the "Strategy Tester" obey the parameters placed in the code
The first time you run the code, the STL and TKP values are OK.
The problem arises after making any changes in the values of StopLoss and TakeProfit variables

//+------------------------------------------------------------------+
//|                                                  OrdemCompra.mq5 |
//|ABRE ORDEM PENDENT COM VALOR NA VARIAVEL price                  . |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "http://www.ubatuirim.com.br"
#property version   "1.00"
input double lot1               = 1;
input double StopLoss           = 33;
input double TakeProfit         = 88;
input int      EA_Magic=12345;   // EA Magic Number
double price,STP,TKP;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
 if(PositionSelect(_Symbol)==true) // we have an opened position
 {
  if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
  {
   // return;           // nao trabalha com buy
  }
  else //if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
  {
   BuyOrder1();     // It is a Sell or not oppened
  }
 }
 else
  BuyOrder1();     // beguin the beguine
  return;          // close with only one
}
//+------------------------------------------------------------------+
 void BuyOrder1()
  {
//--- prepare the request
   MqlTradeCheckResult m_check_result;
   MqlTradeResult mresult;             // To be used to get our trade results
//   MqlTick latest_price;             // To be used for getting recent/latest price quotes
   MqlTradeRequest mrequest={0};       // To be used for sending our trade requests
   price=SymbolInfoDouble ( Symbol (), SYMBOL_ASK );
   price = NormalizeDouble((price),_Digits); 
   Print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAA price = ",price);
   STP=(StopLoss* 0.00001) ;                  // *_Point,_Digits
   STP = price-(StopLoss* 0.00001) ;           // *_Point,_Digits
   TKP= price+(TakeProfit* 0.00001) ;           // *_Point,_Digits
//   mrequest.tp = NormalizeDouble(latest_price.bid + TKP*_Point,_Digits);
//   mrequest.tp = NormalizeDouble(price + TKP);
   mrequest.sl = STP;              // Stop Loss em 
   mrequest.tp = TKP;              // Take Profit em 
   mrequest.action = TRADE_ACTION_DEAL;                                  // immediate order execution
   mrequest.price = price;         // latest ask price
   mrequest.symbol = _Symbol;                                            // currency pair
   //NormalizeDouble( <valor> , digits)
   mrequest.volume = lot1;                                                 // number of lots to trade
   mrequest.magic = EA_Magic;                                             // Order Magic Number
   mrequest.type = ORDER_TYPE_BUY;                                        // sell Order
   mrequest.type_filling = ORDER_FILLING_FOK;                             // Order execution type
   mrequest.deviation=100;                                                // Deviation from current price
   //--- send order
   OrderSend(mrequest,mresult); // abre COMPRA
   //    get the result code
   if(mresult.retcode==10009 || mresult.retcode==10008) //Request is completed or order placed
   {
//    Alert(" 0008                        -  A BUY order has been successfully placed with Ticket#:",mresult.order,"!!");
    Alert("OOOOOOOOOO SUCCESS  OOOOOOOOOOOOOOOO - Price = ",price, "   Stop Loss = ",STP, "   Take Profit = ", TKP);
   }
   else
   {
//     Comment(" 0009  -                   The BUY order request could not be completed -error:",GetLastError());
     Alert("XXXXXXXX    FAIL   XXXXXXXXXXXXXXXX - Price = ",price, "   Stop Loss = ",STP, "   Take Profit = ", TKP);
     ResetLastError();           
//      return;
//   return;
  }    // fim if (autorizaOpr==0)
  
}
//+------------------------------------------------------------------+
Reason: