Entry Problems Help Please

 

Hello to All

There are actually two problems but I believe one is affecting the other. I will post the code in an attachment because of error message 'Text is to long'.

The problem areas are indicated with ??????????????? at the end of the lines where the problem(s) are located.

Do not mind sharing the code. It was the help from the developers here which has helped me to share the code attached.

Please do not use the code with real money at this time. It has been a learning tool.

The problem for this code is that it once was ok. Meaning that it would have BUY and SELL entries.

I was attempting to delete one entry strategy and insert the new strategy. The one with the ????????????.

The strategy was that the Open[3] (3rd bar past) would have to be < (less) that the LOWER BAND of the Bollinger indicator.

This will give ---return (BarHighPatterns)

else

if Open[3] was > than the UPPER Band

This will give --return (BarLowPaterns)

Could the problem be the definition for the iBands--- dBollHigh, dBollLow? OR/AND

Could the use of these definitions in the formula BarHighPatterns = (Close[3] > dBollHigh

BarLowPatterns = (Close[3] < dBollLow----be part of the problem?

Sure

 
I recommend u stick to a more conventional coding style like in some of your older posts.
 

static int iTime_0 = EMPTY ; //< >
if ( iTime_0 < iTime ( 0, 0, 0 ) ) //< >

???????

 

u understand the logic behind parenthesis ?

 

This code is a foundation which was offered by AIS sometime ago. I have done many expansions for learning. If there is someone out there that can be of help, is would be appreciated.

Thank you all in advance.

Regards

 

Works fine: https://www.mql5.com/en/forum/124521/page7

Please look at this: https://forum.mql4.com/ru/14594/page12

 

Hello Ais

It saddens me to know of your situation. I briefly inspected the thread you ask for me to open, and noticed that there was also good news as to you being accepted as a candidate as a programmer for a financial institution. Much congradulation for your accomplishments. I pray that you will recieve urgent help.

The code you had helped me with earlier this year is not in question on my behalf. What has happened, is that I have disected, and rebuilt the code many times over to help understand and to expand the code. If I may, and if you have the time available, I will point out how the lots are calculated.

//--------Calculating Optimize Lot Size--------------- 
double LotsOptimized()                                            //<          >
  {                                                               //<          > 
   double lot=Lots;                                               //<          > 
//---- select lot size                                            //<          > 
   lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/200.0,1);  //<          > 
                                                                  //<          > 
//---- return lot size                                            //<          > 
   if(lot<0.1) lot=0.1;                                           //<          > 
   return(lot);                                                   //<          > 
  }                                                               //<          > 
//--------- 

This piece of expansion to the original code, 1_29, fit very well in the overall code.

My problem lies within 1.1.1 Strategy 4 in the original code. It is here that I was attempting to develope a strategy when:

1. Opening of the 3rd bar past, Open[3], opens below the Bollinger Band, BarLowPattern.

BarLowPatterns    =                                     //????????????
              ( Close[3] < dBollLow  &&   Close[2] < Open[2]  &&  //????????????
                Close[1] > Open[1]                            ) ; //????????????  

2. Yes, the code does open and close positions, but only Buy entries are allowed.

3. The other problem to this is that the entries do not perform as how I explained them. Entries do not follow conditions stated in 2.1.2. Code: Interface: iSignalOpen.

Sorry but the text is too long and is continued on next post.

// < 2.1.2. Code : Interface : iSignalOpen >                      //<          >
int       iSignalOpen ()     //       - i      17 l       1 o     //<          >
{                                                                 //<          >
if    ( ( iTradeBarTime    == iTime   ( 0 , 0 , 0 ) )             //<          >
     && ( iTradeBarOnce    == 1 ) )     return    ( EMPTY     ) ; //<          > 
//                                                                //<          > 
static    int       iTime_0 = EMPTY                             ; //<          >  
if      (           iTime_0 < iTime   ( 0 , 0 , 0 ) )             //<          > 
        {           iTime_0 = iTime   ( 0 , 0 , 0 )             ; //<          >
          iTradeBarTime     = EMPTY                             ; //<          >
          static    double    dHighest , dLowest                ; //<          >
          dHighest = High   [ iHighest ( 0 , 0    , MODE_HIGH ,   //<          >
                              iBaseLag , iBaseBar           ) ] ; //<          >
          dLowest  = Low    [ iLowest  ( 0 , 0    , MODE_LOW  ,   //<          >
                              iBaseLag , iBaseBar           ) ] ; //<          >
                                                                  //<          >
          static double     dBollLow ,  dBollHigh               ; //<          >
                                                                  //<          >                                                        
          dBollLow    = iBands ( NULL     , 0 , iBollPeriod ,     //????????????
                            iBollDevi , 0 ,     PRICE_WEIGHTED ,  //????????????
                            MODE_LOWER    ,     iBollShift  )   ; //???????????? 
          dBollHigh   = iBands ( NULL     , 0 , iBollPeriod ,     //????????????
                            iBollDevi , 0 ,     PRICE_WEIGHTED ,  //????????????
                            MODE_UPPER   ,      iBollShift  )   ; //???????????? 
                                                                  //???????????? 
          static double BarHighPatterns ,  BarLowPatterns       ; //???????????? 
                                                                  //????????????
if ( Open[3] < dBollLow )                                         //????????????
return (BarHighPatterns);                                        //????????????
                                                                     
else                                                              //????????????

if ( Open[3] > dBollHigh)                                         //????????????
return (BarLowPatterns);                                         //????????????
                                                                    
          BarHighPatterns   =                                     //????????????
              ( Close[3] > dBollHigh  &&  Close[2] > Open[2]  &&  //????????????
                Close[1] > Open[1]                            ) ; //????????????
         BarLowPatterns     =                                     //????????????
              ( Close[3] < dBollLow  &&   Close[2] < Open[2]  &&  //????????????
                Close[1] > Open[1]                            ) ; //????????????    
                                                                  //<          >
        } // if                                                   //<          >
double    dAsk    = MarketInfo        ( Symbol () , MODE_ASK  ) ; //<          >
double    dBid    = MarketInfo        ( Symbol () , MODE_BID  ) ; //<          >
if      ( dAsk    > BarHighPatterns )   return    ( OP_BUY    ) ; //<          >Expanded
if      ( dBid    < BarLowPatterns  )   return    ( OP_SELL   ) ; //<          >Expanded
                                        return    ( EMPTY     ) ; //<          >       
}                                                                 //<          >
                                                                  //<          >
// </2.1.2. Code : Interface : iSignalOpen 
 

Part 2.

4. The other problem is that all objects for entry and closes are red. There are subtle changes that I was attempting to correct the problem, but to no avail.

// < 2.1.5. Code : Interface : iTryOpen >                         //<          >
int       iTryOpen ()        //       - i      15 l       - o     //<          >iTryOpen
{                                                                 //<          >
int       iCommand          = iSignalOpen ()                    ; //<          >iSignalOpen
if      ( iCommand         == EMPTY  )                return    ; //<          >
if      ( iCommand         == OP_BUY )                            //<          >
if      ( iCommand         == OP_SELL)                            //<          >????????????????????
        { string    sType   = "Buy"  ;  int  iColor = Blue    ; } //<          >? From
else    {           sType   = "Sell" ;       iColor = Red     ; } //<          >  Here
//                                                                //<          >   |
if      ( iCommand         == OP_BUY  ) int  iMode  = MODE_ASK  ; //<          >   |
else                                                              //<          >   |
if      ( iCommand         == OP_SELL )      iMode  = MODE_BID  ; //<          >? To Here
double    dPrice  = MarketInfo ( Symbol () , iMode            ) ; //<          >
//                                                                //<          >    
OrderSend  ( Symbol ()       , iCommand    ,  LotsOptimized() ,   //<          >LotsOptimized
             NormalizeDouble ( dPrice , Digits )              ,   //<          >
             iSlippage  , 0  , 0 , "" , MAGIC    ,                //<          >MAGIC
                0  , iColor  ) ;                                  //<          >
//                                                                //<          >
int       iTrap   = GetLastError ()                             ; //<          >
if      ( iTrap  == 0 )                                           //<          >
        { Alert   ( sType , " Was a Big Success"            ) ; } //<          >
else    { Alert   ( sType , " open exception "      , iTrap ) ; } //<          >
}                                                                 //<          >
// </2.1.5. Code : Interface : iTryOpen >                         //<          >

Thank you for reading. But more so for your advice you have given so generously in the past.

If you have the time available to advice me for the new problems I bring, thank you. But I do understand the conditions you are under, and I pray for a quick dissmal of the charges filed against you.

Regards

Huckleberry

 
gordon:
I recommend u stick to a more conventional coding style like in some of your older posts.


Thank you Gordon for reading. And yes, I may be stepping into coding problems that are above my understanding. I have much to learn. And though I am stepping where I might not belong, here I am. And learning as I go.

The original code, 1_29 worked fine. I have used it as a learning tool and I have added and have deleted and was a big plate full. My older posts were or in some way connected to this original code, 1_29. Greatful for the help. I am posting here the problems that have arisen with my deletions and additions to the 1_29 code.. If there is anyone who could take the time to advice, so as to simplify, or as you say, be more conventional, I would appriciate the constructive advice.

Thanks again Gordon

Regards

Huckleberry

 
qjol:

u understand the logic behind parenthesis ?

This is an explanation for iTime

3. We have to know about "iTime ( symbol, timeframe, shift )" function following:
3.1. this function always returns a value of "datetime" type;
3.2. there are 2 different cases of the return:
3.2.1. "0" if local history is empty;
3.2.2. open time for the bar indicated with "shift" in all other cases;
3.3. "iTime ( 0, 0, 0 )" returns open time for the zero bar of the current chart;
3.4. while zero bar is the same, "iTime ( 0, 0, 0 )" returns the same value;
3.5. when current zero bar is completed, this bar became bar number 1 and forming of new zero bar is starting;
3.6. "iTime ( 0, 0, 0 )" returns the new value;
3.7. thus, value of "iTime ( 0, 0, 0 )" is changing when zero bar changed.

4. We prevented work with empty history in program block "2.2.3.1. History data inspection".

5. When order is succesfully closed in "iTryClose" function we assign "iTradeBarTime = iTime ( 0, 0, 0 ) ;".

6. In "iSignalOpen" function we inspect if "iTradeBarTime == iTime ( 0, 0, 0 ) )".

7. If it is true and repeated trade is forbidden by "iTradeBarOnce = 1 ;" then we forbid signal to open by "EMPTY" value.

Yes, this maybe a bit advance, but makes sense.

Regards

Huckleberry

 

What I am saying is that the original 1_29 code worked fine.

I am asking, although I may have inserted the complete code, I am asking to stick to the area that I have tweak. Only because, other than what I have tweaked, there were no problems. I am troubleshooting the tweaked areas. In some way I have hurt the code. Let me demonstrate how I have tweaked and the method on how I have or believe the troubleshooting could progress.

The original 1_29 strategy did not work with indicators. The strategy worked with a bar pattern. Please note:

1.1.1. Strategy 4 >=====================================//<          >
                    int       iBaseLag          = 20            ; //<          >
                    int       iBaseBar          = 1             ; //<     
        static    double    dHighest , dLowest                ; //<          >
          dHighest = High   [ iHighest ( 0 , 0    , MODE_HIGH ,   //<          >
                              iBaseLag , iBaseBar           ) ] ; //<          >
          dLowest  = Low    [ iLowest  ( 0 , 0    , MODE_LOW  ,   //<          >
                              iBaseLag , iBaseBar           ) ] ; //<          >
        } // if                                                   //<          >
double    dAsk    = MarketInfo        ( Symbol () , MODE_ASK  ) ; //<          >
double    dBid    = MarketInfo        ( Symbol () , MODE_BID  ) ; //<          >
if      ( dAsk    > dHighest )          return    ( OP_BUY    ) ; //<          >
if      ( dBid    < dLowest  )          return    ( OP_SELL   ) ; //<          >
                                        return    ( EMPTY     ) ; //<          >

This explains the parameters for the bar patterns.

What I have done to tweak is substitute the dHighest, dLowest, with a iBand indicator, and open[x] and close[x] parameters. It is how I presented them, I hurt the code. Please note:

// <      1.1.1. Strategy 4 >=====================================//<          >
                    #define MAGIC      20101117                   //<          >
                    extern double MaximumRisk   = 0.1           ; //<          >
                    extern double Lots          = 0.1           ; //<          >
                    int       iBaseLag          = 20            ; //<          >
                    int       iBaseBar          = 1             ; //<          >
                    int       iBollPeriod       = 30            ; //<          >Expanded
                    int       iBollDevi         = 2             ; //<          >Expanded
                    int       iBollShift        = 0             ; //<          >Expanded 

The iBaseLag, iBaseBar is still used for the iATR for closing. But is not used for the entry.

The new entry is when the open[3] bar is lower than the lower band of the bollinger band, and that the close[3] bar is above the upper band of the Bollinger band. Please note:

// < 2.1.2. Code : Interface : iSignalOpen >                      //<          >
int       iSignalOpen ()     //       - i      17 l       1 o     //<          >
{                                                                 //<          >
if    ( ( iTradeBarTime    == iTime   ( 0 , 0 , 0 ) )             //<          >
     && ( iTradeBarOnce    == 1 ) )     return    ( EMPTY     ) ; //<          > 
//                                                                //<          > 
static    int       iTime_0 = EMPTY                             ; //<          >  
if      (           iTime_0 < iTime   ( 0 , 0 , 0 ) )             //<          > 
        {           iTime_0 = iTime   ( 0 , 0 , 0 )             ; //<          >
          iTradeBarTime     = EMPTY                             ; //<          >
          static    double    dHighest , dLowest                ; //<          >
          dHighest = High   [ iHighest ( 0 , 0    , MODE_HIGH ,   //<          >
                              iBaseLag , iBaseBar           ) ] ; //<          >
          dLowest  = Low    [ iLowest  ( 0 , 0    , MODE_LOW  ,   //<          >
                              iBaseLag , iBaseBar           ) ] ; //<          >
                                                                  //<          >
          static double     dBollLow ,  dBollHigh               ; //<          >
                                                                  //<          >
          dBollLow    = iBands ( NULL     , 0 , iBollPeriod ,     //????????????
                            iBollDevi , 0 ,     PRICE_WEIGHTED ,  //????????????
                            MODE_LOWER    ,     iBollShift  )   ; //???????????? 
          dBollHigh   = iBands ( NULL     , 0 , iBollPeriod ,     //????????????
                            iBollDevi , 0 ,     PRICE_WEIGHTED ,  //????????????
                            MODE_UPPER   ,      iBollShift  )   ; //???????????? 
                                                                  //???????????? 
          static double BarHighPatterns ,  BarLowPatterns       ; //???????????? 
                                                                  //????????????
if ( Open[3] < dBollLow )                                         //????????????
return (BarHighPatterns);                                        //????????????
                                                                     
else                                                              //????????????

if ( Open[3] > dBollHigh)                                         //????????????
return (BarLowPatterns);                                         //????????????
                                                                    
          BarHighPatterns   =                                     //????????????
              ( Close[3] > dBollHigh  &&  Close[2] > Open[2]  &&  //????????????
                Close[1] > Open[1]                            ) ; //????????????
         BarLowPatterns     =                                     //????????????
              ( Close[3] < dBollLow  &&   Close[2] < Open[2]  &&  //????????????
                Close[1] > Open[1]                            ) ; //????????????    
                                                                  //<          >
        } // if                                                   //<          >
double    dAsk    = MarketInfo        ( Symbol () , MODE_ASK  ) ; //<          >
double    dBid    = MarketInfo        ( Symbol () , MODE_BID  ) ; //<          >
if      ( dAsk    > BarHighPatterns )   return    ( OP_BUY    ) ; //<          >Expanded
if      ( dBid    < BarLowPatterns  )   return    ( OP_SELL   ) ; //<          >Expanded
                                        return    ( EMPTY     ) ; //<          >       
}                                                                 //<          >
                                                                  //<          >
// </2.1.2. Code : Interface : iSignalOpen >                      //<          >

When I did the above compiliation was when the code was hurt. The objects on the chart were all red. All entries became Buys. Besides that, the entries were not as planed. There is now an entry on the following bar, after every close. Could someone point out how to properly insert the new pattern?

Regards

Huckleberry

Reason: