Help. How to define TP Level of multiple orders for Martingale Strategy?

 

I tried to find an answer to this but could not find anything.

Example: https://ibb.co/1GWQdRS

Lets say this martingale bot has a
-PipStep range of: 20 pips
-And a TP of 10 pips. 

If the first sell order were to be successfull the trade would've closed 10 pips in profit.

But how would you calculate the TP at which all orders should close in overall profit if the market goes against you and you end up opening 4 trades with a lot multiplier of 2 like the image above shows?

I appreciate any help, I hope I made myself clear.

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Orders in DOM
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Orders in DOM
  • www.mql5.com
For equity securities, the Depth of Market window is available, where you can see the current Buy and Sell orders. Desired direction of a trade operation, required amount and requested price are specified for each order. To obtain information...
Files:
Example_FX.png  28 kb
 
Josh Farlow:

But how would you calculate the TP at which all orders should close in overall profit

  1. Calculate all order average price level.
  2. minus (or add) 10pips to that price.
 
Mohamad Zulhairi Baba:

  1. Calculate all order average price level.
  2. minus (or add) 10pips to that price.
Thanks for your response. 

So is it possible to code a function like that, in which regardless of the number of open trades the Expert Advisor can calculate the average price while weighing in the increased lot size per order?
 
Josh Farlow:

I tried to find an answer to this but could not find anything.

Example: https://ibb.co/1GWQdRS

Lets say this martingale bot has a
-PipStep range of: 20 pips
-And a TP of 10 pips. 

If the first sell order were to be successfull the trade would've closed 10 pips in profit.

But how would you calculate the TP at which all orders should close in overall profit if the market goes against you and you end up opening 4 trades with a lot multiplier of 2 like the image above shows?

I appreciate any help, I hope I made myself clear.

You could use these functions: (call CalculateTP with the first order volume)



 double CalculateTP(double volume)

  { 

    double aux_take_profit; 

    aux_take_profit=tp*CalculatePipValue(volume);

    return(aux_take_profit);

 }


  double CalculateSL(double volume)

  { 

    double aux_stop_loss; 

    aux_stop_loss=-1*grid_size*CalculatePipValue(volume);  

    return(aux_stop_loss);

  }

  

  

  

  double CalculatePipValue(double volume)

   double aux_mm_value=0;

   

   double aux_mm_tick_value = SymbolInfoDouble(Symbol, SYMBOL_TRADE_TICK_VALUE);

   double aux_mm_tick_size = SymbolInfoDouble(Symbol, SYMBOL_TRADE_TICK_SIZE);

   long aux_mm_digits = SymbolInfoInteger(Symbol, SYMBOL_DIGITS);   

   double aux_mm_veces_lots;

   

   if (volume!=0)

   {

     aux_mm_veces_lots = 1/volume;

      

     if (aux_mm_digits==5 || aux_mm_digits==3)

     {

       aux_mm_value=aux_mm_tick_value*10;

     }

     else if (aux_mm_digits==4 || aux_mm_digits==2)

     {

       aux_mm_value = aux_mm_tick_value;

     }

   

     aux_mm_value = aux_mm_value/aux_mm_veces_lots;

   }  

   

   return(aux_mm_value);

}

 
you might want to learn from this

https://www.mql5.com/en/code/12220

 
Francisco Jose Castro Cabal:

You could use these functions: (call CalculateTP with the first order volume)



 double CalculateTP(double volume)

  { 

    double aux_take_profit; 

    aux_take_profit=tp*CalculatePipValue(volume);

    return(aux_take_profit);

 }


  double CalculateSL(double volume)

  { 

    double aux_stop_loss; 

    aux_stop_loss=-1*grid_size*CalculatePipValue(volume);  

    return(aux_stop_loss);

  }

  

  

  

  double CalculatePipValue(double volume)

   double aux_mm_value=0;

   

   double aux_mm_tick_value = SymbolInfoDouble(Symbol, SYMBOL_TRADE_TICK_VALUE);

   double aux_mm_tick_size = SymbolInfoDouble(Symbol, SYMBOL_TRADE_TICK_SIZE);

   long aux_mm_digits = SymbolInfoInteger(Symbol, SYMBOL_DIGITS);   

   double aux_mm_veces_lots;

   

   if (volume!=0)

   {

     aux_mm_veces_lots = 1/volume;

      

     if (aux_mm_digits==5 || aux_mm_digits==3)

     {

       aux_mm_value=aux_mm_tick_value*10;

     }

     else if (aux_mm_digits==4 || aux_mm_digits==2)

     {

       aux_mm_value = aux_mm_tick_value;

     }

   

     aux_mm_value = aux_mm_value/aux_mm_veces_lots;

   }  

   

   return(aux_mm_value);

}

Thank you very much, I will give it a try!
 
Soewono Effendi:
you might want to learn from this

https://www.mql5.com/en/code/12220

Appreciate it my friend!
 
Did you have found a solution?
Reason: