how to read today high and today low before certain time?

Back to topics list To post a new topic, please log in or register
avatar
58
kieruwin 2012.06.04 19:24
 
Want to ask a problem, how to read today high and today low before certain time?


ex: today high and low from 0:00 to 13:00, on 13:00 make a decision.

already tried
double todayHigh = iHigh(NULL, PERIOD_D1, 0); but didn't do anything
double todayHigh = iHigh(NULL, PERIOD_H1, 1); open in wrong desire price

i tried with yesterday high low and works like a charm. here is the code

if (TotalOrders()==0){

if (Hour()>=13 && Hour()<13+1) // start hour

{
RefreshRates();
double yesterdayHigh = iHigh(NULL, PERIOD_D1, 1);
double yesterdayLow = iLow(NULL, PERIOD_D1, 1);
ask=MarketInfo(Symbol(),MODE_ASK);
bid=MarketInfo(Symbol(),MODE_BID);
double priceB=NormalizeDouble(ask,Digits);
double priceS=NormalizeDouble(bid,Digits);


//UP
if (NormalizeDouble(priceB,Digits)>=NormalizeDouble(yesterdayHigh,Digits)){
if (StopLoss>0) {SL=NormalizeDouble(NormalizeDouble(priceB+((Gap)+sp)*Point,Digits)-(StopLoss)*Point,Digits);}else{SL=0;}
if (TakeProfit>0) {TP=NormalizeDouble(NormalizeDouble(priceB+((Gap)+sp)*Point,Digits)+(TakeProfit)*Point,Digits);}else{TP=0;}
if (OrderSend(Symbol(),OP_BUY,XFactor*CoA,NormalizeDouble(priceB+((Gap)+sp)*Point,Digits),Slippage,SL,TP,com+"B20",Magic_Number_B+20,0,Blue)==-1) {
i=GetLastError();
if (i!=1 && i!=0) Print("Buy 20 stop Error :"+error(i)+" at "+Symbol()+" "+Period());
}}

//=====================================================================
//Down
if (NormalizeDouble(priceS,Digits)<=NormalizeDouble(yesterdayLow,Digits)){
if (StopLoss>0) {SL=NormalizeDouble(NormalizeDouble(priceS-(Gap)*Point,Digits)+(StopLoss)*Point,Digits);}else{SL=0;}
if (TakeProfit>0) {TP=NormalizeDouble(NormalizeDouble(priceS-(Gap)*Point,Digits)-(TakeProfit)*Point,Digits);}else{TP=0;}
if (OrderSend(Symbol(),OP_SELL,XFactor*CoB,NormalizeDouble(priceS-(Gap)*Point,Digits),Slippage,SL,TP,com+"S20",Magic_Number_S+20,0,Red)==-1) {
i=GetLastError();
if (i!=1 && i!=0) Print("Sell 20 stop Error :"+error(i)+" at "+Symbol()+" "+Period());
}}


// v end order 0, dont delete this

}}

kindly need a help here,

thank you

K.
 
avatar
1001
dabbler 2012.06.04 19:43 #
 
kieruwin:
Want to ask a problem, how to read today high and today low before certain time?


It would help if you posted your code using the SRC button (for source code) to make the code more readable (syntax coloured)
 
avatar
1001
dabbler 2012.06.04 19:49 #
 

Let's get some easy stuff out of the way first ...

There is no need to use ...

ask=MarketInfo(Symbol(),MODE_ASK);
bid=MarketInfo(Symbol(),MODE_BID);

On the current symbol. Just use Ask and Bid.


There is no need to NormalizeDouble when you use the built in Ask or Bid

double priceB=NormalizeDouble(ask,Digits);
double priceS=NormalizeDouble(bid,Digits);

There is no need to NormalizeDouble TWICE for the same variable.

if (StopLoss>0) {SL=NormalizeDouble(NormalizeDouble(priceS-(Gap)*Point,Digits)+(StopLoss)*Point,Digits);}else{SL=0;}
avatar
1001
dabbler 2012.06.04 19:56 #
 
//already tried
double todayHigh = iHigh(NULL, PERIOD_D1, 0); //but didn't do anything

Define "didn't do anything".

That should work at 13:00 when you come to use it. Use it at 0:00 at the start of the day and you won't get very far.

 
avatar
58
kieruwin 2012.06.05 05:11 #
 
dabbler:

Define "didn't do anything".

That should work at 13:00 when you come to use it. Use it at 0:00 at the start of the day and you won't get very far.


thanks for fast response dabbler,

i just learn there is SRC button there, my mistake, and for those normalizedouble my mistake too, thanks for the info.

back to the problem then, the target is read today high and low from 0:00 to 13:00, if i put these in my code, somewhat it didn't make a trade, even the price for example above the today high should be making Buy here.

double todayHigh = iHigh(NULL, PERIOD_D1, 0);

my code bellow is for start making decision past 13:00 when the market is above high or bellow low. if i change it to 0:00 isn't the decision start at 0:00 not 13:00 anymore?

where is the wrong code ?

if (TotalOrders()==0){
   
   if (Hour()>=13 && Hour()<13+1) // start hour
 
avatar
1001
dabbler 2012.06.05 09:17 #
 
kieruwin:

back to the problem then, the target is read today high and low from 0:00 to 13:00, if i put these in my code, somewhat it didn't make a trade, even the price for example above the today high should be making Buy here.

my code bellow is for start making decision past 13:00 when the market is above high or bellow low. if i change it to 0:00 isn't the decision start at 0:00 not 13:00 anymore?

where is the wrong code ?

I suspect you just need a bit more code, in the right place. Try something like this ...

double todayHigh= -1.0;
double todayLow=  -1.0;

int start(){

   if( Hour()<13 ){
      todayHigh= -1.0;
      todayLow=  -1.0;
   }
   
   if( Hour()>= 13 ){
      if( todayHigh< 0.0 ){
         todayHigh = iHigh(NULL, PERIOD_D1, 0);
         todayLow =  iLow (NULL, PERIOD_D1, 0);
         Print("Today's High is " + DoubleToStr(todayHigh,Digits) );
         Print("Today's Low  is " + DoubleToStr(todayLow, Digits) );
      }
   }

}


 
avatar
14167
RaptorUK 2012.06.05 09:58 #
 
kieruwin:

back to the problem then, the target is read today high and low from 0:00 to 13:00, if i put these in my code, somewhat it didn't make a trade, even the price for example above the today high should be making Buy here.

my code bellow is for start making decision past 13:00 when the market is above high or bellow low. if i change it to 0:00 isn't the decision start at 0:00 not 13:00 anymore?

where is the wrong code ?

It's very simple once you have analysed your problem and realised what information you need to be able to design a solution. There are two functions, iHighest and iLowest that will help you, they return the bar with the highest value and lowest value within a rang of bars . . . then using these bar numbers you can use High or iHigh and Low or iLow to get the actual High and Low values . . . so where is the tricky part ? Well, you need to determine the bar numbers for your time range, 0:00 to 13:00 . . . but that isn't really hard either, just use iBarShift with the time and it returns a bar number. So what is the problem ? you need to use a datetime with iBarShift, so you need the datetime of midnight . . . and eventually we end up at the point of my post: datetime for midnight

You will need some additional logical checks, you can't use this on a Sunday evening, you can't use it before 13:00/14:00*, etc, etc

* Did you mean 0:00 to 12:59 or 0:00 to 13:59 ?

 
avatar
58
kieruwin 2012.06.05 12:56 #
 
dabbler:

I suspect you just need a bit more code, in the right place. Try something like this ...



i will try it dabbler,

thanks a lot

avatar
58
kieruwin 2012.06.05 12:59 #
 
RaptorUK:

It's very simple once you have analysed your problem and realised what information you need to be able to design a solution. There are two functions, iHighest and iLowest that will help you, they return the bar with the highest value and lowest value within a rang of bars . . . then using these bar numbers you can use High or iHigh and Low or iLow to get the actual High and Low values . . . so where is the tricky part ? Well, you need to determine the bar numbers for your time range, 0:00 to 13:00 . . . but that isn't really hard either, just use iBarShift with the time and it returns a bar number. So what is the problem ? you need to use a datetime with iBarShift, so you need the datetime of midnight . . . and eventually we end up at the point of my post: datetime for midnight

You will need some additional logical checks, you can't use this on a Sunday evening, you can't use it before 13:00/14:00*, etc, etc

* Did you mean 0:00 to 12:59 or 0:00 to 13:59 ?


before my code base was all by range, never use bars. he he he now i need it.


thank you too RaptorUK, i will learn more.

 
avatar
1
KMTz 2016.03.09 16:20 #
 

Sorry for dig this up but i can't finish it


my code still return  the wrong high - low even i use  iHighest(Symbol(),PERIOD_H1,MODE_HIGH,6,0)

..

..

input int PlaceOrderHour = 6;
input int PlaceOrderMin = 0;
input int PlaceOrderSec = 5;


double IHIGH = iHigh(Symbol(),PERIOD_D1,0),
       ILOW = iLow(Symbol(),PERIOD_D1,0),
       Spread = MarketInfo(Symbol(),MODE_SPREAD),
       orderB,orderS;


void OnTick()
  {
//---
Comment (TimeCurrent());

   if(OrdersTotal()<=0) //- Check for existing Order First 

   if(Hour() == PlaceOrderHour && Minute() == PlaceOrderMin && Seconds() < PlaceOrderSec )
     { 
     orderB = OrderSend(Symbol(),OP_BUYSTOP,1,IHIGH + Spread*Point,50,IHIGH-((100-Spread)*Point),IHIGH +((100+Spread)*Point),"BO100P UJ",201,TimeCurrent()+50000,clrNONE);
     Alert (Symbol()," Open BUY STOP Order  // Error =   ",GetLastError()); 
     
                                      
     orderS = OrderSend(Symbol(),OP_SELLSTOP,1,ILOW ,50,ILOW+ 100*Point,ILOW -100*Point,"BO100P",201,TimeCurrent()+50000,clrNONE);
     Alert (Symbol()," Open SELL STOP Order // Error =   ",GetLastError());       
     }  
  }


thanks for your help in advance.

Back to topics list  

To add comments, please log in or register