iTime () function is not working with iHigh () and iLow () - page 2

 
Kourosh Emami #: i've removed that iTime() as soon as price passes the position opened... that PositionsTotal () is just preventing opening too many positions

Is this ... what you want?

#include <Trade\Trade.mqh>

input ENUM_TIMEFRAMES   i_eTimeframe   = PERIOD_M15;
input double            i_dbVolume     = 0.1;

CTrade oTrade;

int OnInit() {
   return INIT_SUCCEEDED;
};

void OnTick() {
   static datetime dtBarCurrent  = WRONG_VALUE;
          datetime dtBarPrevious = dtBarCurrent;
                   dtBarCurrent  = iTime( _Symbol, i_eTimeframe, 0 );
          bool     bNewBarEvent  = ( dtBarCurrent != dtBarPrevious );
   static bool     bNewBarTrade  = false;
   static double   dbHigh        = WRONG_VALUE,
                   dbLow         = WRONG_VALUE;
   if( bNewBarEvent ) {
         dbHigh       = iHigh( _Symbol, i_eTimeframe, 1 );
         dbLow        = iLow(  _Symbol, i_eTimeframe, 1 );
         bNewBarTrade = false;
   };
   if( !bNewBarTrade ) {
      double
         dbAsk  = SymbolInfoDouble( _Symbol, SYMBOL_BID ),
         dbBid  = SymbolInfoDouble( _Symbol, SYMBOL_BID );
      if( ( dbBid > dbHigh ) && ( dbHigh > 0.0 ) )
         bNewBarTrade = oTrade.Buy(  i_dbVolume, _Symbol, dbAsk );
      else if( ( dbBid < dbLow ) && ( dbLow > 0.0 ) )
         bNewBarTrade = oTrade.Sell( i_dbVolume, _Symbol, dbBid );
   };
};
 
Fernando Carreiro #:

Here is an example! Try it and let use know!

And please don't use NormaliseDouble on quote prices provided by the terminal. They are already normalised.

NB! Please note, that trades are only placed if the opening bid is above or below the previous candle. If during the lifetime of the current candle the bid price moves above or below the previous candle, no trades are placed. Only at the open of the candle. That is the logic you have presented and that is the logic of the code above.

If something like what i've attached happens with iTime function everything will be fine with my code...but ridiculously it just doesn't let anything happens.. 

Files:
Capture12.PNG  106 kb
 
Kourosh Emami #: If something like what i've attached happens with iTime function everything will be fine with my code...but ridiculously it just doesn't let anything happens.. 

Your logic will not be one trade per candle. It will be one trade as long as none are open.

You are not analysing the problem correctly. Have a look at my code again and consider the logic of it compared to your logic with no "iTime".

And again, please don't use NormaliseDouble on quote prices provided by the terminal. They are already normalised.

 
Fernando Carreiro #:

Your logic will not be one trade per candle. It will be one trade as long as none are open.

You are not analysing the problem correctly. Have a look at my code again and consider the logic of it compared to your logic with no "iTime".

And again, please don't use NormaliseDouble on quote prices provided by the terminal. They are already normalised.

Wow Man actually your last code is working now....gotta analyze your code to see what i was doing wrong...

i really appreciate it man.