Previous Next

GTrade.CalculateCRV()

Returns the chance-risk ratio of the entered prices.

double  GTrade.CalculateCRV(
   double  stopLoss,    // StopLoss value
   double  takeProfit,  // TakeProfit value
   double  pending = 0  // Optional pending value
   );

Parameter

stopLoss

[in]  The price of the StopLoss.

takeProfit

[in]  The price of the TakeProfit.

pending

[in]  The price of the pending order.

Return value

Returns the chance-risk ratio as double. In case of an error, 0 (zero) is returned.


Example:

//--- Include Glib classes
#include <Glib.mqh>

//--- Creating a pointer to an empty class object
GTrade *trade;
GChartPatterns *chartPatterns;


int OnInit ()
{
   //--- Assign the class to the empty class object
   trade = gTrade();
   chartPatterns = gChartPatterns();

   //--- Initialize the class data
   trade.Init();
   chartPatterns.Init();

   return(INIT_SUCCEEDED);
}

void OnDeinit (const int reason)
{
   //--- Free memory on exit
   delete trade;
   delete chartPatterns;
}


void OnTick ()
{
   if ( chartPatterns.Ready() ) //--- Will only be executed when all data is ready
   {
      //--- Create structure array
      GStructChartPatterns patternInfo;

      //--- Waits for a breakout signal
      if  (chartPatterns.Signal(patternInfo)) 
      { 
         //--- If the direction of the formation is Long
         //--- and CRV over 2.6:1,
         if ( patternInfo.targetDirection == DIRECTION_LONG && trade.CalculateCRV(patternInfo.middle, patternInfo.highest) >= 2.6 )
         {
            //--- then open a trade with StopLoss at the center of the formation
            trade.Open(patternInfo.middle);
         }
      }
   }
}


See also

GTrade.CalculateCRV