1

Brand new to both coding and trading.

Two questions I could not understand:

Q1: why doesn't this work?

Q2: Would this even potentially be profitable?

{ 
   double DayOpen = iOpen( NULL, PERIOD_D1, 1 );

   double TakeProfitLevel;
   double StopLossLevel;

   int    TakeProfit  = 10;
   int    StopLoss    = 10;

   TakeProfitLevel = Bid + Point * TakeProfit;   // 0.0001
   StopLossLevel   = Bid - Point * StopLoss;

   int  total  = OrdersTotal();
   if ( total <= 0  && Bid < DayOpen - StopLossLevel )
   { 
      OrderSend( "EURUSD", OP_BUY, 1.0, Ask, 0, StopLossLevel, TakeProfitLevel, "1st Order" );
   }
}
user3666197
  • 1
  • 6
  • 50
  • 92
Rob
  • 69
  • 5
  • 1
    Duplicate question asked in a different way, and without enough information. Please post full code in the future (eg, your code should be within the start() or ontick() block. Please state the actual ERROR you are facing. OrderSend( "EURUSD", ... is highly dependent on broker symbol. Some broker uses "EURUSD-", some "EURUSDm". Consider using Symbol(). – jlee88my Mar 27 '16 at 15:46
  • 1
    You should consider accepting that answer...if you're still around. – not2qubit Nov 08 '19 at 19:31

1 Answers1

2

Q1: Solution

You might have already noticed, that your FxMarketEVENTs data will in principle never match the condition:

Bid < DayOpen - StopLossLevel

The anatomy of calculus is following:

/* ----------------------------------------------------------------------------
            ...............dHIGH[1]                        ~ 1.22ooo
           |
           |       ....... dHIGH[0]                        ~ 1.2oooo
           |      |
dOPEN[0]...|..... |                                        ~ 1.18ooo
          [ ]    [ ]
          [ ]    [ ]
          [ ]    [ ]______ dCLOSE[0] _______________ <Bid> ~ 1.12345 _________
          [ ]     |
          [ ]     | 
dOPEN[1] _[ ]     |  ..... dLOW[0]                         ~ 1.1oooo
           |
           |
           | ............. dLOW[1]

------------------------------------------------------------------------------ */
   StopLossLevel   =                  Bid -    Point * StopLoss;
// -------------
// StopLossLevel   ~                  1.12345 - 0.00010;
// StopLossLevel   ~                  1.12335;

if ( Bid     < DayOpen - StopLossLevel ){...}
if ( 1.12345 < 1.10000 - 1.12335       ){...}
if ( 1.12345 <          -0.02335       ){...} // which it NEVER could be

Comparing numbers and using PriceDOMAIN values in XTO requires a bit more care in MQL4.

A good programming practice for safe MQL4 code-execution recommends:

// StopLossLevel   =                  Bid - ( _Point * StopLoss ); Calculus-safe
// StopLossLevel   = NormalizeDouble( Bid - ( _Point * StopLoss ),
//                                    _Digits                      XTO-safe
                                      );

Epilogue

Q2 has been covered in another answer.

Adding a few cents here, to the reasoning provided there, the profitability is heavily dependent on many attributes.

So as to illustrate the industry experience, let me present you a view into a sensitivity of profit, visually reduced into a single-dimension graph:

enter image description here

You may observe configurations of the very same algorithm to provide yields of about +1500% profits altogether with settings, that do not allow to produce, with the very same behaviour, more than about +20% .. +80%.

It is common to have pretty high-dimensionality parametrisation spaces in quant-modelling, which do not have any simple projection into 2D, 3D, 4D or 5D display-able graphics.

enter image description here

Thus, without thorough quantitative data, any statement about any strategy profitability is, paraphrased the famous Deming quote, "just another opinion".

Community
  • 1
  • 1
user3666197
  • 1
  • 6
  • 50
  • 92